2cf4149e2f3a0b600407000089745a6e5a50cfc8
[freeradius.git] / libltdl / configure.in
1 dnl Process this file with autoconf to create configure.
2
3 AC_INIT(ltdl.c)
4
5 if test -z "$enable_ltdl_install$enable_ltdl_convenience"; then
6   if test -f ${srcdir}/ltconfig && test -f ${srcdir}/ltmain.sh; then
7     # if libltdl is libtoolized, it is assumed to be stand-alone and
8     # installed unless the command line overrides it (tested above)
9     enable_ltdl_install=yes
10   else
11     AC_MSG_WARN([*** The top-level configure must select either])
12     AC_MSG_WARN([*** [A""C_LIBLTDL_INSTALLABLE] or [A""C_LIBLTDL_CONVENIENCE].])
13     AC_MSG_ERROR([*** Maybe you want to --enable-ltdl-install?])
14   fi
15 fi
16
17 AM_INIT_AUTOMAKE(libltdl,1.0,-)
18 AM_CONFIG_HEADER(config.h)
19 AM_MAINTAINER_MODE
20
21 AC_PROG_CC
22 AC_C_CONST
23 AC_C_INLINE
24 AM_PROG_LIBTOOL
25 AC_SUBST(LIBTOOL_DEPS)
26
27 AC_ARG_ENABLE(ltdl-install,
28 [  --enable-ltdl-install   install libltdl])
29
30 AM_CONDITIONAL(INSTALL_LTDL, test x"${enable_ltdl_install-no}" != xno)
31 AM_CONDITIONAL(CONVENIENCE_LTDL, test x"${enable_ltdl_convenience-no}" != xno)
32
33 dnl Read the libtool configuration
34 rm -f conftest
35 ./libtool --config > conftest
36 . ./conftest
37 rm -f conftest
38
39 AC_CACHE_CHECK([which extension is used for shared libraries],
40   libltdl_cv_shlibext, [dnl
41 (
42   last=
43   for spec in $library_names_spec; do
44     last="$spec"
45   done
46 changequote(, )
47   echo "$last" | sed 's/\[.*\]//;s/^[^.]*//;s/\$.*$//;s/\.$//' > conftest
48 changequote([, ])
49 )
50 libltdl_cv_shlibext=`cat conftest`
51 rm -f conftest
52 ])
53 if test -n "$libltdl_cv_shlibext"; then
54   AC_DEFINE_UNQUOTED(LTDL_SHLIB_EXT, "$libltdl_cv_shlibext",
55     [Define to the extension used for shared libraries, say, ".so". ])
56 fi
57
58 AC_CACHE_CHECK([which variable specifies run-time library path],
59   libltdl_cv_shlibpath_var, [libltdl_cv_shlibpath_var="$shlibpath_var"])
60 if test -n "$libltdl_cv_shlibpath_var"; then
61   AC_DEFINE_UNQUOTED(LTDL_SHLIBPATH_VAR, "$libltdl_cv_shlibpath_var",
62     [Define to the name of the environment variable that determines the dynamic library search path. ])
63 fi
64
65 AC_CACHE_CHECK([for objdir],
66   libltdl_cv_objdir, [libltdl_cv_objdir="$objdir"])
67 test -z "$libltdl_cv_objdir" && libltdl_cv_objdir=".libs"
68 AC_DEFINE_UNQUOTED(LTDL_OBJDIR, "$libltdl_cv_objdir/",
69   [Define to the sub-directory in which libtool stores uninstalled libraries. ])
70
71 AC_HEADER_STDC
72 AC_CHECK_HEADERS(malloc.h memory.h stdlib.h stdio.h ctype.h dlfcn.h dl.h dld.h)
73 AC_CHECK_HEADERS(string.h strings.h, break)
74 AC_CHECK_FUNCS(strchr index, break)
75 AC_CHECK_FUNCS(strrchr rindex, break)
76
77 AC_CACHE_CHECK([whether libtool supports -dlopen/-dlpreopen],
78        libltdl_cv_preloaded_symbols, [dnl
79   if test -n "$global_symbol_pipe"; then
80     libltdl_cv_preloaded_symbols=yes
81   else
82     libltdl_cv_preloaded_symbols=no
83   fi
84 ])
85 if test x"$libltdl_cv_preloaded_symbols" = x"yes"; then
86   AC_DEFINE(HAVE_PRELOADED_SYMBOLS, 1,
87     [Define if libtool can extract symbol lists from object files. ])
88 fi
89
90 LIBADD_DL=
91 AC_CHECK_LIB(dl, dlopen, [AC_DEFINE(HAVE_LIBDL, 1) LIBADD_DL="-ldl"],
92 [AC_CHECK_FUNC(dlopen, [AC_DEFINE(HAVE_LIBDL, 1)])])
93 AC_CHECK_FUNC(shl_load, [AC_DEFINE(HAVE_SHL_LOAD, 1)],
94 [AC_CHECK_LIB(dld, shl_load, [AC_DEFINE(HAVE_SHL_LOAD, 1) LIBADD_DL="$LIBADD_DL -ldld"])])
95 AC_CHECK_LIB(dld, dld_link, [AC_DEFINE(HAVE_DLD, 1)dnl
96 test "x$ac_cv_lib_dld_shl_load" = yes || LIBADD_DL="$LIBADD_DL -ldld"])
97 AC_SUBST(LIBADD_DL)
98
99 if test "x$ac_cv_func_dlopen" = xyes || test "x$ac_cv_lib_dl_dlopen" = xyes; then
100  LIBS_SAVE="$LIBS"
101  LIBS="$LIBS $LIBADD_DL"
102  AC_CHECK_FUNCS(dlerror)
103  LIBS="$LIBS_SAVE"
104 fi
105
106 dnl Check for command to grab the raw symbol name followed
107 dnl by C symbol name from nm.
108 AC_REQUIRE([AC_CANONICAL_HOST])dnl
109 AC_REQUIRE([AC_PROG_NM])dnl
110 # Check for command to grab the raw symbol name followed by C symbol from nm.
111 AC_MSG_CHECKING([command to parse $NM output])
112 AC_CACHE_VAL(ac_cv_sys_global_symbol_pipe,
113 [# These are sane defaults that work on at least a few old systems.
114 # {They come from Ultrix.  What could be older than Ultrix?!! ;)}
115
116 changequote(,)dnl
117 # Character class describing NM global symbol codes.
118 ac_symcode='[BCDEGRST]'
119
120 # Regexp to match symbols that can be accessed directly from C.
121 ac_sympat='\([_A-Za-z][_A-Za-z0-9]*\)'
122
123 # Transform the above into a raw symbol and a C symbol.
124 ac_symxfrm='\1 \2\3 \3'
125
126 # Transform an extracted symbol line into a proper C declaration
127 ac_global_symbol_to_cdecl="sed -n -e 's/^. .* \(.*\)$/extern char \1;/p'"
128
129 # Define system-specific variables.
130 case "$host_os" in
131 aix*)
132   ac_symcode='[BCDT]'
133   ;;
134 cygwin* | mingw*)
135   ac_symcode='[ABCDGISTW]'
136   ;;
137 hpux*)
138   ac_global_symbol_to_cdecl="sed -n -e 's/^T .* \(.*\)$/extern char \1();/p' -e 's/^. .* \(.*\)$/extern char \1;/p'"
139   ;;
140 irix*)
141   ac_symcode='[BCDEGRST]'
142   ;;
143 solaris*)
144   ac_symcode='[BDT]'
145   ;;
146 esac
147
148 # If we're using GNU nm, then use its standard symbol codes.
149 if $NM -V 2>&1 | egrep '(GNU|with BFD)' > /dev/null; then
150   ac_symcode='[ABCDGISTW]'
151 fi
152 changequote([,])dnl
153
154 # Try without a prefix undercore, then with it.
155 for ac_symprfx in "" "_"; do
156
157   ac_cv_sys_global_symbol_pipe="sed -n -e 's/^.*[       ]\($ac_symcode\)[       ][      ]*\($ac_symprfx\)$ac_sympat$/$ac_symxfrm/p'"
158
159   # Check to see that the pipe works correctly.
160   ac_pipe_works=no
161   rm -f conftest.$ac_ext
162   cat > conftest.$ac_ext <<EOF
163 #ifdef __cplusplus
164 extern "C" {
165 #endif
166 char nm_test_var;
167 void nm_test_func(){}
168 #ifdef __cplusplus
169 }
170 #endif
171 int main(){nm_test_var='a';nm_test_func;return 0;}
172 EOF
173
174   if AC_TRY_EVAL(ac_compile); then
175     # Now try to grab the symbols.
176     ac_nlist=conftest.nm
177   
178     if AC_TRY_EVAL(NM conftest.$ac_objext \| $ac_cv_sys_global_symbol_pipe \> $ac_nlist) && test -s "$ac_nlist"; then
179
180       # Try sorting and uniquifying the output.
181       if sort "$ac_nlist" | uniq > "$ac_nlist"T; then
182         mv -f "$ac_nlist"T "$ac_nlist"
183       else
184         rm -f "$ac_nlist"T
185       fi
186
187       # Make sure that we snagged all the symbols we need.
188       if egrep ' nm_test_var$' "$ac_nlist" >/dev/null; then
189         if egrep ' nm_test_func$' "$ac_nlist" >/dev/null; then
190           cat <<EOF > conftest.c
191 #ifdef __cplusplus
192 extern "C" {
193 #endif
194
195 EOF
196           # Now generate the symbol file.
197           eval "$ac_global_symbol_to_cdecl"' < "$ac_nlist" >> conftest.c'
198
199           cat <<EOF >> conftest.c
200 #if defined (__STDC__) && __STDC__
201 # define lt_ptr_t void *
202 #else
203 # define lt_ptr_t char *
204 # define const
205 #endif
206
207 /* The mapping between symbol names and symbols. */
208 const struct {
209   const char *name;
210   lt_ptr_t address;
211 }
212 changequote(,)dnl
213 lt_preloaded_symbols[] =
214 changequote([,])dnl
215 {
216 EOF
217         sed 's/^. \(.*\) \(.*\)$/  {"\2", (lt_ptr_t) \&\2},/' < "$ac_nlist" >> conftest.c
218         cat <<\EOF >> conftest.c
219   {0, (lt_ptr_t) 0}
220 };
221
222 #ifdef __cplusplus
223 }
224 #endif
225 EOF
226           # Now try linking the two files.
227           mv conftest.$ac_objext conftstm.$ac_objext
228           ac_save_LIBS="$LIBS"
229           ac_save_CFLAGS="$CFLAGS"
230           LIBS="conftstm.$ac_objext"
231           CFLAGS="$CFLAGS$no_builtin_flag"
232           if AC_TRY_EVAL(ac_link) && test -s conftest; then
233             ac_pipe_works=yes
234           else
235             echo "configure: failed program was:" >&AC_FD_CC
236             cat conftest.c >&AC_FD_CC
237           fi
238           LIBS="$ac_save_LIBS"
239           CFLAGS="$ac_save_CFLAGS"
240         else
241           echo "cannot find nm_test_func in $ac_nlist" >&AC_FD_CC
242         fi
243       else
244         echo "cannot find nm_test_var in $ac_nlist" >&AC_FD_CC
245       fi
246     else
247       echo "cannot run $ac_cv_sys_global_symbol_pipe" >&AC_FD_CC
248     fi
249   else
250     echo "$progname: failed program was:" >&AC_FD_CC
251     cat conftest.c >&AC_FD_CC
252   fi
253   rm -rf conftest* conftst*
254
255   # Do not use the global_symbol_pipe unless it works.
256   if test "$ac_pipe_works" = yes; then
257     if test x"$ac_symprfx" = x"_"; then
258       ac_cv_sys_symbol_underscore=yes
259     else
260       ac_cv_sys_symbol_underscore=no
261     fi
262     break
263   else
264     ac_cv_sys_global_symbol_pipe=
265   fi
266 done
267 ])
268
269 ac_result=yes
270 if test -z "$ac_cv_sys_global_symbol_pipe"; then
271    ac_result=no
272 fi
273 AC_MSG_RESULT($ac_result)
274
275 dnl does the compiler prefix global symbols with an underscore?
276 AC_MSG_CHECKING([for _ prefix in compiled symbols])
277 AC_CACHE_VAL(ac_cv_sys_symbol_underscore,
278 [ac_cv_sys_symbol_underscore=no
279 cat > conftest.$ac_ext <<EOF
280 void nm_test_func(){}
281 int main(){nm_test_func;return 0;}
282 EOF
283 if AC_TRY_EVAL(ac_compile); then
284   # Now try to grab the symbols.
285   ac_nlist=conftest.nm
286   if AC_TRY_EVAL(NM conftest.$ac_objext \| $ac_cv_sys_global_symbol_pipe \> $ac_nlist) && test -s "$ac_nlist"; then
287     # See whether the symbols have a leading underscore.
288     if egrep '^. _nm_test_func' "$ac_nlist" >/dev/null; then
289       ac_cv_sys_symbol_underscore=yes
290     else
291       if egrep '^. nm_test_func ' "$ac_nlist" >/dev/null; then
292         :
293       else
294         echo "configure: cannot find nm_test_func in $ac_nlist" >&AC_FD_CC
295       fi
296     fi
297   else
298     echo "configure: cannot run $ac_cv_sys_global_symbol_pipe" >&AC_FD_CC
299   fi
300 else
301   echo "configure: failed program was:" >&AC_FD_CC
302   cat conftest.c >&AC_FD_CC
303 fi
304 rm -rf conftest*
305 ])
306 AC_MSG_RESULT($ac_cv_sys_symbol_underscore)
307
308 if test x"$ac_cv_sys_symbol_underscore" = xyes; then
309   if test x"$ac_cv_func_dlopen" = xyes ||
310      test x"$ac_cv_lib_dl_dlopen" = xyes ; then
311         AC_CACHE_CHECK([whether we have to add an underscore for dlsym],
312                 libltdl_cv_need_uscore, [dnl
313                 AC_TRY_RUN([
314 #if HAVE_DLFCN_H
315 #include <dlfcn.h>
316 #endif
317
318 #include <stdio.h>
319
320 #ifdef RTLD_GLOBAL
321 # define LTDL_GLOBAL    RTLD_GLOBAL
322 #else
323 # ifdef DL_GLOBAL
324 #  define LTDL_GLOBAL   DL_GLOBAL
325 # else
326 #  define LTDL_GLOBAL   0
327 # endif
328 #endif
329
330 /* We may have to define LTDL_LAZY_OR_NOW in the command line if we
331    find out it does not work in some platform. */
332 #ifndef LTDL_LAZY_OR_NOW
333 # ifdef RTLD_LAZY
334 #  define LTDL_LAZY_OR_NOW      RTLD_LAZY
335 # else
336 #  ifdef DL_LAZY
337 #   define LTDL_LAZY_OR_NOW     DL_LAZY
338 #  else
339 #   ifdef RTLD_NOW
340 #    define LTDL_LAZY_OR_NOW    RTLD_NOW
341 #   else
342 #    ifdef DL_NOW
343 #     define LTDL_LAZY_OR_NOW   DL_NOW
344 #    else
345 #     define LTDL_LAZY_OR_NOW   0
346 #    endif
347 #   endif
348 #  endif
349 # endif
350 #endif
351
352 fnord() { int i=42;}
353 main() { void *self, *ptr1, *ptr2; self=dlopen(0,LTDL_GLOBAL|LTDL_LAZY_OR_NOW);
354     if(self) { ptr1=dlsym(self,"fnord"); ptr2=dlsym(self,"_fnord");
355                if(ptr1 && !ptr2) { dlclose(self); exit(0); } } exit(1); } 
356 ],      libltdl_cv_need_uscore=no, libltdl_cv_need_uscore=yes,
357         libltdl_cv_need_uscore=cross
358 )])
359   fi
360 fi
361
362 if test x"$libltdl_cv_need_uscore" = xyes; then
363   AC_DEFINE(NEED_USCORE, 1,
364     [Define if dlsym() requires a leading underscode in symbol names. ])
365 fi
366
367 dnl Output the makefile
368 AC_OUTPUT(Makefile)
369
370 # Local Variables:
371 # mode:shell-script
372 # sh-indentation:2
373 # End: