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