configure.ac 12.2 KB
Newer Older
1
# -*- Autoconf -*-
2
# This file is part of ltrace.
Petr Machata's avatar
Petr Machata committed
3
# Copyright (C) 2010,2012,2013,2014 Petr Machata, Red Hat Inc.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
# Copyright (C) 2010,2011 Joe Damato
# Copyright (C) 2010 Marc Kleine-Budde
# Copyright (C) 2010 Zachary T Welch
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
# 02110-1301 USA

23
# Process this file with autoconf to produce a configure script.
24
AC_PREREQ([2.65])
25

Petr Machata's avatar
Petr Machata committed
26
AC_INIT([ltrace],[0.7.91],[[email protected]],
27
	[ltrace],[http://ltrace.alioth.debian.org/])
28 29
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_SRCDIR(libltrace.c)
30
AC_CONFIG_MACRO_DIR([config/m4])
31 32 33 34 35
AC_CONFIG_AUX_DIR([config/autoconf])
AC_CANONICAL_BUILD
AC_CANONICAL_HOST

case "${host_os}" in
36 37
    linux-gnu*) HOST_OS="linux-gnu" ;;
    linux-uclibc*) HOST_OS="linux-gnu" ;;
Andrey Zonov's avatar
Andrey Zonov committed
38
    *)		AC_MSG_ERROR([unkown host-os ${host_os}]) ;;
39 40 41 42 43
esac
AC_SUBST(HOST_OS)

case "${host_cpu}" in
    arm*|sa110)		HOST_CPU="arm" ;;
44
    cris*)		HOST_CPU="cris" ;;
45
    mips*)		HOST_CPU="mips" ;;
46
    powerpc|powerpc64|powerpc64le)	HOST_CPU="ppc" ;;
47 48
    sun4u|sparc64)	HOST_CPU="sparc" ;;
    s390x)		HOST_CPU="s390" ;;
49
    i?86|x86_64)	HOST_CPU="x86" ;;
Max Filippov's avatar
Max Filippov committed
50
    xtensa*)		HOST_CPU="xtensa" ;;
51 52 53 54 55 56
    *)			HOST_CPU="${host_cpu}" ;;
esac
AC_SUBST(HOST_CPU)

# Checks for programs.
AC_PROG_CC
57
LT_INIT
58
# libtool-2:  LT_INIT()
59
AM_INIT_AUTOMAKE([foreign no-exeext dist-bzip2])
60
AM_MAINTAINER_MODE
61

62 63 64 65 66 67 68 69 70
#
# We use stat(2).  Even though we don't care about the file size or
# inode number, stat will fail with EOVERFLOW if either of these
# exceeds 32 bits.  We therefore ask for stat64 if available.  Do this
# test as soon as possible, as large file support may influence
# whether other headers are available.
#
AC_SYS_LARGEFILE

71 72 73 74 75 76 77 78 79 80 81 82
AC_ARG_WITH([libelf],
  AS_HELP_STRING([--with-libelf], [Prefix of libelf headers/library]),
  [case "${withval}" in
  (no)
    AC_MSG_ERROR([*** libelf is a required dependency])
    ;;
  (yes)
    AC_MSG_ERROR([*** --with-libelf requires you to specify a path])
    ;;
  (*)
    AM_CPPFLAGS="${AM_CPPFLAGS} -I${withval}/include"
    AM_LDFLAGS="${AM_LDFLAGS} -L${withval}/lib"
83
    libelf_LD_LIBRARY_PATH="${withval}/lib"
84 85 86
    ;;
esac],[])

87 88
# Checks for libraries.

89 90 91 92
saved_CPPFLAGS="${CPPFLAGS}"
saved_LDFLAGS="${LDFLAGS}"
CPPFLAGS="${CPPFLAGS} ${AM_CPPFLAGS}"
LDFLAGS="${LDFLAGS} ${AM_LDFLAGS}"
93
# libelf
94 95 96
AC_CHECK_HEADERS([elf.h gelf.h],,
	[AC_MSG_ERROR([*** libelf.h or gelf.h not found on your system])]
)
97
AC_CHECK_LIB([elf], [elf_begin], [libelf_LIBS="-lelf"],
98
	[AC_MSG_ERROR([*** libelf not found on your system])]
99
)
100 101
CPPFLAGS="${saved_CPPFLAGS}"
LDFLAGS="${saved_LDFLAGS}"
102
AC_SUBST(libelf_LIBS)
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120


