da3b4cb1c54c4e62f36aecb13aa198f49995f523
[platform/upstream/ltrace.git] / configure.ac
1 # -*- Autoconf -*-
2 # This file is part of ltrace.
3 # Copyright (C) 2010,2012,2013 Petr Machata, Red Hat Inc.
4 # Copyright (C) 2010,2011 Joe Damato
5 # Copyright (C) 2010 Marc Kleine-Budde
6 # Copyright (C) 2010 Zachary T Welch
7 #
8 # This program is free software; you can redistribute it and/or
9 # modify it under the terms of the GNU General Public License as
10 # published by the Free Software Foundation; either version 2 of the
11 # License, or (at your option) any later version.
12 #
13 # This program is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 # General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
21 # 02110-1301 USA
22
23 # Process this file with autoconf to produce a configure script.
24 AC_PREREQ([2.65])
25
26 AC_INIT([ltrace],[0.7.91],[ltrace-devel@lists.alioth.debian.org],
27         [ltrace],[http://ltrace.alioth.debian.org/])
28 AC_CONFIG_HEADERS([config.h])
29 AC_CONFIG_SRCDIR(libltrace.c)
30 AC_CONFIG_MACRO_DIR([config/m4])
31 AC_CONFIG_AUX_DIR([config/autoconf])
32 AC_CANONICAL_BUILD
33 AC_CANONICAL_HOST
34
35 case "${host_os}" in
36     linux-gnu*) HOST_OS="linux-gnu" ;;
37     linux-uclibc*) HOST_OS="linux-gnu" ;;
38     *)          AC_MSG_ERROR([unkown host-os ${host_os}]) ;;
39 esac
40 AC_SUBST(HOST_OS)
41
42 case "${host_cpu}" in
43     arm*|sa110)         HOST_CPU="arm" ;;
44     cris*)              HOST_CPU="cris" ;;
45     mips*)              HOST_CPU="mips" ;;
46     powerpc|powerpc64)  HOST_CPU="ppc" ;;
47     sun4u|sparc64)      HOST_CPU="sparc" ;;
48     s390x)              HOST_CPU="s390" ;;
49     i?86|x86_64)        HOST_CPU="x86" ;;
50     *)                  HOST_CPU="${host_cpu}" ;;
51 esac
52 AC_SUBST(HOST_CPU)
53
54 # Checks for programs.
55 AC_PROG_CC
56 LT_INIT
57 # libtool-2:  LT_INIT()
58 AM_INIT_AUTOMAKE([foreign no-exeext dist-bzip2])
59 AM_MAINTAINER_MODE
60
61 #
62 # We use stat(2).  Even though we don't care about the file size or
63 # inode number, stat will fail with EOVERFLOW if either of these
64 # exceeds 32 bits.  We therefore ask for stat64 if available.  Do this
65 # test as soon as possible, as large file support may influence
66 # whether other headers are available.
67 #
68 AC_SYS_LARGEFILE
69
70 AC_ARG_WITH([libelf],
71   AS_HELP_STRING([--with-libelf], [Prefix of libelf headers/library]),
72   [case "${withval}" in
73   (no)
74     AC_MSG_ERROR([*** libelf is a required dependency])
75     ;;
76   (yes)
77     AC_MSG_ERROR([*** --with-libelf requires you to specify a path])
78     ;;
79   (*)
80     AM_CPPFLAGS="${AM_CPPFLAGS} -I${withval}/include"
81     AM_LDFLAGS="${AM_LDFLAGS} -L${withval}/lib"
82     libelf_LD_LIBRARY_PATH="${withval}/lib"
83     ;;
84 esac],[])
85
86 # Checks for libraries.
87
88 saved_CPPFLAGS="${CPPFLAGS}"
89 saved_LDFLAGS="${LDFLAGS}"
90 CPPFLAGS="${CPPFLAGS} ${AM_CPPFLAGS}"
91 LDFLAGS="${LDFLAGS} ${AM_LDFLAGS}"
92 # libelf
93 AC_CHECK_HEADERS([elf.h gelf.h],,
94         [AC_MSG_ERROR([*** libelf.h or gelf.h not found on your system])]
95 )
96 AC_CHECK_LIB([elf], [elf_begin],,
97         [AC_MSG_ERROR([*** libelf not found on your system])]
98 )
99 CPPFLAGS="${saved_CPPFLAGS}"
100 LDFLAGS="${saved_LDFLAGS}"
101
102
103 # HAVE_LIBIBERTY
104 AC_CHECK_LIB([iberty], [cplus_demangle], [
105         AC_DEFINE([HAVE_LIBIBERTY], [1], [we have libiberty])
106         liberty_LIBS="-liberty"], [
107         liberty_LIBS=""])
108 AC_SUBST(liberty_LIBS)
109
110
111 # HAVE_LIBSUPC__
112 AC_CHECK_LIB([supc++], [__cxa_demangle], [
113         AC_DEFINE([HAVE_LIBSUPC__], [1], [we have libsupc++])
114         libsupcxx_LIBS="-lsupc++"], [
115         libsupcxx_LIBS=""])
116 AC_SUBST(libsupcxx_LIBS)
117
118
119 # HAVE_LIBSTDC__
120 AC_CHECK_LIB([stdc++], [__cxa_demangle], [
121         AC_DEFINE([HAVE_LIBSTDC__], [1], [we have libstdc++])
122         libstdcxx_LIBS="-lstdc++"], [
123         libstdcxx_LIBS=""])
124 AC_SUBST(libstdcxx_LIBS)
125
126
127 dnl Check security_get_boolean_active availability.
128 AC_CHECK_HEADERS(selinux/selinux.h)
129 AC_CHECK_LIB(selinux, security_get_boolean_active)
130
131
132 # HAVE_LIBUNWIND
133 AC_ARG_WITH(libunwind,
134   AS_HELP_STRING([--with-libunwind], [Use libunwind frame unwinding support]),
135   [case "${withval}" in
136   (yes|no) enable_libunwind=$withval;;
137   (*) enable_libunwind=yes
138     AM_CPPFLAGS="${AM_CPPFLAGS} -I${withval}/include"
139     AM_LDFLAGS="${AM_LDFLAGS} -L${withval}/lib"
140     libunwind_LD_LIBRARY_PATH="${withval}/lib"
141     ;;
142 esac],[enable_libunwind=maybe])
143
144 saved_CPPFLAGS="${CPPFLAGS}"
145 CPPFLAGS="${CPPFLAGS} ${AM_CPPFLAGS}"
146 AC_CHECK_HEADERS([libunwind.h], [have_libunwind_h=yes])
147 AC_CHECK_HEADERS([libunwind-ptrace.h], [have_libunwind_ptrace_h=yes])
148 CPPFLAGS="${saved_CPPFLAGS}"
149
150 AC_MSG_CHECKING([whether to use libunwind support])
151 case "${enable_libunwind}" in
152 (yes|maybe)
153   if test x$have_libunwind_h = xyes -o x$have_libunwind_ptrace_h = xyes; then
154     enable_libunwind=yes
155   elif test $enable_libunwind = maybe; then
156     enable_libunwind=no
157   else
158     AC_MSG_RESULT([$enable_libunwind])
159     AC_MSG_ERROR([libunwind.h or libunwind-ptrace.h cannot be found])   
160   fi
161   ;;
162 (*) ;;
163 esac
164 AC_MSG_RESULT([$enable_libunwind])
165
166 if test x"$enable_libunwind" = xyes; then
167   case "${host_cpu}" in
168       arm*|sa110)         UNWIND_ARCH="arm" ;;
169       i?86)               UNWIND_ARCH="x86" ;;
170       powerpc)            UNWIND_ARCH="ppc32" ;;
171       powerpc64)          UNWIND_ARCH="ppc64" ;;
172       mips*)              UNWIND_ARCH="mips" ;;
173       *)                  UNWIND_ARCH="${host_cpu}" ;;
174   esac
175
176   saved_LDFLAGS="${LDFLAGS}"
177   LDFLAGS="${LDFLAGS} ${AM_LDFLAGS}"
178   AC_CHECK_LIB([unwind], [backtrace], [libunwind_LIBS=-lunwind],
179                [AC_MSG_ERROR([Couldn't find or use libunwind.])])
180
181   AC_CHECK_LIB([unwind-${UNWIND_ARCH}], [_U${UNWIND_ARCH}_init_remote],
182                [libunwind_LIBS="-lunwind-${UNWIND_ARCH} $libunwind_LIBS"],
183                [AC_MSG_ERROR([Couldn't find or use libunwind-${UNWIND_ARCH}.])],
184                [$libunwind_LIBS])
185
186   AC_CHECK_LIB([unwind-ptrace], [_UPT_create],
187                [libunwind_LIBS="-lunwind-ptrace $libunwind_LIBS"],
188                [AC_MSG_ERROR([Couldn't find or use libunwind-ptrace.])],
189                [$libunwind_LIBS])
190
191   AC_SUBST(libunwind_LIBS)
192   AC_DEFINE([HAVE_LIBUNWIND], [1], [we have libunwind])
193   LDFLAGS="${saved_LDFLAGS}"
194 fi
195
196
197 saved_CPPFLAGS="${CPPFLAGS}"
198 saved_LDFLAGS="${LDFLAGS}"
199 CPPFLAGS="${CPPFLAGS} ${AM_CPPFLAGS}"
200 LDFLAGS="${LDFLAGS} ${AM_LDFLAGS}"
201 # HAVE_ELF_C_READ_MMAP
202 AC_MSG_CHECKING([whether elf_begin accepts ELF_C_READ_MMAP])
203 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <gelf.h>]], [[
204 int main () {
205         Elf *elf = elf_begin(4, ELF_C_READ_MMAP, 0);
206         return 0;
207 }
208         ]])],[
209         AC_DEFINE([HAVE_ELF_C_READ_MMAP], [1], [we have read mmap support])
210         AC_MSG_RESULT([yes])],[
211         AC_MSG_RESULT([no])])
212
213 saved_CFLAGS="${CFLAGS}"
214 CFLAGS="${CFLAGS} -Wall -Werror"
215 AC_MSG_CHECKING([whether elf_hash takes a char* argument])
216 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <libelf.h>]], [[
217         (void) elf_hash("name");
218         ]])],
219         [AC_DEFINE([ELF_HASH_TAKES_CHARP], [1],
220                 [elf_hash() takes char* (as opposed to unsigned char *)])
221          AC_MSG_RESULT([yes])],
222         [AC_MSG_RESULT([no])])
223 CFLAGS="${saved_CFLAGS}"
224 CPPFLAGS="${saved_CPPFLAGS}"
225 LDFLAGS="${saved_LDFLAGS}"
226
227 AM_CPPFLAGS=" \
228         -DSYSCONFDIR="'\"$(sysconfdir)\"'" \
229         -DPKGDATADIR="'\"$(pkgdatadir)\"'" \
230         ${AM_CPPFLAGS} \
231         -I\$(top_srcdir)/sysdeps/${HOST_OS}/${HOST_CPU} \
232         -I\$(top_srcdir)/sysdeps/${HOST_OS} \
233         -I\$(top_srcdir)/sysdeps \
234         -I\$(top_srcdir) \
235 "
236
237 # Checks for header files.
238 AC_CHECK_HEADERS([ \
239         fcntl.h \
240         limits.h \
241         stddef.h \
242         stdint.h \
243         stdlib.h \
244         string.h \
245         sys/ioctl.h \
246         sys/param.h \
247         sys/time.h \
248         unistd.h \
249 ])
250
251 # Checks for typedefs, structures, and compiler characteristics.
252 AC_TYPE_UID_T
253 AC_C_INLINE
254 AC_TYPE_PID_T
255 AC_TYPE_SIZE_T
256 AC_CHECK_SIZEOF([long])
257
258
259 # Checks for library functions.
260 AC_FUNC_FORK
261 AC_CHECK_FUNCS([ \
262         alarm \
263         atexit \
264         gettimeofday \
265         memset \
266         strchr \
267         strdup \
268         strerror \
269         strsignal \
270         strtol \
271         strtoul \
272 ])
273
274 #
275 # Define HAVE_OPEN_MEMSTREAM if open_memstream is available.  glibc
276 # before 2.10, eglibc and uClibc all need _GNU_SOURCE defined for
277 # open_memstream to become visible, so check for that as well.  If
278 # unavailable, require that tmpfile be present.  There's no
279 # HAVE_TMPFILE, as we plain require that to be present as a fallback.
280 #
281 AC_CHECK_FUNCS([open_memstream], [],
282         [AC_MSG_CHECKING([for open_memstream with _GNU_SOURCE])
283          AC_LINK_IFELSE(
284                 [AC_LANG_PROGRAM([[#define _GNU_SOURCE 1
285                                    #include <stdio.h>]],
286                                  [[char *buf; size_t sz;
287                                    return open_memstream(&buf, &sz) != 0;]])],
288
289                  [AC_MSG_RESULT([yes])
290                   AC_DEFINE([HAVE_OPEN_MEMSTREAM], [1],
291                         [Define if open_memstream exists.])],
292
293                  [AC_MSG_RESULT([no])
294                   AC_CHECK_FUNC([tmpfile], [],
295                         [AC_MSG_ERROR(
296                             [Either open_memstream or tmpfile required.])])])])
297
298 #
299 # Define HAVE_GETOPT_LONG if that is available.
300 #
301 AC_CHECK_HEADER([getopt.h], [AC_CHECK_FUNCS([getopt_long])])
302
303 #
304 # Debugging
305 #
306 AC_MSG_CHECKING([whether to enable debugging])
307 AC_ARG_ENABLE(debug,
308     AS_HELP_STRING([--enable-debug], [enable debugging @<:@default=no@:>@]),
309         [case "$enableval" in
310         y | yes) CONFIG_DEBUG=yes ;;
311         *) CONFIG_DEBUG=no ;;
312     esac],
313     [CONFIG_DEBUG=no])
314 AC_MSG_RESULT([${CONFIG_DEBUG}])
315 if test "${CONFIG_DEBUG}" = "yes"; then
316     AC_DEFINE(DEBUG, 1, [debugging])
317 fi
318
319 # Ignore the compiler's warnings at your own risk.
320 AM_CFLAGS="${AM_CFLAGS} -Wall -Wsign-compare -Wfloat-equal -Wformat-security"
321 AC_ARG_ENABLE([werror],
322     AS_HELP_STRING([--disable-werror], [disable use of -Werror]),
323     [enable_werror=$enableval], [enable_werror=yes])
324 if test x$enable_werror = xyes; then
325     AM_CFLAGS="${AM_CFLAGS} -Werror"
326 fi
327
328 AC_ARG_ENABLE([valgrind],
329     AS_HELP_STRING([--enable-valgrind],[run all tests under valgrind]),
330     [use_valgrind=$enableval], [use_valgrind=no])
331 if test x$use_valgrind = xyes; then
332     AC_CHECK_PROG(HAVE_VALGRIND, valgrind, yes, no)
333     if test x$HAVE_VALGRIND = xno; then
334         AC_MSG_ERROR([valgrind not found])
335     fi
336 fi
337 AM_CONDITIONAL(USE_VALGRIND, test "$use_valgrind" = yes)
338
339 AC_SUBST(AM_CPPFLAGS)
340 AC_SUBST(AM_CFLAGS)
341 AC_SUBST(AM_LDFLAGS)
342 AC_SUBST(libelf_LD_LIBRARY_PATH)
343 AC_SUBST(libunwind_LD_LIBRARY_PATH)
344
345 AC_CONFIG_FILES([
346         Makefile
347         sysdeps/Makefile
348         sysdeps/linux-gnu/Makefile
349         sysdeps/linux-gnu/alpha/Makefile
350         sysdeps/linux-gnu/arm/Makefile
351         sysdeps/linux-gnu/cris/Makefile
352         sysdeps/linux-gnu/ia64/Makefile
353         sysdeps/linux-gnu/m68k/Makefile
354         sysdeps/linux-gnu/metag/Makefile
355         sysdeps/linux-gnu/mips/Makefile
356         sysdeps/linux-gnu/ppc/Makefile
357         sysdeps/linux-gnu/s390/Makefile
358         sysdeps/linux-gnu/sparc/Makefile
359         sysdeps/linux-gnu/x86/Makefile
360         testsuite/Makefile
361         testsuite/ltrace.main/Makefile
362         testsuite/ltrace.minor/Makefile
363         testsuite/ltrace.torture/Makefile
364 ])
365 AC_OUTPUT