-
-
Notifications
You must be signed in to change notification settings - Fork 61
/
Copy pathbuild.sh
executable file
·77 lines (64 loc) · 1.23 KB
/
build.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
77
#!/bin/bash
PROGNAME=${0##*/}
CURDIR="$( cd "$(dirname "$0")" ; pwd -P )"
BUILD_TYPE="Release"
BUILD_DIR="build"
if which nproc; then
# Linux
CORES="$(nproc --all)"
elif which sysctl; then
# MacOS
CORES="$(sysctl -n hw.logicalcpu)"
else
CORES=2
fi
JOBS=$(( CORES / 2 ))
usage() {
cat <<EOF
Usage: $PROGNAME [options]
Options:
-h, --help Display this help and exit
-c, --clean Clean build
-d, --debug Build with debug mode
-j, --jobs Use N cores to build
EOF
}
clean() {
rm -rf "$BUILD_DIR"
}
while (( "$#" )); do
case "$1" in
-h|--help)
usage
exit 0
;;
-j|--jobs)
JOBS="$2"
shift 2
;;
-d|--debug)
BUILD_TYPE="Debug"
shift
;;
-c|--clean)
clean
shift
;;
-*|--*=)
echo "Invalid arguments"
exit 1
;;
*)
break
;;
esac
done
BUILD_OPTIONS="-DCMAKE_BUILD_TYPE=${BUILD_TYPE}"
mkdir -p "${BUILD_DIR}"
cd "${BUILD_DIR}"
if cmake .. ${BUILD_OPTIONS}; then
make -j "${JOBS}" && cd "$CURDIR"
else
cd "$CURDIR"
exit 1
fi