forked from skepner/ae
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmk
More file actions
executable file
·174 lines (150 loc) · 3.88 KB
/
Copy pathmk
File metadata and controls
executable file
·174 lines (150 loc) · 3.88 KB
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#! /bin/bash
BUILD_DEFAULT_DIR=build
BUILD_DEBUG_DIR=build #.debug
BUILD_DIR="${BUILD_DEFAULT_DIR}"
SETUP_ARGS=-Doptimization=3
BUILT=NO
# ----------------------------------------------------------------------
build()
{
trap 'fail "build failed"' ERR
if [[ ! -d "${BUILD_DIR}" || ! -f "${BUILD_DIR}/meson-private/coredata.dat" ]]; then
rm -rf "${BUILD_DIR}"
find_compiler
meson setup "${BUILD_DIR}" -Ddebug=true ${SETUP_ARGS}
# --buildtype debugoptimized
# -Dcpp_args=-O3
else
find_mk_time
fi
${MK_TIME} meson compile -C "${BUILD_DIR}" ${MESON_FLAGS}
BUILT=YES
}
# ----------------------------------------------------------------------
build_default()
{
build
}
# ----------------------------------------------------------------------
build_debug_asan()
{
# run python using ~/bin/python-address-sanitizer
BUILD_DIR="${BUILD_DEBUG_DIR}"
SETUP_ARGS="-Doptimization=g -Db_sanitize=address"
if [[ $(uname) == "Darwin" ]]; then
# -Db_lundef=false see: https://github.com/mesonbuild/meson/issues/764
SETUP_ARGS="${SETUP_ARGS} -Db_lundef=false"
# export LDFLAGS=-shared-libasan
export PATH="/opt/homebrew/opt/llvm/bin:${PATH}"
fi
export CPPFLAGS=-fno-omit-frame-pointer
build
}
# ----------------------------------------------------------------------
build_debug()
{
# run python using ~/bin/python-address-sanitizer
BUILD_DIR="${BUILD_DEBUG_DIR}"
SETUP_ARGS="-Doptimization=0"
export CPPFLAGS=-fno-omit-frame-pointer
build
}
# ----------------------------------------------------------------------
run_test()
{
meson test -C "${BUILD_DIR}" --print-errorlogs
}
# ----------------------------------------------------------------------
find_compiler()
{
case $(uname) in
Darwin)
if [[ -x /usr/local/opt/llvm/bin/clang++ ]]; then
export CXX=/usr/local/opt/llvm/bin/clang++
elif [[ -x /opt/homebrew/opt/llvm/bin/clang++ ]]; then
export CXX=/opt/homebrew/opt/llvm/bin/clang++
else
echo "> clang++ not found" >&/dev/null
exit 1
fi
MK_TIME=gtime
;;
Linux)
export CXX=$(which g++-11)
MK_TIME=time
;;
*)
fail "Unsupported platform: $(name)"
esac
if [[ ! -x "${CXX}" ]]; then
fail "Compiler not found: ${CXX}"
fi
}
# ----------------------------------------------------------------------
find_mk_time()
{
case $(uname) in
Darwin)
MK_TIME=gtime
;;
Linux)
MK_TIME=time
;;
*)
fail "Unsupported platform: $(name)"
esac
}
# ----------------------------------------------------------------------
clean()
{
remove "${BUILD_DEFAULT_DIR}" "${BUILD_DEBUG_DIR}"
}
cleanclean()
{
clean
for fn in $(cat subprojects/.gitignore); do
remove subprojects/${fn}
done
}
# ----------------------------------------------------------------------
remove()
{
echo "rm -rf $@"
rm -rf "$@"
}
# ----------------------------------------------------------------------
fail()
{
echo "> ERROR: $@" >&2
exit 1
}
# ----------------------------------------------------------------------
trap 'fail "build failed"' ERR
cd "$(dirname $0)"
for arg in "$@"; do
case "${arg}" in
clean)
clean
;;
cleanclean)
cleanclean
;;
debug)
build_debug
;;
debug_no_asan|debug-no-asan)
build_debug_no_asan
;;
test)
run_test
;;
-h)
fail "Usage: $0 [-h] [clean] [debug] [debug-no-asan] [test]"
;;
*)
fail "Unknown arg: ${arg}"
esac
done
if [ $# == 0 ]; then
build_default
fi