s3: fix building of pam_smbpass.
[Samba/gbeck.git] / lib / replace / libreplace_ld.m4
blob9529c5e0a53db7b5d3907c626786bddeb4caebd4
2 # This offers a nice overview how to build shared libraries on all platforms
3 #        http://www.fortran-2000.com/ArnaudRecipes/sharedlib.html
6 AC_DEFUN([AC_LIBREPLACE_STLD],
8         AC_PATH_PROG(PROG_AR, ar)
10         STLD=${PROG_AR}
12         AC_SUBST(STLD)
15 AC_DEFUN([AC_LIBREPLACE_STLD_FLAGS],
17         STLD_FLAGS="-rcs"
18         AC_SUBST(STLD_FLAGS)
21 AC_DEFUN([AC_LD_EXPORT_DYNAMIC],
23 saved_LDFLAGS="$LDFLAGS"
24 if AC_TRY_COMMAND([${CC-cc} $CFLAGS -Wl,--version 2>&1 | grep "GNU ld" >/dev/null]); then
25         LD_EXPORT_DYNAMIC="-Wl,-export-dynamic"
26 else
27         case "$host_os" in
28                 hpux* )
29                   LD_EXPORT_DYNAMIC="-Wl,-E"
30                   ;;
31                 *)
32                   LD_EXPORT_DYNAMIC=""
33                   ;;
34           esac
36 AC_SUBST(LD_EXPORT_DYNAMIC)
37 LDFLAGS="$saved_LDFLAGS"
40 AC_DEFUN([AC_LD_PICFLAG],
42 case "$host_os" in
43         *linux*) 
44                 PICFLAG="-fPIC" 
45                 ;;
46         *solaris*)
47                 if test "${GCC}" = "yes"; then
48                         PICFLAG="-fPIC"
49                 else
50                         PICFLAG="-KPIC"
51                 fi
52                 ;;
53         *sunos*)
54                 PICFLAG="-KPIC"   # Is this correct for SunOS
55                 ;;
56         *netbsd* | *freebsd* | *dragonfly* )  
57                 PICFLAG="-fPIC -DPIC"
58                 ;;
59         *openbsd*)
60                 PICFLAG="-fPIC"
61                 ;;
62         *irix*)
63                 if test "${GCC}" = "yes"; then
64                         PICFLAG="-fPIC"
65                 else 
66                         PICFLAG="-KPIC"
67                 fi
68                 ;;
69         *aix*)
70                 # as AIX code is always position independent...
71                 PICFLAG="-O2"
72                 ;;
73         *hpux*)
74                 if test $ac_cv_prog_cc_Ae = yes; then
75                         PICFLAG="+z +ESnolit"
76                 elif test "${GCC}" = "yes"; then
77                         PICFLAG="-fPIC"
78                 fi
79                 if test "$host_cpu" = "ia64"; then
80                         PICFLAG="+z"
81                 fi
82                 ;;
83         *osf*)
84                 PICFLAG="-fPIC"
85                 ;;
86         *unixware*)
87                 PICFLAG="-KPIC"
88                 ;;
89         *darwin*)
90                 PICFLAG="-fno-common"
91                 ;;
92 esac
93 AC_SUBST(PICFLAG)
96 AC_DEFUN([AC_LIBREPLACE_LD_SHLIB_LINKER],
98         LD_SHLIB_LINKER="${CC}"
100         case "$host_os" in
101                 *irix*)
102                         LD_SHLIB_LINKER="${PROG_LD}"
103                         ;;
104         esac
106         AC_SUBST(LD_SHLIB_LINKER)
109 AC_DEFUN([AC_LIBREPLACE_LD_SHLIB_FLAGS],
111         LD_SHLIB_FLAGS="-shared"
113         case "$host_os" in
114                 *linux*)
115                         LD_SHLIB_FLAGS="-shared -Wl,-Bsymbolic"
116                         ;;
117                 *solaris*)
118                         LD_SHLIB_FLAGS="-G"
119                         if test "${GCC}" = "no"; then
120                                 ## ${CFLAGS} added for building 64-bit shared 
121                                 ## libs using Sun's Compiler
122                                 LD_SHLIB_FLAGS="-G \${CFLAGS}"
123                         fi
124                         ;;
125                 *sunos*)
126                         LD_SHLIB_FLAGS="-G"
127                         ;;
128                 *irix*)
129                         LD_SHLIB_FLAGS="-shared"
130                         ;;
131                 *aix*)
132                         LD_SHLIB_FLAGS="-Wl,-G,-bexpall,-bbigtoc"
133                         ;;
134                 *hpux*)
135                         if test "${GCC}" = "yes"; then
136                                 LD_SHLIB_FLAGS="-shared"
137                         else
138                                 LD_SHLIB_FLAGS="-b"
139                         fi
140                         ;;
141                 *osf*)
142                         LD_SHLIB_FLAGS="-shared"
143                         ;;
144                 *darwin*)
145                         LD_SHLIB_FLAGS="-dynamiclib -Wl,-search_paths_first"
146                         ;;
147         esac
149         AC_SUBST(LD_SHLIB_FLAGS)
152 AC_DEFUN([AC_LIBREPLACE_LD_SHLIB_DISALLOW_UNDEF_FLAG],
154         LD_SHLIB_DISALLOW_UNDEF_FLAG=""
156         #
157         # TODO: enforce error not only warnings
158         #
159         # NOTE: -Wl,--no-allow-shlib-undefined isn't what we want...
160         #       as it bails out on broken system libraries
161         #
162         case "$host_os" in
163                 *osf*)
164                         LD_SHLIB_DISALLOW_UNDEF_FLAG="-warning_unresolved"
165                         ;;
166                 *darwin*)
167                         LD_SHLIB_DISALLOW_UNDEF_FLAG="-undefined error"
168                         ;;
169         esac
171         AC_SUBST(LD_SHLIB_DISALLOW_UNDEF_FLAG)
174 AC_DEFUN([AC_LIBREPLACE_SHLD],
176         AC_REQUIRE([AC_LIBREPLACE_LD_SHLIB_LINKER])
177         SHLD="$LD_SHLIB_LINKER"
178         AC_SUBST(SHLD)
181 AC_DEFUN([AC_LIBREPLACE_SHLD_FLAGS],
183         AC_REQUIRE([AC_LIBREPLACE_LD_SHLIB_FLAGS])
184         AC_REQUIRE([AC_LIBREPLACE_LD_SHLIB_DISALLOW_UNDEF_FLAG])
185         SHLD_FLAGS="$LD_SHLIB_FLAGS $LD_SHLIB_DISALLOW_UNDEF_FLAG"
186         AC_SUBST(SHLD_FLAGS)
189 AC_DEFUN([AC_LD_SHLIBEXT],
191         SHLIBEXT="so"
192         case "$host_os" in
193                 *hpux*)
194                         if test "$host_cpu" = "ia64"; then
195                                 SHLIBEXT="so"
196                         else
197                                 SHLIBEXT="sl"
198                         fi
199                 ;;
200                 *darwin*)
201                         SHLIBEXT="dylib"
202                 ;;
203         esac
204         AC_SUBST(SHLIBEXT)
207 AC_DEFUN([AC_LD_SONAMEFLAG],
209         AC_SUBST(SONAMEFLAG)
210         SONAMEFLAG=""
211         case "$host_os" in 
212                 *linux*)
213                         SONAMEFLAG="-Wl,-soname="
214                         ;;
215                 *solaris*)
216                         SONAMEFLAG="-h "
217                         if test "${GCC}" = "yes"; then
218                                 SONAMEFLAG="-Wl,-soname="
219                         fi
220                         ;;
221                 *sunos*)
222                         SONAMEFLAG="-Wl,-h,"
223                         ;;
224                 *netbsd* | *freebsd* | *dragonfly* )
225                         SONAMEFLAG="-Wl,-soname,"
226                         ;;
227                 *openbsd*)
228                         SONAMEFLAG="-Wl,-soname,"
229                         ;;
230                 *irix*)
231                         SONAMEFLAG="-Wl,-soname,"
232                         ;;
233                 *hpux*)
234                         SONAMEFLAG="-Wl,+h,"
235                         ;;
236                 *osf*)
237                         SONAMEFLAG="-Wl,-soname,"
238                         ;;
239                 *unixware*)
240                         SONAMEFLAG="-Wl,-soname,"
241                         ;;
242                 *darwin*)
243                         SONAMEFLAG="#"
244                         ;;
245                 *aix*)
246                         # Not supported
247                         SONAMEFLAG="#"
248                         ;;
249                 esac
252 AC_DEFUN([AC_LIBREPLACE_MDLD],
254         AC_REQUIRE([AC_LIBREPLACE_LD_SHLIB_LINKER])
255         MDLD="$LD_SHLIB_LINKER"
256         AC_SUBST(MDLD)
259 AC_DEFUN([AC_LIBREPLACE_LD_SHLIB_ALLOW_UNDEF_FLAG],
261         LD_ALLOW_SHLIB_UNDEF_FLAG=""
263         case "$host_os" in
264                 *linux*)
265                         LD_SHLIB_ALLOW_UNDEF_FLAG="-Wl,--allow-shlib-undefined"
266                         ;;
267                 *osf*)
268                         LD_SHLIB_ALLOW_UNDEF_FLAG="-Wl,-expect_unresolved,\"*\""
269                         ;;
270                 *darwin*)
271                         LD_SHLIB_ALLOW_UNDEF_FLAG="-undefined dynamic_lookup"
272                         ;;
273                 *aix*)
274                         LD_SHLIB_ALLOW_UNDEF_FLAG="-Wl,-bnoentry"
275                         ;;
276         esac
278         AC_SUBST(LD_SHLIB_ALLOW_UNDEF_FLAG)
281 AC_DEFUN([AC_LIBREPLACE_MDLD_FLAGS],
283         AC_REQUIRE([AC_LIBREPLACE_LD_SHLIB_FLAGS])
284         AC_REQUIRE([AC_LIBREPLACE_LD_SHLIB_ALLOW_UNDEF_FLAG])
285         MDLD_FLAGS="$LD_SHLIB_FLAGS $LD_SHLIB_ALLOW_UNDEF_FLAG"
286         AC_SUBST(MDLD_FLAGS)
289 AC_DEFUN([AC_LIBREPLACE_RUNTIME_LIB_PATH_VAR],
291         case "$host_os" in
292                 *linux*)
293                         LIB_PATH_VAR=LD_LIBRARY_PATH
294                 ;;
295                 *bsd*)
296                         LIB_PATH_VAR=LD_LIBRARY_PATH
297                 ;;
298                 *solaris*)
299                         LIB_PATH_VAR=LD_LIBRARY_PATH
300                 ;;
301                 *hpux*)
302                         LIB_PATH_VAR=SHLIB_PATH
303                 ;;
304                 *osf*)
305                         LIB_PATH_VAR=LD_LIBRARY_PATH
306                 ;;
307                 *aix*)
308                         LIB_PATH_VAR=LIB_PATH
309                         ;;
310                 *irix*)
311                         LIB_PATH_VAR=LD_LIBRARY_PATH
312                         ;;
313                 *darwin*)
314                         LIB_PATH_VAR=DYLD_LIBRARY_PATH
315                         ;;
316         esac
318         AC_SUBST(LIB_PATH_VAR)