17492e6f83d8f032965336a321630f14cad1735a
[asterisk/asterisk.git] / build_tools / strip_nonapi
1 #!/bin/sh -e
2
3 # This script is designed to remove all non-API global symbols from an object
4 # file. The only global symbols that should be retained are those that belong
5 # to the official namespace. Unfortunately doing this is platform-specific, as
6 # the object file manipulation tools are not consistent across platforms.
7 #
8 # On platforms where this script does not know what to do, the object file
9 # will retain non-API global symbols, and this may have unpleasant side effects.
10 #
11 # Prefixes that belong to the official namespace are:
12 #       ast_
13 #       _ast_
14 #       __ast_
15 #       astman_
16 #       pbx_
17 #       resample_
18
19 FILTER="${GREP} -v -e ^ast_ -e ^_ast_ -e ^__ast_ -e ^astman_ -e ^pbx_ -e ^resample_"
20
21 case "${PROC}" in
22         powerpc64)
23                 TEXTSYM=" D "
24                 ;;
25         *)
26                 TEXTSYM=" T "
27                 ;;
28 esac
29
30 case "${OSARCH}" in
31     linux-gnu|FreeBSD)
32         nm ${1} | ${GREP} -e "$TEXTSYM" | cut -d" " -f3 | ${FILTER} > striplist
33         sed -e "s/^/-N /" striplist | xargs -n 40 ${STRIP} ${1}
34         rm -f striplist
35         ;;
36     *)
37         ;;
38 esac