toxcore/other/analysis/gen-file.sh
iphydf de4af4c270
feat: Add async event handling (callbacks) code.
Instead of synchronously handling events as they happen in
`tox_iterate`, this first collects all events in a structure and then
lets the client process them. This allows clients to process events in
parallel, since the data structure returned is mostly immutable.

This also makes toxcore compatible with languages that don't (easily)
support callbacks from C into the non-C language.

If we remove the callbacks, this allows us to add fields to the events
without breaking the API.
2022-02-06 17:28:28 +00:00

101 lines
3.0 KiB
Bash

#!/bin/bash
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/fuzzing")
CPPFLAGS+=("-Itesting/groupchats")
CPPFLAGS+=("-Itoxcore")
CPPFLAGS+=("-Itoxcore/events")
CPPFLAGS+=("-Itoxav")
CPPFLAGS+=("-Itoxencryptsave")
LDFLAGS=("-lopus" "-lsodium" "-lvpx" "-lpthread" "-lconfig" "-lgtest")
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")
put() {
if [ "$SKIP_LINES" = "" ]; then
echo "#line 1 \"$1\"" >>amalgamation.cc
fi
cat "$1" >>amalgamation.cc
}
putmain() {
NS=$(echo "${1//[^a-zA-Z0-9_]/_}" | sed -e 's/^__*//')
echo "namespace $NS {" >>amalgamation.cc
if [ "$SKIP_LINES" = "" ]; then
echo "#line 1 \"$1\"" >>amalgamation.cc
fi
sed -e 's/^int main(/static &/' "$1" >>amalgamation.cc
echo "} // namespace $NS" >>amalgamation.cc
}
callmain() {
NS=$(echo "${1//[^a-zA-Z0-9_]/_}" | sed -e 's/^__*//')
echo " call($NS::main, argc, argv);" >>amalgamation.cc
}
: >amalgamation.cc
# Include all C and C++ code
FIND_QUERY="find . '-(' -name '*.c' -or -name '*.cc' '-)'"
# Excludes
FIND_QUERY="$FIND_QUERY -and -not -wholename './_build/*'"
FIND_QUERY="$FIND_QUERY -and -not -wholename './super_donators/*'"
FIND_QUERY="$FIND_QUERY -and -not -name amalgamation.cc"
FIND_QUERY="$FIND_QUERY -and -not -name av_test.c"
FIND_QUERY="$FIND_QUERY -and -not -name cracker.c"
FIND_QUERY="$FIND_QUERY -and -not -name dht_test.c"
FIND_QUERY="$FIND_QUERY -and -not -name trace.cc"
FIND_QUERY="$FIND_QUERY -and -not -name version_test.c"
FIND_QUERY="$FIND_QUERY -and -not -wholename './testing/fuzzing/*'"
if [ "$SKIP_GTEST" == 1 ]; then
FIND_QUERY="$FIND_QUERY -and -not -name '*_test.cc'"
fi
readarray -t FILES <<<"$(eval "$FIND_QUERY")"
(for i in "${FILES[@]}"; do
grep -o '#include <[^>]*>' "$i" |
grep -E -v '<win|<ws|<iphlp|<libc|<mach/|<crypto_|<randombytes|<u.h>|<sys/filio|<stropts.h>|<linux'
done) | sort -u >>amalgamation.cc
put auto_tests/check_compat.h
echo 'namespace {' >>amalgamation.cc
for i in "${FILES[@]}"; do
if ! grep -q '^int main(' "$i"; then
put "$i"
fi
done
for i in "${FILES[@]}"; do
if grep -q '^int main(' "$i"; then
putmain "$i"
fi
done
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 "static void call(int m(int, const char *const *), int argc, char **argv) { m(argc, argv); }" >>amalgamation.cc
echo '} // namespace' >>amalgamation.cc
echo "int main(int argc, char **argv) {" >>amalgamation.cc
for i in "${FILES[@]}"; do
if grep -q '^int main(' "$i"; then
callmain "$i"
fi
done
echo " return 0;" >>amalgamation.cc
echo "}" >>amalgamation.cc