# HAVE_LIBIBERTY
AC_CHECK_LIB([iberty], [cplus_demangle], [
	AC_DEFINE([HAVE_LIBIBERTY], [1], [we have libiberty])
	liberty_LIBS="-liberty"], [
	liberty_LIBS=""])
AC_SUBST(liberty_LIBS)


# HAVE_LIBSUPC__
AC_CHECK_LIB([supc++], [__cxa_demangle], [
	AC_DEFINE([HAVE_LIBSUPC__], [1], [we have libsupc++])
	libsupcxx_LIBS="-lsupc++"], [
	libsupcxx_LIBS=""])
AC_SUBST(libsupcxx_LIBS)


121 122 123 124 125 126 127 128
# HAVE_LIBSTDC__
AC_CHECK_LIB([stdc++], [__cxa_demangle], [
	AC_DEFINE([HAVE_LIBSTDC__], [1], [we have libstdc++])
	libstdcxx_LIBS="-lstdc++"], [
	libstdcxx_LIBS=""])
AC_SUBST(libstdcxx_LIBS)


129 130 131 132
dnl Check security_get_boolean_active availability.
AC_CHECK_HEADERS(selinux/selinux.h)
AC_CHECK_LIB(selinux, security_get_boolean_active)

133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
dnl Whether (and which) elfutils libdw.so to use for unwinding.
AC_ARG_WITH(elfutils,
  AS_HELP_STRING([--with-elfutils], [Use elfutils libdwfl unwinding support]),
  [case "${withval}" in
  (yes|no) enable_elfutils=$withval;;
  (*) enable_elfutils=yes
    AM_CPPFLAGS="${AM_CPPFLAGS} -I${withval}/include"
    AM_LDFLAGS="${AM_LDFLAGS} -L${withval}/lib"
    elfutils_LD_LIBRARY_PATH="${withval}/lib:${withval}/lib/elfutils"
    ;;
esac],[enable_elfutils=maybe])

dnl Check whether we have the elfutils libdwfl.h header installed.
saved_CPPFLAGS="${CPPFLAGS}"
CPPFLAGS="${CPPFLAGS} ${AM_CPPFLAGS}"
AC_CHECK_HEADERS([elfutils/libdwfl.h],[have_libdwfl_h=yes])
CPPFLAGS="${saved_CPPFLAGS}"

dnl And whether libdw.so provides the unwinding functions.
saved_LDFLAGS="${LDFLAGS}"
LDFLAGS="${LDFLAGS} ${AM_LDFLAGS}"
AC_CHECK_LIB([dw], [dwfl_getthread_frames], [have_libdw_dwfl_frames=yes])
LDFLAGS="${saved_LDFLAGS}"

AC_MSG_CHECKING([whether to use elfutils libdwfl unwinding support])
case "${enable_elfutils}" in
(yes|maybe)
  if test x$have_libdwfl_h = xyes -a x$have_libdw_dwfl_frames = xyes; then
    enable_elfutils=yes
  elif test $enable_elfutils = maybe; then
    enable_elfutils=no
  else
    AC_MSG_RESULT([$enable_elfutils])
    AC_MSG_ERROR([Missing elfutils/libdwfl.h or dwfl_getthread_frames not in libdw.so])
  fi
  ;;
(*) ;;
esac
AC_MSG_RESULT([$enable_elfutils])

if test x"$enable_elfutils" = xyes; then
  libdw_LIBS=-ldw
  AC_SUBST(libdw_LIBS)
  AC_DEFINE([HAVE_LIBDW], [1], [we have elfutils libdw])
fi
178

