Imported Upstream version 2.3.1
[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 ' [BCDGINRST] .' | 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 "Checking that $so does not expose internal symbols"
34                 if echo "$EXPORTED_SYMBOLS" | grep -v "^${prefix}\(_\|$\)"; then
35                         echo "Ouch, internal symbols exposed"
36                         stat=1
37                 fi
38
39                 def=$soname.def
40                 if ! test -f "$def"; then
41                         echo "'$def' not found; skipping"
42                 else
43                         echo "Checking that $so has the same symbol list as $def"
44                         {
45                                 echo EXPORTS
46                                 echo "$EXPORTED_SYMBOLS" | sed -e "s/^${symprefix}hb/hb/g"
47                                 # cheat: copy the last line from the def file!
48                                 tail -n1 "$def"
49                         } | c++filt | diff "$def" - >&2 || stat=1
50                 fi
51
52                 tested=true
53         done
54 done
55 if ! $tested; then
56         echo "check-symbols.sh: no shared libraries found; skipping test"
57         exit 77
58 fi
59
60 exit $stat