-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·89 lines (77 loc) · 2.1 KB
/
Copy pathbuild.sh
File metadata and controls
executable file
·89 lines (77 loc) · 2.1 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
#! /bin/bash
Help()
{
# Display Help
echo "Build script for ease of use."
echo
echo "Syntax: ./build.sh [-f|-t|-j|-m|-c|-h]"
echo "Example ./build.sh -t <executable-target-name> -j <number-of-threads>"
echo "Options:"
echo "-f Path to the Makefile."
echo "-t Target to be built. Default to all."
echo "-j Number of cores to be used during building."
echo "-m Mode of build. 'Release' or 'Debug'."
echo "-c Clear build. Specify which build to clear: 'Release' or 'Debug' or both."
echo "-h Prints this help."
}
# Default values
MAKEFILE="./Makefile"
TARGETNAMES="all" # All targets in Makefile
NBTHREADS=""
BUILD_MODE="Debug"
# Get the options
while getopts ":f:t:j:m:c:h" option; do
case $option in
f)
MAKEFILE=$OPTARG;;
t)
TARGETNAMES=$OPTARG;;
j)
NBTHREADS=$OPTARG;;
m)
BUILD_MODE=$OPTARG;;
c)
CLEAR=$OPTARG;;
h)
Help
exit;;
\?)
echo "Error: Invalid option"
exit;;
esac
done
if [[ $CLEAR != Release ]] && [[ $CLEAR != Debug ]] && [[ $CLEAR != All ]]; then
echo "Invalid option for -c flag. Either 'Release', 'Debug' or 'All'".
elif [[ $CLEAR == All ]]; then
echo "Clearing all builds."
rm -rf build
rm -rf out
else
echo "Clearing $CLEAR build."
rm -rf build/$CLEAR
rm -rf out/bin/$CLEAR
rm -rf out/lib/$CLEAR
fi
if [[ $BUILD_MODE != Debug ]] && [[ $BUILD_MODE != Release ]]; then
echo "'$BUILD_MODE' is an invalid value of build mode option. Valid options are 'Release' and 'Debug'."
exit
fi
if [[ ! -d "build/$BUILD_MODE" ]]; then
mkdir -p build/$BUILD_MODE;
fi
if [[ ! -d "out" ]]; then
mkdir out
if [[ ! -d "out/bin" ]]; then
mkdir -p "out/bin"
elif [[ ! -d "out/lib" ]]; then
mkdir -p "out/lib"
fi
if [[ ! -d "out/bin/$BUILD_MODE" ]]; then
mkdir -p "out/bin/$BUILD_MODE"
elif [[ ! -d "out/lib/$BUILD_MODE" ]]; then
mkdir -p "out/lib/$BUILD_MODE"
fi
fi
cd "build/$BUILD_MODE"
cmake -D CMAKE_BUILD_TYPE=$BUILD_MODE ../..
make -f $MAKEFILE -j $NBTHREADS $TARGETNAMES