* linux-low.c (linux_stabilize_threads): Wrap debug output in a
[binutils-gdb.git] / gdb / gdbserver / configure.ac
1 dnl Autoconf configure script for GDB server.
2 dnl Copyright (C) 2000, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
3 dnl 2010 Free Software Foundation, Inc.
4 dnl
5 dnl This file is part of GDB.
6 dnl
7 dnl This program is free software; you can redistribute it and/or modify
8 dnl it under the terms of the GNU General Public License as published by
9 dnl the Free Software Foundation; either version 3 of the License, or
10 dnl (at your option) any later version.
11 dnl
12 dnl This program is distributed in the hope that it will be useful,
13 dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
14 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 dnl GNU General Public License for more details.
16 dnl
17 dnl You should have received a copy of the GNU General Public License
18 dnl along with this program. If not, see <http://www.gnu.org/licenses/>.
19
20 dnl Process this file with autoconf to produce a configure script.
21
22 AC_PREREQ(2.59)dnl
23
24 AC_INIT(server.c)
25 AC_CONFIG_HEADER(config.h:config.in)
26 AC_CONFIG_LIBOBJ_DIR(../gnulib)
27
28 AC_PROG_CC
29 AC_GNU_SOURCE
30
31 AC_CANONICAL_SYSTEM
32
33 AC_PROG_INSTALL
34
35 AC_ARG_PROGRAM
36
37 AC_HEADER_STDC
38
39 AC_CHECK_HEADERS(sgtty.h termio.h termios.h sys/reg.h string.h dnl
40 proc_service.h sys/procfs.h thread_db.h linux/elf.h dnl
41 stdlib.h unistd.h dnl
42 errno.h fcntl.h signal.h sys/file.h malloc.h dnl
43 sys/ioctl.h netinet/in.h sys/socket.h netdb.h dnl
44 netinet/tcp.h arpa/inet.h sys/wait.h)
45 AC_CHECK_FUNCS(pread pwrite pread64)
46 AC_REPLACE_FUNCS(memmem)
47
48 # Check for UST
49 ustlibs=""
50 ustinc=""
51
52 AC_ARG_WITH(ust, [ --with-ust=PATH Specify prefix directory for the installed UST package
53 Equivalent to --with-ust-include=PATH/include
54 plus --with-ust-lib=PATH/lib])
55 AC_ARG_WITH(ust_include, [ --with-ust-include=PATH Specify directory for installed UST include files])
56 AC_ARG_WITH(ust_lib, [ --with-ust-lib=PATH Specify the directory for the installed UST library])
57
58 case $with_ust in
59 no)
60 ustlibs=
61 ustinc=
62 ;;
63 "" | yes)
64 ustlibs=" -lust "
65 ustinc=""
66 ;;
67 *)
68 ustlibs="-L$with_ust/lib -lust"
69 ustinc="-I$with_ust/include "
70 ;;
71 esac
72 if test "x$with_ust_include" != x; then
73 ustinc="-I$with_ust_include "
74 fi
75 if test "x$with_ust_lib" != x; then
76 ustlibs="-L$with_ust_lib -lust"
77 fi
78
79 if test "x$with_ust" != "xno"; then
80 saved_CFLAGS="$CFLAGS"
81 CFLAGS="$CFLAGS $ustinc"
82 AC_MSG_CHECKING([for ust])
83 AC_TRY_COMPILE([
84 #define CONFIG_UST_GDB_INTEGRATION
85 #include <ust/ust.h>
86 ],[],
87 [AC_MSG_RESULT([yes]); AC_DEFINE(HAVE_UST, 1, [Define if UST is available])],
88 [AC_MSG_RESULT([no]); ustlibs= ; ustinc= ])
89 CFLAGS="$saved_CFLAGS"
90 fi
91
92 # Flags needed for UST
93 AC_SUBST(ustlibs)
94 AC_SUBST(ustinc)
95
96 AC_ARG_ENABLE(werror,
97 AS_HELP_STRING([--enable-werror], [treat compile warnings as errors]),
98 [case "${enableval}" in
99 yes | y) ERROR_ON_WARNING="yes" ;;
100 no | n) ERROR_ON_WARNING="no" ;;
101 *) AC_MSG_ERROR(bad value ${enableval} for --enable-werror) ;;
102 esac])
103
104 # Enable -Werror by default when using gcc
105 if test "${GCC}" = yes -a -z "${ERROR_ON_WARNING}" ; then
106 ERROR_ON_WARNING=yes
107 fi
108
109 WERROR_CFLAGS=""
110 if test "${ERROR_ON_WARNING}" = yes ; then
111 WERROR_CFLAGS="-Werror"
112 fi
113
114 build_warnings="-Wall -Wdeclaration-after-statement -Wpointer-arith \
115 -Wformat-nonliteral -Wno-char-subscripts"
116
117 WARN_CFLAGS=""
118 if test "x$GCC" = xyes
119 then
120 AC_MSG_CHECKING(compiler warning flags)
121 # Separate out the -Werror flag as some files just cannot be
122 # compiled with it enabled.
123 for w in ${build_warnings}; do
124 case $w in
125 -Werr*) WERROR_CFLAGS=-Werror ;;
126 *) # Check that GCC accepts it
127 saved_CFLAGS="$CFLAGS"
128 CFLAGS="$CFLAGS $w"
129 AC_TRY_COMPILE([],[],WARN_CFLAGS="${WARN_CFLAGS} $w",)
130 CFLAGS="$saved_CFLAGS"
131 esac
132 done
133 AC_MSG_RESULT(${WARN_CFLAGS} ${WERROR_CFLAGS})
134 fi
135 AC_SUBST(WARN_CFLAGS)
136 AC_SUBST(WERROR_CFLAGS)
137
138 dnl dladdr is glibc-specific. It is used by thread-db.c but only for
139 dnl debugging messages. It lives in -ldl which is handled below so we don't
140 dnl use AC_CHECK_LIB (or AC_SEARCH_LIBS) here. Instead we just temporarily
141 dnl augment LIBS.
142 old_LIBS="$LIBS"
143 LIBS="$LIBS -ldl"
144 AC_CHECK_FUNCS(dladdr)
145 LIBS="$old_LIBS"
146
147 have_errno=no
148 AC_MSG_CHECKING(for errno)
149 AC_TRY_LINK([
150 #if HAVE_ERRNO_H
151 #include <errno.h>
152 #endif], [static int x; x = errno;],
153 [AC_MSG_RESULT(yes - in errno.h); AC_DEFINE(HAVE_ERRNO, 1, [Define if errno is available]) have_errno=yes])
154 if test $have_errno = no; then
155 AC_TRY_LINK([
156 #if HAVE_ERRNO_H
157 #include <errno.h>
158 #endif], [extern int errno; static int x; x = errno;],
159 [AC_MSG_RESULT(yes - must define); AC_DEFINE(HAVE_ERRNO, 1, [Define if errno is available]) AC_DEFINE(MUST_DEFINE_ERRNO, 1, [Checking if errno must be defined])],
160 [AC_MSG_RESULT(no)])
161 fi
162
163 AC_CHECK_DECLS([strerror, perror, memmem])
164
165 AC_CHECK_TYPES(socklen_t, [], [],
166 [#include <sys/types.h>
167 #include <sys/socket.h>
168 ])
169
170 ACX_PKGVERSION([GDB])
171 ACX_BUGURL([http://www.gnu.org/software/gdb/bugs/])
172 AC_DEFINE_UNQUOTED([PKGVERSION], ["$PKGVERSION"], [Additional package description])
173 AC_DEFINE_UNQUOTED([REPORT_BUGS_TO], ["$REPORT_BUGS_TO"], [Bug reporting address])
174
175 # Check for various supplementary target information (beyond the
176 # triplet) which might affect the choices in configure.srv.
177 case "${target}" in
178 changequote(,)dnl
179 i[34567]86-*-linux*)
180 changequote([,])dnl
181 AC_CACHE_CHECK([if building for x86-64], [gdb_cv_i386_is_x86_64],
182 [save_CPPFLAGS="$CPPFLAGS"
183 CPPFLAGS="$CPPFLAGS $CFLAGS"
184 AC_EGREP_CPP([got it], [
185 #if __x86_64__
186 got it
187 #endif
188 ], [gdb_cv_i386_is_x86_64=yes],
189 [gdb_cv_i386_is_x86_64=no])
190 CPPFLAGS="$save_CPPFLAGS"])
191 ;;
192 m68k-*-*)
193 AC_CACHE_CHECK([if building for Coldfire], [gdb_cv_m68k_is_coldfire],
194 [save_CPPFLAGS="$CPPFLAGS"
195 CPPFLAGS="$CPPFLAGS $CFLAGS"
196 AC_EGREP_CPP([got it], [
197 #ifdef __mcoldfire__
198 got it
199 #endif
200 ], [gdb_cv_m68k_is_coldfire=yes],
201 [gdb_cv_m68k_is_coldfire=no])
202 CPPFLAGS="$save_CPPFLAGS"])
203 ;;
204 esac
205
206 . ${srcdir}/configure.srv
207
208 if test "${srv_mingwce}" = "yes"; then
209 LIBS="$LIBS -lws2"
210 elif test "${srv_mingw}" = "yes"; then
211 LIBS="$LIBS -lws2_32"
212 elif test "${srv_qnx}" = "yes"; then
213 LIBS="$LIBS -lsocket"
214 fi
215
216 if test "${srv_mingw}" = "yes"; then
217 AC_DEFINE(USE_WIN32API, 1,
218 [Define if we should use the Windows API, instead of the
219 POSIX API. On Windows, we use the Windows API when
220 building for MinGW, but the POSIX API when building
221 for Cygwin.])
222 fi
223
224 if test "${srv_linux_usrregs}" = "yes"; then
225 AC_DEFINE(HAVE_LINUX_USRREGS, 1,
226 [Define if the target supports PTRACE_PEEKUSR for register ]
227 [access.])
228 fi
229
230 if test "${srv_linux_regsets}" = "yes"; then
231 AC_DEFINE(HAVE_LINUX_REGSETS, 1,
232 [Define if the target supports register sets.])
233
234 AC_MSG_CHECKING(for PTRACE_GETREGS)
235 AC_CACHE_VAL(gdbsrv_cv_have_ptrace_getregs,
236 [AC_TRY_COMPILE([#include <sys/ptrace.h>],
237 [PTRACE_GETREGS;],
238 [gdbsrv_cv_have_ptrace_getregs=yes],
239 [gdbsrv_cv_have_ptrace_getregs=no])])
240 AC_MSG_RESULT($gdbsrv_cv_have_ptrace_getregs)
241 if test "${gdbsrv_cv_have_ptrace_getregs}" = "yes"; then
242 AC_DEFINE(HAVE_PTRACE_GETREGS, 1,
243 [Define if the target supports PTRACE_GETREGS for register ]
244 [access.])
245 fi
246
247 AC_MSG_CHECKING(for PTRACE_GETFPXREGS)
248 AC_CACHE_VAL(gdbsrv_cv_have_ptrace_getfpxregs,
249 [AC_TRY_COMPILE([#include <sys/ptrace.h>],
250 [PTRACE_GETFPXREGS;],
251 [gdbsrv_cv_have_ptrace_getfpxregs=yes],
252 [gdbsrv_cv_have_ptrace_getfpxregs=no])])
253 AC_MSG_RESULT($gdbsrv_cv_have_ptrace_getfpxregs)
254 if test "${gdbsrv_cv_have_ptrace_getfpxregs}" = "yes"; then
255 AC_DEFINE(HAVE_PTRACE_GETFPXREGS, 1,
256 [Define if the target supports PTRACE_GETFPXREGS for extended ]
257 [register access.])
258 fi
259 fi
260
261 if test "$ac_cv_header_sys_procfs_h" = yes; then
262 BFD_HAVE_SYS_PROCFS_TYPE(lwpid_t)
263 BFD_HAVE_SYS_PROCFS_TYPE(psaddr_t)
264 BFD_HAVE_SYS_PROCFS_TYPE(prgregset_t)
265 BFD_HAVE_SYS_PROCFS_TYPE(elf_fpregset_t)
266 fi
267
268 dnl Check for libdl, but do not add it to LIBS as only gdbserver
269 dnl needs it (and gdbreplay doesn't).
270 old_LIBS="$LIBS"
271 AC_CHECK_LIB(dl, dlopen)
272 LIBS="$old_LIBS"
273
274 srv_thread_depfiles=
275 srv_libs=
276 USE_THREAD_DB=
277
278 if test "$srv_linux_thread_db" = "yes"; then
279 if test "$ac_cv_lib_dl_dlopen" = "yes"; then
280 srv_libs="-ldl"
281 AC_MSG_CHECKING(for the dynamic export flag)
282 old_LDFLAGS="$LDFLAGS"
283 # Older GNU ld supports --export-dynamic but --dynamic-list may not be
284 # supported there.
285 RDYNAMIC="-Wl,--dynamic-list=${srcdir}/proc-service.list"
286 LDFLAGS="$LDFLAGS $RDYNAMIC"
287 AC_TRY_LINK([], [],
288 [found="-Wl,--dynamic-list"
289 RDYNAMIC='-Wl,--dynamic-list=$(srcdir)/proc-service.list'],
290 [RDYNAMIC="-rdynamic"
291 LDFLAGS="$old_LDFLAGS $RDYNAMIC"
292 AC_TRY_LINK([], [],
293 [found="-rdynamic"],
294 [found="no"
295 RDYNAMIC=""])])
296 AC_SUBST(RDYNAMIC)
297 LDFLAGS="$old_LDFLAGS"
298 AC_MSG_RESULT($found)
299 else
300 srv_libs="-lthread_db"
301 fi
302
303 srv_thread_depfiles="thread-db.o proc-service.o"
304 USE_THREAD_DB="-DUSE_THREAD_DB"
305 AC_CACHE_CHECK([for TD_VERSION], gdbsrv_cv_have_td_version,
306 [AC_TRY_COMPILE([#include <thread_db.h>], [TD_VERSION;],
307 [gdbsrv_cv_have_td_version=yes],
308 [gdbsrv_cv_have_td_version=no])])
309 if test $gdbsrv_cv_have_td_version = yes; then
310 AC_DEFINE(HAVE_TD_VERSION, 1, [Define if TD_VERSION is available.])
311 fi
312 fi
313
314 AC_ARG_WITH(libthread-db,
315 AS_HELP_STRING([--with-libthread-db=PATH], [use given libthread_db directly]),
316 [srv_libthread_db_path="${withval}"
317 srv_libs="$srv_libthread_db_path"
318 ])
319
320 if test "$srv_libs" != "" -a "$srv_libs" != "-ldl"; then
321 AC_DEFINE(USE_LIBTHREAD_DB_DIRECTLY, 1, [Define if we should use libthread_db directly.])
322 fi
323
324 if test "$srv_xmlfiles" != ""; then
325 srv_xmlbuiltin="xml-builtin.o"
326 AC_DEFINE(USE_XML, 1, [Define if an XML target description is available.])
327
328 tmp_xmlfiles=$srv_xmlfiles
329 srv_xmlfiles=""
330 for f in $tmp_xmlfiles; do
331 srv_xmlfiles="$srv_xmlfiles \$(XML_DIR)/$f"
332 done
333 fi
334
335 GDBSERVER_DEPFILES="$srv_regobj $srv_tgtobj $srv_hostio_err_objs $srv_thread_depfiles"
336 GDBSERVER_LIBS="$srv_libs"
337
338 dnl Check whether the target supports __sync_*_compare_and_swap.
339 AC_CACHE_CHECK([whether the target supports __sync_*_compare_and_swap],
340 gdbsrv_cv_have_sync_builtins, [
341 AC_TRY_LINK([], [int foo, bar; bar = __sync_val_compare_and_swap(&foo, 0, 1);],
342 gdbsrv_cv_have_sync_builtins=yes,
343 gdbsrv_cv_have_sync_builtins=no)])
344 if test $gdbsrv_cv_have_sync_builtins = yes; then
345 AC_DEFINE(HAVE_SYNC_BUILTINS, 1,
346 [Define to 1 if the target supports __sync_*_compare_and_swap])
347 fi
348
349 dnl Check for -fvisibility=hidden support in the compiler.
350 saved_cflags="$CFLAGS"
351 CFLAGS="$CFLAGS -fvisibility=hidden"
352 AC_COMPILE_IFELSE(AC_LANG_PROGRAM([]),
353 [gdbsrv_cv_have_visibility_hidden=yes],
354 [gdbsrv_cv_have_visibility_hidden=no])
355 CFLAGS="$saved_cflags"
356
357 IPA_DEPFILES=""
358
359 # Rather than allowing to build a broken IPA, we simply disable it if
360 # we don't find a compiler supporting all the features we need.
361 if test "$ipa_obj" != "" \
362 -a "$gdbsrv_cv_have_sync_builtins" = yes \
363 -a "$gdbsrv_cv_have_visibility_hidden" = yes; then
364 IPA_DEPFILES="$ipa_obj"
365 extra_libraries="libinproctrace.so"
366 fi
367
368 AC_SUBST(GDBSERVER_DEPFILES)
369 AC_SUBST(GDBSERVER_LIBS)
370 AC_SUBST(USE_THREAD_DB)
371 AC_SUBST(srv_xmlbuiltin)
372 AC_SUBST(srv_xmlfiles)
373 AC_SUBST(IPA_DEPFILES)
374 AC_SUBST(extra_libraries)
375
376 AC_OUTPUT(Makefile,
377 [case x$CONFIG_HEADERS in
378 xconfig.h:config.in)
379 echo > stamp-h ;;
380 esac
381 ])