diff options
Diffstat (limited to 'other/analysis/gen-file.sh')
-rw-r--r-- | other/analysis/gen-file.sh | 85 |
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 | ||
3 | CPPFLAGS="$CPPFLAGS -DMIN_LOGGER_LEVEL=LOGGER_LEVEL_TRACE" | 3 | CPPFLAGS="-DMIN_LOGGER_LEVEL=LOGGER_LEVEL_TRACE" |
4 | CPPFLAGS="$CPPFLAGS -isystem /usr/include/opus" | 4 | CPPFLAGS+=("-isystem" "/usr/include/opus") |
5 | CPPFLAGS="$CPPFLAGS -Iauto_tests" | 5 | CPPFLAGS+=("-Iauto_tests") |
6 | CPPFLAGS="$CPPFLAGS -Iother" | 6 | CPPFLAGS+=("-Iother") |
7 | CPPFLAGS="$CPPFLAGS -Iother/bootstrap_daemon/src" | 7 | CPPFLAGS+=("-Iother/bootstrap_daemon/src") |
8 | CPPFLAGS="$CPPFLAGS -Iother/fun" | 8 | CPPFLAGS+=("-Iother/fun") |
9 | CPPFLAGS="$CPPFLAGS -Itesting" | 9 | CPPFLAGS+=("-Itesting") |
10 | CPPFLAGS="$CPPFLAGS -Itoxcore" | 10 | CPPFLAGS+=("-Itesting/groupchats") |
11 | CPPFLAGS="$CPPFLAGS -Itoxav" | 11 | CPPFLAGS+=("-Itoxcore") |
12 | CPPFLAGS="$CPPFLAGS -Itoxencryptsave" | 12 | CPPFLAGS+=("-Itoxav") |
13 | CPPFLAGS+=("-Itoxencryptsave") | ||
13 | 14 | ||
14 | LDFLAGS="$LDFLAGS -lopus -lsodium -lvpx -lpthread -lconfig" | 15 | LDFLAGS=("-lopus" "-lsodium" "-lvpx" "-lpthread" "-lconfig") |
16 | LDFLAGS+=("-fuse-ld=gold") | ||
17 | LDFLAGS+=("-Wl,--detect-odr-violations") | ||
18 | LDFLAGS+=("-Wl,--warn-common") | ||
19 | LDFLAGS+=("-Wl,--warn-execstack") | ||
20 | LDFLAGS+=("-Wl,-z,noexecstack") | ||
21 | LDFLAGS+=("-Wl,-z,now") | ||
15 | 22 | ||
16 | put() { | 23 | put() { |
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 | ||
23 | putmain() { | 30 | putmain() { |
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 | ||
32 | callmain() { | 39 | callmain() { |
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 | ||
38 | echo "#include <algorithm>" >> amalgamation.cc | 45 | echo "#include <algorithm>" >>amalgamation.cc |
39 | echo "#include <cstdio>" >> amalgamation.cc | 46 | echo "#include <cstdio>" >>amalgamation.cc |
40 | echo "#include <memory>" >> amalgamation.cc | 47 | echo "#include <memory>" >>amalgamation.cc |
41 | echo "#include <random>" >> amalgamation.cc | 48 | echo "#include <random>" >>amalgamation.cc |
42 | 49 | ||
43 | put auto_tests/check_compat.h | 50 | put auto_tests/check_compat.h |
44 | 51 | ||
@@ -53,33 +60,35 @@ FIND_QUERY="$FIND_QUERY -and -not -name av_test.c" | |||
53 | FIND_QUERY="$FIND_QUERY -and -not -name dht_test.c" | 60 | FIND_QUERY="$FIND_QUERY -and -not -name dht_test.c" |
54 | FIND_QUERY="$FIND_QUERY -and -not -name version_test.c" | 61 | FIND_QUERY="$FIND_QUERY -and -not -name version_test.c" |
55 | 62 | ||
56 | (for i in $(eval "$FIND_QUERY"); do | 63 | readarray -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' | ||
59 | done) | sort -u >> amalgamation.cc | ||
60 | 64 | ||
61 | echo 'namespace {' >> amalgamation.cc | 65 | (for i in "${FILES[@]}"; do |
62 | for 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' | ||
68 | done) | sort -u >>amalgamation.cc | ||
69 | |||
70 | echo 'namespace {' >>amalgamation.cc | ||
71 | for 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 |
66 | done | 75 | done |
67 | 76 | ||
68 | for i in $(eval "$FIND_QUERY"); do | 77 | for 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 |
72 | done | 81 | done |
73 | 82 | ||
74 | echo "static void call(int m(), int argc, char **argv) { m(); }" >> amalgamation.cc | 83 | echo "static void call(int m(), int argc, char **argv) { m(); }" >>amalgamation.cc |
75 | echo "static void call(int m(int, char **), int argc, char **argv) { m(argc, argv); }" >> amalgamation.cc | 84 | echo "static void call(int m(int, char **), int argc, char **argv) { m(argc, argv); }" >>amalgamation.cc |
76 | echo '} // namespace' >> amalgamation.cc | 85 | echo '} // namespace' >>amalgamation.cc |
77 | 86 | ||
78 | echo "int main(int argc, char **argv) {" >> amalgamation.cc | 87 | echo "int main(int argc, char **argv) {" >>amalgamation.cc |
79 | for i in $(eval "$FIND_QUERY"); do | 88 | for 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 |
83 | done | 92 | done |
84 | echo " return 0;" >> amalgamation.cc | 93 | echo " return 0;" >>amalgamation.cc |
85 | echo "}" >> amalgamation.cc | 94 | echo "}" >>amalgamation.cc |