configure.ac revision 2ae374a196ca76406cd14503622060c2c5dc4cef
1# -*- Autoconf -*-
2# This file is part of ltrace.
3# Copyright (C) 2010,2012 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.
24AC_PREREQ(2.65)
25
26AC_INIT([ltrace],[0.7.2],[ltrace-devel@lists.alioth.debian.org])
27AC_CONFIG_HEADERS([config.h])
28AC_CONFIG_SRCDIR(libltrace.c)
29AC_CONFIG_MACRO_DIR([config/m4])
30AC_CONFIG_AUX_DIR([config/autoconf])
31AC_CANONICAL_BUILD
32AC_CANONICAL_HOST
33
34case "${host_os}" in
35    linux-gnu*)	HOST_OS="linux-gnu" ;;
36    *)		AC_MSG_ERROR([unkown host-os ${host_os}]) ;;
37esac
38AC_SUBST(HOST_OS)
39
40case "${host_cpu}" in
41    arm*|sa110)		HOST_CPU="arm" ;;
42    cris*)		HOST_CPU="cris" ;;
43    mips*el)		HOST_CPU="mipsel" ;;
44    mips*)		HOST_CPU="mips" ;;
45    powerpc|powerpc64)	HOST_CPU="ppc" ;;
46    sun4u|sparc64)	HOST_CPU="sparc" ;;
47    s390x)		HOST_CPU="s390" ;;
48    i?86|x86_64)	HOST_CPU="x86" ;;
49    *)			HOST_CPU="${host_cpu}" ;;
50esac
51AC_SUBST(HOST_CPU)
52
53# Checks for programs.
54AC_PROG_CC
55LT_INIT
56# libtool-2:  LT_INIT()
57AM_INIT_AUTOMAKE([foreign no-exeext dist-bzip2])
58AM_MAINTAINER_MODE
59
60AC_ARG_WITH([libelf],
61  AS_HELP_STRING([--with-libelf], [Prefix of libelf headers/library]),
62  [case "${withval}" in
63  (no)
64    AC_MSG_ERROR([*** libelf is a required dependency])
65    ;;
66  (yes)
67    AC_MSG_ERROR([*** --with-libelf requires you to specify a path])
68    ;;
69  (*)
70    AM_CPPFLAGS="${AM_CPPFLAGS} -I${withval}/include"
71    AM_LDFLAGS="${AM_LDFLAGS} -L${withval}/lib"
72    libelf_LD_LIBRARY_PATH="${withval}/lib"
73    ;;
74esac],[])
75
76# Checks for libraries.
77
78saved_CPPFLAGS="${CPPFLAGS}"
79saved_LDFLAGS="${LDFLAGS}"
80CPPFLAGS="${CPPFLAGS} ${AM_CPPFLAGS}"
81LDFLAGS="${LDFLAGS} ${AM_LDFLAGS}"
82# libelf
83AC_CHECK_HEADERS([elf.h gelf.h],,
84	[AC_MSG_ERROR([*** libelf.h or gelf.h not found on your system])]
85)
86AC_CHECK_LIB([elf], [elf_begin],,
87	[AC_MSG_ERROR([*** libelf not found on your system])]
88)
89CPPFLAGS="${saved_CPPFLAGS}"
90LDFLAGS="${saved_LDFLAGS}"
91
92
93# HAVE_LIBIBERTY
94AC_CHECK_LIB([iberty], [cplus_demangle], [
95	AC_DEFINE([HAVE_LIBIBERTY], [1], [we have libiberty])
96	liberty_LIBS="-liberty"], [
97	liberty_LIBS=""])
98AC_SUBST(liberty_LIBS)
99
100
101# HAVE_LIBSUPC__
102AC_CHECK_LIB([supc++], [__cxa_demangle], [
103	AC_DEFINE([HAVE_LIBSUPC__], [1], [we have libsupc++])
104	libsupcxx_LIBS="-lsupc++"], [
105	libsupcxx_LIBS=""])
106AC_SUBST(libsupcxx_LIBS)
107
108
109# HAVE_LIBSTDC__
110AC_CHECK_LIB([stdc++], [__cxa_demangle], [
111	AC_DEFINE([HAVE_LIBSTDC__], [1], [we have libstdc++])
112	libstdcxx_LIBS="-lstdc++"], [
113	libstdcxx_LIBS=""])
114AC_SUBST(libstdcxx_LIBS)
115
116
117dnl Check security_get_boolean_active availability.
118AC_CHECK_HEADERS(selinux/selinux.h)
119AC_CHECK_LIB(selinux, security_get_boolean_active)
120
121
122# HAVE_LIBUNWIND
123AC_ARG_WITH(libunwind,
124  AS_HELP_STRING([--with-libunwind], [Use libunwind frame unwinding support]),
125  [case "${withval}" in
126  (yes|no) enable_libunwind=$withval;;
127  (*) enable_libunwind=yes
128    AM_CPPFLAGS="${AM_CPPFLAGS} -I${withval}/include"
129    AM_LDFLAGS="${AM_LDFLAGS} -L${withval}/lib"
130    libunwind_LD_LIBRARY_PATH="${withval}/lib"
131    ;;
132esac],[enable_libunwind=maybe])
133
134saved_CPPFLAGS="${CPPFLAGS}"
135CPPFLAGS="${CPPFLAGS} ${AM_CPPFLAGS}"
136AC_CHECK_HEADERS([libunwind.h], [have_libunwind_h=yes])
137AC_CHECK_HEADERS([libunwind-ptrace.h], [have_libunwind_ptrace_h=yes])
138CPPFLAGS="${saved_CPPFLAGS}"
139
140AC_MSG_CHECKING([whether to use libunwind support])
141case "${enable_libunwind}" in
142(yes|maybe)
143  if test x$have_libunwind_h = xyes -o x$have_libunwind_ptrace_h = xyes; then
144    enable_libunwind=yes
145  elif test $enable_libunwind = maybe; then
146    enable_libunwind=no
147  else
148    AC_MSG_RESULT([$enable_libunwind])
149    AC_MSG_ERROR([libunwind.h or libunwind-ptrace.h cannot be found])	
150  fi
151  ;;
152(*) ;;
153esac
154AC_MSG_RESULT([$enable_libunwind])
155
156if test x"$enable_libunwind" = xyes; then
157  case "${host_cpu}" in
158      arm*|sa110)         UNWIND_ARCH="arm" ;;
159      i?86)               UNWIND_ARCH="x86" ;;
160      powerpc)            UNWIND_ARCH="ppc32" ;;
161      powerpc64)          UNWIND_ARCH="ppc64" ;;
162      mips*)              UNWIND_ARCH="mips" ;;
163      *)                  UNWIND_ARCH="${host_cpu}" ;;
164  esac
165
166  saved_LDFLAGS="${LDFLAGS}"
167  LDFLAGS="${LDFLAGS} ${AM_LDFLAGS}"
168  AC_CHECK_LIB([unwind], [backtrace], [libunwind_LIBS=-lunwind],
169	       [AC_MSG_ERROR([Couldn't find or use libunwind.])])
170
171  AC_CHECK_LIB([unwind-${UNWIND_ARCH}], [_U${UNWIND_ARCH}_init_remote],
172	       [libunwind_LIBS="-lunwind-${UNWIND_ARCH} $libunwind_LIBS"],
173	       [AC_MSG_ERROR([Couldn't find or use libunwind-${UNWIND_ARCH}.])],
174	       [$libunwind_LIBS])
175
176  AC_CHECK_LIB([unwind-ptrace], [_UPT_create],
177	       [libunwind_LIBS="-lunwind-ptrace $libunwind_LIBS"],
178	       [AC_MSG_ERROR([Couldn't find or use libunwind-ptrace.])],
179	       [$libunwind_LIBS])
180
181  AC_SUBST(libunwind_LIBS)
182  AC_DEFINE([HAVE_LIBUNWIND], [1], [we have libunwind])
183  LDFLAGS="${saved_LDFLAGS}"
184fi
185
186
187saved_CPPFLAGS="${CPPFLAGS}"
188saved_LDFLAGS="${LDFLAGS}"
189CPPFLAGS="${CPPFLAGS} ${AM_CPPFLAGS}"
190LDFLAGS="${LDFLAGS} ${AM_LDFLAGS}"
191# HAVE_ELF_C_READ_MMAP
192AC_MSG_CHECKING([whether elf_begin accepts ELF_C_READ_MMAP])
193AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <gelf.h>]], [[
194int main () {
195	Elf *elf = elf_begin(4, ELF_C_READ_MMAP, 0);
196	return 0;
197}
198	]])],[
199	AC_DEFINE([HAVE_ELF_C_READ_MMAP], [1], [we have read mmap support])
200	AC_MSG_RESULT([yes])],[
201	AC_MSG_RESULT([no])])
202
203saved_CFLAGS="${CFLAGS}"
204CFLAGS="${CFLAGS} -Wall -Werror"
205AC_MSG_CHECKING([whether elf_hash takes a char* argument])
206AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <libelf.h>]], [[
207	(void) elf_hash("name");
208	]])],
209	[AC_DEFINE([ELF_HASH_TAKES_CHARP], [1],
210		[elf_hash() takes char* (as opposed to unsigned char *)])
211	 AC_MSG_RESULT([yes])],
212	[AC_MSG_RESULT([no])])
213CFLAGS="${saved_CFLAGS}"
214CPPFLAGS="${saved_CPPFLAGS}"
215LDFLAGS="${saved_LDFLAGS}"
216
217AM_CPPFLAGS=" \
218	${AM_CPPFLAGS} \
219	-I\$(top_srcdir)/sysdeps/${HOST_OS}/${HOST_CPU} \
220	-I\$(top_srcdir)/sysdeps/${HOST_OS} \
221	-I\$(top_srcdir)/sysdeps \
222	-I\$(top_srcdir) \
223"
224
225# Checks for header files.
226AC_CHECK_HEADERS([ \
227	fcntl.h \
228	limits.h \
229	stddef.h \
230	stdint.h \
231	stdlib.h \
232	string.h \
233	sys/ioctl.h \
234	sys/param.h \
235	sys/time.h \
236	unistd.h \
237])
238
239# Checks for typedefs, structures, and compiler characteristics.
240AC_TYPE_UID_T
241AC_C_INLINE
242AC_TYPE_PID_T
243AC_TYPE_SIZE_T
244AC_CHECK_SIZEOF([long])
245
246
247# Checks for library functions.
248AC_FUNC_FORK
249AC_CHECK_FUNCS([ \
250	alarm \
251	atexit \
252	gettimeofday \
253	memset \
254	strchr \
255	strdup \
256	strerror \
257	strtol \
258	strtoul \
259])
260
261#
262# Define HAVE_OPEN_MEMSTREAM if that is available.  If not, require
263# that tmpfile be present.
264#
265AC_CHECK_FUNCS([open_memstream], [],
266	[AC_CHECK_FUNC([tmpfile], [],
267		[AC_MSG_ERROR([Either open_memstream or tmpfile required.])])])
268
269#
270# Debugging
271#
272AC_MSG_CHECKING([whether to enable debugging])
273AC_ARG_ENABLE(debug,
274    AS_HELP_STRING([--enable-debug], [enable debugging @<:@default=no@:>@]),
275	[case "$enableval" in
276	y | yes) CONFIG_DEBUG=yes ;;
277        *) CONFIG_DEBUG=no ;;
278    esac],
279    [CONFIG_DEBUG=no])
280AC_MSG_RESULT([${CONFIG_DEBUG}])
281if test "${CONFIG_DEBUG}" = "yes"; then
282    AC_DEFINE(DEBUG, 1, [debugging])
283fi
284
285# Ignore the compiler's warnings at your own risk.
286AM_CFLAGS="${AM_CFLAGS} -Wall -Wsign-compare -Wfloat-equal -Wformat-security"
287AC_ARG_ENABLE([werror],
288    AS_HELP_STRING([--disable-werror], [disable use of -Werror]),
289    [enable_werror=$enableval], [enable_werror=yes])
290if test x$enable_werror = xyes; then
291    AM_CFLAGS="${AM_CFLAGS} -Werror"
292fi
293
294AC_ARG_ENABLE([valgrind],
295    AS_HELP_STRING([--enable-valgrind],[run all tests under valgrind]),
296    [use_valgrind=$enableval], [use_valgrind=no])
297if test x$use_valgrind = xyes; then
298    AC_CHECK_PROG(HAVE_VALGRIND, valgrind, yes, no)
299    if test x$HAVE_VALGRIND = xno; then
300        AC_MSG_ERROR([valgrind not found])
301    fi
302fi
303AM_CONDITIONAL(USE_VALGRIND, test "$use_valgrind" = yes)
304
305AC_SUBST(AM_CPPFLAGS)
306AC_SUBST(AM_CFLAGS)
307AC_SUBST(AM_LDFLAGS)
308AC_SUBST(libelf_LD_LIBRARY_PATH)
309AC_SUBST(libunwind_LD_LIBRARY_PATH)
310
311AC_CONFIG_FILES([
312	Makefile
313	sysdeps/Makefile
314	sysdeps/linux-gnu/Makefile
315	sysdeps/linux-gnu/alpha/Makefile
316	sysdeps/linux-gnu/arm/Makefile
317	sysdeps/linux-gnu/cris/Makefile
318	sysdeps/linux-gnu/ia64/Makefile
319	sysdeps/linux-gnu/m68k/Makefile
320	sysdeps/linux-gnu/mipsel/Makefile
321	sysdeps/linux-gnu/ppc/Makefile
322	sysdeps/linux-gnu/s390/Makefile
323	sysdeps/linux-gnu/sparc/Makefile
324	sysdeps/linux-gnu/x86/Makefile
325	testsuite/Makefile
326	testsuite/ltrace.main/Makefile
327	testsuite/ltrace.minor/Makefile
328	testsuite/ltrace.torture/Makefile
329])
330AC_OUTPUT
331