r25987: libreplace: rename AC_LD_SHLDFLAGS into AC_LIBREPLACE_SHLD_FLAGS
[jelmer/samba4-debian.git] / source / lib / replace / libreplace_ld.m4
1 #
2 # This offers a nice overview how to build shared libraries on all platforms
3 #        http://www.fortran-2000.com/ArnaudRecipes/sharedlib.html
4 #
5
6 AC_DEFUN([AC_LD_EXPORT_DYNAMIC],
7 [
8 saved_LDFLAGS="$LDFLAGS"
9 if AC_TRY_COMMAND([${CC-cc} $CFLAGS -Wl,--version 2>&1 | grep "GNU ld" >/dev/null]); then
10         LD_EXPORT_DYNAMIC="-Wl,-export-dynamic"
11 else
12         case "$host_os" in
13                 hpux* )
14                   LD_EXPORT_DYNAMIC="-Wl,-E"
15                   ;;
16                 *)
17                   LD_EXPORT_DYNAMIC=""
18                   ;;
19           esac
20 fi
21 AC_SUBST(LD_EXPORT_DYNAMIC)
22 LDFLAGS="$saved_LDFLAGS"
23 ])
24
25 AC_DEFUN([AC_LD_PICFLAG],
26 [
27 case "$host_os" in
28         *linux*) 
29                 PICFLAG="-fPIC" 
30                 ;;
31         *solaris*)
32                 if test "${GCC}" = "yes"; then
33                         PICFLAG="-fPIC"
34                 else
35                         PICFLAG="-KPIC"
36                 fi
37                 ;;
38         *sunos*)
39                 PICFLAG="-KPIC"   # Is this correct for SunOS
40                 ;;
41         *netbsd* | *freebsd* | *dragonfly* )  
42                 PICFLAG="-fPIC -DPIC"
43                 ;;
44         *openbsd*)
45                 PICFLAG="-fPIC"
46                 ;;
47         *irix*)
48                 if test "${GCC}" = "yes"; then
49                         PICFLAG="-fPIC"
50                 else 
51                         PICFLAG="-KPIC"
52                 fi
53                 ;;
54         *aix*)
55                 # as AIX code is always position independent...
56                 PICFLAG="-O2"
57                 ;;
58         *hpux*)
59                 if test $ac_cv_prog_cc_Ae = yes; then
60                         PICFLAG="+z +ESnolit"
61                 elif test "${GCC}" = "yes"; then
62                         PICFLAG="-fPIC"
63                 fi
64                 if test "$host_cpu" = "ia64"; then
65                         PICFLAG="+z"
66                 fi
67                 ;;
68         *osf*)
69                 PICFLAG="-fPIC"
70                 ;;
71         *unixware*)
72                 PICFLAG="-KPIC"
73                 ;;
74         *darwin*)
75                 PICFLAG="-fno-common"
76                 ;;
77 esac
78 AC_SUBST(PICFLAG)
79 ])
80
81 AC_DEFUN([AC_LIBREPLACE_SHLD_FLAGS],
82 [
83         SHLD_FLAGS="-shared"
84
85         case "$host_os" in
86                 *linux*)
87                         SHLD_FLAGS="-shared -Wl,-Bsymbolic"
88                         ;;
89                 *solaris*)
90                         SHLD_FLAGS="-G"
91                         if test "${GCC}" = "no"; then
92                                 ## ${CFLAGS} added for building 64-bit shared 
93                                 ## libs using Sun's Compiler
94                                 SHLD_FLAGS="-G \${CFLAGS}"
95                         fi
96                         ;;
97                 *sunos*)
98                         SHLD_FLAGS="-G"
99                         ;;
100                 *irix*)
101                         SHLD_FLAGS="-shared"
102                         ;;
103                 *aix*)
104                         SHLD_FLAGS="-Wl,-G,-bexpall,-bbigtoc"
105                         ;;
106                 *hpux*)
107                         if test "${GCC}" = "yes"; then
108                                 SHLD_FLAGS="-shared"
109                         else
110                                 SHLD_FLAGS="-b"
111                         fi
112                         ;;
113                 *osf*)
114                         SHLD_FLAGS="-shared -warning_unresolved"
115                         ;;
116                 *darwin*)
117                         SHLD_FLAGS="-bundle -flat_namespace -undefined warning -Wl,-search_paths_first"
118                         ;;
119         esac
120
121         AC_SUBST(SHLD_FLAGS)
122 ])
123
124 AC_DEFUN([AC_LD_SHLIBEXT],
125 [
126         SHLIBEXT="so"
127         case "$host_os" in
128                 *hpux*)
129                         if test "$host_cpu" = "ia64"; then
130                                 SHLIBEXT="so"
131                         else
132                                 SHLIBEXT="sl"
133                         fi
134                 ;;
135                 *darwin*)
136                         SHLIBEXT="dylib"
137                 ;;
138         esac
139         AC_SUBST(SHLIBEXT)
140 ])
141
142 AC_DEFUN([AC_LD_SONAMEFLAG],
143 [
144         AC_SUBST(SONAMEFLAG)
145         SONAMEFLAG=""
146         case "$host_os" in 
147                 *linux*)
148                         SONAMEFLAG="-Wl,-soname="
149                         ;;
150                 *solaris*)
151                         SONAMEFLAG="-h "
152                         if test "${GCC}" = "yes"; then
153                                 SONAMEFLAG="-Wl,-soname="
154                         fi
155                         ;;
156                 *sunos*)
157                         SONAMEFLAG="-Wl,-h,"
158                         ;;
159                 *netbsd* | *freebsd* | *dragonfly* )
160                         SONAMEFLAG="-Wl,-soname,"
161                         ;;
162                 *openbsd*)
163                         SONAMEFLAG="-Wl,-soname,"
164                         ;;
165                 *irix*)
166                         SONAMEFLAG="-Wl,-soname,"
167                         ;;
168                 *hpux*)
169                         SONAMEFLAG="-Wl,+h,"
170                         ;;
171                 *osf*)
172                         SONAMEFLAG="-Wl,-soname,"
173                         ;;
174                 *unixware*)
175                         SONAMEFLAG="-Wl,-soname,"
176                         ;;
177                 *darwin*)
178                         SONAMEFLAG="#"
179                         ;;
180                 *aix*)
181                         # Not supported
182                         SONAMEFLAG="#"
183                         ;;
184                 esac
185 ])
186
187 AC_DEFUN([AC_LIBREPLACE_MDLD],
188 [
189         MDLD="${CC}"
190
191         case "$host_os" in
192                 *irix*)
193                         MDLD="${PROG_LD}"
194                         ;;
195         esac
196
197         AC_SUBST(MDLD)
198 ])
199
200 AC_DEFUN([AC_LIBREPLACE_MDLD_FLAGS],
201 [
202         MDLD_FLAGS="-shared"
203
204         case "$host_os" in
205                 *linux*)
206                         MDLD_FLAGS="-shared -Wl,-Bsymbolic -Wl,--allow-shlib-undefined"
207                         ;;
208                 *solaris*)
209                         MDLD_FLAGS="-G"
210                         if test "${GCC}" = "no"; then
211                                 ## ${CFLAGS} added for building 64-bit shared
212                                 ## libs using Sun's Compiler
213                                 NDLD_FLAGS="-G \${CFLAGS}"
214                         fi
215                         ;;
216                 *sunos*)
217                         MDLD_FLAGS="-G"
218                         ;;
219                 *aix*)
220                         MDLD_FLAGS="-Wl,-G,-bexpall,-bbigtoc"
221                         ;;
222                 *hpux*)
223                         if test "${GCC}" = "yes"; then
224                                 MDLD_FLAGS="-shared"
225                         else
226                                 MDLD_FLAGS="-b"
227                         fi
228                         ;;
229                 *osf*)
230                         MDLD_FLAGS="-shared -expect_unresolved '*'"
231                         ;;
232                 *darwin*)
233                         MDLD_FLAGS="-bundle -flat_namespace -undefined suppress -Wl,-search_paths_first"
234                         ;;
235         esac
236
237         AC_SUBST(MDLD_FLAGS)
238 ])