Replace hardcoded -ldl with check for availability
[deliverable/binutils-gdb.git] / gdb / acinclude.m4
1 dnl written by Rob Savoye <rob@cygnus.com> for Cygnus Support
2 dnl major rewriting for Tcl 7.5 by Don Libes <libes@nist.gov>
3
4 # Keep these includes in sync with the aclocal_m4_deps list in
5 # Makefile.in.
6
7 sinclude(acx_configure_dir.m4)
8
9 dnl gdb/configure.in uses BFD_NEED_DECLARATION, so get its definition.
10 sinclude(../bfd/bfd.m4)
11
12 dnl This gets the standard macros.
13 sinclude(../config/acinclude.m4)
14
15 dnl This gets AC_PLUGINS, needed by ACX_LARGEFILE.
16 sinclude(../config/plugins.m4)
17
18 dnl For ACX_LARGEFILE.
19 sinclude(../config/largefile.m4)
20
21 dnl For AM_SET_LEADING_DOT.
22 sinclude(../config/lead-dot.m4)
23
24 dnl This gets autoconf bugfixes.
25 sinclude(../config/override.m4)
26
27 dnl For ZW_GNU_GETTEXT_SISTER_DIR.
28 sinclude(../config/gettext-sister.m4)
29
30 dnl For AC_LIB_HAVE_LINKFLAGS.
31 sinclude(../config/lib-ld.m4)
32 sinclude(../config/lib-prefix.m4)
33 sinclude(../config/lib-link.m4)
34
35 dnl For ACX_PKGVERSION and ACX_BUGURL.
36 sinclude(../config/acx.m4)
37
38 dnl for TCL definitions
39 sinclude(../config/tcl.m4)
40
41 dnl For dependency tracking macros.
42 sinclude([../config/depstand.m4])
43
44 dnl For AM_LC_MESSAGES
45 sinclude([../config/lcmessage.m4])
46
47 dnl For AM_LANGINFO_CODESET.
48 sinclude([../config/codeset.m4])
49
50 sinclude([../config/zlib.m4])
51
52 ## ----------------------------------------- ##
53 ## ANSIfy the C compiler whenever possible. ##
54 ## From Franc,ois Pinard ##
55 ## ----------------------------------------- ##
56
57 # Copyright (C) 1996-2013 Free Software Foundation, Inc.
58
59 # This program is free software; you can redistribute it and/or modify
60 # it under the terms of the GNU General Public License as published by
61 # the Free Software Foundation; either version 2, or (at your option)
62 # any later version.
63
64 # This program is distributed in the hope that it will be useful,
65 # but WITHOUT ANY WARRANTY; without even the implied warranty of
66 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
67 # GNU General Public License for more details.
68
69 # You should have received a copy of the GNU General Public License
70 # along with this program; if not, see <http://www.gnu.org/licenses/>.
71
72 # serial 1
73
74 # @defmac AC_PROG_CC_STDC
75 # @maindex PROG_CC_STDC
76 # @ovindex CC
77 # If the C compiler in not in ANSI C mode by default, try to add an option
78 # to output variable @code{CC} to make it so. This macro tries various
79 # options that select ANSI C on some system or another. It considers the
80 # compiler to be in ANSI C mode if it handles function prototypes correctly.
81 #
82 # If you use this macro, you should check after calling it whether the C
83 # compiler has been set to accept ANSI C; if not, the shell variable
84 # @code{am_cv_prog_cc_stdc} is set to @samp{no}. If you wrote your source
85 # code in ANSI C, you can make an un-ANSIfied copy of it by using the
86 # program @code{ansi2knr}, which comes with Ghostscript.
87 # @end defmac
88
89 AC_DEFUN([AM_PROG_CC_STDC],
90 [AC_REQUIRE([AC_PROG_CC])
91 AC_BEFORE([$0], [AC_C_INLINE])
92 AC_BEFORE([$0], [AC_C_CONST])
93 dnl Force this before AC_PROG_CPP. Some cpp's, eg on HPUX, require
94 dnl a magic option to avoid problems with ANSI preprocessor commands
95 dnl like #elif.
96 dnl FIXME: can't do this because then AC_AIX won't work due to a
97 dnl circular dependency.
98 dnl AC_BEFORE([$0], [AC_PROG_CPP])
99 AC_MSG_CHECKING([for ${CC-cc} option to accept ANSI C])
100 AC_CACHE_VAL(am_cv_prog_cc_stdc,
101 [am_cv_prog_cc_stdc=no
102 ac_save_CC="$CC"
103 # Don't try gcc -ansi; that turns off useful extensions and
104 # breaks some systems' header files.
105 # AIX -qlanglvl=ansi
106 # Ultrix and OSF/1 -std1
107 # HP-UX 10.20 and later -Ae
108 # HP-UX older versions -Aa -D_HPUX_SOURCE
109 # SVR4 -Xc -D__EXTENSIONS__
110 for ac_arg in "" -qlanglvl=ansi -std1 -Ae "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__"
111 do
112 CC="$ac_save_CC $ac_arg"
113 AC_TRY_COMPILE(
114 [#include <stdarg.h>
115 #include <stdio.h>
116 #include <sys/types.h>
117 #include <sys/stat.h>
118 /* Most of the following tests are stolen from RCS 5.7's src/conf.sh. */
119 struct buf { int x; };
120 FILE * (*rcsopen) (struct buf *, struct stat *, int);
121 static char *e (p, i)
122 char **p;
123 int i;
124 {
125 return p[i];
126 }
127 static char *f (char * (*g) (char **, int), char **p, ...)
128 {
129 char *s;
130 va_list v;
131 va_start (v,p);
132 s = g (p, va_arg (v,int));
133 va_end (v);
134 return s;
135 }
136 int test (int i, double x);
137 struct s1 {int (*f) (int a);};
138 struct s2 {int (*f) (double a);};
139 int pairnames (int, char **, FILE *(*)(struct buf *, struct stat *, int), int, int);
140 int argc;
141 char **argv;
142 ], [
143 return f (e, argv, 0) != argv[0] || f (e, argv, 1) != argv[1];
144 ],
145 [am_cv_prog_cc_stdc="$ac_arg"; break])
146 done
147 CC="$ac_save_CC"
148 ])
149 if test -z "$am_cv_prog_cc_stdc"; then
150 AC_MSG_RESULT([none needed])
151 else
152 AC_MSG_RESULT([$am_cv_prog_cc_stdc])
153 fi
154 case "x$am_cv_prog_cc_stdc" in
155 x|xno) ;;
156 *) CC="$CC $am_cv_prog_cc_stdc" ;;
157 esac
158 ])
159
160 dnl Originally from Bruno Haible, but with some modifications
161 dnl for the GDB project.
162
163 AC_DEFUN([AM_ICONV],
164 [
165 dnl Some systems have iconv in libc, some have it in libiconv (OSF/1 and
166 dnl those with the standalone portable GNU libiconv installed).
167
168 AC_ARG_WITH([libiconv-prefix],
169 AS_HELP_STRING([--with-libiconv-prefix=DIR], [search for libiconv in DIR/include and DIR/lib]), [
170 for dir in `echo "$withval" | tr : ' '`; do
171 if test -d $dir/include; then LIBICONV_INCLUDE="-I$dir/include"; fi
172 if test -d $dir/lib; then LIBICONV_LIBDIR="-L$dir/lib"; fi
173 done
174 ])
175
176 BUILD_LIBICONV_LIBDIRS="../libiconv/lib/.libs ../libiconv/lib/_libs"
177 BUILD_LIBICONV_INCLUDE="-I../libiconv/include"
178
179 AC_CACHE_CHECK(for iconv, am_cv_func_iconv, [
180 am_cv_func_iconv="no, consider installing GNU libiconv"
181 am_cv_lib_iconv=no
182 am_cv_use_build_libiconv=no
183 am_cv_build_libiconv_path=
184
185 # If libiconv is part of the build tree, then try using it over
186 # any system iconv.
187 if test -d ../libiconv; then
188 for lib_dir in $BUILD_LIBICONV_LIBDIRS; do
189 am_save_LIBS="$LIBS"
190 am_save_CPPFLAGS="$CPPFLAGS"
191 LIBS="$LIBS $lib_dir/libiconv.a"
192 CPPFLAGS="$CPPFLAGS $BUILD_LIBICONV_INCLUDE"
193 AC_TRY_LINK([#include <stdlib.h>
194 #include <iconv.h>],
195 [iconv_t cd = iconv_open("","");
196 iconv(cd,NULL,NULL,NULL,NULL);
197 iconv_close(cd);],
198 am_cv_use_build_libiconv=yes
199 am_cv_build_libiconv_path=$lib_dir/libiconv.a
200 am_cv_lib_iconv=yes
201 am_cv_func_iconv=yes)
202 LIBS="$am_save_LIBS"
203 CPPFLAGS="$am_save_CPPFLAGS"
204 if test "$am_cv_use_build_libiconv" = "yes"; then
205 break
206 fi
207 done
208 fi
209
210 # Next, try to find iconv in libc.
211 if test "$am_cv_func_iconv" != yes; then
212 AC_TRY_LINK([#include <stdlib.h>
213 #include <iconv.h>],
214 [iconv_t cd = iconv_open("","");
215 iconv(cd,NULL,NULL,NULL,NULL);
216 iconv_close(cd);],
217 am_cv_func_iconv=yes)
218 fi
219
220 # If iconv was not in libc, try -liconv. In this case, arrange to
221 # look in the libiconv prefix, if it was specified by the user.
222 if test "$am_cv_func_iconv" != yes; then
223 am_save_CPPFLAGS="$CPPFLAGS"
224 am_save_LIBS="$LIBS"
225 if test -n "$LIBICONV_INCLUDE"; then
226 CPPFLAGS="$CPPFLAGS $LIBICONV_INCLUDE"
227 LIBS="$LIBS $LIBICONV_LIBDIR"
228 fi
229 LIBS="$LIBS -liconv"
230 AC_TRY_LINK([#include <stdlib.h>
231 #include <iconv.h>],
232 [iconv_t cd = iconv_open("","");
233 iconv(cd,NULL,NULL,NULL,NULL);
234 iconv_close(cd);],
235 am_cv_lib_iconv=yes
236 am_cv_func_iconv=yes)
237 LIBS="$am_save_LIBS"
238 CPPFLAGS="$am_save_CPPFLAGS"
239 fi
240 ])
241
242 # Set the various flags based on the cache variables. We can't rely
243 # on the flags to remain set from the above code, due to caching.
244 LIBICONV=
245 if test "$am_cv_lib_iconv" = yes; then
246 LIBICONV="-liconv"
247 else
248 LIBICONV_LIBDIR=
249 LIBICONV_INCLUDE=
250 fi
251 if test "$am_cv_use_build_libiconv" = yes; then
252 LIBICONV="$am_cv_build_libiconv_path"
253 LIBICONV_LIBDIR=""
254 LIBICONV_INCLUDE="$BUILD_LIBICONV_INCLUDE"
255 fi
256 CPPFLAGS="$CPPFLAGS $LIBICONV_INCLUDE"
257 LIBS="$LIBS $LIBICONV_LIBDIR $LIBICONV"
258
259 if test "$am_cv_func_iconv" = yes; then
260 AC_DEFINE(HAVE_ICONV, 1, [Define if you have the iconv() function.])
261 AC_MSG_CHECKING([for iconv declaration])
262 AC_CACHE_VAL(am_cv_proto_iconv, [
263 AC_TRY_COMPILE([
264 #include <stdlib.h>
265 #include <iconv.h>
266 extern
267 #ifdef __cplusplus
268 "C"
269 #endif
270 #if defined(__STDC__) || defined(__cplusplus)
271 size_t iconv (iconv_t cd, char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft);
272 #else
273 size_t iconv();
274 #endif
275 ], [], am_cv_proto_iconv_arg1="", am_cv_proto_iconv_arg1="const")
276 am_cv_proto_iconv="extern size_t iconv (iconv_t cd, $am_cv_proto_iconv_arg1 char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft);"])
277 am_cv_proto_iconv=`echo "[$]am_cv_proto_iconv" | tr -s ' ' | sed -e 's/( /(/'`
278 AC_MSG_RESULT([$]{ac_t:-
279 }[$]am_cv_proto_iconv)
280 AC_DEFINE_UNQUOTED(ICONV_CONST, $am_cv_proto_iconv_arg1,
281 [Define as const if the declaration of iconv() needs const.])
282 fi
283 ])
284
285 dnl written by Guido Draheim <guidod@gmx.de>, original by Alexandre Oliva
286 dnl Version 1.3 (2001/03/02)
287 dnl source http://www.gnu.org/software/ac-archive/Miscellaneous/ac_define_dir.html
288
289 AC_DEFUN([AC_DEFINE_DIR], [
290 test "x$prefix" = xNONE && prefix="$ac_default_prefix"
291 test "x$exec_prefix" = xNONE && exec_prefix='${prefix}'
292 ac_define_dir=`eval echo [$]$2`
293 ac_define_dir=`eval echo [$]ac_define_dir`
294 ifelse($3, ,
295 AC_DEFINE_UNQUOTED($1, "$ac_define_dir"),
296 AC_DEFINE_UNQUOTED($1, "$ac_define_dir", $3))
297 ])
298
299 dnl See whether we need a declaration for a function.
300 dnl The result is highly dependent on the INCLUDES passed in, so make sure
301 dnl to use a different cache variable name in this macro if it is invoked
302 dnl in a different context somewhere else.
303 dnl gcc_AC_CHECK_DECL(SYMBOL,
304 dnl [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND [, INCLUDES]]])
305 AC_DEFUN([gcc_AC_CHECK_DECL],
306 [AC_MSG_CHECKING([whether $1 is declared])
307 AC_CACHE_VAL(gcc_cv_have_decl_$1,
308 [AC_TRY_COMPILE([$4],
309 [#ifndef $1
310 char *(*pfn) = (char *(*)) $1 ;
311 #endif], eval "gcc_cv_have_decl_$1=yes", eval "gcc_cv_have_decl_$1=no")])
312 if eval "test \"`echo '$gcc_cv_have_decl_'$1`\" = yes"; then
313 AC_MSG_RESULT(yes) ; ifelse([$2], , :, [$2])
314 else
315 AC_MSG_RESULT(no) ; ifelse([$3], , :, [$3])
316 fi
317 ])dnl
318
319 dnl Check multiple functions to see whether each needs a declaration.
320 dnl Arrange to define HAVE_DECL_<FUNCTION> to 0 or 1 as appropriate.
321 dnl gcc_AC_CHECK_DECLS(SYMBOLS,
322 dnl [ACTION-IF-NEEDED [, ACTION-IF-NOT-NEEDED [, INCLUDES]]])
323 AC_DEFUN([gcc_AC_CHECK_DECLS],
324 [for ac_func in $1
325 do
326 changequote(, )dnl
327 ac_tr_decl=HAVE_DECL_`echo $ac_func | tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'`
328 changequote([, ])dnl
329 gcc_AC_CHECK_DECL($ac_func,
330 [AC_DEFINE_UNQUOTED($ac_tr_decl, 1) $2],
331 [AC_DEFINE_UNQUOTED($ac_tr_decl, 0) $3],
332 dnl It is possible that the include files passed in here are local headers
333 dnl which supply a backup declaration for the relevant prototype based on
334 dnl the definition of (or lack of) the HAVE_DECL_ macro. If so, this test
335 dnl will always return success. E.g. see libiberty.h's handling of
336 dnl `basename'. To avoid this, we define the relevant HAVE_DECL_ macro to
337 dnl 1 so that any local headers used do not provide their own prototype
338 dnl during this test.
339 #undef $ac_tr_decl
340 #define $ac_tr_decl 1
341 $4
342 )
343 done
344 dnl Automatically generate config.h entries via autoheader.
345 if test x = y ; then
346 patsubst(translit([$1], [a-z], [A-Z]), [\w+],
347 [AC_DEFINE([HAVE_DECL_\&], 1,
348 [Define to 1 if we found this declaration otherwise define to 0.])])dnl
349 fi
350 ])
351
352 dnl Find the location of the private Tcl headers
353 dnl When Tcl is installed, this is TCL_INCLUDE_SPEC/tcl-private/generic
354 dnl When Tcl is in the build tree, this is not needed.
355 dnl
356 dnl Note: you must use first use SC_LOAD_TCLCONFIG!
357 AC_DEFUN([CY_AC_TCL_PRIVATE_HEADERS], [
358 AC_MSG_CHECKING([for Tcl private headers])
359 private_dir=""
360 dir=`echo ${TCL_INCLUDE_SPEC}/tcl-private/generic | sed -e s/-I//`
361 if test -f ${dir}/tclInt.h ; then
362 private_dir=${dir}
363 fi
364
365 if test x"${private_dir}" = x; then
366 AC_ERROR(could not find private Tcl headers)
367 else
368 TCL_PRIVATE_INCLUDE="-I${private_dir}"
369 AC_MSG_RESULT(${private_dir})
370 fi
371 ])
372
373 dnl Find the location of the private Tk headers
374 dnl When Tk is installed, this is TK_INCLUDE_SPEC/tk-private/generic
375 dnl When Tk is in the build tree, this not needed.
376 dnl
377 dnl Note: you must first use SC_LOAD_TKCONFIG
378 AC_DEFUN([CY_AC_TK_PRIVATE_HEADERS], [
379 AC_MSG_CHECKING([for Tk private headers])
380 private_dir=""
381 dir=`echo ${TK_INCLUDE_SPEC}/tk-private/generic | sed -e s/-I//`
382 if test -f ${dir}/tkInt.h; then
383 private_dir=${dir}
384 fi
385
386 if test x"${private_dir}" = x; then
387 AC_ERROR(could not find Tk private headers)
388 else
389 TK_PRIVATE_INCLUDE="-I${private_dir}"
390 AC_MSG_RESULT(${private_dir})
391 fi
392 ])
393
394 dnl GDB_AC_DEFINE_RELOCATABLE([VARIABLE], [ARG-NAME], [SHELL-VARIABLE])
395 dnl For use in processing directory values for --with-foo.
396 dnl If the path in SHELL_VARIABLE is relative to the prefix, then the
397 dnl result is relocatable, then this will define the C macro
398 dnl VARIABLE_RELOCATABLE to 1; otherwise it is defined as 0.
399 AC_DEFUN([GDB_AC_DEFINE_RELOCATABLE], [
400 if test "x$exec_prefix" = xNONE || test "x$exec_prefix" = 'x${prefix}'; then
401 if test "x$prefix" = xNONE; then
402 test_prefix=/usr/local
403 else
404 test_prefix=$prefix
405 fi
406 else
407 test_prefix=$exec_prefix
408 fi
409 value=0
410 case [$3] in
411 "${test_prefix}"|"${test_prefix}/"*|\
412 '${exec_prefix}'|'${exec_prefix}/'*)
413 value=1
414 ;;
415 esac
416 AC_DEFINE_UNQUOTED([$1]_RELOCATABLE, $value, [Define if the $2 directory should be relocated when GDB is moved.])
417 ])
418
419 dnl GDB_AC_WITH_DIR([VARIABLE], [ARG-NAME], [HELP], [DEFAULT])
420 dnl Add a new --with option that defines a directory.
421 dnl The result is stored in VARIABLE. AC_DEFINE_DIR is called
422 dnl on this variable, as is AC_SUBST.
423 dnl ARG-NAME is the base name of the argument (without "--with").
424 dnl HELP is the help text to use.
425 dnl If the user's choice is relative to the prefix, then the
426 dnl result is relocatable, then this will define the C macro
427 dnl VARIABLE_RELOCATABLE to 1; otherwise it is defined as 0.
428 dnl DEFAULT is the default value, which is used if the user
429 dnl does not specify the argument.
430 AC_DEFUN([GDB_AC_WITH_DIR], [
431 AC_ARG_WITH([$2], AS_HELP_STRING([--with-][$2][=PATH], [$3]), [
432 [$1]=$withval], [[$1]=[$4]])
433 AC_DEFINE_DIR([$1], [$1], [$3])
434 AC_SUBST([$1])
435 GDB_AC_DEFINE_RELOCATABLE([$1], [$2], ${ac_define_dir})
436 ])
437
438 dnl GDB_AC_CHECK_BFD([MESSAGE], [CV], [CODE], [HEADER])
439 dnl Check whether BFD provides a feature.
440 dnl MESSAGE is the "checking" message to display.
441 dnl CV is the name of the cache variable where the result is stored.
442 dnl The result will be "yes" or "no".
443 dnl CODE is some code to compile that checks for the feature.
444 dnl A link test is run.
445 dnl HEADER is the name of an extra BFD header to include.
446 AC_DEFUN([GDB_AC_CHECK_BFD], [
447 OLD_CFLAGS=$CFLAGS
448 OLD_LDFLAGS=$LDFLAGS
449 OLD_LIBS=$LIBS
450 # Put the old CFLAGS/LDFLAGS last, in case the user's (C|LD)FLAGS
451 # points somewhere with bfd, with -I/foo/lib and -L/foo/lib. We
452 # always want our bfd.
453 CFLAGS="-I${srcdir}/../include -I../bfd -I${srcdir}/../bfd $CFLAGS"
454 LDFLAGS="-L../bfd -L../libiberty $LDFLAGS"
455 intl=`echo $LIBINTL | sed 's,${top_builddir}/,,g'`
456 # -ldl is provided by bfd/Makfile.am (LIBDL) <PLUGINS>.
457 if test "$plugins" = "yes"; then
458 AC_SEARCH_LIBS(dlopen, dl)
459 fi
460 LIBS="-lbfd -liberty $intl $LIBS"
461 AC_CACHE_CHECK([$1], [$2],
462 [AC_TRY_LINK(
463 [#include <stdlib.h>
464 #include "bfd.h"
465 #include "$4"
466 ],
467 [return $3;], [[$2]=yes], [[$2]=no])])
468 CFLAGS=$OLD_CFLAGS
469 LDFLAGS=$OLD_LDFLAGS
470 LIBS=$OLD_LIBS])
This page took 0.038947 seconds and 5 git commands to generate.