2020-05-04 09:19:14 +08:00
|
|
|
#!/bin/bash
|
2018-07-17 09:18:04 +08:00
|
|
|
|
2020-05-04 09:19:14 +08:00
|
|
|
CPPFLAGS="-DMIN_LOGGER_LEVEL=LOGGER_LEVEL_TRACE"
|
|
|
|
CPPFLAGS+=("-isystem" "/usr/include/opus")
|
|
|
|
CPPFLAGS+=("-Iauto_tests")
|
|
|
|
CPPFLAGS+=("-Iother")
|
|
|
|
CPPFLAGS+=("-Iother/bootstrap_daemon/src")
|
|
|
|
CPPFLAGS+=("-Iother/fun")
|
|
|
|
CPPFLAGS+=("-Itesting")
|
|
|
|
CPPFLAGS+=("-Itesting/groupchats")
|
|
|
|
CPPFLAGS+=("-Itoxcore")
|
|
|
|
CPPFLAGS+=("-Itoxav")
|
|
|
|
CPPFLAGS+=("-Itoxencryptsave")
|
2018-07-17 09:18:04 +08:00
|
|
|
|
2021-12-15 05:18:41 +08:00
|
|
|
LDFLAGS=("-lopus" "-lsodium" "-lvpx" "-lpthread" "-lconfig" "-lgtest")
|
2020-05-04 09:19:14 +08:00
|
|
|
LDFLAGS+=("-fuse-ld=gold")
|
|
|
|
LDFLAGS+=("-Wl,--detect-odr-violations")
|
|
|
|
LDFLAGS+=("-Wl,--warn-common")
|
|
|
|
LDFLAGS+=("-Wl,--warn-execstack")
|
|
|
|
LDFLAGS+=("-Wl,-z,noexecstack")
|
|
|
|
LDFLAGS+=("-Wl,-z,now")
|
2018-02-23 10:22:38 +08:00
|
|
|
|
|
|
|
put() {
|
|
|
|
if [ "$SKIP_LINES" = "" ]; then
|
2020-05-04 09:19:14 +08:00
|
|
|
echo "#line 1 \"$1\"" >>amalgamation.cc
|
2018-07-17 09:18:04 +08:00
|
|
|
fi
|
2020-05-04 09:19:14 +08:00
|
|
|
cat "$1" >>amalgamation.cc
|
2018-07-17 09:18:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
putmain() {
|
2020-05-04 09:19:14 +08:00
|
|
|
echo "namespace ${1//[^a-zA-Z0-9_]/_} {" >>amalgamation.cc
|
2018-07-17 09:18:04 +08:00
|
|
|
if [ "$SKIP_LINES" = "" ]; then
|
2020-05-04 09:19:14 +08:00
|
|
|
echo "#line 1 \"$1\"" >>amalgamation.cc
|
2018-02-23 10:22:38 +08:00
|
|
|
fi
|
2020-05-04 09:19:14 +08:00
|
|
|
sed -e 's/^int main(/static &/' "$1" >>amalgamation.cc
|
|
|
|
echo "} // namespace ${1//[^a-zA-Z0-9_]/_}" >>amalgamation.cc
|
2018-07-17 09:18:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
callmain() {
|
2020-05-04 09:19:14 +08:00
|
|
|
echo " call(${1//[^a-zA-Z0-9_]/_}::main, argc, argv);" >>amalgamation.cc
|
2018-02-23 10:22:38 +08:00
|
|
|
}
|
|
|
|
|
2020-05-04 09:19:14 +08:00
|
|
|
: >amalgamation.cc
|
2018-07-17 09:18:04 +08:00
|
|
|
|
|
|
|
put auto_tests/check_compat.h
|
|
|
|
|
2021-12-15 05:18:41 +08:00
|
|
|
FIND_QUERY="find . '-(' -name '*.c' -or -name '*.cc' '-)'"
|
2018-08-12 19:35:01 +08:00
|
|
|
FIND_QUERY="$FIND_QUERY -and -not -wholename './_build/*'"
|
2018-07-17 09:18:04 +08:00
|
|
|
FIND_QUERY="$FIND_QUERY -and -not -wholename './super_donators/*'"
|
2021-12-15 03:33:18 +08:00
|
|
|
FIND_QUERY="$FIND_QUERY -and -not -name amalgamation.cc"
|
2018-07-17 09:18:04 +08:00
|
|
|
FIND_QUERY="$FIND_QUERY -and -not -name av_test.c"
|
|
|
|
FIND_QUERY="$FIND_QUERY -and -not -name dht_test.c"
|
2021-12-15 05:18:41 +08:00
|
|
|
FIND_QUERY="$FIND_QUERY -and -not -name trace.cc"
|
2018-07-17 09:18:04 +08:00
|
|
|
FIND_QUERY="$FIND_QUERY -and -not -name version_test.c"
|
|
|
|
|
2020-05-04 09:19:14 +08:00
|
|
|
readarray -t FILES <<<"$(eval "$FIND_QUERY")"
|
2020-05-02 07:34:13 +08:00
|
|
|
|
2020-05-04 09:19:14 +08:00
|
|
|
(for i in "${FILES[@]}"; do
|
|
|
|
grep -o '#include <[^>]*>' "$i" |
|
2021-12-07 02:41:27 +08:00
|
|
|
grep -E -v '<win|<ws|<iphlp|<libc|<mach/|<crypto_|<randombytes|<u.h>|<sys/filio|<stropts.h>|<linux'
|
2020-05-04 09:19:14 +08:00
|
|
|
done) | sort -u >>amalgamation.cc
|
|
|
|
|
|
|
|
echo 'namespace {' >>amalgamation.cc
|
|
|
|
for i in "${FILES[@]}"; do
|
2020-05-02 07:34:13 +08:00
|
|
|
if ! grep -q '^int main(' "$i"; then
|
|
|
|
put "$i"
|
2018-07-17 09:18:04 +08:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2020-05-04 09:19:14 +08:00
|
|
|
for i in "${FILES[@]}"; do
|
2020-05-02 07:34:13 +08:00
|
|
|
if grep -q '^int main(' "$i"; then
|
|
|
|
putmain "$i"
|
2018-07-17 09:18:04 +08:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2020-05-04 09:19:14 +08:00
|
|
|
echo "static void call(int m(), int argc, char **argv) { m(); }" >>amalgamation.cc
|
|
|
|
echo "static void call(int m(int, char **), int argc, char **argv) { m(argc, argv); }" >>amalgamation.cc
|
|
|
|
echo '} // namespace' >>amalgamation.cc
|
2018-07-17 09:18:04 +08:00
|
|
|
|
2020-05-04 09:19:14 +08:00
|
|
|
echo "int main(int argc, char **argv) {" >>amalgamation.cc
|
|
|
|
for i in "${FILES[@]}"; do
|
2020-05-02 07:34:13 +08:00
|
|
|
if grep -q '^int main(' "$i"; then
|
|
|
|
callmain "$i"
|
2018-07-17 09:18:04 +08:00
|
|
|
fi
|
|
|
|
done
|
2020-05-04 09:19:14 +08:00
|
|
|
echo " return 0;" >>amalgamation.cc
|
|
|
|
echo "}" >>amalgamation.cc
|