change and rename gmp_string_asprintf to return an std::string
[binutils-gdb.git] / gdb / acinclude.m4
blob64574e2631428b088beb0ec8f9805f6c9db58abd
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>
4 # Keep these includes in sync with the aclocal_m4_deps list in
5 # Makefile.in.
7 m4_include(acx_configure_dir.m4)
9 # This gets GDB_AC_TRANSFORM.
10 m4_include(transform.m4)
12 # This gets AM_GDB_WARNINGS.
13 m4_include(../gdbsupport/warning.m4)
15 # AM_GDB_UBSAN
16 m4_include(sanitize.m4)
18 # This gets GDB_AC_SELFTEST.
19 m4_include(../gdbsupport/selftest.m4)
21 dnl gdb/configure.in uses BFD_NEED_DECLARATION, so get its definition.
22 m4_include(../bfd/bfd.m4)
24 dnl This gets the standard macros.
25 m4_include(../config/acinclude.m4)
27 dnl This gets GCC_ENABLE.
28 sinclude(../config/enable.m4)
30 dnl This gets AC_PLUGINS, needed by ACX_LARGEFILE.
31 m4_include(../config/plugins.m4)
33 dnl For ACX_LARGEFILE.
34 m4_include(../config/largefile.m4)
36 dnl For AM_SET_LEADING_DOT.
37 m4_include(../config/lead-dot.m4)
39 dnl This gets autoconf bugfixes.
40 m4_include(../config/override.m4)
42 dnl For ZW_GNU_GETTEXT_SISTER_DIR.
43 m4_include(../config/gettext-sister.m4)
45 dnl For AC_LIB_HAVE_LINKFLAGS.
46 m4_include(../config/lib-ld.m4)
47 m4_include(../config/lib-prefix.m4)
48 m4_include(../config/lib-link.m4)
50 dnl For ACX_PKGVERSION and ACX_BUGURL.
51 m4_include(../config/acx.m4)
53 dnl for TCL definitions
54 m4_include(../config/tcl.m4)
56 dnl For dependency tracking macros.
57 m4_include([../config/depstand.m4])
59 dnl For AM_LC_MESSAGES
60 m4_include([../config/lcmessage.m4])
62 dnl For AM_LANGINFO_CODESET.
63 m4_include([../config/codeset.m4])
65 m4_include([../config/iconv.m4])
67 m4_include([../config/zlib.m4])
69 m4_include([../gdbsupport/common.m4])
71 dnl For libiberty_INIT.
72 m4_include(libiberty.m4)
74 dnl For GDB_AC_PTRACE.
75 m4_include(../gdbsupport/ptrace.m4)
77 m4_include(ax_cxx_compile_stdcxx.m4)
79 m4_include([../config/ax_pthread.m4])
81 dnl written by Guido Draheim <guidod@gmx.de>, original by Alexandre Oliva 
82 dnl Version 1.3 (2001/03/02)
83 dnl source http://www.gnu.org/software/ac-archive/Miscellaneous/ac_define_dir.html
85 AC_DEFUN([AC_DEFINE_DIR], [
86   test "x$prefix" = xNONE && prefix="$ac_default_prefix"
87   test "x$exec_prefix" = xNONE && exec_prefix='${prefix}'
88   ac_define_dir=`eval echo [$]$2`
89   ac_define_dir=`eval echo [$]ac_define_dir`
90   ifelse($3, ,
91     AC_DEFINE_UNQUOTED($1, "$ac_define_dir"),
92     AC_DEFINE_UNQUOTED($1, "$ac_define_dir", $3))
95 dnl See whether we need a declaration for a function.
96 dnl The result is highly dependent on the INCLUDES passed in, so make sure
97 dnl to use a different cache variable name in this macro if it is invoked
98 dnl in a different context somewhere else.
99 dnl gcc_AC_CHECK_DECL(SYMBOL,
100 dnl     [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND [, INCLUDES]]])
101 AC_DEFUN(
102   [gcc_AC_CHECK_DECL],
103   [AC_MSG_CHECKING([whether $1 is declared])
104    AC_CACHE_VAL(
105      [gcc_cv_have_decl_$1],
106      [AC_COMPILE_IFELSE(
107         [AC_LANG_PROGRAM(
108            [$4],
109            [#ifndef $1
110             char *(*pfn) = (char *(*)) $1 ;
111             #endif]
112          )],
113         [eval "gcc_cv_have_decl_$1=yes"],
114         [eval "gcc_cv_have_decl_$1=no"]
115       )]
116    )
117 if eval "test \"`echo '$gcc_cv_have_decl_'$1`\" = yes"; then
118   AC_MSG_RESULT(yes) ; ifelse([$2], , :, [$2])
119 else
120   AC_MSG_RESULT(no) ; ifelse([$3], , :, [$3])
122 ])dnl
124 dnl Check multiple functions to see whether each needs a declaration.
125 dnl Arrange to define HAVE_DECL_<FUNCTION> to 0 or 1 as appropriate.
126 dnl gcc_AC_CHECK_DECLS(SYMBOLS,
127 dnl     [ACTION-IF-NEEDED [, ACTION-IF-NOT-NEEDED [, INCLUDES]]])
128 AC_DEFUN([gcc_AC_CHECK_DECLS],
129 [for ac_func in $1
131 changequote(, )dnl
132   ac_tr_decl=HAVE_DECL_`echo $ac_func | tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'`
133 changequote([, ])dnl
134 gcc_AC_CHECK_DECL($ac_func,
135   [AC_DEFINE_UNQUOTED($ac_tr_decl, 1) $2],
136   [AC_DEFINE_UNQUOTED($ac_tr_decl, 0) $3],
137 dnl It is possible that the include files passed in here are local headers
138 dnl which supply a backup declaration for the relevant prototype based on
139 dnl the definition of (or lack of) the HAVE_DECL_ macro.  If so, this test
140 dnl will always return success.  E.g. see libiberty.h's handling of
141 dnl `basename'.  To avoid this, we define the relevant HAVE_DECL_ macro to
142 dnl 1 so that any local headers used do not provide their own prototype
143 dnl during this test.
144 #undef $ac_tr_decl
145 #define $ac_tr_decl 1
146   $4
148 done
149 dnl Automatically generate config.h entries via autoheader.
150 if test x = y ; then
151   patsubst(translit([$1], [a-z], [A-Z]), [\w+],
152     [AC_DEFINE([HAVE_DECL_\&], 1,
153       [Define to 1 if we found this declaration otherwise define to 0.])])dnl
157 dnl Find the location of the private Tcl headers
158 dnl When Tcl is installed, this is TCL_INCLUDE_SPEC/tcl-private/generic
159 dnl When Tcl is in the build tree, this is not needed.
161 dnl Note: you must use first use SC_LOAD_TCLCONFIG!
162 AC_DEFUN([CY_AC_TCL_PRIVATE_HEADERS], [
163   AC_MSG_CHECKING([for Tcl private headers])
164   private_dir=""
165   dir=`echo ${TCL_INCLUDE_SPEC}/tcl-private/generic | sed -e s/-I//`
166   if test -f ${dir}/tclInt.h ; then
167     private_dir=${dir}
168   fi
170   if test x"${private_dir}" = x; then
171     AC_MSG_ERROR(could not find private Tcl headers)
172   else
173     TCL_PRIVATE_INCLUDE="-I${private_dir}"
174     AC_MSG_RESULT(${private_dir})
175   fi
178 dnl Find the location of the private Tk headers
179 dnl When Tk is installed, this is TK_INCLUDE_SPEC/tk-private/generic
180 dnl When Tk is in the build tree, this not needed.
182 dnl Note: you must first use SC_LOAD_TKCONFIG
183 AC_DEFUN([CY_AC_TK_PRIVATE_HEADERS], [
184   AC_MSG_CHECKING([for Tk private headers])
185   private_dir=""
186   dir=`echo ${TK_INCLUDE_SPEC}/tk-private/generic | sed -e s/-I//`
187   if test -f ${dir}/tkInt.h; then
188     private_dir=${dir}
189   fi
191   if test x"${private_dir}" = x; then
192     AC_MSG_ERROR(could not find Tk private headers)
193   else
194     TK_PRIVATE_INCLUDE="-I${private_dir}"
195     AC_MSG_RESULT(${private_dir})
196   fi
199 dnl GDB_AC_DEFINE_RELOCATABLE([VARIABLE], [ARG-NAME], [SHELL-VARIABLE])
200 dnl For use in processing directory values for --with-foo.
201 dnl If the path in SHELL_VARIABLE is relative to the prefix, then the
202 dnl result is relocatable, then this will define the C macro
203 dnl VARIABLE_RELOCATABLE to 1; otherwise it is defined as 0.
204 AC_DEFUN([GDB_AC_DEFINE_RELOCATABLE], [
205   if test "x$exec_prefix" = xNONE || test "x$exec_prefix" = 'x${prefix}'; then
206      if test "x$prefix" = xNONE; then
207         test_prefix=/usr/local
208      else
209         test_prefix=$prefix
210      fi
211   else
212      test_prefix=$exec_prefix
213   fi
214   value=0
215   case [$3] in
216      "${test_prefix}"|"${test_prefix}/"*|\
217         '${exec_prefix}'|'${exec_prefix}/'*)
218      value=1
219      ;;
220   esac
221   AC_DEFINE_UNQUOTED([$1]_RELOCATABLE, $value, [Define if the $2 directory should be relocated when GDB is moved.])
224 dnl GDB_AC_WITH_DIR([VARIABLE], [ARG-NAME], [HELP], [DEFAULT])
225 dnl Add a new --with option that defines a directory.
226 dnl The result is stored in VARIABLE.  AC_DEFINE_DIR is called
227 dnl on this variable, as is AC_SUBST.
228 dnl ARG-NAME is the base name of the argument (without "--with").
229 dnl HELP is the help text to use.
230 dnl If the user's choice is relative to the prefix, then the
231 dnl result is relocatable, then this will define the C macro
232 dnl VARIABLE_RELOCATABLE to 1; otherwise it is defined as 0.
233 dnl DEFAULT is the default value, which is used if the user
234 dnl does not specify the argument.
235 AC_DEFUN([GDB_AC_WITH_DIR], [
236   AC_ARG_WITH([$2], AS_HELP_STRING([--with-][$2][=PATH], [$3]), [
237     [$1]=$withval], [[$1]=[$4]])
238   AC_DEFINE_DIR([$1], [$1], [$3])
239   AC_SUBST([$1])
240   GDB_AC_DEFINE_RELOCATABLE([$1], [$2], ${ac_define_dir})
241   ])
243 dnl GDB_AC_CHECK_BFD([MESSAGE], [CV], [CODE], [HEADER])
244 dnl Check whether BFD provides a feature.
245 dnl MESSAGE is the "checking" message to display.
246 dnl CV is the name of the cache variable where the result is stored.
247 dnl The result will be "yes" or "no".
248 dnl CODE is some code to compile that checks for the feature.
249 dnl A link test is run.
250 dnl HEADER is the name of an extra BFD header to include.
251 AC_DEFUN([GDB_AC_CHECK_BFD], [
252   OLD_CFLAGS=$CFLAGS
253   OLD_LDFLAGS=$LDFLAGS
254   OLD_LIBS=$LIBS
255   # Put the old CFLAGS/LDFLAGS last, in case the user's (C|LD)FLAGS
256   # points somewhere with bfd, with -I/foo/lib and -L/foo/lib.  We
257   # always want our bfd.
258   CFLAGS="-I${srcdir}/../include -I../bfd -I${srcdir}/../bfd $CFLAGS"
259   ZLIBDIR=`echo $zlibdir | sed 's,\$(top_builddir)/,,g'`
260   LDFLAGS="-L../bfd -L../libiberty $ZLIBDIR $LDFLAGS"
261   intl=`echo $LIBINTL | sed 's,${top_builddir}/,,g'`
262   LIBS="-lbfd -liberty -lz $intl $LIBS"
263   AC_CACHE_CHECK(
264     [$1],
265     [$2],
266     [AC_LINK_IFELSE(
267        [AC_LANG_PROGRAM(
268           [#include <stdlib.h>
269            #include "bfd.h"
270            #include "$4"],
271           [return $3;]
272         )],
273        [[$2]=yes],
274        [[$2]=no]
275      )]
276   )
277   CFLAGS=$OLD_CFLAGS
278   LDFLAGS=$OLD_LDFLAGS
279   LIBS=$OLD_LIBS])
281 dnl GDB_GUILE_PROGRAM_NAMES([PKG-CONFIG], [VERSION])
283 dnl Define and substitute 'GUILD' to contain the absolute file name of
284 dnl the 'guild' command for VERSION, using PKG-CONFIG.  (This is
285 dnl similar to Guile's 'GUILE_PROGS' macro.)
286 AC_DEFUN([GDB_GUILE_PROGRAM_NAMES], [
287   AC_CACHE_CHECK([for the absolute file name of the 'guild' command],
288     [ac_cv_guild_program_name],
289     [ac_cv_guild_program_name="`$1 --variable guild $2`"
291      # In Guile up to 2.0.11 included, guile-2.0.pc would not define
292      # the 'guild' and 'bindir' variables.  In that case, try to guess
293      # what the program name is, at the risk of getting it wrong if
294      # Guile was configured with '--program-suffix' or similar.
295      if test "x$ac_cv_guild_program_name" = "x"; then
296        guile_exec_prefix="`$1 --variable exec_prefix $2`"
297        ac_cv_guild_program_name="$guile_exec_prefix/bin/guild"
298      fi
299   ])
301   if ! "$ac_cv_guild_program_name" --version >&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD; then
302     AC_MSG_ERROR(['$ac_cv_guild_program_name' appears to be unusable])
303   fi
305   GUILD="$ac_cv_guild_program_name"
306   AC_SUBST([GUILD])
309 dnl GDB_GUILD_TARGET_FLAG
311 dnl Compute the value of GUILD_TARGET_FLAG.
312 dnl For native builds this is empty.
313 dnl For cross builds this is --target=<host>.
314 AC_DEFUN([GDB_GUILD_TARGET_FLAG], [
315   if test "$cross_compiling" = no; then
316     GUILD_TARGET_FLAG=
317   else
318     GUILD_TARGET_FLAG="--target=$host"
319   fi
320   AC_SUBST(GUILD_TARGET_FLAG)
323 dnl GDB_TRY_GUILD([SRC-FILE])
325 dnl We precompile the .scm files and install them with gdb, so make sure
326 dnl guild works for this host.
327 dnl The .scm files are precompiled for several reasons:
328 dnl 1) To silence Guile during gdb startup (Guile's auto-compilation output
329 dnl    is unnecessarily verbose).
330 dnl 2) Make gdb developers see compilation errors/warnings during the build,
331 dnl    and not leave it to later when the user runs gdb.
332 dnl 3) As a convenience for the user, so that one copy of the files is built
333 dnl    instead of one copy per user.
335 dnl Make sure guild can handle this host by trying to compile SRC-FILE, and
336 dnl setting ac_cv_guild_ok to yes or no.
337 dnl Note that guild can handle cross-compilation.
338 dnl It could happen that guild can't handle the host, but guile would still
339 dnl work.  For the time being we're conservative, and if guild doesn't work
340 dnl we punt.
341 AC_DEFUN([GDB_TRY_GUILD], [
342   AC_REQUIRE([GDB_GUILD_TARGET_FLAG])
343   AC_CACHE_CHECK([whether guild supports this host],
344     [ac_cv_guild_ok],
345     [echo "$ac_cv_guild_program_name compile $GUILD_TARGET_FLAG -o conftest.go $1" >&AS_MESSAGE_LOG_FD
346      if "$ac_cv_guild_program_name" compile $GUILD_TARGET_FLAG -o conftest.go "$1" >&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD; then
347        ac_cv_guild_ok=yes
348      else
349        ac_cv_guild_ok=no
350      fi])