2012-09-04 17:12:00 +02:00
|
|
|
dnl Helper macros for Tor configure.ac
|
2007-03-04 20:47:34 +01:00
|
|
|
dnl Copyright (c) 2001-2004, Roger Dingledine
|
2008-02-07 06:31:47 +01:00
|
|
|
dnl Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson
|
|
|
|
dnl Copyright (c) 2007-2008, Roger Dingledine, Nick Mathewson
|
2017-03-15 21:13:17 +01:00
|
|
|
dnl Copyright (c) 2007-2017, The Tor Project, Inc.
|
2007-03-04 20:47:34 +01:00
|
|
|
dnl See LICENSE for licensing information
|
|
|
|
|
|
|
|
AC_DEFUN([TOR_EXTEND_CODEPATH],
|
|
|
|
[
|
|
|
|
if test -d "$1/lib"; then
|
|
|
|
LDFLAGS="-L$1/lib $LDFLAGS"
|
|
|
|
else
|
|
|
|
LDFLAGS="-L$1 $LDFLAGS"
|
|
|
|
fi
|
|
|
|
if test -d "$1/include"; then
|
|
|
|
CPPFLAGS="-I$1/include $CPPFLAGS"
|
|
|
|
else
|
|
|
|
CPPFLAGS="-I$1 $CPPFLAGS"
|
|
|
|
fi
|
|
|
|
])
|
|
|
|
|
2007-04-30 22:50:09 +02:00
|
|
|
AC_DEFUN([TOR_DEFINE_CODEPATH],
|
|
|
|
[
|
|
|
|
if test x$1 = "x(system)"; then
|
|
|
|
TOR_LDFLAGS_$2=""
|
|
|
|
TOR_CPPFLAGS_$2=""
|
|
|
|
else
|
|
|
|
if test -d "$1/lib"; then
|
|
|
|
TOR_LDFLAGS_$2="-L$1/lib"
|
2010-01-24 20:34:47 +01:00
|
|
|
TOR_LIBDIR_$2="$1/lib"
|
2007-04-30 22:50:09 +02:00
|
|
|
else
|
|
|
|
TOR_LDFLAGS_$2="-L$1"
|
2010-01-24 20:34:47 +01:00
|
|
|
TOR_LIBDIR_$2="$1"
|
2007-04-30 22:50:09 +02:00
|
|
|
fi
|
|
|
|
if test -d "$1/include"; then
|
|
|
|
TOR_CPPFLAGS_$2="-I$1/include"
|
|
|
|
else
|
|
|
|
TOR_CPPFLAGS_$2="-I$1"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
AC_SUBST(TOR_CPPFLAGS_$2)
|
|
|
|
AC_SUBST(TOR_LDFLAGS_$2)
|
|
|
|
])
|
|
|
|
|
2016-04-13 00:59:40 +02:00
|
|
|
dnl 1: flags
|
|
|
|
dnl 2: try to link too if this is nonempty.
|
|
|
|
dnl 3: what to do on success compiling
|
|
|
|
dnl 4: what to do on failure compiling
|
|
|
|
AC_DEFUN([TOR_TRY_COMPILE_WITH_CFLAGS], [
|
2012-05-11 21:08:16 +02:00
|
|
|
AS_VAR_PUSHDEF([VAR],[tor_cv_cflags_$1])
|
|
|
|
AC_CACHE_CHECK([whether the compiler accepts $1], VAR, [
|
|
|
|
tor_saved_CFLAGS="$CFLAGS"
|
2012-06-11 17:00:48 +02:00
|
|
|
CFLAGS="$CFLAGS -pedantic -Werror $1"
|
2016-03-28 21:59:35 +02:00
|
|
|
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
|
2012-05-11 21:08:16 +02:00
|
|
|
[AS_VAR_SET(VAR,yes)],
|
|
|
|
[AS_VAR_SET(VAR,no)])
|
2013-10-21 19:07:47 +02:00
|
|
|
if test x$2 != x; then
|
|
|
|
AS_VAR_PUSHDEF([can_link],[tor_can_link_$1])
|
2016-03-28 21:59:35 +02:00
|
|
|
AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
|
2013-10-21 19:07:47 +02:00
|
|
|
[AS_VAR_SET(can_link,yes)],
|
|
|
|
[AS_VAR_SET(can_link,no)])
|
|
|
|
AS_VAR_POPDEF([can_link])
|
|
|
|
fi
|
2012-05-11 21:08:16 +02:00
|
|
|
CFLAGS="$tor_saved_CFLAGS"
|
|
|
|
])
|
|
|
|
if test x$VAR = xyes; then
|
2016-04-13 00:59:40 +02:00
|
|
|
$3
|
|
|
|
else
|
|
|
|
$4
|
2012-05-11 21:08:16 +02:00
|
|
|
fi
|
|
|
|
AS_VAR_POPDEF([VAR])
|
|
|
|
])
|
|
|
|
|
2016-04-13 00:59:40 +02:00
|
|
|
dnl 1:flags
|
|
|
|
dnl 2:also try to link (yes: non-empty string)
|
|
|
|
dnl will set yes or no in $tor_can_link_$1 (as modified by AS_VAR_PUSHDEF)
|
|
|
|
AC_DEFUN([TOR_CHECK_CFLAGS], [
|
2016-06-01 22:35:00 +02:00
|
|
|
TOR_TRY_COMPILE_WITH_CFLAGS($1, $2, CFLAGS="$CFLAGS $1", true)
|
2016-04-13 00:59:40 +02:00
|
|
|
])
|
|
|
|
|
2012-05-11 21:08:16 +02:00
|
|
|
dnl 1:flags
|
2012-06-11 17:00:48 +02:00
|
|
|
dnl 2:extra ldflags
|
|
|
|
dnl 3:extra libraries
|
2012-05-11 21:08:16 +02:00
|
|
|
AC_DEFUN([TOR_CHECK_LDFLAGS], [
|
|
|
|
AS_VAR_PUSHDEF([VAR],[tor_cv_ldflags_$1])
|
|
|
|
AC_CACHE_CHECK([whether the linker accepts $1], VAR, [
|
2012-06-11 17:00:48 +02:00
|
|
|
tor_saved_CFLAGS="$CFLAGS"
|
2012-05-11 21:08:16 +02:00
|
|
|
tor_saved_LDFLAGS="$LDFLAGS"
|
2012-06-11 17:00:48 +02:00
|
|
|
tor_saved_LIBS="$LIBS"
|
|
|
|
CFLAGS="$CFLAGS -pedantic -Werror"
|
|
|
|
LDFLAGS="$LDFLAGS $2 $1"
|
|
|
|
LIBS="$LIBS $3"
|
2012-06-18 17:47:05 +02:00
|
|
|
AC_RUN_IFELSE([AC_LANG_PROGRAM([#include <stdio.h>], [fputs("", stdout)])],
|
|
|
|
[AS_VAR_SET(VAR,yes)],
|
|
|
|
[AS_VAR_SET(VAR,no)],
|
2016-03-28 21:59:35 +02:00
|
|
|
[AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
|
2012-06-18 17:47:05 +02:00
|
|
|
[AS_VAR_SET(VAR,yes)],
|
|
|
|
[AS_VAR_SET(VAR,no)])])
|
2012-06-11 17:00:48 +02:00
|
|
|
CFLAGS="$tor_saved_CFLAGS"
|
2012-05-11 21:08:16 +02:00
|
|
|
LDFLAGS="$tor_saved_LDFLAGS"
|
2012-06-11 17:00:48 +02:00
|
|
|
LIBS="$tor_saved_LIBS"
|
2012-05-11 21:08:16 +02:00
|
|
|
])
|
|
|
|
if test x$VAR = xyes; then
|
|
|
|
LDFLAGS="$LDFLAGS $1"
|
|
|
|
fi
|
|
|
|
AS_VAR_POPDEF([VAR])
|
|
|
|
])
|
|
|
|
|
2007-04-11 18:28:44 +02:00
|
|
|
dnl 1:libname
|
|
|
|
AC_DEFUN([TOR_WARN_MISSING_LIB], [
|
|
|
|
h=""
|
|
|
|
if test x$2 = xdevpkg; then
|
|
|
|
h=" headers for"
|
|
|
|
fi
|
2007-06-01 12:20:37 +02:00
|
|
|
if test -f /etc/debian_version && test x"$tor_$1_$2_debian" != x; then
|
2016-03-28 21:59:35 +02:00
|
|
|
AC_MSG_WARN([On Debian, you can install$h $1 using "apt-get install $tor_$1_$2_debian"])
|
2007-05-27 17:33:48 +02:00
|
|
|
if test x"$tor_$1_$2_debian" != x"$tor_$1_devpkg_debian"; then
|
2016-03-28 21:59:35 +02:00
|
|
|
AC_MSG_WARN([ You will probably need $tor_$1_devpkg_debian too.])
|
2007-05-27 17:33:48 +02:00
|
|
|
fi
|
2007-04-11 18:28:44 +02:00
|
|
|
fi
|
2007-06-01 12:20:37 +02:00
|
|
|
if test -f /etc/fedora-release && test x"$tor_$1_$2_redhat" != x; then
|
2016-03-28 21:59:35 +02:00
|
|
|
AC_MSG_WARN([On Fedora, you can install$h $1 using "dnf install $tor_$1_$2_redhat"])
|
2008-02-07 02:08:33 +01:00
|
|
|
if test x"$tor_$1_$2_redhat" != x"$tor_$1_devpkg_redhat"; then
|
2016-03-28 21:59:35 +02:00
|
|
|
AC_MSG_WARN([ You will probably need to install $tor_$1_devpkg_redhat too.])
|
2007-05-27 17:33:48 +02:00
|
|
|
fi
|
2007-04-11 18:28:44 +02:00
|
|
|
else
|
2007-06-01 12:20:37 +02:00
|
|
|
if test -f /etc/redhat-release && test x"$tor_$1_$2_redhat" != x; then
|
2016-03-28 21:59:35 +02:00
|
|
|
AC_MSG_WARN([On most Redhat-based systems, you can get$h $1 by installing the $tor_$1_$2_redhat RPM package])
|
2007-05-27 17:33:48 +02:00
|
|
|
if test x"$tor_$1_$2_redhat" != x"$tor_$1_devpkg_redhat"; then
|
2016-03-28 21:59:35 +02:00
|
|
|
AC_MSG_WARN([ You will probably need to install $tor_$1_devpkg_redhat too.])
|
2007-05-27 17:33:48 +02:00
|
|
|
fi
|
2007-04-11 18:28:44 +02:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
])
|
|
|
|
|
2007-03-04 20:47:34 +01:00
|
|
|
dnl Look for a library, and its associated includes, and how to link
|
|
|
|
dnl against it.
|
2007-03-10 08:38:42 +01:00
|
|
|
dnl
|
2007-04-11 18:28:44 +02:00
|
|
|
dnl TOR_SEARCH_LIBRARY(1:libname, 2:IGNORED, 3:linkargs, 4:headers,
|
2007-03-06 21:25:32 +01:00
|
|
|
dnl 5:prototype,
|
2008-08-22 18:55:28 +02:00
|
|
|
dnl 6:code, 7:IGNORED, 8:searchextra)
|
|
|
|
dnl
|
|
|
|
dnl Special variables:
|
|
|
|
dnl ALT_{libname}_WITHVAL -- another possible value for --with-$1-dir.
|
|
|
|
dnl Used to support renaming --with-ssl-dir to --with-openssl-dir
|
|
|
|
dnl
|
2007-03-04 20:47:34 +01:00
|
|
|
AC_DEFUN([TOR_SEARCH_LIBRARY], [
|
2007-04-11 18:28:44 +02:00
|
|
|
try$1dir=""
|
|
|
|
AC_ARG_WITH($1-dir,
|
2015-02-19 09:34:14 +01:00
|
|
|
AS_HELP_STRING(--with-$1-dir=PATH, [specify path to $1 installation]),
|
2007-04-11 18:28:44 +02:00
|
|
|
[
|
|
|
|
if test x$withval != xno ; then
|
|
|
|
try$1dir="$withval"
|
|
|
|
fi
|
|
|
|
])
|
2008-08-22 18:55:28 +02:00
|
|
|
if test "x$try$1dir" = x && test "x$ALT_$1_WITHVAL" != x ; then
|
|
|
|
try$1dir="$ALT_$1_WITHVAL"
|
|
|
|
fi
|
|
|
|
|
2007-03-04 20:47:34 +01:00
|
|
|
tor_saved_LIBS="$LIBS"
|
|
|
|
tor_saved_LDFLAGS="$LDFLAGS"
|
|
|
|
tor_saved_CPPFLAGS="$CPPFLAGS"
|
|
|
|
AC_CACHE_CHECK([for $1 directory], tor_cv_library_$1_dir, [
|
|
|
|
tor_$1_dir_found=no
|
|
|
|
tor_$1_any_linkable=no
|
2007-03-10 08:38:42 +01:00
|
|
|
|
2007-04-11 18:28:44 +02:00
|
|
|
for tor_trydir in "$try$1dir" "(system)" "$prefix" /usr/local /usr/pkg $8; do
|
2007-03-04 20:47:34 +01:00
|
|
|
LDFLAGS="$tor_saved_LDFLAGS"
|
|
|
|
LIBS="$tor_saved_LIBS $3"
|
|
|
|
CPPFLAGS="$tor_saved_CPPFLAGS"
|
|
|
|
|
|
|
|
if test -z "$tor_trydir" ; then
|
|
|
|
continue;
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Skip the directory if it isn't there.
|
2007-06-01 12:20:37 +02:00
|
|
|
if test ! -d "$tor_trydir" && test "$tor_trydir" != "(system)"; then
|
2007-03-04 20:47:34 +01:00
|
|
|
continue;
|
|
|
|
fi
|
|
|
|
|
|
|
|
# If this isn't blank, try adding the directory (or appropriate
|
|
|
|
# include/libs subdirectories) to the command line.
|
|
|
|
if test "$tor_trydir" != "(system)"; then
|
|
|
|
TOR_EXTEND_CODEPATH($tor_trydir)
|
|
|
|
fi
|
|
|
|
|
2007-03-10 08:38:42 +01:00
|
|
|
# Can we link against (but not necessarily run, or find the headers for)
|
|
|
|
# the binary?
|
2010-10-11 11:55:30 +02:00
|
|
|
AC_LINK_IFELSE([AC_LANG_PROGRAM([$5], [$6])],
|
2007-03-04 20:47:34 +01:00
|
|
|
[linkable=yes], [linkable=no])
|
|
|
|
|
2007-12-12 00:06:48 +01:00
|
|
|
if test "$linkable" = yes; then
|
2007-03-04 20:47:34 +01:00
|
|
|
tor_$1_any_linkable=yes
|
2007-03-10 08:38:42 +01:00
|
|
|
# Okay, we can link against it. Can we find the headers?
|
2010-10-11 11:55:30 +02:00
|
|
|
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([$4], [$6])],
|
2007-03-04 20:47:34 +01:00
|
|
|
[buildable=yes], [buildable=no])
|
2007-12-12 00:06:48 +01:00
|
|
|
if test "$buildable" = yes; then
|
2007-03-04 20:47:34 +01:00
|
|
|
tor_cv_library_$1_dir=$tor_trydir
|
|
|
|
tor_$1_dir_found=yes
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2007-12-12 00:06:48 +01:00
|
|
|
if test "$tor_$1_dir_found" = no; then
|
|
|
|
if test "$tor_$1_any_linkable" = no ; then
|
2008-08-22 18:55:28 +02:00
|
|
|
AC_MSG_WARN([Could not find a linkable $1. If you have it installed somewhere unusual, you can specify an explicit path using --with-$1-dir])
|
2007-04-11 18:28:44 +02:00
|
|
|
TOR_WARN_MISSING_LIB($1, pkg)
|
|
|
|
AC_MSG_ERROR([Missing libraries; unable to proceed.])
|
2007-03-04 20:47:34 +01:00
|
|
|
else
|
2007-04-11 18:28:44 +02:00
|
|
|
AC_MSG_WARN([We found the libraries for $1, but we could not find the C header files. You may need to install a devel package.])
|
|
|
|
TOR_WARN_MISSING_LIB($1, devpkg)
|
|
|
|
AC_MSG_ERROR([Missing headers; unable to proceed.])
|
2007-03-04 20:47:34 +01:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
LDFLAGS="$tor_saved_LDFLAGS"
|
2007-03-06 21:25:32 +01:00
|
|
|
LIBS="$tor_saved_LIBS"
|
2007-03-04 20:47:34 +01:00
|
|
|
CPPFLAGS="$tor_saved_CPPFLAGS"
|
|
|
|
]) dnl end cache check
|
|
|
|
|
|
|
|
LIBS="$LIBS $3"
|
2007-12-12 00:06:48 +01:00
|
|
|
if test "$tor_cv_library_$1_dir" != "(system)"; then
|
2007-03-04 20:47:34 +01:00
|
|
|
TOR_EXTEND_CODEPATH($tor_cv_library_$1_dir)
|
|
|
|
fi
|
|
|
|
|
2007-05-01 03:08:15 +02:00
|
|
|
TOR_DEFINE_CODEPATH($tor_cv_library_$1_dir, $1)
|
2007-04-30 22:50:09 +02:00
|
|
|
|
2007-12-23 19:20:22 +01:00
|
|
|
if test "$cross_compiling" != yes; then
|
2007-03-04 20:47:34 +01:00
|
|
|
AC_CACHE_CHECK([whether we need extra options to link $1],
|
|
|
|
tor_cv_library_$1_linker_option, [
|
2007-05-26 02:39:10 +02:00
|
|
|
orig_LDFLAGS="$LDFLAGS"
|
2007-03-04 20:47:34 +01:00
|
|
|
runs=no
|
|
|
|
linked_with=nothing
|
2007-03-15 15:18:24 +01:00
|
|
|
if test -d "$tor_cv_library_$1_dir/lib"; then
|
|
|
|
tor_trydir="$tor_cv_library_$1_dir/lib"
|
|
|
|
else
|
|
|
|
tor_trydir="$tor_cv_library_$1_dir"
|
|
|
|
fi
|
2007-03-04 20:47:34 +01:00
|
|
|
for tor_tryextra in "(none)" "-Wl,-R$tor_trydir" "-R$tor_trydir" \
|
2007-03-06 21:25:32 +01:00
|
|
|
"-Wl,-rpath,$tor_trydir" ; do
|
2007-03-04 20:47:34 +01:00
|
|
|
if test "$tor_tryextra" = "(none)"; then
|
2007-05-26 02:39:10 +02:00
|
|
|
LDFLAGS="$orig_LDFLAGS"
|
2007-03-04 20:47:34 +01:00
|
|
|
else
|
2007-05-26 02:39:10 +02:00
|
|
|
LDFLAGS="$tor_tryextra $orig_LDFLAGS"
|
2007-03-04 20:47:34 +01:00
|
|
|
fi
|
2010-10-11 11:55:30 +02:00
|
|
|
AC_RUN_IFELSE([AC_LANG_PROGRAM([$5], [$6])],
|
2016-03-28 22:29:19 +02:00
|
|
|
[runnable=yes], [runnable=no],
|
|
|
|
[AC_LINK_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
|
|
|
|
[runnable=yes],
|
|
|
|
[runnable=no])])
|
2007-03-04 20:47:34 +01:00
|
|
|
if test "$runnable" = yes; then
|
|
|
|
tor_cv_library_$1_linker_option=$tor_tryextra
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
if test "$runnable" = no; then
|
2008-08-22 18:55:28 +02:00
|
|
|
AC_MSG_ERROR([Found linkable $1 in $tor_cv_library_$1_dir, but it does not seem to run, even with -R. Maybe specify another using --with-$1-dir}])
|
2007-03-04 20:47:34 +01:00
|
|
|
fi
|
2007-05-26 02:39:10 +02:00
|
|
|
LDFLAGS="$orig_LDFLAGS"
|
2007-03-06 21:25:32 +01:00
|
|
|
]) dnl end cache check check for extra options.
|
2007-03-04 20:47:34 +01:00
|
|
|
|
|
|
|
if test "$tor_cv_library_$1_linker_option" != "(none)" ; then
|
2007-05-26 01:59:47 +02:00
|
|
|
TOR_LDFLAGS_$1="$TOR_LDFLAGS_$1 $tor_cv_library_$1_linker_option"
|
2007-03-04 20:47:34 +01:00
|
|
|
fi
|
|
|
|
fi # cross-compile
|
|
|
|
|
2007-04-30 22:50:09 +02:00
|
|
|
LIBS="$tor_saved_LIBS"
|
|
|
|
LDFLAGS="$tor_saved_LDFLAGS"
|
2007-05-26 01:59:47 +02:00
|
|
|
CPPFLAGS="$tor_saved_CPPFLAGS"
|
2007-04-30 22:50:09 +02:00
|
|
|
|
2007-03-04 20:47:34 +01:00
|
|
|
]) dnl end defun
|
|
|
|
|
2008-01-30 20:25:31 +01:00
|
|
|
dnl Check whether the prototype for a function is present or missing.
|
|
|
|
dnl Apple has a nasty habit of putting functions in their libraries (so that
|
|
|
|
dnl AC_CHECK_FUNCS passes) but not actually declaring them in the headers.
|
|
|
|
dnl
|
|
|
|
dnl TOR_CHECK_PROTYPE(1:functionname, 2:macroname, 2: includes)
|
|
|
|
AC_DEFUN([TOR_CHECK_PROTOTYPE], [
|
|
|
|
AC_CACHE_CHECK([for declaration of $1], tor_cv_$1_declared, [
|
2010-10-11 11:55:30 +02:00
|
|
|
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([$3],[void *ptr= $1 ;])],
|
2008-01-30 20:25:31 +01:00
|
|
|
tor_cv_$1_declared=yes,tor_cv_$1_declared=no)])
|
|
|
|
if test x$tor_cv_$1_declared != xno ; then
|
|
|
|
AC_DEFINE($2, 1,
|
|
|
|
[Defined if the prototype for $1 seems to be present.])
|
|
|
|
fi
|
2008-02-07 06:31:47 +01:00
|
|
|
])
|