-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.bash
executable file
·133 lines (105 loc) · 2.82 KB
/
build.bash
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/bin/bash
# mariebuild build script.
# Use this only if you have no version of mariebuild which can build itself.
SRCDIR="src/"
BUILD_ROOT="build/"
DEBUG_DIR="$BUILD_ROOT""debug/"
RELEASE_DIR="$BUILD_ROOT""release/"
OBJ_DIR="obj/"
CC="clang"
BASE_CFLAGS="-std=c17 -pedantic-errors -Wall -Wextra -Werror -Wno-gnu-statement-expression -Iinclude/ -Isrc/"
DEBUG_CFLAGS="-ggdb -DDEFAULT_LOG_LEVEL=LOG_DEBUG"
RELEASE_CFLAGS="-Oz"
LDFLAGS="-lm -Llib/ -lmcfg_2"
BIN_NAME="mb"
function build_objs() {
COMPILED_OBJECTS=()
unameOut="$(uname -s)"
case "${unameOut}" in
Darwin*)
if [ -d /opt/homebrew/include/ ]; then
EXTRA_CFLAGS="-I/opt/homebrew/include"
else
EXTRA_CFLAGS="-I/usr/local/include"
fi
esac
for i in $1
do
OUTNAME="$OBJ$i.o"
INNAME="$SRCDIR$i.c"
if ! [ -d $(dirname "$OUTNAME") ]; then
echo " MKDIR -p $(dirname $OUTNAME)"
mkdir -p "$(dirname $OUTNAME)"
fi
echo " CC $INNAME"
$CC $CFLAGS $EXTRA_CFLAGS -c -o $OUTNAME $INNAME || exit
COMPILED_OBJECTS+=("${OUTNAME}")
done
}
function build() {
OBJECTS=("stringutil cptrlist signals logging types executor c_rule target build main")
echo "==> Compiling Sources for \"$BIN_DEST\""
build_objs "${OBJECTS[@]}"
unameOut="$(uname -s)"
case "${unameOut}" in
Darwin*) LDFLAGS="$LDFLAGS -L/usr/local/lib -largp";;
esac
unameOut="$(uname -s)"
case "${unameOut}" in
Darwin*)
if [ -d /opt/homebrew/lib/ ]; then
EXTRA_LDFLAGS="-L/opt/homebrew/lib -largp"
else
EXTRA_LDFLAGS="-L/usr/local/lib -largp"
fi
printf " -> Linking for Darwin, EXTRA_LDFLAGS=$EXTRA_LDFLAGS\\n";;
esac
echo "==> Linking \"$BIN_DEST\""
echo " LD -o $BIN_DEST ${COMPILED_OBJECTS[@]} $LDFLAGS $EXTRA_LDFLAGS"
$CC $CFLAGS -o $BIN_DEST ${COMPILED_OBJECTS[@]} $LDFLAGS $EXTRA_LDFLAGS
if [ $RELEASE ]; then
echo " STRIP $BIN_DEST"
STRIPFLAGS="--strip-all"
unameOut="\$(uname -s)"
case "${unameOut}" in
Darwin*) STRIPFLAGS="-S -X";;
esac
strip $STRIPFLAGS $BIN_DEST
fi
}
function setup() {
if [ ! -f "lib/libmcfg_2.a" ]; then
echo "==> libmcfg_2 is missing, running setup.bash"
# set IFS to an emtpy string so that leading spaces are kept around
SAVE_IFS=$IFS
IFS=''
(
bash setup.bash 2>&1 |
while read -r line; do
echo "setup.bash: $line";
done
) || exit
IFS=$SAVE_IFS
echo "==> successfully built libmcfg_2"
fi
}
echo "MB build script. "
if [ "$1" = "--release" ]; then
echo "==> Building in release mode"
CFLAGS="$BASE_CFLAGS $RELEASE_CFLAGS"
OBJ="$RELEASE_DIR""$OBJ_DIR"
BIN_DEST="$RELEASE_DIR""$BIN_NAME"
RELEASE=1
else
CFLAGS="$BASE_CFLAGS $DEBUG_CFLAGS"
OBJ="$DEBUG_DIR""$OBJ_DIR"
BIN_DEST="$DEBUG_DIR""$BIN_NAME"
fi
if [ "$1" = "--compile-flags" ]; then
sed --posix 's/ /\n/g' <<<"${CFLAGS[@]}" > compile_flags.txt
echo "==> Generated compile_flags.txt"
exit
fi
setup
build
echo "==> Finished build!"