-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·109 lines (87 loc) · 2.15 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/bin/bash -e
BASE=$(dirname $(realpath "$0"))
NAME=$(basename "$0")
cd "$BASE"
usage() {
echo "
Usage:
$NAME [options]
Build libinote and tests.
Options:
-c, --clean clean-up: delete the build directory and object files
-d, --debug compile with debug symbols
-g, --gdb with gdb
-h, --help display this help
-m, --mach <arch> target architecture
possible value: i686; by default: current arch
-i, --install install dir
-t, --test run tests
Example:
# compile libinote
$0
# compile libinote with debug symbols
$0 -d
# compile libinote, run tests
$0 -t
# compile libinote, run tests via gdb
$0 -dgt
"
}
getVersion() {
local value
local i
for i in INOTE_VERSION_MAJOR INOTE_VERSION_MINOR INOTE_VERSION_PATCH; do
value=$(awk "/$i/{print \$3}" $BASE/src/conf.h)
eval export $i=$value
done
export VERSION=$INOTE_VERSION_MAJOR.$INOTE_VERSION_MINOR.$INOTE_VERSION_PATCH
}
cleanup() {
(cd src/libinote && make clean)
(cd src/test && make clean)
}
unset CC CFLAGS CLEAN DBG_FLAGS GDB HELP INSTALL ARCH STRIP TEST
OPTIONS=`getopt -o cdghi:m:t --long clean,debug,gdb,help,install:,mach:,test \
-n "$NAME" -- "$@"`
[ $? != 0 ] && usage && exit 1
eval set -- "$OPTIONS"
while true; do
case "$1" in
-c|--clean) CLEAN=1; shift;;
-d|--debug) export DBG_FLAGS="-ggdb -DDEBUG"; export STRIP=test; shift;;
-g|--gdb) GDB="-g"; shift;;
-h|--help) HELP=1; shift;;
-i|--install) INSTALL=$2; shift 2;;
-m|--mach) ARCH=$2; shift 2;;
-t|--test) TEST=1; shift;;
--) shift; break;;
*) break;;
esac
done
case "$ARCH" in
x86|i386|i586|i686) ARCH=i686;;
*)
ARCH=$(uname -m);;
esac
[ -n "$HELP" ] && usage && exit 0
cd "$BASE"
SRCDIR="$BASE/src"
[ -z "$INSTALL" ] && INSTALL="$BASE/build/$ARCH/usr"
export DESTDIR="$INSTALL"
cleanup
[ -n "$CLEAN" ] && exit 0
CFLAGS="$DBG_FLAGS"
unset LDFLAGS
if [ "$ARCH" = "i686" ]; then
CFLAGS="$CFLAGS -m32 -I/usr/i686-linux-gnu/include"
LDFLAGS="-m32"
fi
export CFLAGS=$CFLAGS
export LDFLAGS=$LDFLAGS
for i in src/libinote src/test; do
( cd $i; make clean; make all; make install )
done
if [ -n "$TEST" ]; then
cd src/test
./inote.sh $GDB
fi