s3-aio_pthread: Optimize aio_pthread_handle_completion
[Samba.git] / lib / replace / libreplace_ld.m4
blobbf0df6186dd9894773d3b654e747006fb15b509c
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*|*gnu*)
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 "${GCC}" = "yes"; then
75                         PICFLAG="-fPIC"
76                 elif test "$host_cpu" = "ia64"; then
77                         PICFLAG="+z"
78                 elif test $ac_cv_prog_cc_Ae = yes; then
79                         PICFLAG="+z +ESnolit"
80                 fi
81                 ;;
82         *osf*)
83                 PICFLAG="-fPIC"
84                 ;;
85         *unixware*)
86                 PICFLAG="-KPIC"
87                 ;;
88         *darwin*)
89                 PICFLAG="-fno-common"
90                 ;;
91 esac
92 AC_SUBST(PICFLAG)
95 AC_DEFUN([AC_LIBREPLACE_LD_SHLIB_LINKER],
97         LD_SHLIB_LINKER="${CC}"
99         case "$host_os" in
100                 *irix*)
101                         LD_SHLIB_LINKER="${PROG_LD}"
102                         ;;
103         esac
105         AC_SUBST(LD_SHLIB_LINKER)
108 AC_DEFUN([AC_LIBREPLACE_LD_SHLIB_FLAGS],
110         LD_SHLIB_FLAGS="-shared"
112         case "$host_os" in
113                 *linux*|*gnu*)
114                         LD_SHLIB_FLAGS="-shared -Wl,-Bsymbolic"
115                         ;;
116                 *solaris*)
117                         LD_SHLIB_FLAGS="-G"
118                         if test "${GCC}" = "no"; then
119                                 ## ${CFLAGS} added for building 64-bit shared 
120                                 ## libs using Sun's Compiler
121                                 LD_SHLIB_FLAGS="-G \${CFLAGS}"
122                         fi
123                         ;;
124                 *sunos*)
125                         LD_SHLIB_FLAGS="-G"
126                         ;;
127                 *irix*)
128                         LD_SHLIB_FLAGS="-shared"
129                         ;;
130                 *aix*)
131                         LD_SHLIB_FLAGS="-Wl,-G,-bexpall,-bbigtoc"
132                         ;;
133                 *hpux*)
134                         if test "${GCC}" = "yes"; then
135                                 LD_SHLIB_FLAGS="-shared"
136                         else
137                                 LD_SHLIB_FLAGS="-b"
138                         fi
139                         ;;
140                 *osf*)
141                         LD_SHLIB_FLAGS="-shared"
142                         ;;
143                 *darwin*)
144                         LD_SHLIB_FLAGS="-dynamiclib -Wl,-search_paths_first"
145                         ;;
146         esac
148         AC_SUBST(LD_SHLIB_FLAGS)
151 AC_DEFUN([AC_LIBREPLACE_LD_SHLIB_DISALLOW_UNDEF_FLAG],
153         LD_SHLIB_DISALLOW_UNDEF_FLAG=""
155         #
156         # TODO: enforce error not only warnings
157         #
158         # NOTE: -Wl,--no-allow-shlib-undefined isn't what we want...
159         #       as it bails out on broken system libraries
160         #
161         case "$host_os" in
162                 *osf*)
163                         LD_SHLIB_DISALLOW_UNDEF_FLAG="-warning_unresolved"
164                         ;;
165                 *darwin*)
166                         LD_SHLIB_DISALLOW_UNDEF_FLAG="-undefined error"
167                         ;;
168         esac
170         AC_SUBST(LD_SHLIB_DISALLOW_UNDEF_FLAG)
173 AC_DEFUN([AC_LIBREPLACE_SHLD],
175         AC_REQUIRE([AC_LIBREPLACE_LD_SHLIB_LINKER])
176         SHLD="$LD_SHLIB_LINKER"
177         AC_SUBST(SHLD)
180 AC_DEFUN([AC_LIBREPLACE_SHLD_FLAGS],
182         AC_REQUIRE([AC_LIBREPLACE_LD_SHLIB_FLAGS])
183         AC_REQUIRE([AC_LIBREPLACE_LD_SHLIB_DISALLOW_UNDEF_FLAG])
184         SHLD_FLAGS="$LD_SHLIB_FLAGS $LD_SHLIB_DISALLOW_UNDEF_FLAG"
185         AC_SUBST(SHLD_FLAGS)
188 AC_DEFUN([AC_LD_SHLIBEXT],
190         SHLIBEXT="so"
191         case "$host_os" in
192                 *hpux*)
193                         if test "$host_cpu" = "ia64"; then
194                                 SHLIBEXT="so"
195                         else
196                                 SHLIBEXT="sl"
197                         fi
198                 ;;
199                 *darwin*)
200                         SHLIBEXT="dylib"
201                 ;;
202         esac
203         AC_SUBST(SHLIBEXT)
206 AC_DEFUN([AC_LD_SONAMEFLAG],
208         AC_SUBST(SONAMEFLAG)
209         SONAMEFLAG=""
210         case "$host_os" in 
211                 *linux*|*gnu*|*qnx*)
212                         SONAMEFLAG="-Wl,-soname="
213                         ;;
214                 *solaris*)
215                         SONAMEFLAG="-h "
216                         if test "${GCC}" = "yes"; then
217                                 SONAMEFLAG="-Wl,-soname="
218                         fi
219                         ;;
220                 *sunos*)
221                         SONAMEFLAG="-Wl,-h,"
222                         ;;
223                 *netbsd* | *freebsd* | *dragonfly* )
224                         SONAMEFLAG="-Wl,-soname,"
225                         ;;
226                 *openbsd*)
227                         SONAMEFLAG="-Wl,-soname,"
228                         ;;
229                 *irix*)
230                         SONAMEFLAG="-Wl,-soname,"
231                         ;;
232                 *hpux*)
233                         SONAMEFLAG="-Wl,+h,"
234                         ;;
235                 *osf*)
236                         SONAMEFLAG="-Wl,-soname,"
237                         ;;
238                 *unixware*)
239                         SONAMEFLAG="-Wl,-soname,"
240                         ;;
241                 *darwin*)
242                         SONAMEFLAG="#"
243                         ;;
244                 *aix*)
245                         # Not supported
246                         SONAMEFLAG="#"
247                         ;;
248                 esac
251 AC_DEFUN([AC_LD_VERSIONSCRIPT],
253         AC_SUBST(VERSIONSCRIPT)
254         VERSIONSCRIPT=""
255         case "$host_os" in 
256                 *linux*|*gnu*)
257                         VERSIONSCRIPT="-Wl,--version-script"
258                         ;;
259                 *solaris*)
260                         if test "${GCC}" = "yes"; then
261                                 VERSIONSCRIPT="-Wl,--version-script"
262                         fi
263                         ;;
264                 esac
267 AC_DEFUN([AC_LIBREPLACE_MDLD],
269         AC_REQUIRE([AC_LIBREPLACE_LD_SHLIB_LINKER])
270         MDLD="$LD_SHLIB_LINKER"
271         AC_SUBST(MDLD)
274 AC_DEFUN([AC_LIBREPLACE_LD_SHLIB_ALLOW_UNDEF_FLAG],
276         LD_ALLOW_SHLIB_UNDEF_FLAG=""
278         case "$host_os" in
279                 *linux*|*gnu*)
280                         LD_SHLIB_ALLOW_UNDEF_FLAG="-Wl,--allow-shlib-undefined"
281                         ;;
282                 *osf*)
283                         LD_SHLIB_ALLOW_UNDEF_FLAG="-Wl,-expect_unresolved,\"*\""
284                         ;;
285                 *darwin*)
286                         LD_SHLIB_ALLOW_UNDEF_FLAG="-undefined dynamic_lookup"
287                         ;;
288                 *aix*)
289                         LD_SHLIB_ALLOW_UNDEF_FLAG="-Wl,-bnoentry"
290                         ;;
291         esac
293         AC_SUBST(LD_SHLIB_ALLOW_UNDEF_FLAG)
296 AC_DEFUN([AC_LIBREPLACE_MDLD_FLAGS],
298         AC_REQUIRE([AC_LIBREPLACE_LD_SHLIB_FLAGS])
299         AC_REQUIRE([AC_LIBREPLACE_LD_SHLIB_ALLOW_UNDEF_FLAG])
300         MDLD_FLAGS="$LD_SHLIB_FLAGS $LD_SHLIB_ALLOW_UNDEF_FLAG"
301         AC_SUBST(MDLD_FLAGS)
304 AC_DEFUN([AC_LIBREPLACE_RUNTIME_LIB_PATH_VAR],
306         case "$host_os" in
307                 *linux*|*gnu*)
308                         LIB_PATH_VAR=LD_LIBRARY_PATH
309                 ;;
310                 *bsd*)
311                         LIB_PATH_VAR=LD_LIBRARY_PATH
312                 ;;
313                 *solaris*)
314                         LIB_PATH_VAR=LD_LIBRARY_PATH
315                 ;;
316                 *hpux*)
317                         LIB_PATH_VAR=SHLIB_PATH
318                 ;;
319                 *osf*)
320                         LIB_PATH_VAR=LD_LIBRARY_PATH
321                 ;;
322                 *aix*)
323                         LIB_PATH_VAR=LIBPATH
324                         ;;
325                 *irix*)
326                         LIB_PATH_VAR=LD_LIBRARY_PATH
327                         ;;
328                 *darwin*)
329                         LIB_PATH_VAR=DYLD_LIBRARY_PATH
330                         ;;
331                 *)
332                         LIB_PATH_VAR=LD_LIBRARY_PATH
333                         ;;
334         esac
336         AC_SUBST(LIB_PATH_VAR)