Doc: group obsolete NMEA sentences
[marnav.git] / bin / bld
blobd6a18deb7651c27a965619a38c5a4b2ae9610f5b
1 #!/bin/bash -eu
3 export SCRIPT_BASE=$(dirname `readlink -f $0`)
4 export BASE=${SCRIPT_BASE}/..
5 export CONFIG_BASE=${SCRIPT_BASE}/buildconf.d
7 # takes default value if provided by the environment
8 export BUILD_DIR=${BUILD_DIR:-${BASE}/build}
10 # ask system about number of processors, accept already specified number
11 export NUM_PROC=${NUM_PROC:-$(cat /proc/cpuinfo | grep -E "^processor" | wc -l)}
13 function valid_target()
15 for t in ${CONFIG_BASE}/* ; do
16 if [ "x$1" == "x$(basename $t)" ] ; then
17 echo "found"
18 return
20 done
21 echo "notfound"
24 # read command line arguments
26 args=$(getopt \
27 --options "hl" \
28 --longopt "help" \
29 --longopt "list" \
30 --longopt "prepare" \
31 --longopt "build" \
32 -- "$@")
33 if [ $? != 0 ] ; then
34 echo "error: parameters. aborting." >&2
35 exit 1
38 eval set -- "${args}"
40 # handle arguments
42 target=""
43 only_prepare="no"
44 only_build="no"
45 while [ $# -ne 0 ] ; do
46 case "$1" in
47 --help|-h)
48 echo ""
49 echo "usage: $(basename $0) [option] [target]"
50 echo ""
51 echo "options:"
52 echo " --help|-h : print help information"
53 echo " --list|-l : list all targets"
54 echo " --prepare : prepares the build, does not build"
55 echo " --build : prepares and builds, does not perform tests"
56 echo ""
57 exit 0
59 --list|-l)
60 for t in ${CONFIG_BASE}/* ; do
61 echo $(basename $t)
62 done
63 exit 0
65 --prepare)
66 only_prepare="yes"
68 --build)
69 only_build="yes"
72 if [ $# -gt 1 ] ; then
73 target="$2"
76 esac
77 shift
78 done
80 # check specified target
82 if [ -z "$target" ] ; then
83 echo "error: no target specified. aborting." >&2
84 exit 1
87 if [ $(valid_target "$target") != "found" ] ; then
88 echo "error: invalid target specified: $target. aborting." >&2
89 exit 1
92 # check for tools
93 if [ -z "$(which cmake)" ] ; then
94 echo "error: no cmake found. aborting."
95 exit 1
97 if [ -z "$(which make)" ] ; then
98 echo "error: no make found. aborting."
99 exit 1
102 # prepare
103 if [ -d ${BUILD_DIR} ] ; then
104 rm -fr ${BUILD_DIR}
106 mkdir -p ${BUILD_DIR}
107 cd ${BUILD_DIR}
108 cmake -G "Unix Makefiles" \
109 -DCMAKE_INSTALL_PREFIX=${BUILD_DIR}/local \
110 $(cat ${CONFIG_BASE}/${target}) \
111 -DCMAKE_EXPORT_COMPILE_COMMANDS=YES \
112 ${BASE}
114 # only prepare, do not build or test
115 if [ "$only_prepare" == "yes" ] ; then exit 0 ; fi
117 # build
118 cmake --build . -- -j ${NUM_PROC}
120 # only build, do not test
121 if [ "$only_build" == "yes" ] ; then exit 0 ; fi
123 # perform tests if not disabled
124 if [[ $(cat "${CONFIG_BASE}/${target}" | grep -E "ENABLE_TESTS=OFF") ]] ; then
125 echo "tests disabled"
126 else
127 cmake --build . --target unittest
128 cmake --build . --target test