-
Notifications
You must be signed in to change notification settings - Fork 138
/
RunExamplesLinux.sh
executable file
·76 lines (68 loc) · 2.17 KB
/
RunExamplesLinux.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/bin/bash
DEFAULT_BUILD_DIRS=("build_linux/build" "build_linux/build/Debug" "bin/Linux-x86_64/build")
BUILD_DIR="${DEFAULT_BUILD_DIRS[0]}"
if [ "$#" -ge 1 ]; then
if [ "$1" != "--" ]; then
HELLO_EXAMPLE="Example_HelloTriangle"
BUILD_DIR=$1
if [[ "$BUILD_DIR" == */ ]]; then
BUILD_DIR="${BUILD_DIR::-1}" # Remove trailing '/' character from path
fi
if [ -f "$BUILD_DIR/build/$HELLO_EXAMPLE" ] || [ -f "$BUILD_DIR/build/${HELLO_EXAMPLE}D" ]; then
BUILD_DIR="$BUILD_DIR/build"
fi
fi
shift
else
for DIR in "${DEFAULT_BUILD_DIRS[@]}"; do
if [ -d "$DIR" ]; then
if [ -f "$DIR/libLLGL.so" ] || [ -f "$DIR/libLLGLD.so" ] || [ -f "$DIR/libLLGL.a" ] || [ -f "$DIR/libLLGLD.a" ]; then
BUILD_DIR="$DIR"
break
fi
fi
done
fi
# Validate build folder: Check for libLLGL.so/.a or libLLGLD.so/.a files
if [ -d "$BUILD_DIR" ]; then
if [ -f "$BUILD_DIR/libLLGL.so" ] || [ -f "$BUILD_DIR/libLLGLD.so" ] || [ -f "$BUILD_DIR/libLLGL.a" ] || [ -f "$BUILD_DIR/libLLGLD.a" ]; then
echo "Run examples from build directory: $BUILD_DIR"
else
echo "Error: Missing LLGL base lib (libLLGL.so/.a or libLLGLD.so/.a) in build folder: $BUILD_DIR"
exit 1
fi
else
echo "Error: Build folder not found: $BUILD_DIR"
exit 1
fi
list_examples()
{
EXCLUDED=(MultiRenderer MultiThreading PBR ComputeShader)
EXAMPLE_DIRS=($(ls examples/Cpp))
for DIR in "${EXAMPLE_DIRS[@]}"; do
if ! echo "${EXCLUDED[@]}}" | grep -qw "$DIR"; then
# Include example if its source and binary files exist
if [ -f "examples/Cpp/$DIR/Example.cpp" ] && [ -f "$BUILD_DIR/Example_$DIR" -o -f "$BUILD_DIR/Example_${DIR}D" ]; then
echo "$DIR"
fi
fi
done
}
run_example()
(
EXAMPLE=$1
shift
EXE="../../../$BUILD_DIR/Example_$EXAMPLE"
EXE_D="${EXE}D"
cd examples/Cpp/$EXAMPLE
if [ -f "$EXE_D" ]; then
eval $EXE_D $@
else
eval $EXE $@
fi
)
EXAMPLES=($(list_examples))
PS3="Select example: "
select OPT in "${EXAMPLES[@]}"; do
run_example $OPT $@
done