-
Notifications
You must be signed in to change notification settings - Fork 0
/
make.sh
executable file
·82 lines (73 loc) · 1.66 KB
/
make.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
78
79
80
81
82
#! /bin/bash
function showHelp
{
msg=$1
if test "${msg}" != ""; then
echo "make.sh: ${msg}"
fi
echo "make.sh -- Make script for this project"
echo "USAGE: make.sh [option]"
echo
echo "Options:"
echo " -h | --help -- Show help"
echo " -d | --debug -- Build debug version"
echo " -c | --cmake -- Force a cmake run"
echo " -f | --format -- Format the source code"
}
MAKESH=$(realpath $0)
SANDBOX=$(dirname $MAKESH)
BUILD_TYPE=Release
FORCECMAKE=false
FORMATSOURCE=false
# Parse command line
while [[ $# -gt 0 ]]; do
opt="$1"
case $opt in
-h|--help)
showHelp
exit 1
;;
-d|--debug)
BUILD_TYPE=Debug
;;
-c|--cmake)
FORCECMAKE=true
;;
-f|--format)
FORMATSOURCE=true
;;
-*)
showHelp "Unknown option ${opt}"
break
;;
*)
break
;;
esac
shift # past argument or value
done
# Setup variables
BUILD_DIR="${SANDBOX}/build/${BUILD_TYPE}"
INSTALL_DIR="${SANDBOX}/install"
CPUS=$(cat /proc/cpuinfo | grep '^processor' | wc -l)
JOBS=${JOBS:-${CPUS}}
# format the source
if test "${FORMATSOURCE}" == true; then
cd ${SANDBOX}
uncrustify -c uncrustify.cfg --replace $(find forth test apps -name '*.cpp' -o -name '*.hpp')
exit 0
fi
if test "${FORCECMAKE}" == true; then
rm -f "${BUILD_DIR}/CMakeCache.txt" "${BUILD_DIR}/Makefile"
fi
# Try to run cmake
if [ \! -f "${BUILD_DIR}/Makefile" ] ; then
(
mkdir -p ${BUILD_DIR}
cd ${BUILD_DIR}
cmake -G Ninja -DCMAKE_BUILD_TYPE=${BUILD_TYPE} -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR} ${SANDBOX}
)
fi
cd ${BUILD_DIR}
export CTEST_OUTPUT_ON_FAILURE=1
ninja -j ${JOBS} install && ninja test