179 180
# HAVE_LIBUNWIND
AC_ARG_WITH(libunwind,
181 182 183 184
  AS_HELP_STRING([--with-libunwind], [Use libunwind frame unwinding support]),
  [case "${withval}" in
  (yes|no) enable_libunwind=$withval;;
  (*) enable_libunwind=yes
185 186
    AM_CPPFLAGS="${AM_CPPFLAGS} -I${withval}/include"
    AM_LDFLAGS="${AM_LDFLAGS} -L${withval}/lib"
187
    libunwind_LD_LIBRARY_PATH="${withval}/lib"
188 189 190
    ;;
esac],[enable_libunwind=maybe])

191 192
saved_CPPFLAGS="${CPPFLAGS}"
CPPFLAGS="${CPPFLAGS} ${AM_CPPFLAGS}"
193 194
AC_CHECK_HEADERS([libunwind.h], [have_libunwind_h=yes])
AC_CHECK_HEADERS([libunwind-ptrace.h], [have_libunwind_ptrace_h=yes])
195
CPPFLAGS="${saved_CPPFLAGS}"
196 197 198 199 200 201 202 203 204 205 206

AC_MSG_CHECKING([whether to use libunwind support])
case "${enable_libunwind}" in
(yes|maybe)
  if test x$have_libunwind_h = xyes -o x$have_libunwind_ptrace_h = xyes; then
    enable_libunwind=yes
  elif test $enable_libunwind = maybe; then
    enable_libunwind=no
  else
    AC_MSG_RESULT([$enable_libunwind])
    AC_MSG_ERROR([libunwind.h or libunwind-ptrace.h cannot be found])	
207
  fi
208 209 210 211
  ;;
(*) ;;
esac
AC_MSG_RESULT([$enable_libunwind])
212 213

if test x"$enable_libunwind" = xyes; then
214
  case "${host_cpu}" in
215 216 217 218 219 220
      arm*|sa110)	  UNWIND_ARCH="arm" ;;
      i?86)		  UNWIND_ARCH="x86" ;;
      powerpc)		  UNWIND_ARCH="ppc32" ;;
      powerpc64|powerpc64le)	UNWIND_ARCH="ppc64" ;;
      mips*)		  UNWIND_ARCH="mips" ;;
      *)		  UNWIND_ARCH="${host_cpu}" ;;
221 222
  esac

Petr Machata's avatar
Petr Machata committed
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238
  saved_LDFLAGS="${LDFLAGS}"
  LDFLAGS="${LDFLAGS} ${AM_LDFLAGS}"
  AC_CHECK_LIB([unwind], [backtrace], [libunwind_LIBS=-lunwind],
	       [AC_MSG_ERROR([Couldn't find or use libunwind.])])

  AC_CHECK_LIB([unwind-${UNWIND_ARCH}], [_U${UNWIND_ARCH}_init_remote],
	       [libunwind_LIBS="-lunwind-${UNWIND_ARCH} $libunwind_LIBS"],
	       [AC_MSG_ERROR([Couldn't find or use libunwind-${UNWIND_ARCH}.])],
	       [$libunwind_LIBS])

  AC_CHECK_LIB([unwind-ptrace], [_UPT_create],
	       [libunwind_LIBS="-lunwind-ptrace $libunwind_LIBS"],
	       [AC_MSG_ERROR([Couldn't find or use libunwind-ptrace.])],
	       [$libunwind_LIBS])

  AC_SUBST(libunwind_LIBS)
239
  AC_DEFINE([HAVE_LIBUNWIND], [1], [we have libunwind])
240
  LDFLAGS="${saved_LDFLAGS}"
241 242
fi

243 244 245 246 247 248 249
if test x"$enable_elfutils" = xyes -a x"$enable_libunwind" = xyes; then
  AC_MSG_ERROR([Cannot enable both --with-libunwind and --with-elfutils])
fi

if test x"$enable_elfutils" = xyes -o x"$enable_libunwind" = xyes; then
  AC_DEFINE([HAVE_UNWINDER], [1], [we have an unwinder available])
fi
250

251 252 253 254
saved_CPPFLAGS="${CPPFLAGS}"
saved_LDFLAGS="${LDFLAGS}"
CPPFLAGS="${CPPFLAGS} ${AM_CPPFLAGS}"
LDFLAGS="${LDFLAGS} ${AM_LDFLAGS}"
255 256 257 258 259 260 261 262 263 264 265 266
# HAVE_ELF_C_READ_MMAP
AC_MSG_CHECKING([whether elf_begin accepts ELF_C_READ_MMAP])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <gelf.h>]], [[
int main () {
	Elf *elf = elf_begin(4, ELF_C_READ_MMAP, 0);
	return 0;
}
	]])],[
	AC_DEFINE([HAVE_ELF_C_READ_MMAP], [1], [we have read mmap support])
	AC_MSG_RESULT([yes])],[
	AC_MSG_RESULT([no])])

267 268
saved_CFLAGS="${CFLAGS}"
CFLAGS="${CFLAGS} -Wall -Werror"
269
AC_MSG_CHECKING([whether elf_hash takes a char* argument])
270 271 272
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <libelf.h>]], [[
	(void) elf_hash("name");
	]])],
273 274
	[AC_DEFINE([ELF_HASH_TAKES_CHARP], [1],
		[elf_hash() takes char* (as opposed to unsigned char *)])
275 276 277
	 AC_MSG_RESULT([yes])],
	[AC_MSG_RESULT([no])])
