e54742b0cb474fef3afc4ba210fa2cfb271fc254
[openafs.git] / src / config / shlib-build.in
1 #!/bin/sh
2 #
3 # Builds a shared library, incorporating the random portability work that we
4 # have to do.  Gets the basic information from Autoconf and knows how to find
5 # the appropriate system-specific map or version file and set library SONAMEs.
6 #
7 # This is not libtool.  If it appears to be in danger of evolving into
8 # libtool, please shoot it and start over, possibly by rewriting AFS in Ada.
9
10 # We take the following regular arguments: -d <srcdir>, -f <filename>, -l
11 # <library>, -M <major>, and -m <minor>.  If -f is given, it overrides -l and
12 # specifies the complete filename of the shared library to build.  We then
13 # expect a -- option indicating the end of our arguments and the rest of the
14 # arguments are passed along verbatim to the linker.
15
16 set -e
17
18 linker="@SHLIB_LINKER@"
19 suffix="@SHLIB_SUFFIX@"
20 sysname="@AFS_SYSNAME@"
21
22 library=
23 major=
24 minor=
25 srcdir=.
26 done=
27 while [ -z "$done" ] && [ $# -gt 0 ] ; do
28     case "$1" in
29     -d)
30         shift
31         srcdir="$1"
32         shift
33         ;;
34     -f)
35         shift
36         filename="$1"
37         shift
38         ;;
39     -l)
40         shift
41         library="$1"
42         shift
43         ;;
44     -M)
45         shift
46         major="$1"
47         shift
48         ;;
49     -m)
50         shift
51         minor="$1"
52         shift
53         ;;
54     --)
55         shift
56         done=yes
57         ;;
58     *)
59         echo 'Usage: shlib-build -l <lib> -M <major> -m <minor> -- ...' >&2
60         exit 1
61         ;;
62     esac
63 done
64 if [ -z "$library" ] ; then
65     echo 'Usage: shlib-install -l <lib> -M <major> -m <minor>' >&2
66     exit 1
67 fi
68
69 # Print out what we're doing while we do it for debugging.
70 export=
71 if [ -z "$filename" ] ; then
72     if [ -z "$major" ] ; then
73         filename="$library.$suffix"
74         soname=
75     else
76         filename="$library.$suffix.$major.$minor"
77         soname="$library.$suffix.$major"
78     fi
79 fi
80 case $sysname in
81 rs_aix*)
82     if [ -f "$srcdir/$library.map" ] ; then
83         cat $srcdir/$library.map | \
84         awk '/local:/ {inglobal=0};
85              inglobal { sub(/;/,""); print };
86              /global:/ { inglobal=1};' \
87         > $library.exp
88         export="-bE:$library.exp"
89     fi
90     echo "$linker $export -o $filename $*"
91     $linker $export -o "$filename" "$@"
92     ;;
93 sun*_5*)
94     if [ -f "$srcdir/$library.map" ] ; then
95         export="-Wl,-M$srcdir/$library.map"
96     fi
97     if [ -z "$soname" ] ; then
98         echo "$linker $export -o $filename $*"
99         $linker $export -o "$filename" "$@"
100     else
101         echo "$linker $export -h $soname -o $filename $*"
102         $linker $export -h "$soname" -o "$filename" "$@"
103     fi
104     ;;
105 *_linux*)
106     if [ -f "$srcdir/$library.map" ] ; then
107         export="-Wl,--version-script=$srcdir/$library.map"
108     fi
109     if [ -z "$soname" ] ; then
110         echo "$linker $export -o $filename $*"
111         $linker $export -o "$filename" "$@"
112     else
113         echo "$linker $export -Wl,-h,$soname -o $filename $*"
114         $linker $export -Wl,-h,"$soname" -o "$filename" "$@"
115     fi
116     ;;
117 hp_ux*)
118     if [ -f "$srcdir/$library.hp" ] ; then
119         export="-c $srcdir/$library.hp"
120     fi
121     echo "$linker $export -o $filename $*"
122     $linker $export -o "$filename" "$@"
123     ;;
124 *darwin*)
125     if [ -f "$srcdir/$library.map" ] ; then
126         # For 10.4 and later, the Mac exports list is a list of symbols,
127         # prefixed with an '_'
128         cat $srcdir/$library.map | \
129         awk '/local:/ {inglobal=0};
130              /^[\t ]+#/ {next};
131              inglobal { sub(/;/,""); sub(/[\t ]+/,"_"); print };
132              /global:/ { inglobal=1};' \
133         > $library.exp
134         export="-Wl,-exported_symbols_list,$library.exp"
135     fi
136     echo "$linker $export -o $filename $*"
137     $linker $export -o "$filename" "$@"
138     ;;
139 *)
140     echo "$linker -o $filename $*"
141     $linker -o "$filename" "$@"
142     ;;
143 esac