Imported Upstream version 1.7.6
[platform/upstream/harfbuzz.git] / src / check-symbols.sh
1 #!/bin/sh
2
3 LC_ALL=C
4 export LC_ALL
5
6 test -z "$srcdir" && srcdir=.
7 test -z "$libs" && libs=.libs
8 stat=0
9
10 IGNORED_SYMBOLS='_fini\|_init\|_fdata\|_ftext\|_fbss\|__bss_start\|__bss_start__\|__bss_end__\|_edata\|_end\|_bss_end__\|__end__\|__gcov_flush\|llvm_.*'
11
12 if which nm 2>/dev/null >/dev/null; then
13         :
14 else
15         echo "check-symbols.sh: 'nm' not found; skipping test"
16         exit 77
17 fi
18
19 tested=false
20 for soname in harfbuzz harfbuzz-subset harfbuzz-icu harfbuzz-gobject; do
21         for suffix in so dylib; do
22                 so=$libs/lib$soname.$suffix
23                 if ! test -f "$so"; then continue; fi
24
25                 # On macOS, C symbols are prefixed with _
26                 symprefix=
27                 if test $suffix = dylib; then symprefix=_; fi
28
29                 EXPORTED_SYMBOLS="`nm "$so" | grep ' [BCDGINRSTVW] .' | grep -v " $symprefix\\($IGNORED_SYMBOLS\\>\\)" | cut -d' ' -f3 | c++filt`"
30
31                 prefix=$symprefix`basename "$so" | sed 's/libharfbuzz/hb/; s/-/_/g; s/[.].*//'`
32
33                 echo
34                 echo "Checking that $so does not expose internal symbols"
35                 if echo "$EXPORTED_SYMBOLS" | grep -v "^${prefix}\(_\|$\)"; then
36                         echo "Ouch, internal symbols exposed"
37                         stat=1
38                 fi
39
40                 def=$soname.def
41                 if ! test -f "$def"; then
42                         echo "'$def' not found; skipping"
43                 else
44                         echo
45                         echo "Checking that $so has the same symbol list as $def"
46                         {
47                                 echo EXPORTS
48                                 echo "$EXPORTED_SYMBOLS" | sed -e "s/^${symprefix}hb/hb/g"
49                                 # cheat: copy the last line from the def file!
50                                 tail -n1 "$def"
51                         } | c++filt | diff "$def" - >&2 || stat=1
52                 fi
53
54                 tested=true
55         done
56 done
57 if ! $tested; then
58         echo "check-symbols.sh: no shared libraries found; skipping test"
59         exit 77
60 fi
61
62 exit $stat