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