configure.ac revision 36f2968bac2047b4dc58cac8997db32353669a56
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.1],[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  saved_LDFLAGS="${LDFLAGS}"
158  LDFLAGS="${LDFLAGS} ${AM_LDFLAGS}"
159  AC_CHECK_LIB(unwind, backtrace, libunwind_LIBS=-lunwind, libunwind_LIBS=)
160  AC_SUBST(libunwind_LIBS)
161  AC_CHECK_LIB(unwind-ptrace, _UPT_create, libunwind_ptrace_LIBS=-lunwind-ptrace, libunwind_ptrace_LIBS=)
162  AC_SUBST(libunwind_ptrace_LIBS)
163
164  case "${host_cpu}" in
165      arm*|sa110)         UNWIND_ARCH="arm" ;;
166      i?86)               UNWIND_ARCH="x86" ;;
167      powerpc)            UNWIND_ARCH="ppc32" ;;
168      powerpc64)          UNWIND_ARCH="ppc64" ;;
169      mips*)              UNWIND_ARCH="mips" ;;
170      *)                  UNWIND_ARCH="${host_cpu}" ;;
171  esac
172
173  AC_CHECK_LIB(unwind-${UNWIND_ARCH}, _U${UNWIND_ARCH}_init_remote, libunwind_arch_LIBS=-lunwind-${UNWIND_ARCH}, libunwind_arch_LIBS=)
174  AC_SUBST(libunwind_arch_LIBS)
175  AC_DEFINE([HAVE_LIBUNWIND], [1], [we have libunwind])
176  LDFLAGS="${saved_LDFLAGS}"
177fi
178
179
180saved_CPPFLAGS="${CPPFLAGS}"
181saved_LDFLAGS="${LDFLAGS}"
182CPPFLAGS="${CPPFLAGS} ${AM_CPPFLAGS}"
183LDFLAGS="${LDFLAGS} ${AM_LDFLAGS}"
184# HAVE_ELF_C_READ_MMAP
185AC_MSG_CHECKING([whether elf_begin accepts ELF_C_READ_MMAP])
186AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <gelf.h>]], [[
187int main () {
188	Elf *elf = elf_begin(4, ELF_C_READ_MMAP, 0);
189	return 0;
190}
191	]])],[
192	AC_DEFINE([HAVE_ELF_C_READ_MMAP], [1], [we have read mmap support])
193	AC_MSG_RESULT([yes])],[
194	AC_MSG_RESULT([no])])
195
196saved_CFLAGS="${CFLAGS}"
197CFLAGS="${CFLAGS} -Wall -Werror"
198AC_MSG_CHECKING([whether elf_hash takes a char* argument])
199AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <libelf.h>]], [[
200	(void) elf_hash("name");
201	]])],
202	[AC_DEFINE([ELF_HASH_TAKES_CHARP], [1],
203		[elf_hash() takes char* (as opposed to unsigned char *)])
204	 AC_MSG_RESULT([yes])],
205	[AC_MSG_RESULT([no])])
206CFLAGS="${saved_CFLAGS}"
207CPPFLAGS="${saved_CPPFLAGS}"
208LDFLAGS="${saved_LDFLAGS}"
209
210AM_CPPFLAGS=" \
211	${AM_CPPFLAGS} \
212	-I\$(top_srcdir)/sysdeps/${HOST_OS}/${HOST_CPU} \
213	-I\$(top_srcdir)/sysdeps/${HOST_OS} \
214	-I\$(top_srcdir)/sysdeps \
215	-I\$(top_srcdir) \
216"
217
218# Checks for header files.
219AC_CHECK_HEADERS([ \
220	fcntl.h \
221	limits.h \
222	stddef.h \
223	stdint.h \
224	stdlib.h \
225	string.h \
226	sys/ioctl.h \
227	sys/param.h \
228	sys/time.h \
229	unistd.h \
230])
231
232# Checks for typedefs, structures, and compiler characteristics.
233AC_TYPE_UID_T
234AC_C_INLINE
235AC_TYPE_PID_T
236AC_TYPE_SIZE_T
237AC_CHECK_SIZEOF([long])
238
239
240# Checks for library functions.
241AC_FUNC_ERROR_AT_LINE
242AC_FUNC_FORK
243AC_CHECK_FUNCS([ \
244	alarm \
245	atexit \
246	getcwd \
247	gettimeofday \
248	memset \
249	mkdir \
250	rmdir \
251	strchr \
252	strdup \
253	strerror \
254	strtol \
255	strtoul \
256])
257
258
259#
260# Debugging
261#
262AC_MSG_CHECKING([whether to enable debugging])
263AC_ARG_ENABLE(debug,
264    AS_HELP_STRING([--enable-debug], [enable debugging @<:@default=no@:>@]),
265	[case "$enableval" in
266	y | yes) CONFIG_DEBUG=yes ;;
267        *) CONFIG_DEBUG=no ;;
268    esac],
269    [CONFIG_DEBUG=no])
270AC_MSG_RESULT([${CONFIG_DEBUG}])
271if test "${CONFIG_DEBUG}" = "yes"; then
272    AC_DEFINE(DEBUG, 1, [debugging])
273fi
274
275# Ignore the compiler's warnings at your own risk.
276AM_CFLAGS="${AM_CFLAGS} -Wall -Wsign-compare -Wfloat-equal -Wformat-security"
277AC_ARG_ENABLE([werror],
278    AS_HELP_STRING([--disable-werror], [disable use of -Werror]),
279    [enable_werror=$enableval], [enable_werror=yes])
280if test x$enable_werror = xyes; then
281    AM_CFLAGS="${AM_CFLAGS} -Werror"
282fi
283
284AC_ARG_ENABLE([valgrind],
285    AS_HELP_STRING([--enable-valgrind],[run all tests under valgrind]),
286    [use_valgrind=$enableval], [use_valgrind=no])
287if test x$use_valgrind = xyes; then
288    AC_CHECK_PROG(HAVE_VALGRIND, valgrind, yes, no)
289    if test x$HAVE_VALGRIND = xno; then
290        AC_MSG_ERROR([valgrind not found])
291    fi
292fi
293AM_CONDITIONAL(USE_VALGRIND, test "$use_valgrind" = yes)
294
295AC_SUBST(AM_CPPFLAGS)
296AC_SUBST(AM_CFLAGS)
297AC_SUBST(AM_LDFLAGS)
298AC_SUBST(libelf_LD_LIBRARY_PATH)
299AC_SUBST(libunwind_LD_LIBRARY_PATH)
300
301AC_CONFIG_FILES([
302	Makefile
303	sysdeps/Makefile
304	sysdeps/linux-gnu/Makefile
305	sysdeps/linux-gnu/alpha/Makefile
306	sysdeps/linux-gnu/arm/Makefile
307	sysdeps/linux-gnu/cris/Makefile
308	sysdeps/linux-gnu/ia64/Makefile
309	sysdeps/linux-gnu/m68k/Makefile
310	sysdeps/linux-gnu/mipsel/Makefile
311	sysdeps/linux-gnu/ppc/Makefile
312	sysdeps/linux-gnu/s390/Makefile
313	sysdeps/linux-gnu/sparc/Makefile
314	sysdeps/linux-gnu/x86/Makefile
315	testsuite/Makefile
316	testsuite/ltrace.main/Makefile
317	testsuite/ltrace.minor/Makefile
318	testsuite/ltrace.torture/Makefile
319])
320AC_OUTPUT
321