xref: /netbsd-src/external/gpl3/gdb/dist/gdbsupport/common.m4 (revision 5ba1f45f2a09259cc846f20c7c5501604d633c90)
18dffb485Schristosdnl Autoconf configure snippets for common.
2*5ba1f45fSchristosdnl Copyright (C) 1995-2024 Free Software Foundation, Inc.
38dffb485Schristosdnl
48dffb485Schristosdnl This file is part of GDB.
58dffb485Schristosdnl
68dffb485Schristosdnl This program is free software; you can redistribute it and/or modify
78dffb485Schristosdnl it under the terms of the GNU General Public License as published by
88dffb485Schristosdnl the Free Software Foundation; either version 3 of the License, or
98dffb485Schristosdnl (at your option) any later version.
108dffb485Schristosdnl
118dffb485Schristosdnl This program is distributed in the hope that it will be useful,
128dffb485Schristosdnl but WITHOUT ANY WARRANTY; without even the implied warranty of
138dffb485Schristosdnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
148dffb485Schristosdnl GNU General Public License for more details.
158dffb485Schristosdnl
168dffb485Schristosdnl You should have received a copy of the GNU General Public License
178dffb485Schristosdnl along with this program.  If not, see <http://www.gnu.org/licenses/>.
188dffb485Schristos
198dffb485Schristosdnl Invoke configury needed by the files in 'common'.
208dffb485SchristosAC_DEFUN([GDB_AC_COMMON], [
218dffb485Schristos  # Set the 'development' global.
228dffb485Schristos  . $srcdir/../bfd/development.sh
238dffb485Schristos
248dffb485Schristos  AC_HEADER_STDC
258dffb485Schristos  AC_FUNC_ALLOCA
268dffb485Schristos
278dffb485Schristos  WIN32APILIBS=
288dffb485Schristos  case ${host} in
298dffb485Schristos    *mingw32*)
308dffb485Schristos      AC_DEFINE(USE_WIN32API, 1,
318dffb485Schristos		[Define if we should use the Windows API, instead of the
328dffb485Schristos		 POSIX API.  On Windows, we use the Windows API when
338dffb485Schristos		 building for MinGW, but the POSIX API when building
348dffb485Schristos		 for Cygwin.])
358dffb485Schristos      WIN32APILIBS="-lws2_32"
368dffb485Schristos      ;;
378dffb485Schristos  esac
388dffb485Schristos
398dffb485Schristos  dnl Note that this requires codeset.m4, which is included
408dffb485Schristos  dnl by the users of common.m4.
418dffb485Schristos  AM_LANGINFO_CODESET
428dffb485Schristos
438dffb485Schristos  AC_CHECK_HEADERS(linux/perf_event.h locale.h memory.h signal.h dnl
448dffb485Schristos		   sys/resource.h sys/socket.h dnl
458dffb485Schristos		   sys/un.h sys/wait.h dnl
468dffb485Schristos		   thread_db.h wait.h dnl
478dffb485Schristos		   termios.h dnl
488dffb485Schristos		   dlfcn.h dnl
498dffb485Schristos		   linux/elf.h proc_service.h dnl
508dffb485Schristos		   poll.h sys/poll.h sys/select.h)
518dffb485Schristos
528dffb485Schristos  AC_FUNC_MMAP
534b169a6bSchristos  AC_FUNC_FORK
54*5ba1f45fSchristos  # Some systems (e.g. Solaris) have `socketpair' in libsocket.
55*5ba1f45fSchristos  AC_SEARCH_LIBS(socketpair, socket)
568dffb485Schristos  AC_CHECK_FUNCS([fdwalk getrlimit pipe pipe2 poll socketpair sigaction \
578dffb485Schristos		  ptrace64 sbrk setns sigaltstack sigprocmask \
584b169a6bSchristos		  setpgid setpgrp getrusage getauxval sigtimedwait])
598dffb485Schristos
604b169a6bSchristos  # This is needed for RHEL 5 and uclibc-ng < 1.0.39.
614b169a6bSchristos  # These did not define ADDR_NO_RANDOMIZE in sys/personality.h,
624b169a6bSchristos  # only in linux/personality.h.
638dffb485Schristos  AC_CHECK_DECLS([ADDR_NO_RANDOMIZE],,, [#include <sys/personality.h>])
648dffb485Schristos
658dffb485Schristos  AC_CHECK_DECLS([strstr])
668dffb485Schristos
678dffb485Schristos  # ----------------------- #
688dffb485Schristos  # Checks for structures.  #
698dffb485Schristos  # ----------------------- #
708dffb485Schristos
718dffb485Schristos  AC_CHECK_MEMBERS([struct stat.st_blocks, struct stat.st_blksize])
728dffb485Schristos
734b169a6bSchristos  # On FreeBSD we need libutil for the kinfo_get* functions.  On
744b169a6bSchristos  # GNU/kFreeBSD systems, FreeBSD libutil is renamed to libutil-freebsd.
754b169a6bSchristos  # Figure out which one to use.
764b169a6bSchristos  AC_SEARCH_LIBS(kinfo_getfile, util util-freebsd)
774b169a6bSchristos
784b169a6bSchristos  # Define HAVE_KINFO_GETFILE if kinfo_getfile is available.
794b169a6bSchristos  AC_CHECK_FUNCS(kinfo_getfile)
804b169a6bSchristos
814b169a6bSchristos  # ----------------------- #
824b169a6bSchristos  # Check for threading.    #
834b169a6bSchristos  # ----------------------- #
844b169a6bSchristos
854b169a6bSchristos  AC_ARG_ENABLE(threading,
864b169a6bSchristos    AS_HELP_STRING([--enable-threading], [include support for parallel processing of data (yes/no)]),
874b169a6bSchristos    [case "$enableval" in
884b169a6bSchristos    yes) want_threading=yes ;;
894b169a6bSchristos    no) want_threading=no ;;
904b169a6bSchristos    *) AC_MSG_ERROR([bad value $enableval for threading]) ;;
914b169a6bSchristos    esac],
92*5ba1f45fSchristos    [want_threading=auto])
938dffb485Schristos
948dffb485Schristos  # Check for std::thread.  This does not work on some platforms, like
95*5ba1f45fSchristos  # mingw using the win32 threads model with gcc older than 13, and
96*5ba1f45fSchristos  # DJGPP.
978dffb485Schristos  AC_LANG_PUSH([C++])
988dffb485Schristos  AX_PTHREAD([threads=yes], [threads=no])
998dffb485Schristos  save_LIBS="$LIBS"
1008dffb485Schristos  LIBS="$PTHREAD_LIBS $LIBS"
1018dffb485Schristos  save_CXXFLAGS="$CXXFLAGS"
1028dffb485Schristos  CXXFLAGS="$PTHREAD_CFLAGS $save_CXXFLAGS"
1038dffb485Schristos  AC_CACHE_CHECK([for std::thread],
1048dffb485Schristos		 gdb_cv_cxx_std_thread,
1058dffb485Schristos		 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
1064b169a6bSchristos  dnl NOTE: this must be kept in sync with common-defs.h.
1074b169a6bSchristos  [[#if defined (__MINGW32__) || defined (__CYGWIN__)
1084b169a6bSchristos    # ifdef _WIN32_WINNT
1094b169a6bSchristos    #  if _WIN32_WINNT < 0x0501
1104b169a6bSchristos    #   undef _WIN32_WINNT
1114b169a6bSchristos    #   define _WIN32_WINNT 0x0501
1124b169a6bSchristos    #  endif
1134b169a6bSchristos    # else
1144b169a6bSchristos    #  define _WIN32_WINNT 0x0501
1154b169a6bSchristos    # endif
1164b169a6bSchristos    #endif	/* __MINGW32__ || __CYGWIN__ */
1174b169a6bSchristos    #include <thread>
118*5ba1f45fSchristos    #include <mutex>
1198dffb485Schristos    void callback() { }]],
1208dffb485Schristos  [[std::thread t(callback);]])],
1218dffb485Schristos				gdb_cv_cxx_std_thread=yes,
1228dffb485Schristos				gdb_cv_cxx_std_thread=no)])
1238dffb485Schristos
1244b169a6bSchristos  if test "$threads" = "yes"; then
1258dffb485Schristos    # This check must be here, while LIBS includes any necessary
1268dffb485Schristos    # threading library.
1278dffb485Schristos    AC_CHECK_FUNCS([pthread_sigmask pthread_setname_np])
1284b169a6bSchristos  fi
1298dffb485Schristos  LIBS="$save_LIBS"
1308dffb485Schristos  CXXFLAGS="$save_CXXFLAGS"
1314b169a6bSchristos
132*5ba1f45fSchristos  if test "$want_threading" != "no"; then
1338dffb485Schristos    if test "$gdb_cv_cxx_std_thread" = "yes"; then
1348dffb485Schristos      AC_DEFINE(CXX_STD_THREAD, 1,
1358dffb485Schristos		[Define to 1 if std::thread works.])
136*5ba1f45fSchristos    else
137*5ba1f45fSchristos	if test "$want_threading" = "yes"; then
138*5ba1f45fSchristos	    AC_MSG_ERROR([std::thread does not work; disable threading])
139*5ba1f45fSchristos	else
140*5ba1f45fSchristos	    AC_MSG_WARN([std::thread does not work; disabling threading])
141*5ba1f45fSchristos	fi
1428dffb485Schristos    fi
1434b169a6bSchristos  fi
1448dffb485Schristos  AC_LANG_POP
1458dffb485Schristos
1468dffb485Schristos  dnl Check if sigsetjmp is available.  Using AC_CHECK_FUNCS won't
1478dffb485Schristos  dnl do since sigsetjmp might only be defined as a macro.
1484b169a6bSchristos  AC_CACHE_CHECK(
1494b169a6bSchristos    [for sigsetjmp],
1504b169a6bSchristos    [gdb_cv_func_sigsetjmp],
1514b169a6bSchristos    [AC_COMPILE_IFELSE(
1524b169a6bSchristos       [AC_LANG_PROGRAM(
1534b169a6bSchristos          [#include <setjmp.h>],
1544b169a6bSchristos          [sigjmp_buf env;
1554b169a6bSchristos           while (! sigsetjmp (env, 1))
1564b169a6bSchristos             siglongjmp (env, 1);]
1574b169a6bSchristos        )],
1584b169a6bSchristos       [gdb_cv_func_sigsetjmp=yes],
1594b169a6bSchristos       [gdb_cv_func_sigsetjmp=no]
1604b169a6bSchristos     )]
1614b169a6bSchristos  )
1628dffb485Schristos  if test "$gdb_cv_func_sigsetjmp" = "yes"; then
1638dffb485Schristos    AC_DEFINE(HAVE_SIGSETJMP, 1, [Define if sigsetjmp is available. ])
1648dffb485Schristos  fi
1658dffb485Schristos
1668dffb485Schristos  AC_ARG_WITH(intel_pt,
1678dffb485Schristos    AS_HELP_STRING([--with-intel-pt], [include Intel Processor Trace support (auto/yes/no)]),
1688dffb485Schristos    [], [with_intel_pt=auto])
1698dffb485Schristos  AC_MSG_CHECKING([whether to use intel pt])
1708dffb485Schristos  AC_MSG_RESULT([$with_intel_pt])
1718dffb485Schristos
1728dffb485Schristos  if test "${with_intel_pt}" = no; then
1738dffb485Schristos    AC_MSG_WARN([Intel Processor Trace support disabled; some features may be unavailable.])
1748dffb485Schristos    HAVE_LIBIPT=no
1758dffb485Schristos  else
1768dffb485Schristos    AC_PREPROC_IFELSE([AC_LANG_SOURCE([[
1778dffb485Schristos  #include <linux/perf_event.h>
1788dffb485Schristos  #ifndef PERF_ATTR_SIZE_VER5
1798dffb485Schristos  # error
1808dffb485Schristos  #endif
1818dffb485Schristos    ]])], [perf_event=yes], [perf_event=no])
1828dffb485Schristos    if test "$perf_event" != yes; then
1838dffb485Schristos      if test "$with_intel_pt" = yes; then
1848dffb485Schristos	AC_MSG_ERROR([linux/perf_event.h missing or too old])
1858dffb485Schristos      else
1868dffb485Schristos	AC_MSG_WARN([linux/perf_event.h missing or too old; some features may be unavailable.])
1878dffb485Schristos      fi
1888dffb485Schristos    fi
1898dffb485Schristos
1908dffb485Schristos    AC_LIB_HAVE_LINKFLAGS([ipt], [], [#include "intel-pt.h"], [pt_insn_alloc_decoder (0);])
1918dffb485Schristos    if test "$HAVE_LIBIPT" != yes; then
1928dffb485Schristos      if test "$with_intel_pt" = yes; then
1938dffb485Schristos	AC_MSG_ERROR([libipt is missing or unusable])
1948dffb485Schristos      else
1958dffb485Schristos	AC_MSG_WARN([libipt is missing or unusable; some features may be unavailable.])
1968dffb485Schristos      fi
1978dffb485Schristos    else
1988dffb485Schristos      save_LIBS=$LIBS
1998dffb485Schristos      LIBS="$LIBS $LIBIPT"
2008dffb485Schristos      AC_CHECK_FUNCS(pt_insn_event)
2018dffb485Schristos      AC_CHECK_MEMBERS([struct pt_insn.enabled, struct pt_insn.resynced], [], [],
2028dffb485Schristos		       [#include <intel-pt.h>])
2038dffb485Schristos      LIBS=$save_LIBS
2048dffb485Schristos    fi
2058dffb485Schristos  fi
2068dffb485Schristos
2074b169a6bSchristos  # Check if the compiler and runtime support printing long longs.
2084b169a6bSchristos
2094b169a6bSchristos  AC_CACHE_CHECK([for long long support in printf],
2104b169a6bSchristos		 gdb_cv_printf_has_long_long,
2114b169a6bSchristos		 [AC_RUN_IFELSE([AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT],
2124b169a6bSchristos  [[char buf[32];
2134b169a6bSchristos    long long l = 0;
2144b169a6bSchristos    l = (l << 16) + 0x0123;
2154b169a6bSchristos    l = (l << 16) + 0x4567;
2164b169a6bSchristos    l = (l << 16) + 0x89ab;
2174b169a6bSchristos    l = (l << 16) + 0xcdef;
2184b169a6bSchristos    sprintf (buf, "0x%016llx", l);
2194b169a6bSchristos    return (strcmp ("0x0123456789abcdef", buf));]])],
2204b169a6bSchristos				gdb_cv_printf_has_long_long=yes,
2214b169a6bSchristos				gdb_cv_printf_has_long_long=no,
2224b169a6bSchristos				gdb_cv_printf_has_long_long=no)])
2234b169a6bSchristos  if test "$gdb_cv_printf_has_long_long" = yes; then
2244b169a6bSchristos    AC_DEFINE(PRINTF_HAS_LONG_LONG, 1,
2254b169a6bSchristos	      [Define to 1 if the "%ll" format works to print long longs.])
2264b169a6bSchristos  fi
2274b169a6bSchristos
2288dffb485Schristos  BFD_SYS_PROCFS_H
2298dffb485Schristos  if test "$ac_cv_header_sys_procfs_h" = yes; then
2308dffb485Schristos    BFD_HAVE_SYS_PROCFS_TYPE(gregset_t)
2318dffb485Schristos    BFD_HAVE_SYS_PROCFS_TYPE(fpregset_t)
2328dffb485Schristos    BFD_HAVE_SYS_PROCFS_TYPE(prgregset_t)
2338dffb485Schristos    BFD_HAVE_SYS_PROCFS_TYPE(prfpregset_t)
2348dffb485Schristos    BFD_HAVE_SYS_PROCFS_TYPE(prgregset32_t)
2358dffb485Schristos    BFD_HAVE_SYS_PROCFS_TYPE(lwpid_t)
2368dffb485Schristos    BFD_HAVE_SYS_PROCFS_TYPE(psaddr_t)
2378dffb485Schristos    BFD_HAVE_SYS_PROCFS_TYPE(elf_fpregset_t)
2388dffb485Schristos  fi
239*5ba1f45fSchristos
240*5ba1f45fSchristos  dnl xxhash support
241*5ba1f45fSchristos  # Check for xxhash
242*5ba1f45fSchristos  AC_ARG_WITH(xxhash,
243*5ba1f45fSchristos    AS_HELP_STRING([--with-xxhash], [use libxxhash for hashing (faster) (auto/yes/no)]),
244*5ba1f45fSchristos    [], [with_xxhash=auto])
245*5ba1f45fSchristos
246*5ba1f45fSchristos  if test "x$with_xxhash" != "xno"; then
247*5ba1f45fSchristos    AC_LIB_HAVE_LINKFLAGS([xxhash], [],
248*5ba1f45fSchristos			  [#include <xxhash.h>],
249*5ba1f45fSchristos			  [XXH32("foo", 3, 0);
250*5ba1f45fSchristos			  ])
251*5ba1f45fSchristos    if test "$HAVE_LIBXXHASH" != yes; then
252*5ba1f45fSchristos      if test "$with_xxhash" = yes; then
253*5ba1f45fSchristos	AC_MSG_ERROR([xxhash is missing or unusable])
254*5ba1f45fSchristos      fi
255*5ba1f45fSchristos    fi
256*5ba1f45fSchristos    if test "x$with_xxhash" = "xauto"; then
257*5ba1f45fSchristos      with_xxhash="$HAVE_LIBXXHASH"
258*5ba1f45fSchristos    fi
259*5ba1f45fSchristos  fi
260*5ba1f45fSchristos
261*5ba1f45fSchristos  AC_MSG_CHECKING([whether to use xxhash])
262*5ba1f45fSchristos  AC_MSG_RESULT([$with_xxhash])
2638dffb485Schristos])
2644b169a6bSchristos
2654b169a6bSchristosdnl Check that the provided value ($1) is either "yes" or "no".  If not,
2664b169a6bSchristosdnl emit an error message mentionning the configure option $2, and abort
2674b169a6bSchristosdnl the script.
2684b169a6bSchristosAC_DEFUN([GDB_CHECK_YES_NO_VAL],
2694b169a6bSchristos	 [
2704b169a6bSchristos	   case $1 in
2714b169a6bSchristos	     yes | no)
2724b169a6bSchristos	       ;;
2734b169a6bSchristos	     *)
2744b169a6bSchristos	       AC_MSG_ERROR([bad value $1 for $2])
2754b169a6bSchristos	       ;;
2764b169a6bSchristos	   esac
2774b169a6bSchristos	  ])
2784b169a6bSchristos
2794b169a6bSchristosdnl Check that the provided value ($1) is either "yes", "no" or "auto".  If not,
2804b169a6bSchristosdnl emit an error message mentionning the configure option $2, and abort
2814b169a6bSchristosdnl the script.
2824b169a6bSchristosAC_DEFUN([GDB_CHECK_YES_NO_AUTO_VAL],
2834b169a6bSchristos	 [
2844b169a6bSchristos	   case $1 in
2854b169a6bSchristos	     yes | no | auto)
2864b169a6bSchristos	       ;;
2874b169a6bSchristos	     *)
2884b169a6bSchristos	       AC_MSG_ERROR([bad value $1 for $2])
2894b169a6bSchristos	       ;;
2904b169a6bSchristos	   esac
2914b169a6bSchristos	  ])
292