Bump version to 12.0.50.DATE-git.
[binutils-gdb.git] / gdbsupport / common.m4
blob2e709dbbdbb3882b355d3d2e8f1b9fc486052da1
1 dnl Autoconf configure snippets for common.
2 dnl Copyright (C) 1995-2021 Free Software Foundation, Inc.
3 dnl
4 dnl This file is part of GDB.
5 dnl 
6 dnl This program is free software; you can redistribute it and/or modify
7 dnl it under the terms of the GNU General Public License as published by
8 dnl the Free Software Foundation; either version 3 of the License, or
9 dnl (at your option) any later version.
10 dnl
11 dnl This program is distributed in the hope that it will be useful,
12 dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
13 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 dnl GNU General Public License for more details.
15 dnl
16 dnl You should have received a copy of the GNU General Public License
17 dnl along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 dnl Invoke configury needed by the files in 'common'.
20 AC_DEFUN([GDB_AC_COMMON], [
21   # Set the 'development' global.
22   . $srcdir/../bfd/development.sh
24   AC_HEADER_STDC
25   AC_FUNC_ALLOCA
27   WIN32APILIBS=
28   case ${host} in
29     *mingw32*)
30       AC_DEFINE(USE_WIN32API, 1,
31                 [Define if we should use the Windows API, instead of the
32                  POSIX API.  On Windows, we use the Windows API when
33                  building for MinGW, but the POSIX API when building
34                  for Cygwin.])
35       WIN32APILIBS="-lws2_32"
36       ;;
37   esac
39   dnl Note that this requires codeset.m4, which is included
40   dnl by the users of common.m4.
41   AM_LANGINFO_CODESET
43   AC_CHECK_HEADERS(linux/perf_event.h locale.h memory.h signal.h dnl
44                    sys/resource.h sys/socket.h dnl
45                    sys/un.h sys/wait.h dnl
46                    thread_db.h wait.h dnl
47                    termios.h dnl
48                    dlfcn.h dnl
49                    linux/elf.h proc_service.h dnl
50                    poll.h sys/poll.h sys/select.h)
52   AC_FUNC_MMAP
53   AC_FUNC_FORK
54   AC_CHECK_FUNCS([fdwalk getrlimit pipe pipe2 poll socketpair sigaction \
55                   ptrace64 sbrk setns sigaltstack sigprocmask \
56                   setpgid setpgrp getrusage getauxval])
58   AC_CHECK_DECLS([strstr])
60   # ----------------------- #
61   # Checks for structures.  #
62   # ----------------------- #
64   AC_CHECK_MEMBERS([struct stat.st_blocks, struct stat.st_blksize])
66   # On FreeBSD we need libutil for the kinfo_get* functions.  On
67   # GNU/kFreeBSD systems, FreeBSD libutil is renamed to libutil-freebsd.
68   # Figure out which one to use.
69   AC_SEARCH_LIBS(kinfo_getfile, util util-freebsd)
71   # Define HAVE_KINFO_GETFILE if kinfo_getfile is available.
72   AC_CHECK_FUNCS(kinfo_getfile)
74   # Check for std::thread.  This does not work on some platforms, like
75   # mingw and DJGPP.
76   AC_LANG_PUSH([C++])
77   AX_PTHREAD([threads=yes], [threads=no])
78   if test "$threads" = "yes"; then
79     save_LIBS="$LIBS"
80     LIBS="$PTHREAD_LIBS $LIBS"
81     save_CXXFLAGS="$CXXFLAGS"
82     CXXFLAGS="$PTHREAD_CFLAGS $save_CXXFLAGS"
83     AC_CACHE_CHECK([for std::thread],
84                    gdb_cv_cxx_std_thread,
85                    [AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
86     [[#include <thread>
87       void callback() { }]],
88     [[std::thread t(callback);]])],
89                                   gdb_cv_cxx_std_thread=yes,
90                                   gdb_cv_cxx_std_thread=no)])
92     # This check must be here, while LIBS includes any necessary
93     # threading library.
94     AC_CHECK_FUNCS([pthread_sigmask pthread_setname_np])
96     LIBS="$save_LIBS"
97     CXXFLAGS="$save_CXXFLAGS"
98   fi
99   if test "$gdb_cv_cxx_std_thread" = "yes"; then
100     AC_DEFINE(CXX_STD_THREAD, 1,
101               [Define to 1 if std::thread works.])
102   fi
103   AC_LANG_POP
105   dnl Check if sigsetjmp is available.  Using AC_CHECK_FUNCS won't
106   dnl do since sigsetjmp might only be defined as a macro.
107   AC_CACHE_CHECK(
108     [for sigsetjmp],
109     [gdb_cv_func_sigsetjmp],
110     [AC_COMPILE_IFELSE(
111        [AC_LANG_PROGRAM(
112           [#include <setjmp.h>],
113           [sigjmp_buf env;
114            while (! sigsetjmp (env, 1))
115              siglongjmp (env, 1);]
116         )],
117        [gdb_cv_func_sigsetjmp=yes],
118        [gdb_cv_func_sigsetjmp=no]
119      )]
120   )
121   if test "$gdb_cv_func_sigsetjmp" = "yes"; then
122     AC_DEFINE(HAVE_SIGSETJMP, 1, [Define if sigsetjmp is available. ])
123   fi
125   AC_ARG_WITH(intel_pt,
126     AS_HELP_STRING([--with-intel-pt], [include Intel Processor Trace support (auto/yes/no)]),
127     [], [with_intel_pt=auto])
128   AC_MSG_CHECKING([whether to use intel pt])
129   AC_MSG_RESULT([$with_intel_pt])
131   if test "${with_intel_pt}" = no; then
132     AC_MSG_WARN([Intel Processor Trace support disabled; some features may be unavailable.])
133     HAVE_LIBIPT=no
134   else
135     AC_PREPROC_IFELSE([AC_LANG_SOURCE([[
136   #include <linux/perf_event.h>
137   #ifndef PERF_ATTR_SIZE_VER5
138   # error
139   #endif
140     ]])], [perf_event=yes], [perf_event=no])
141     if test "$perf_event" != yes; then
142       if test "$with_intel_pt" = yes; then
143         AC_MSG_ERROR([linux/perf_event.h missing or too old])
144       else
145         AC_MSG_WARN([linux/perf_event.h missing or too old; some features may be unavailable.])
146       fi
147     fi
149     AC_LIB_HAVE_LINKFLAGS([ipt], [], [#include "intel-pt.h"], [pt_insn_alloc_decoder (0);])
150     if test "$HAVE_LIBIPT" != yes; then
151       if test "$with_intel_pt" = yes; then
152         AC_MSG_ERROR([libipt is missing or unusable])
153       else
154         AC_MSG_WARN([libipt is missing or unusable; some features may be unavailable.])
155       fi
156     else
157       save_LIBS=$LIBS
158       LIBS="$LIBS $LIBIPT"
159       AC_CHECK_FUNCS(pt_insn_event)
160       AC_CHECK_MEMBERS([struct pt_insn.enabled, struct pt_insn.resynced], [], [],
161                        [#include <intel-pt.h>])
162       LIBS=$save_LIBS
163     fi
164   fi
166   BFD_SYS_PROCFS_H
167   if test "$ac_cv_header_sys_procfs_h" = yes; then
168     BFD_HAVE_SYS_PROCFS_TYPE(gregset_t)
169     BFD_HAVE_SYS_PROCFS_TYPE(fpregset_t)
170     BFD_HAVE_SYS_PROCFS_TYPE(prgregset_t)
171     BFD_HAVE_SYS_PROCFS_TYPE(prfpregset_t)
172     BFD_HAVE_SYS_PROCFS_TYPE(prgregset32_t)
173     BFD_HAVE_SYS_PROCFS_TYPE(lwpid_t)
174     BFD_HAVE_SYS_PROCFS_TYPE(psaddr_t)
175     BFD_HAVE_SYS_PROCFS_TYPE(elf_fpregset_t)
176   fi