CFLAGS="${saved_CFLAGS}"
278 279
CPPFLAGS="${saved_CPPFLAGS}"
LDFLAGS="${saved_LDFLAGS}"
280

281
AM_CPPFLAGS=" \
282
	-DSYSCONFDIR="'\"$(sysconfdir)\"'" \
283
	-DPKGDATADIR="'\"$(pkgdatadir)\"'" \
284
	${AM_CPPFLAGS} \
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322
	-I\$(top_srcdir)/sysdeps/${HOST_OS}/${HOST_CPU} \
	-I\$(top_srcdir)/sysdeps/${HOST_OS} \
	-I\$(top_srcdir)/sysdeps \
	-I\$(top_srcdir) \
"

# Checks for header files.
AC_CHECK_HEADERS([ \
	fcntl.h \
	limits.h \
	stddef.h \
	stdint.h \
	stdlib.h \
	string.h \
	sys/ioctl.h \
	sys/param.h \
	sys/time.h \
	unistd.h \
])

# Checks for typedefs, structures, and compiler characteristics.
AC_TYPE_UID_T
AC_C_INLINE
AC_TYPE_PID_T
AC_TYPE_SIZE_T
AC_CHECK_SIZEOF([long])


# Checks for library functions.
AC_FUNC_FORK
AC_CHECK_FUNCS([ \
	alarm \
	atexit \
	gettimeofday \
	memset \
	strchr \
	strdup \
	strerror \
323
	strsignal \
324 325 326 327
	strtol \
	strtoul \
])

328
#
329 330 331 332 333
# Define HAVE_OPEN_MEMSTREAM if open_memstream is available.  glibc
# before 2.10, eglibc and uClibc all need _GNU_SOURCE defined for
# open_memstream to become visible, so check for that as well.  If
# unavailable, require that tmpfile be present.  There's no
# HAVE_TMPFILE, as we plain require that to be present as a fallback.
334 335
#
AC_CHECK_FUNCS([open_memstream], [],
336 337 338 339 340 341 342 343 344 345 346 347 348 349 350
	[AC_MSG_CHECKING([for open_memstream with _GNU_SOURCE])
	 AC_LINK_IFELSE(
		[AC_LANG_PROGRAM([[#define _GNU_SOURCE 1
				   #include <stdio.h>]],
				 [[char *buf; size_t sz;
				   return open_memstream(&buf, &sz) != 0;]])],

		 [AC_MSG_RESULT([yes])
		  AC_DEFINE([HAVE_OPEN_MEMSTREAM], [1],
			[Define if open_memstream exists.])],

		 [AC_MSG_RESULT([no])
		  AC_CHECK_FUNC([tmpfile], [],
			[AC_MSG_ERROR(
			    [Either open_memstream or tmpfile required.])])])])
351

352 353 354 355 356
#
# Define HAVE_GETOPT_LONG if that is available.
#
AC_CHECK_HEADER([getopt.h], [AC_CHECK_FUNCS([getopt_long])])

357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372
#
# Debugging
#
AC_MSG_CHECKING([whether to enable debugging])
AC_ARG_ENABLE(debug,
    AS_HELP_STRING([--enable-debug], [enable debugging @<:@[email protected]:>@]),
	[case "$enableval" in
	y | yes) CONFIG_DEBUG=yes ;;
        *) CONFIG_DEBUG=no ;;
    esac],
    [CONFIG_DEBUG=no])
