Home | History | Annotate | Line # | Download | only in gdbserver
      1 dnl Autoconf configure script for GDB server.
      2 dnl Copyright (C) 2000-2024 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/>.
     18 
     19 dnl Process this file with autoconf to produce a configure script.
     20 
     21 AC_INIT
     22 AC_CONFIG_MACRO_DIRS([../config])
     23 AC_CONFIG_SRCDIR([server.cc])
     24 AC_CONFIG_HEADERS(config.h:config.in, [echo > stamp-h])
     25 
     26 AM_MAINTAINER_MODE
     27 
     28 AC_PROG_CC
     29 AC_PROG_CXX
     30 AC_USE_SYSTEM_EXTENSIONS
     31 AC_SYS_LARGEFILE
     32 AM_PROG_INSTALL_STRIP
     33 
     34 # Set build, build_cpu, build_vendor and build_os.
     35 AC_CANONICAL_BUILD
     36 
     37 # Set host, host_cpu, host_vendor, and host_os.
     38 AC_CANONICAL_HOST
     39 
     40 # Set target, target_cpu, target_vendor, and target_os.
     41 AC_CANONICAL_TARGET
     42 
     43 AC_PROG_INSTALL
     44 AC_CHECK_TOOL(AR, ar)
     45 AC_PROG_RANLIB
     46 
     47 AC_ARG_PROGRAM
     48 
     49 # We require a C++17 compiler.  Check if one is available, and if
     50 # necessary, set CXX_DIALECT to some -std=xxx switch.
     51 AX_CXX_COMPILE_STDCXX(17, , mandatory)
     52 
     53 AC_HEADER_STDC
     54 
     55 GDB_AC_COMMON
     56 # This is set by GDB_AC_COMMON.
     57 AC_SUBST(WIN32APILIBS)
     58 
     59 GDB_AC_SELFTEST
     60 
     61 ACX_NONCANONICAL_TARGET
     62 ACX_NONCANONICAL_HOST
     63 
     64 # Dependency checking.
     65 ZW_CREATE_DEPDIR
     66 
     67 dnl Set up for gettext.
     68 ZW_GNU_GETTEXT_SISTER_DIR
     69 
     70 # Create sub-directories for objects and dependencies.
     71 CONFIG_SRC_SUBDIR="arch gdbsupport nat target"
     72 AC_SUBST(CONFIG_SRC_SUBDIR)
     73 
     74 AC_CONFIG_COMMANDS([gdbdepdir],[
     75   for subdir in ${CONFIG_SRC_SUBDIR}
     76   do
     77       $SHELL $ac_aux_dir/mkinstalldirs $subdir/$DEPDIR
     78   done],
     79   [ac_aux_dir=$ac_aux_dir DEPDIR=$DEPDIR CONFIG_SRC_SUBDIR="$CONFIG_SRC_SUBDIR"])
     80 
     81 ZW_PROG_COMPILER_DEPENDENCIES([CC])
     82 
     83 AC_CHECK_HEADERS([ \
     84   arpa/inet.h \
     85   fcntl.h \
     86   linux/elf.h \
     87   netdb.h \
     88   netinet/in.h \
     89   netinet/tcp.h \
     90   signal.h \
     91   string.h \
     92   sys/file.h \
     93   sys/ioctl.h \
     94   sys/procfs.h \
     95   sys/reg.h \
     96   sys/socket.h \
     97   termios.h \
     98   ws2tcpip.h \
     99 ])
    100 
    101 AC_FUNC_FORK
    102 AC_CHECK_FUNCS([ \
    103   pread \
    104   pread64 \
    105   pwrite \
    106 ])
    107 
    108 # Check the return and argument types of ptrace.
    109 GDB_AC_PTRACE
    110 
    111 # Check for UST
    112 ustlibs=""
    113 ustinc=""
    114 
    115 AC_ARG_WITH(ust, [  --with-ust=PATH       Specify prefix directory for the installed UST package
    116                           Equivalent to --with-ust-include=PATH/include
    117                           plus --with-ust-lib=PATH/lib])
    118 AC_ARG_WITH(ust_include, [  --with-ust-include=PATH Specify directory for installed UST include files])
    119 AC_ARG_WITH(ust_lib, [  --with-ust-lib=PATH   Specify the directory for the installed UST library])
    120 
    121 case $with_ust in
    122   no)
    123     ustlibs=
    124     ustinc=
    125     ;;
    126   "" | yes)
    127     ustlibs=" -lust "
    128     ustinc=""
    129     ;;
    130   *)
    131     ustlibs="-L$with_ust/lib -lust"
    132     ustinc="-I$with_ust/include "
    133     ;;
    134 esac
    135 if test "x$with_ust_include" != x; then
    136   ustinc="-I$with_ust_include "
    137 fi
    138 if test "x$with_ust_lib" != x; then
    139   ustlibs="-L$with_ust_lib -lust"
    140 fi
    141 
    142 if test "x$with_ust" != "xno"; then
    143   saved_CFLAGS="$CFLAGS"
    144   CFLAGS="$CFLAGS $ustinc"
    145   AC_MSG_CHECKING([for ust])
    146   AC_COMPILE_IFELSE(
    147     [AC_LANG_PROGRAM(
    148        [
    149 #define CONFIG_UST_GDB_INTEGRATION
    150 #include <ust/ust.h>
    151        ],
    152        []
    153      )],
    154     [AC_MSG_RESULT([yes]);
    155      AC_DEFINE(HAVE_UST, 1, [Define if UST is available])],
    156     [AC_MSG_RESULT([no])
    157      ustlibs= ; ustinc= ]
    158   )
    159   CFLAGS="$saved_CFLAGS"
    160 fi
    161 
    162 # Flags needed for UST
    163 AC_SUBST(ustlibs)
    164 AC_SUBST(ustinc)
    165 
    166 AM_GDB_COMPILER_TYPE
    167 AM_GDB_WARNINGS
    168 
    169 dnl dladdr is glibc-specific.  It is used by thread-db.c but only for
    170 dnl debugging messages.  It lives in -ldl which is handled below so we don't
    171 dnl use AC_CHECK_LIB (or AC_SEARCH_LIBS) here.  Instead we just temporarily
    172 dnl augment LIBS.
    173 old_LIBS="$LIBS"
    174 LIBS="$LIBS -ldl"
    175 AC_CHECK_FUNCS(dladdr)
    176 LIBS="$old_LIBS"
    177 
    178 libiberty_INIT
    179 
    180 AC_CHECK_DECLS([perror, vasprintf, vsnprintf])
    181 
    182 AC_CHECK_TYPES(socklen_t, [], [],
    183 [#include <sys/types.h>
    184 #if HAVE_SYS_SOCKET_H
    185 # include <sys/socket.h>
    186 #elif HAVE_WS2TCPIP_H
    187 # include <ws2tcpip.h>
    188 #endif
    189 ])
    190 
    191 case "${target}" in
    192   *-android*)
    193     # Starting with NDK version 9, <elf.h> actually includes definitions
    194     # of Elf32_auxv_t and Elf64_auxv_t. But sadly, <elf.h> includes
    195     # <sys/exec_elf.h> which defines some of the ELF types incorrectly,
    196     # leading to conflicts with the defintions from <linux/elf.h>.
    197     # This makes it impossible for us to include both <elf.h> and
    198     # <linux/elf.h>, which means that, in practice, we do not have
    199     # access to Elf32_auxv_t and Elf64_auxv_t on this platform.
    200     # Therefore, do not try to auto-detect availability, as it would
    201     # get it wrong on this platform.
    202     ;;
    203   *)
    204     AC_CHECK_TYPES([Elf32_auxv_t, Elf64_auxv_t], [], [],
    205     #include <elf.h>
    206     )
    207 esac
    208 
    209 ACX_PKGVERSION([GDB])
    210 ACX_BUGURL([http://www.gnu.org/software/gdb/bugs/])
    211 AC_DEFINE_UNQUOTED([PKGVERSION], ["$PKGVERSION"], [Additional package description])
    212 AC_DEFINE_UNQUOTED([REPORT_BUGS_TO], ["$REPORT_BUGS_TO"], [Bug reporting address])
    213 
    214 # Check for various supplementary target information (beyond the
    215 # triplet) which might affect the choices in configure.srv.
    216 case "${target}" in
    217 changequote(,)dnl
    218   i[34567]86-*-linux*)
    219 changequote([,])dnl
    220     AC_CACHE_CHECK([if building for x86-64], [gdb_cv_i386_is_x86_64],
    221       	           [save_CPPFLAGS="$CPPFLAGS"
    222                     CPPFLAGS="$CPPFLAGS $CFLAGS"
    223                     AC_EGREP_CPP([got it], [
    224 #if __x86_64__
    225 got it
    226 #endif
    227                  ], [gdb_cv_i386_is_x86_64=yes],
    228                     [gdb_cv_i386_is_x86_64=no])
    229                     CPPFLAGS="$save_CPPFLAGS"])
    230     ;;
    231 
    232   x86_64-*-linux*)
    233     AC_CACHE_CHECK([if building for x32], [gdb_cv_x86_is_x32],
    234 		   [save_CPPFLAGS="$CPPFLAGS"
    235 		    CPPFLAGS="$CPPFLAGS $CFLAGS"
    236 		    AC_EGREP_CPP([got it], [
    237 #if __x86_64__ && __ILP32__
    238 got it
    239 #endif
    240 		 ], [gdb_cv_x86_is_x32=yes],
    241 		    [gdb_cv_x86_is_x32=no])
    242 		    CPPFLAGS="$save_CPPFLAGS"])
    243     ;;
    244 
    245   m68k-*-*)
    246     AC_CACHE_CHECK([if building for Coldfire], [gdb_cv_m68k_is_coldfire],
    247       	           [save_CPPFLAGS="$CPPFLAGS"
    248                     CPPFLAGS="$CPPFLAGS $CFLAGS"
    249                     AC_EGREP_CPP([got it], [
    250 #ifdef __mcoldfire__
    251 got it
    252 #endif
    253                  ], [gdb_cv_m68k_is_coldfire=yes],
    254                     [gdb_cv_m68k_is_coldfire=no])
    255                     CPPFLAGS="$save_CPPFLAGS"])
    256     ;;
    257 esac
    258 
    259 . ${srcdir}/configure.srv
    260 
    261 if test "${srv_mingwce}" = "yes"; then
    262   LIBS="$LIBS -lws2"
    263 elif test "${srv_mingw}" = "yes"; then
    264   # WIN32APILIBS is set by GDB_AC_COMMON.
    265   LIBS="$LIBS $WIN32APILIBS"
    266 fi
    267 
    268 if test "${srv_linux_usrregs}" = "yes"; then
    269   AC_DEFINE(HAVE_LINUX_USRREGS, 1,
    270 	    [Define if the target supports PTRACE_PEEKUSR for register ]
    271 	    [access.])
    272 fi
    273 
    274 if test "${srv_linux_regsets}" = "yes"; then
    275   AC_DEFINE(HAVE_LINUX_REGSETS, 1,
    276 	    [Define if the target supports register sets.])
    277 
    278   AC_MSG_CHECKING(for PTRACE_GETREGS)
    279   AC_CACHE_VAL(
    280     [gdbsrv_cv_have_ptrace_getregs],
    281     [AC_COMPILE_IFELSE(
    282        [AC_LANG_PROGRAM([#include <sys/ptrace.h>], [PTRACE_GETREGS;])],
    283        [gdbsrv_cv_have_ptrace_getregs=yes],
    284        [gdbsrv_cv_have_ptrace_getregs=no]
    285      )]
    286   )
    287   AC_MSG_RESULT($gdbsrv_cv_have_ptrace_getregs)
    288   if test "${gdbsrv_cv_have_ptrace_getregs}" = "yes"; then
    289     AC_DEFINE(HAVE_PTRACE_GETREGS, 1,
    290 	      [Define if the target supports PTRACE_GETREGS for register ]
    291 	      [access.])
    292   fi
    293 
    294   AC_MSG_CHECKING(for PTRACE_GETFPXREGS)
    295   AC_CACHE_VAL(
    296     [gdbsrv_cv_have_ptrace_getfpxregs],
    297     [AC_COMPILE_IFELSE(
    298        [AC_LANG_PROGRAM([#include <sys/ptrace.h>], [PTRACE_GETFPXREGS;])],
    299        [gdbsrv_cv_have_ptrace_getfpxregs=yes],
    300        [gdbsrv_cv_have_ptrace_getfpxregs=no]
    301      )]
    302   )
    303   AC_MSG_RESULT($gdbsrv_cv_have_ptrace_getfpxregs)
    304   if test "${gdbsrv_cv_have_ptrace_getfpxregs}" = "yes"; then
    305     AC_DEFINE(HAVE_PTRACE_GETFPXREGS, 1,
    306 	      [Define if the target supports PTRACE_GETFPXREGS for extended ]
    307 	      [register access.])
    308   fi
    309 fi
    310 
    311 if test "${srv_linux_btrace}" = "yes"; then
    312   AC_DEFINE(HAVE_LINUX_BTRACE, 1,
    313 	    [Define if the target supports branch tracing.])
    314 fi
    315 
    316 dnl Some systems (e.g., Android) have lwpid_t defined in libthread_db.h.
    317 if test "$bfd_cv_have_sys_procfs_type_lwpid_t" != yes; then
    318   GDBSERVER_HAVE_THREAD_DB_TYPE(lwpid_t)
    319 fi
    320 
    321 dnl Some systems (e.g., Android) have psaddr_t defined in libthread_db.h.
    322 if test "$bfd_cv_have_sys_procfs_type_psaddr_t" != yes; then
    323   GDBSERVER_HAVE_THREAD_DB_TYPE(psaddr_t)
    324 fi
    325 
    326 dnl Check for libdl, but do not add it to LIBS as only gdbserver
    327 dnl needs it (and gdbreplay doesn't).
    328 old_LIBS="$LIBS"
    329 AC_CHECK_LIB(dl, dlopen)
    330 LIBS="$old_LIBS"
    331 
    332 srv_thread_depfiles=
    333 srv_libs=
    334 
    335 if test "$srv_linux_thread_db" = "yes"; then
    336   if test "$ac_cv_lib_dl_dlopen" = "yes"; then
    337     srv_libs="-ldl"
    338     AC_MSG_CHECKING(for the dynamic export flag)
    339     old_LDFLAGS="$LDFLAGS"
    340     # Older GNU ld supports --export-dynamic but --dynamic-list may not be
    341     # supported there.
    342     RDYNAMIC="-Wl,--dynamic-list=${srcdir}/proc-service.list"
    343     LDFLAGS="$LDFLAGS $RDYNAMIC"
    344     AC_LINK_IFELSE(
    345       [AC_LANG_PROGRAM([],[])],
    346       [found="-Wl,--dynamic-list"
    347        RDYNAMIC='-Wl,--dynamic-list=$(srcdir)/proc-service.list'],
    348       [RDYNAMIC="-rdynamic"
    349        LDFLAGS="$old_LDFLAGS $RDYNAMIC"
    350        AC_LINK_IFELSE(
    351 	 [AC_LANG_PROGRAM([], [])],
    352 	 [found="-rdynamic"],
    353 	 [found="no"
    354 	  RDYNAMIC=""]
    355        )]
    356     )
    357     AC_SUBST(RDYNAMIC)
    358     LDFLAGS="$old_LDFLAGS"
    359     AC_MSG_RESULT($found)
    360   else
    361     srv_libs="-lthread_db"
    362   fi
    363 
    364   srv_thread_depfiles="thread-db.o proc-service.o"
    365   AC_DEFINE(USE_THREAD_DB, 1, [Define if we should use libthread_db.])
    366   AC_CACHE_CHECK(
    367     [for TD_VERSION],
    368     [gdbsrv_cv_have_td_version],
    369     [AC_COMPILE_IFELSE(
    370        [AC_LANG_PROGRAM([#include <thread_db.h>], [TD_VERSION;])],
    371        [gdbsrv_cv_have_td_version=yes],
    372        [gdbsrv_cv_have_td_version=no]
    373      )]
    374   )
    375   if test "$gdbsrv_cv_have_td_version" = yes; then
    376     AC_DEFINE(HAVE_TD_VERSION, 1, [Define if TD_VERSION is available.])
    377   fi
    378 fi
    379 
    380 AC_ARG_WITH(libthread-db,
    381 AS_HELP_STRING([--with-libthread-db=PATH], [use given libthread_db directly]),
    382 [srv_libthread_db_path="${withval}"
    383   srv_libs="$srv_libthread_db_path"
    384 ])
    385 
    386 if test "$srv_libs" != "" -a "$srv_libs" != "-ldl"; then
    387   AC_DEFINE(USE_LIBTHREAD_DB_DIRECTLY, 1, [Define if we should use libthread_db directly.])
    388 fi
    389 
    390 if test "$srv_xmlfiles" != ""; then
    391   srv_xmlbuiltin="xml-builtin.o"
    392   AC_DEFINE(USE_XML, 1, [Define if an XML target description is available.])
    393 
    394   tmp_xmlfiles=$srv_xmlfiles
    395   srv_xmlfiles=""
    396   for f in $tmp_xmlfiles; do
    397     srv_xmlfiles="$srv_xmlfiles \$(XML_DIR)/$f"
    398   done
    399 fi
    400 
    401 GDBSERVER_DEPFILES="$srv_regobj $srv_tgtobj $srv_thread_depfiles"
    402 GDBSERVER_LIBS="$srv_libs"
    403 
    404 dnl Check whether the target supports __sync_*_compare_and_swap.
    405 AC_CACHE_CHECK(
    406   [whether the target supports __sync_*_compare_and_swap],
    407   [gdbsrv_cv_have_sync_builtins],
    408   [AC_LINK_IFELSE(
    409      [AC_LANG_PROGRAM(
    410 	[],
    411 	[int foo, bar;
    412 	 bar = __sync_val_compare_and_swap(&foo, 0, 1);]
    413       )],
    414      [gdbsrv_cv_have_sync_builtins=yes],
    415      [gdbsrv_cv_have_sync_builtins=no]
    416    )]
    417 )
    418 if test "$gdbsrv_cv_have_sync_builtins" = yes; then
    419   AC_DEFINE(HAVE_SYNC_BUILTINS, 1,
    420     [Define to 1 if the target supports __sync_*_compare_and_swap])
    421 fi
    422 
    423 dnl Check for -fvisibility=hidden support in the compiler.
    424 saved_cflags="$CFLAGS"
    425 CFLAGS="$CFLAGS -fvisibility=hidden"
    426 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
    427 		        [gdbsrv_cv_have_visibility_hidden=yes],
    428 	        	[gdbsrv_cv_have_visibility_hidden=no])
    429 CFLAGS="$saved_cflags"
    430 
    431 IPA_DEPFILES=""
    432 extra_libraries=""
    433 
    434 # check whether to enable the inprocess agent
    435 if test "$ipa_obj" != "" \
    436    -a "$gdbsrv_cv_have_sync_builtins" = yes \
    437    -a "$gdbsrv_cv_have_visibility_hidden" = yes; then
    438    have_ipa=true
    439 else
    440    have_ipa=false
    441 fi
    442 
    443 AC_ARG_ENABLE(inprocess-agent,
    444 AS_HELP_STRING([--enable-inprocess-agent], [inprocess agent]),
    445 [case "$enableval" in
    446   yes) want_ipa=true ;;
    447   no) want_ipa=false ;;
    448   *) AC_MSG_ERROR([bad value $enableval for inprocess-agent]) ;;
    449 esac],
    450 [want_ipa=$have_ipa])
    451 
    452 if $want_ipa ; then
    453    if $have_ipa ; then
    454      IPA_DEPFILES="$ipa_obj"
    455      extra_libraries="$extra_libraries libinproctrace.so"
    456    else
    457      AC_MSG_ERROR([inprocess agent not supported for this target])
    458    fi
    459 fi
    460 
    461 AC_SUBST(GDBSERVER_DEPFILES)
    462 AC_SUBST(GDBSERVER_LIBS)
    463 AC_SUBST(srv_xmlbuiltin)
    464 AC_SUBST(srv_xmlfiles)
    465 AC_SUBST(IPA_DEPFILES)
    466 AC_SUBST(extra_libraries)
    467 
    468 GNULIB=../gnulib/import
    469 
    470 GNULIB_STDINT_H=
    471 if test x"$STDINT_H" != x; then
    472   GNULIB_STDINT_H=$GNULIB/$STDINT_H
    473 fi
    474 AC_SUBST(GNULIB_STDINT_H)
    475 
    476 # Check for libiconv.  It is a requirement for Linux hosts, and others hosts
    477 # don't use it at all.  Define MAYBE_LIBICONV only if the host is Linux.
    478 AM_ICONV
    479 MAYBE_LIBICONV=
    480 case "$host" in
    481   *linux*)
    482     if test "$am_cv_func_iconv" != yes; then
    483       AC_MSG_ERROR([could not find libiconv (required for host $host)])
    484     fi
    485 
    486     MAYBE_LIBICONV="$LIBICONV"
    487     ;;
    488 esac
    489 
    490 AC_SUBST(MAYBE_LIBICONV)
    491 
    492 AC_CONFIG_FILES([Makefile])
    493 
    494 AC_OUTPUT
    495