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")
|
2021-12-05 20:11:20 +08:00
|
|
|
CPPFLAGS+=("-Itesting/fuzzing")
|
2020-05-04 09:19:14 +08:00
|
|
|
CPPFLAGS+=("-Itoxcore")
|
2022-02-07 00:41:31 +08:00
|
|
|
CPPFLAGS+=("-Itoxcore/events")
|
2020-05-04 09:19:14 +08:00
|
|
|
CPPFLAGS+=("-Itoxav")
|
|
|
|
CPPFLAGS+=("-Itoxencryptsave")
|
2018-07-17 09:18:04 +08:00
|
|
|
|
2022-02-07 07:53:41 +08:00
|
|
|
LDFLAGS=("-lopus" "-lmsgpackc" "-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() {
|
2022-01-10 18:57:28 +08:00
|
|
|
NS=$(echo "${1//[^a-zA-Z0-9_]/_}" | sed -e 's/^__*//')
|
|
|
|
echo "namespace $NS {" >>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
|
2022-01-10 18:57:28 +08:00
|
|
|
echo "} // namespace $NS" >>amalgamation.cc
|
2018-07-17 09:18:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
callmain() {
|
2022-01-10 18:57:28 +08:00
|
|
|
NS=$(echo "${1//[^a-zA-Z0-9_]/_}" | sed -e 's/^__*//')
|
|
|
|
echo " call($NS::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
|
|
|
|
2021-12-05 20:11:20 +08:00
|
|
|
# Include all C and C++ code
|
2021-12-15 05:18:41 +08:00
|
|
|
FIND_QUERY="find . '-(' -name '*.c' -or -name '*.cc' '-)'"
|
2021-12-05 20:11:20 +08:00
|
|
|
# Excludes
|
2018-08-12 19:35:01 +08:00
|
|
|
FIND_QUERY="$FIND_QUERY -and -not -wholename './_build/*'"
|
2022-02-25 00:42:04 +08:00
|
|
|
FIND_QUERY="$FIND_QUERY -and -not -wholename './other/docker/*'"
|
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"
|
2022-01-10 18:57:28 +08:00
|
|
|
FIND_QUERY="$FIND_QUERY -and -not -name cracker.c"
|
2018-07-17 09:18:04 +08:00
|
|
|
FIND_QUERY="$FIND_QUERY -and -not -name version_test.c"
|
2021-12-05 20:11:20 +08:00
|
|
|
FIND_QUERY="$FIND_QUERY -and -not -wholename './testing/fuzzing/*'"
|
2018-07-17 09:18:04 +08:00
|
|
|
|
2022-01-14 08:28:06 +08:00
|
|
|
if [ "$SKIP_GTEST" == 1 ]; then
|
|
|
|
FIND_QUERY="$FIND_QUERY -and -not -name '*_test.cc'"
|
|
|
|
fi
|
|
|
|
|
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
|
|
|
|
|
2022-01-10 18:57:28 +08:00
|
|
|
put auto_tests/check_compat.h
|
|
|
|
|
2020-05-04 09:19:14 +08:00
|
|
|
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
|
2021-12-29 01:55:51 +08:00
|
|
|
echo "static void call(int m(int, const char *const *), int argc, char **argv) { m(argc, argv); }" >>amalgamation.cc
|
2020-05-04 09:19:14 +08:00
|
|
|
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
|