1941b876e7c5fde6845f8e745c9a489c5a965ac8
[oota-llvm.git] / autoconf / m4 / ltdl.m4
1 ## ltdl.m4 - Configure ltdl for the target system. -*-Autoconf-*-
2 ## Copyright (C) 1999-2000 Free Software Foundation, Inc.
3 ##
4 ## This program is free software; you can redistribute it and/or modify
5 ## it under the terms of the GNU General Public License as published by
6 ## the Free Software Foundation; either version 2 of the License, or
7 ## (at your option) any later version.
8 ##
9 ## This program is distributed in the hope that it will be useful, but
10 ## WITHOUT ANY WARRANTY; without even the implied warranty of
11 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 ## General Public License for more details.
13 ##
14 ## You should have received a copy of the GNU General Public License
15 ## along with this program; if not, write to the Free Software
16 ## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 ##
18 ## As a special exception to the GNU General Public License, if you
19 ## distribute this file as part of a program that contains a
20 ## configuration script generated by Autoconf, you may include it under
21 ## the same distribution terms that you use for the rest of that program.
22
23 # serial 6 AC_LIB_LTDL
24
25 # AC_WITH_LTDL
26 # ------------
27 # Clients of libltdl can use this macro to allow the installer to
28 # choose between a shipped copy of the ltdl sources or a preinstalled
29 # version of the library.
30 AC_DEFUN([AC_WITH_LTDL],
31 [AC_REQUIRE([AC_LIB_LTDL])
32 AC_SUBST([LIBLTDL])
33 AC_SUBST([INCLTDL])
34
35 # Unless the user asks us to check, assume no installed ltdl exists.
36 use_installed_libltdl=no
37
38 AC_ARG_WITH([included_ltdl],
39     [  --with-included-ltdl    use the GNU ltdl sources included here])
40
41 if test "x$with_included_ltdl" != xyes; then
42   # We are not being forced to use the included libltdl sources, so
43   # decide whether there is a useful installed version we can use.
44   AC_CHECK_HEADER([ltdl.h],
45       [AC_CHECK_LIB([ltdl], [lt_dlcaller_register],
46           [with_included_ltdl=no],
47           [with_included_ltdl=yes])
48   ])
49 fi
50
51 if test "x$enable_ltdl_install" != xyes; then
52   # If the user did not specify an installable libltdl, then default
53   # to a convenience lib.
54   AC_LIBLTDL_CONVENIENCE
55 fi
56
57 if test "x$with_included_ltdl" = xno; then
58   # If the included ltdl is not to be used. then Use the
59   # preinstalled libltdl we found.
60   AC_DEFINE([HAVE_LTDL], 1,
61     [Define this if a modern libltdl is already installed])
62   LIBLTDL=-lltdl
63 fi
64
65 # Report our decision...
66 AC_MSG_CHECKING([whether to use included libltdl])
67 AC_MSG_RESULT([$with_included_ltdl])
68
69 AC_CONFIG_SUBDIRS([libltdl])
70 ])# AC_WITH_LTDL
71
72
73 # AC_LIB_LTDL
74 # -----------
75 # Perform all the checks necessary for compilation of the ltdl objects
76 #  -- including compiler checks and header checks.
77 AC_DEFUN([AC_LIB_LTDL],
78 [AC_PREREQ(2.50)
79 AC_REQUIRE([AC_PROG_CC])
80 AC_REQUIRE([AC_C_CONST])
81 AC_REQUIRE([AC_HEADER_STDC])
82 AC_REQUIRE([AC_HEADER_DIRENT])
83 AC_REQUIRE([_LT_AC_CHECK_DLFCN])
84 AC_REQUIRE([AC_LTDL_ENABLE_INSTALL])
85 AC_REQUIRE([AC_LTDL_SHLIBEXT])
86 AC_REQUIRE([AC_LTDL_SHLIBPATH])
87 AC_REQUIRE([AC_LTDL_SYSSEARCHPATH])
88 AC_REQUIRE([AC_LTDL_OBJDIR])
89 AC_REQUIRE([AC_LTDL_DLPREOPEN])
90 AC_REQUIRE([AC_LTDL_DLLIB])
91 AC_REQUIRE([AC_LTDL_SYMBOL_USCORE])
92 AC_REQUIRE([AC_LTDL_DLSYM_USCORE])
93 AC_REQUIRE([AC_LTDL_SYS_DLOPEN_DEPLIBS])
94 AC_REQUIRE([AC_LTDL_FUNC_ARGZ])
95
96 AC_CHECK_HEADERS([assert.h ctype.h errno.h malloc.h memory.h stdlib.h \
97                   stdio.h unistd.h])
98 AC_CHECK_HEADERS([dl.h sys/dl.h dld.h mach-o/dyld.h])
99 AC_CHECK_HEADERS([string.h strings.h], [break])
100
101 AC_CHECK_FUNCS([strchr index], [break])
102 AC_CHECK_FUNCS([strrchr rindex], [break])
103 AC_CHECK_FUNCS([memcpy bcopy], [break])
104 AC_CHECK_FUNCS([memmove strcmp])
105 AC_CHECK_FUNCS([closedir opendir readdir])
106 ])# AC_LIB_LTDL
107
108
109 # AC_LTDL_ENABLE_INSTALL
110 # ----------------------
111 AC_DEFUN([AC_LTDL_ENABLE_INSTALL],
112 [AC_ARG_ENABLE([ltdl-install],
113     [AC_HELP_STRING([--enable-ltdl-install], [install libltdl])])
114
115 AM_CONDITIONAL(INSTALL_LTDL, test x"${enable_ltdl_install-no}" != xno)
116 AM_CONDITIONAL(CONVENIENCE_LTDL, test x"${enable_ltdl_convenience-no}" != xno)
117 ])])# AC_LTDL_ENABLE_INSTALL
118
119
120 # AC_LTDL_SYS_DLOPEN_DEPLIBS
121 # --------------------------
122 AC_DEFUN([AC_LTDL_SYS_DLOPEN_DEPLIBS],
123 [AC_REQUIRE([AC_CANONICAL_HOST])
124 AC_CACHE_CHECK([whether deplibs are loaded by dlopen],
125   [libltdl_cv_sys_dlopen_deplibs],
126   [# PORTME does your system automatically load deplibs for dlopen?
127   # or its logical equivalent (e.g. shl_load for HP-UX < 11)
128   # For now, we just catch OSes we know something about -- in the
129   # future, we'll try test this programmatically.
130   libltdl_cv_sys_dlopen_deplibs=unknown
131   case "$host_os" in
132   aix3*|aix4.1.*|aix4.2.*)
133     # Unknown whether this is true for these versions of AIX, but
134     # we want this `case' here to explicitly catch those versions.
135     libltdl_cv_sys_dlopen_deplibs=unknown
136     ;;
137   aix[[45]]*)
138     libltdl_cv_sys_dlopen_deplibs=yes
139     ;;
140   darwin*)
141     # Assuming the user has installed a libdl from somewhere, this is true
142     # If you are looking for one http://www.opendarwin.org/projects/dlcompat
143     libltdl_cv_sys_dlopen_deplibs=yes
144     ;;   
145   gnu* | linux* | kfreebsd*-gnu | knetbsd*-gnu)
146     # GNU and its variants, using gnu ld.so (Glibc)
147     libltdl_cv_sys_dlopen_deplibs=yes
148     ;;
149   hpux10*|hpux11*)
150     libltdl_cv_sys_dlopen_deplibs=yes
151     ;;
152   irix[[12345]]*|irix6.[[01]]*)
153     # Catch all versions of IRIX before 6.2, and indicate that we don't
154     # know how it worked for any of those versions.
155     libltdl_cv_sys_dlopen_deplibs=unknown
156     ;;
157   irix*)
158     # The case above catches anything before 6.2, and it's known that
159     # at 6.2 and later dlopen does load deplibs.
160     libltdl_cv_sys_dlopen_deplibs=yes
161     ;;
162   netbsd*)
163     libltdl_cv_sys_dlopen_deplibs=yes
164     ;;
165   openbsd*)
166     libltdl_cv_sys_dlopen_deplibs=yes
167     ;;
168   osf[[1234]]*)
169     # dlopen did load deplibs (at least at 4.x), but until the 5.x series,
170     # it did *not* use an RPATH in a shared library to find objects the
171     # library depends on, so we explictly say `no'.
172     libltdl_cv_sys_dlopen_deplibs=no
173     ;;
174   osf5.0|osf5.0a|osf5.1)
175     # dlopen *does* load deplibs and with the right loader patch applied
176     # it even uses RPATH in a shared library to search for shared objects
177     # that the library depends on, but there's no easy way to know if that
178     # patch is installed.  Since this is the case, all we can really
179     # say is unknown -- it depends on the patch being installed.  If
180     # it is, this changes to `yes'.  Without it, it would be `no'.
181     libltdl_cv_sys_dlopen_deplibs=unknown
182     ;;
183   osf*)
184     # the two cases above should catch all versions of osf <= 5.1.  Read
185     # the comments above for what we know about them.
186     # At > 5.1, deplibs are loaded *and* any RPATH in a shared library
187     # is used to find them so we can finally say `yes'.
188     libltdl_cv_sys_dlopen_deplibs=yes
189     ;;
190   solaris*)
191     libltdl_cv_sys_dlopen_deplibs=yes
192     ;;
193   esac
194   ])
195 if test "$libltdl_cv_sys_dlopen_deplibs" != yes; then
196  AC_DEFINE([LTDL_DLOPEN_DEPLIBS], [1],
197     [Define if the OS needs help to load dependent libraries for dlopen().])
198 fi
199 ])# AC_LTDL_SYS_DLOPEN_DEPLIBS
200
201
202 # AC_LTDL_SHLIBEXT
203 # ----------------
204 AC_DEFUN([AC_LTDL_SHLIBEXT],
205 [AC_REQUIRE([AC_LIBTOOL_SYS_DYNAMIC_LINKER])
206 AC_CACHE_CHECK([which extension is used for loadable modules],
207   [libltdl_cv_shlibext],
208 [
209 module=yes
210 eval libltdl_cv_shlibext=$shrext_cmds
211   ])
212 if test -n "$libltdl_cv_shlibext"; then
213   AC_DEFINE_UNQUOTED(LTDL_SHLIB_EXT, "$libltdl_cv_shlibext",
214     [Define to the extension used for shared libraries, say, ".so".])
215 fi
216 ])# AC_LTDL_SHLIBEXT
217
218
219 # AC_LTDL_SHLIBPATH
220 # -----------------
221 AC_DEFUN([AC_LTDL_SHLIBPATH],
222 [AC_REQUIRE([AC_LIBTOOL_SYS_DYNAMIC_LINKER])
223 AC_CACHE_CHECK([which variable specifies run-time library path],
224   [libltdl_cv_shlibpath_var], [libltdl_cv_shlibpath_var="$shlibpath_var"])
225 if test -n "$libltdl_cv_shlibpath_var"; then
226   AC_DEFINE_UNQUOTED(LTDL_SHLIBPATH_VAR, "$libltdl_cv_shlibpath_var",
227     [Define to the name of the environment variable that determines the dynamic library search path.])
228 fi
229 ])# AC_LTDL_SHLIBPATH
230
231
232 # AC_LTDL_SYSSEARCHPATH
233 # ---------------------
234 AC_DEFUN([AC_LTDL_SYSSEARCHPATH],
235 [AC_REQUIRE([AC_LIBTOOL_SYS_DYNAMIC_LINKER])
236 AC_CACHE_CHECK([for the default library search path],
237   [libltdl_cv_sys_search_path],
238   [libltdl_cv_sys_search_path="$sys_lib_dlsearch_path_spec"])
239 if test -n "$libltdl_cv_sys_search_path"; then
240   sys_search_path=
241   for dir in $libltdl_cv_sys_search_path; do
242     if test -z "$sys_search_path"; then
243       sys_search_path="$dir"
244     else
245       sys_search_path="$sys_search_path$PATH_SEPARATOR$dir"
246     fi
247   done
248   AC_DEFINE_UNQUOTED(LTDL_SYSSEARCHPATH, "$sys_search_path",
249     [Define to the system default library search path.])
250 fi
251 ])# AC_LTDL_SYSSEARCHPATH
252
253
254 # AC_LTDL_OBJDIR
255 # --------------
256 AC_DEFUN([AC_LTDL_OBJDIR],
257 [AC_CACHE_CHECK([for objdir],
258   [libltdl_cv_objdir],
259   [libltdl_cv_objdir="$objdir"
260   if test -n "$objdir"; then
261     :
262   else
263     rm -f .libs 2>/dev/null
264     mkdir .libs 2>/dev/null
265     if test -d .libs; then
266       libltdl_cv_objdir=.libs
267     else
268       # MS-DOS does not allow filenames that begin with a dot.
269       libltdl_cv_objdir=_libs
270     fi
271   rmdir .libs 2>/dev/null
272   fi
273   ])
274 AC_DEFINE_UNQUOTED(LTDL_OBJDIR, "$libltdl_cv_objdir/",
275   [Define to the sub-directory in which libtool stores uninstalled libraries.])
276 ])# AC_LTDL_OBJDIR
277
278
279 # AC_LTDL_DLPREOPEN
280 # -----------------
281 AC_DEFUN([AC_LTDL_DLPREOPEN],
282 [AC_REQUIRE([AC_LIBTOOL_SYS_GLOBAL_SYMBOL_PIPE])
283 AC_CACHE_CHECK([whether libtool supports -dlopen/-dlpreopen],
284   [libltdl_cv_preloaded_symbols],
285   [if test -n "$lt_cv_sys_global_symbol_pipe"; then
286     libltdl_cv_preloaded_symbols=yes
287   else
288     libltdl_cv_preloaded_symbols=no
289   fi
290   ])
291 if test x"$libltdl_cv_preloaded_symbols" = xyes; then
292   AC_DEFINE(HAVE_PRELOADED_SYMBOLS, 1,
293     [Define if libtool can extract symbol lists from object files.])
294 fi
295 ])# AC_LTDL_DLPREOPEN
296
297
298 # AC_LTDL_DLLIB
299 # -------------
300 AC_DEFUN([AC_LTDL_DLLIB],
301 [LIBADD_DL=
302 AC_SUBST(LIBADD_DL)
303 AC_LANG_PUSH([C])
304
305 AC_CHECK_FUNC([shl_load],
306       [AC_DEFINE([HAVE_SHL_LOAD], [1],
307                  [Define if you have the shl_load function.])],
308   [AC_CHECK_LIB([dld], [shl_load],
309         [AC_DEFINE([HAVE_SHL_LOAD], [1],
310                    [Define if you have the shl_load function.])
311         LIBADD_DL="$LIBADD_DL -ldld"],
312     [AC_CHECK_LIB([dl], [dlopen],
313           [AC_DEFINE([HAVE_LIBDL], [1],
314                      [Define if you have the libdl library or equivalent.])
315                 LIBADD_DL="-ldl" libltdl_cv_lib_dl_dlopen="yes"],
316       [AC_TRY_LINK([#if HAVE_DLFCN_H
317 #  include <dlfcn.h>
318 #endif
319       ],
320         [dlopen(0, 0);],
321             [AC_DEFINE([HAVE_LIBDL], [1],
322                              [Define if you have the libdl library or equivalent.]) libltdl_cv_func_dlopen="yes"],
323         [AC_CHECK_LIB([svld], [dlopen],
324               [AC_DEFINE([HAVE_LIBDL], [1],
325                          [Define if you have the libdl library or equivalent.])
326                     LIBADD_DL="-lsvld" libltdl_cv_func_dlopen="yes"],
327           [AC_CHECK_LIB([dld], [dld_link],
328                 [AC_DEFINE([HAVE_DLD], [1],
329                            [Define if you have the GNU dld library.])
330                 LIBADD_DL="$LIBADD_DL -ldld"],
331                 [AC_CHECK_FUNC([_dyld_func_lookup],
332                        [AC_DEFINE([HAVE_DYLD], [1],
333                           [Define if you have the _dyld_func_lookup function.])])
334           ])
335         ])
336       ])
337     ])
338   ])
339 ])
340
341 if test x"$libltdl_cv_func_dlopen" = xyes || test x"$libltdl_cv_lib_dl_dlopen" = xyes
342 then
343   lt_save_LIBS="$LIBS"
344   LIBS="$LIBS $LIBADD_DL"
345   AC_CHECK_FUNCS([dlerror])
346   LIBS="$lt_save_LIBS"
347 fi
348 AC_LANG_POP
349 ])# AC_LTDL_DLLIB
350
351
352 # AC_LTDL_SYMBOL_USCORE
353 # ---------------------
354 # does the compiler prefix global symbols with an underscore?
355 AC_DEFUN([AC_LTDL_SYMBOL_USCORE],
356 [AC_REQUIRE([AC_LIBTOOL_SYS_GLOBAL_SYMBOL_PIPE])
357 AC_CACHE_CHECK([for _ prefix in compiled symbols],
358   [ac_cv_sys_symbol_underscore],
359   [ac_cv_sys_symbol_underscore=no
360   cat > conftest.$ac_ext <<EOF
361 void nm_test_func(){}
362 int main(){nm_test_func;return 0;}
363 EOF
364   if AC_TRY_EVAL(ac_compile); then
365     # Now try to grab the symbols.
366     ac_nlist=conftest.nm
367     if AC_TRY_EVAL(NM conftest.$ac_objext \| $lt_cv_sys_global_symbol_pipe \> $ac_nlist) && test -s "$ac_nlist"; then
368       # See whether the symbols have a leading underscore.
369       if grep '^. _nm_test_func' "$ac_nlist" >/dev/null; then
370         ac_cv_sys_symbol_underscore=yes
371       else
372         if grep '^. nm_test_func ' "$ac_nlist" >/dev/null; then
373           :
374         else
375           echo "configure: cannot find nm_test_func in $ac_nlist" >&AC_FD_CC
376         fi
377       fi
378     else
379       echo "configure: cannot run $lt_cv_sys_global_symbol_pipe" >&AC_FD_CC
380     fi
381   else
382     echo "configure: failed program was:" >&AC_FD_CC
383     cat conftest.c >&AC_FD_CC
384   fi
385   rm -rf conftest*
386   ])
387 ])# AC_LTDL_SYMBOL_USCORE
388
389
390 # AC_LTDL_DLSYM_USCORE
391 # --------------------
392 AC_DEFUN([AC_LTDL_DLSYM_USCORE],
393 [AC_REQUIRE([AC_LTDL_SYMBOL_USCORE])
394 if test x"$ac_cv_sys_symbol_underscore" = xyes; then
395   if test x"$libltdl_cv_func_dlopen" = xyes ||
396      test x"$libltdl_cv_lib_dl_dlopen" = xyes ; then
397         AC_CACHE_CHECK([whether we have to add an underscore for dlsym],
398           [libltdl_cv_need_uscore],
399           [libltdl_cv_need_uscore=unknown
400           save_LIBS="$LIBS"
401           LIBS="$LIBS $LIBADD_DL"
402           _LT_AC_TRY_DLOPEN_SELF(
403             [libltdl_cv_need_uscore=no], [libltdl_cv_need_uscore=yes],
404             [],                          [libltdl_cv_need_uscore=cross])
405           LIBS="$save_LIBS"
406         ])
407   fi
408 fi
409
410 if test x"$libltdl_cv_need_uscore" = xyes; then
411   AC_DEFINE(NEED_USCORE, 1,
412     [Define if dlsym() requires a leading underscore in symbol names.])
413 fi
414 ])# AC_LTDL_DLSYM_USCORE
415
416 # AC_LTDL_FUNC_ARGZ
417 # -----------------
418 AC_DEFUN([AC_LTDL_FUNC_ARGZ],
419 [AC_CHECK_HEADERS([argz.h])
420
421 AC_CHECK_TYPES([error_t],
422   [],
423   [AC_DEFINE([error_t], [int],
424     [Define to a type to use for `error_t' if it is not otherwise available.])],
425   [#if HAVE_ARGZ_H
426 #  include <argz.h>
427 #endif])
428
429 AC_CHECK_FUNCS([argz_append argz_create_sep argz_insert argz_next argz_stringify])
430 ])# AC_LTDL_FUNC_ARGZ