summaryrefslogtreecommitdiff
path: root/other/analysis/gen-file.sh
diff options
context:
space:
mode:
Diffstat (limited to 'other/analysis/gen-file.sh')
-rw-r--r--other/analysis/gen-file.sh85
1 files changed, 47 insertions, 38 deletions
diff --git a/other/analysis/gen-file.sh b/other/analysis/gen-file.sh
index ad8df3b8..1c2a3f6d 100644
--- a/other/analysis/gen-file.sh
+++ b/other/analysis/gen-file.sh
@@ -1,44 +1,51 @@
1#!/bin/sh 1#!/bin/bash
2 2
3CPPFLAGS="$CPPFLAGS -DMIN_LOGGER_LEVEL=LOGGER_LEVEL_TRACE" 3CPPFLAGS="-DMIN_LOGGER_LEVEL=LOGGER_LEVEL_TRACE"
4CPPFLAGS="$CPPFLAGS -isystem /usr/include/opus" 4CPPFLAGS+=("-isystem" "/usr/include/opus")
5CPPFLAGS="$CPPFLAGS -Iauto_tests" 5CPPFLAGS+=("-Iauto_tests")
6CPPFLAGS="$CPPFLAGS -Iother" 6CPPFLAGS+=("-Iother")
7CPPFLAGS="$CPPFLAGS -Iother/bootstrap_daemon/src" 7CPPFLAGS+=("-Iother/bootstrap_daemon/src")
8CPPFLAGS="$CPPFLAGS -Iother/fun" 8CPPFLAGS+=("-Iother/fun")
9CPPFLAGS="$CPPFLAGS -Itesting" 9CPPFLAGS+=("-Itesting")
10CPPFLAGS="$CPPFLAGS -Itoxcore" 10CPPFLAGS+=("-Itesting/groupchats")
11CPPFLAGS="$CPPFLAGS -Itoxav" 11CPPFLAGS+=("-Itoxcore")
12CPPFLAGS="$CPPFLAGS -Itoxencryptsave" 12CPPFLAGS+=("-Itoxav")
13CPPFLAGS+=("-Itoxencryptsave")
13 14
14LDFLAGS="$LDFLAGS -lopus -lsodium -lvpx -lpthread -lconfig" 15LDFLAGS=("-lopus" "-lsodium" "-lvpx" "-lpthread" "-lconfig")
16LDFLAGS+=("-fuse-ld=gold")
17LDFLAGS+=("-Wl,--detect-odr-violations")
18LDFLAGS+=("-Wl,--warn-common")
19LDFLAGS+=("-Wl,--warn-execstack")
20LDFLAGS+=("-Wl,-z,noexecstack")
21LDFLAGS+=("-Wl,-z,now")
15 22
16put() { 23put() {
17 if [ "$SKIP_LINES" = "" ]; then 24 if [ "$SKIP_LINES" = "" ]; then
18 echo "#line 1 \"$1\"" >> amalgamation.cc 25 echo "#line 1 \"$1\"" >>amalgamation.cc
19 fi 26 fi
20 cat "$1" >> amalgamation.cc 27 cat "$1" >>amalgamation.cc
21} 28}
22 29
23putmain() { 30putmain() {
24 echo "namespace $(echo "$1" | sed -e 's/[^a-zA-Z0-9_]/_/g') {" >> amalgamation.cc 31 echo "namespace ${1//[^a-zA-Z0-9_]/_} {" >>amalgamation.cc
25 if [ "$SKIP_LINES" = "" ]; then 32 if [ "$SKIP_LINES" = "" ]; then
26 echo "#line 1 \"$1\"" >> amalgamation.cc 33 echo "#line 1 \"$1\"" >>amalgamation.cc
27 fi 34 fi
28 sed -e 's/^int main(/static &/' "$1" >> amalgamation.cc 35 sed -e 's/^int main(/static &/' "$1" >>amalgamation.cc
29 echo "} // namespace $(echo "$1" | sed -e 's/[^a-zA-Z0-9_]/_/g')" >> amalgamation.cc 36 echo "} // namespace ${1//[^a-zA-Z0-9_]/_}" >>amalgamation.cc
30} 37}
31 38
32callmain() { 39callmain() {
33 echo " call($(echo "$1" | sed -e 's/[^a-zA-Z0-9_]/_/g')::main, argc, argv);" >> amalgamation.cc 40 echo " call(${1//[^a-zA-Z0-9_]/_}::main, argc, argv);" >>amalgamation.cc
34} 41}
35 42
36:> amalgamation.cc 43: >amalgamation.cc
37 44
38echo "#include <algorithm>" >> amalgamation.cc 45echo "#include <algorithm>" >>amalgamation.cc
39echo "#include <cstdio>" >> amalgamation.cc 46echo "#include <cstdio>" >>amalgamation.cc
40echo "#include <memory>" >> amalgamation.cc 47echo "#include <memory>" >>amalgamation.cc
41echo "#include <random>" >> amalgamation.cc 48echo "#include <random>" >>amalgamation.cc
42 49
43put auto_tests/check_compat.h 50put auto_tests/check_compat.h
44 51
@@ -53,33 +60,35 @@ FIND_QUERY="$FIND_QUERY -and -not -name av_test.c"
53FIND_QUERY="$FIND_QUERY -and -not -name dht_test.c" 60FIND_QUERY="$FIND_QUERY -and -not -name dht_test.c"
54FIND_QUERY="$FIND_QUERY -and -not -name version_test.c" 61FIND_QUERY="$FIND_QUERY -and -not -name version_test.c"
55 62
56(for i in $(eval "$FIND_QUERY"); do 63readarray -t FILES <<<"$(eval "$FIND_QUERY")"
57 grep -o '#include <[^>]*>' "$i" \
58 | grep -E -v '<win|<ws|<iphlp|<libc|<mach/|<crypto_|<randombytes|<u.h>|<sys/filio|<linux'
59done) | sort -u >> amalgamation.cc
60 64
61echo 'namespace {' >> amalgamation.cc 65(for i in "${FILES[@]}"; do
62for i in $(eval "$FIND_QUERY"); do 66 grep -o '#include <[^>]*>' "$i" |
67 grep -E -v '<win|<ws|<iphlp|<libc|<mach/|<crypto_|<randombytes|<u.h>|<sys/filio|<linux'
68done) | sort -u >>amalgamation.cc
69
70echo 'namespace {' >>amalgamation.cc
71for i in "${FILES[@]}"; do
63 if ! grep -q '^int main(' "$i"; then 72 if ! grep -q '^int main(' "$i"; then
64 put "$i" 73 put "$i"
65 fi 74 fi
66done 75done
67 76
68for i in $(eval "$FIND_QUERY"); do 77for i in "${FILES[@]}"; do
69 if grep -q '^int main(' "$i"; then 78 if grep -q '^int main(' "$i"; then
70 putmain "$i" 79 putmain "$i"
71 fi 80 fi
72done 81done
73 82
74echo "static void call(int m(), int argc, char **argv) { m(); }" >> amalgamation.cc 83echo "static void call(int m(), int argc, char **argv) { m(); }" >>amalgamation.cc
75echo "static void call(int m(int, char **), int argc, char **argv) { m(argc, argv); }" >> amalgamation.cc 84echo "static void call(int m(int, char **), int argc, char **argv) { m(argc, argv); }" >>amalgamation.cc
76echo '} // namespace' >> amalgamation.cc 85echo '} // namespace' >>amalgamation.cc
77 86
78echo "int main(int argc, char **argv) {" >> amalgamation.cc 87echo "int main(int argc, char **argv) {" >>amalgamation.cc
79for i in $(eval "$FIND_QUERY"); do 88for i in "${FILES[@]}"; do
80 if grep -q '^int main(' "$i"; then 89 if grep -q '^int main(' "$i"; then
81 callmain "$i" 90 callmain "$i"
82 fi 91 fi
83done 92done
84echo " return 0;" >> amalgamation.cc 93echo " return 0;" >>amalgamation.cc
85echo "}" >> amalgamation.cc 94echo "}" >>amalgamation.cc