xref: /freebsd/sys/contrib/libsodium/dist-build/generate-emscripten-symbols.sh (revision 59c8e88e72633afbc47a4ace0d2170d00d51f7dc)
1#! /bin/sh
2
3set -e
4
5symbols() {
6  {
7    SUMO="$1"
8    while read symbol standard sumo; do
9      found="$standard"
10      if [ "x$SUMO" = "xsumo" ]; then
11        found="$sumo"
12      fi
13      if [ "$found" = "1" ]; then
14        eval "defined_${symbol}=yes"
15      else
16        eval "defined_${symbol}=no"
17      fi
18    done < emscripten-symbols.def
19
20    nm /usr/local/lib/libsodium.23.dylib | \
21    fgrep ' T _' | \
22    cut -d' ' -f3 | {
23      while read symbol; do
24        eval "found=\$defined_${symbol}"
25        if [ "$found" = "yes" ]; then
26          echo "$symbol"
27        elif [ "$found" != "no" ]; then
28          echo >&2
29          echo "*** [$symbol] was not expected ***" >&2
30          echo >&2
31          exit 1
32        fi
33      done
34    }
35  } | \
36    sort | \
37    {
38      out='"_malloc","_free"'
39      while read symbol ; do
40        if [ ! -z "$out" ]; then
41          out="${out},"
42        fi
43        out="${out}\"${symbol}\""
44      done
45      echo "[${out}]"
46    }
47}
48
49out=$(symbols standard)
50sed s/EXPORTED_FUNCTIONS_STANDARD=\'.*\'/EXPORTED_FUNCTIONS_STANDARD=\'${out}\'/ < emscripten.sh > emscripten.sh.tmp && \
51  mv -f emscripten.sh.tmp emscripten.sh
52
53out=$(symbols sumo)
54sed s/EXPORTED_FUNCTIONS_SUMO=\'.*\'/EXPORTED_FUNCTIONS_SUMO=\'${out}\'/ < emscripten.sh > emscripten.sh.tmp && \
55  mv -f emscripten.sh.tmp emscripten.sh
56
57chmod +x emscripten.sh
58