AC_MSG_RESULT([${CONFIG_DEBUG}])
if test "${CONFIG_DEBUG}" = "yes"; then
    AC_DEFINE(DEBUG, 1, [debugging])
fi

373 374 375 376 377 378 379 380 381
# Ignore the compiler's warnings at your own risk.
AM_CFLAGS="${AM_CFLAGS} -Wall -Wsign-compare -Wfloat-equal -Wformat-security"
AC_ARG_ENABLE([werror],
    AS_HELP_STRING([--disable-werror], [disable use of -Werror]),
    [enable_werror=$enableval], [enable_werror=yes])
if test x$enable_werror = xyes; then
    AM_CFLAGS="${AM_CFLAGS} -Werror"
fi

382 383 384 385 386 387 388 389 390 391
AC_ARG_ENABLE([valgrind],
    AS_HELP_STRING([--enable-valgrind],[run all tests under valgrind]),
    [use_valgrind=$enableval], [use_valgrind=no])
if test x$use_valgrind = xyes; then
    AC_CHECK_PROG(HAVE_VALGRIND, valgrind, yes, no)
    if test x$HAVE_VALGRIND = xno; then
        AC_MSG_ERROR([valgrind not found])
    fi
fi
AM_CONDITIONAL(USE_VALGRIND, test "$use_valgrind" = yes)
392
AM_CONDITIONAL(HAVE_LIBDW, test x"$enable_elfutils" = xyes)
393

394
AC_SUBST(AM_CPPFLAGS)
395
AC_SUBST(AM_CFLAGS)
396
AC_SUBST(AM_LDFLAGS)
397
AC_SUBST(libelf_LD_LIBRARY_PATH)
398
AC_SUBST(elfutils_LD_LIBRARY_PATH)
399
AC_SUBST(libunwind_LD_LIBRARY_PATH)
400 401 402 403 404

AC_CONFIG_FILES([
	Makefile
	sysdeps/Makefile
	sysdeps/linux-gnu/Makefile
Petr Machata's avatar
Petr Machata committed
405
	sysdeps/linux-gnu/aarch64/Makefile
406 407
	sysdeps/linux-gnu/alpha/Makefile
	sysdeps/linux-gnu/arm/Makefile
Edgar E. Iglesias's avatar
Edgar E. Iglesias committed
408
	sysdeps/linux-gnu/cris/Makefile
409 410
	sysdeps/linux-gnu/ia64/Makefile
	sysdeps/linux-gnu/m68k/Makefile
411
	sysdeps/linux-gnu/metag/Makefile
412
	sysdeps/linux-gnu/mips/Makefile
413 414 415 416
	sysdeps/linux-gnu/ppc/Makefile
	sysdeps/linux-gnu/s390/Makefile
	sysdeps/linux-gnu/sparc/Makefile
	sysdeps/linux-gnu/x86/Makefile
Max Filippov's avatar
Max Filippov committed
417
	sysdeps/linux-gnu/xtensa/Makefile
418 419 420 421
	testsuite/Makefile
	testsuite/ltrace.main/Makefile
	testsuite/ltrace.minor/Makefile
	testsuite/ltrace.torture/Makefile
422 423
])
AC_OUTPUT