1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 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 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273
|
##############################################################################
# 1. Initialize the autoconf build
##############################################################################
# Process this file with autoconf to produce a configure script.
AC_INIT([torsocks], [2.0.0],[dgoulet@ev0ke.net],[],[https://torproject.org])
AC_CONFIG_AUX_DIR([config])
AC_CANONICAL_TARGET
# Get hostname and other information.
AC_CANONICAL_HOST
AC_CONFIG_MACRO_DIR([config])
# Create a config.g file to store defines generated by configure
AC_CONFIG_HEADER([include/config.h])
# Automake initialization
AM_INIT_AUTOMAKE([foreign dist-bzip2 no-dist-gzip])
# Silent compilation. Easier to spot errors!
m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
dnl Checks for programs.
AC_PROG_CC
AC_PROG_INSTALL
AC_PROG_LN_S
##############################################################################
# 2. Check for some standard headers and libraries
##############################################################################
dnl Check if the C compiler accepts -Wall
AC_MSG_CHECKING(if the C compiler accepts -Wall)
OLDCFLAGS="$CFLAGS"
CFLAGS="$CFLAGS -Wall"
AC_TRY_COMPILE(,,
[AC_MSG_RESULT(yes)],
[
CFLAGS="$OLDCFLAGS"
AC_MSG_RESULT(no)
]
)
dnl Checks for standard header files.
AC_HEADER_STDC
AC_CHECK_HEADERS(dlfcn.h sys/syscall.h sys/socket.h arpa/inet.h \
assert.h netdb.h errno.h stdarg.h time.h,,
[AC_MSG_ERROR("Required header not found")]
)
dnl Checks for required library functions.
AC_CHECK_FUNCS(strcspn strdup strerror strcasecmp strncasecmp mmap munmap \
socket connect close syscall recv send memset memcpy strlen \
strncpy strcmp malloc calloc strstr strtoul free,,
[AC_MSG_ERROR("Required function not found")]
)
##############################################################################
# 3. Determine libraries we need to include when linking libtorsocks.
# OpenBSD and OSX have some special requirements here.
# Also check the host we're building on, as some of the code
# in torsocks.c and elsewhere is platform-dependent.
##############################################################################
dnl Check for a function to convert an ascii ip address
dnl to a sin_addr.
AC_CHECK_FUNC(inet_aton, AC_DEFINE([HAVE_INET_ATON],[],[Description]),
[AC_CHECK_FUNC(inet_addr, AC_DEFINE([HAVE_INET_ADDR],[],[Description]),
[AC_CHECK_LIB(nsl, inet_addr,
[
AC_DEFINE([HAVE_INET_ADDR],[],[Description])
LIBS="${LIBS} -lnsl"
],
[AC_MSG_ERROR("Neither inet_aton or inet_addr present")]
)]
)]
)
dnl Look for gethostbyname (needed by torsocks)
AC_CHECK_FUNC(gethostbyname, AC_DEFINE([HAVE_GETHOSTBYNAME],[],[Description]),
[AC_CHECK_LIB(xnet, gethostbyname, AC_DEFINE([HAVE_GETHOSTBYNAME],[],[Description]),
[AC_MSG_ERROR(["gethostbyname not found, name lookups in torsocks disabled"])]
)]
)
dnl Do we have dlopen(3) in libdl?
AC_SEARCH_LIBS([dlopen], [dl],,
[AC_MSG_ERROR("dlopen function not found in libdl")]
)
dnl OpenBSD needs -lpthread. It also doesn't support AI_V4MAPPED.
case $host in
*-*-openbsd*)
AC_DEFINE(OPENBSD, 1, "Define to handle OpenBSD")
AC_SEARCH_LIBS(pthread_create, [pthread])
;;
*-*-freebsd*)
AC_DEFINE(FREEBSD, 1, "Define to handle FreeBSD")
;;
*-*-darwin*)
dnl Needed to compile tests.
dnl See https://bugs.g10code.com/gnupg/issue1292:
dnl "On OS X (at least in 10.6 and I believe starting at 10.3) the DNS resolution
dnl services fail to compile. This is a result of the addition of BIND9 compatible
dnl resolution libraries on OS X that are being picked up by the configure script
dnl instead of -lresolv causing the tests for useable resolution services to fail
dnl thus disabling features like pka auto lookup."
LIBS="-lresolv $LIBS"
;;
esac
if test "x${enable_envconf}" = "x"; then
AC_DEFINE([ALLOW_ENV_CONFIG],[],[Description])
fi
dnl Get libc full system path. Use prefix or some hardcoded standard
dnl location on Unixish system.
AC_MSG_CHECKING(file name of the C library)
AS_CASE([$host_os],
[darwin*], [libc_name="libSystem.dylib"],
[linux*|kfreebsd*-gnu],
[
libc_name=`ldd /usr/bin/yes | grep 'libc\.' | cut -d ' ' -f 1 | tr -d '\t'`
if test "${libc_name}" == ""; then
# Default libc on most system.
libc_name="libc.so.6"
fi
],
[libc_name="libc.so"]
)
AC_DEFINE_UNQUOTED([LIBC_NAME],["${libc_name}"], [Description])
AC_MSG_RESULT($libc_name)
##############################################################################
# 5. Determine how to preload libtorsocks.so on this system.
# On Linux this is with the LD_PRELOAD variable, on OSX
# we need to use DYLD_INSERT_LIBRARIES.
##############################################################################
# This variable is used for the LDFLAGS in test/Makefile.am
TESTLDFLAGS="$LDFLAGS"
AC_SUBST(TESTLDFLAGS)
# Version information for libtorsocks
TORSOCKSLDFLAGS="$LDFLAGS -version-info 1:0:0"
# Check for the gcc hardening flags.
AX_CHECK_COMPILE_FLAG([-fPIE],[CFLAGS="$CFLAGS -fPIE"],[],[])
AX_CHECK_COMPILE_FLAG([-fwrapv],[CFLAGS="$CFLAGS -fwrapv"],[],[])
AX_CHECK_COMPILE_FLAG([--param ssp-buffer-size=1],
[CFLAGS="$CFLAGS --param ssp-buffer-size=1"],[],[])
AX_CHECK_COMPILE_FLAG([-fstack-protector-all],
[CFLAGS="$CFLAGS -fstack-protector-all"],[],[]
)
AX_CHECK_COMPILE_FLAG([-fno-strict-overflow],
[CFLAGS="$CFLAGS -fno-strict-overflow"],[],[]
)
dnl Add hardening linker flags
AX_CHECK_LINK_FLAG([-pie],[LDFLAGS="$LDFLAGS -pie"],[],[])
AX_CHECK_LINK_FLAG([-z relro],[LDFLAGS="$LDFLAGS -z relro"],[],[])
AX_CHECK_LINK_FLAG([-z now],[LDFLAGS="$LDFLAGS -z now"],[],[])
LDFLAGS="$LDFLAGS -D_FORTIFY_SOURCE=2"
dnl Linker checks for Mac OSX, which uses DYLD_INSERT_LIBRARIES
dnl instead of LD_PRELOAD
case "$host_os" in
darwin*)
dnl Check if the linker accepts -dynamiclib; necessary on Mac OS X
AC_MSG_CHECKING(if the linker accepts -dynamiclib)
OLDLDFLAGS="$TORSOCKSLDFLAGS"
TORSOCKSLDFLAGS="$TORSOCKSLDFLAGS -dynamiclib"
AC_TRY_COMPILE(,, [AC_MSG_RESULT(yes)],
[
TORSOCKSLDFLAGS="$OLDLDFLAGS"
AC_MSG_RESULT(no)
]
)
# dnl Check if the linker accepts -multiply_defined suppress; necessary on Mac OS X
# AC_MSG_CHECKING(if the linker accepts -multiply_defined suppress)
# OLDLDFLAGS="$LDFLAGS"
# LDFLAGS="$LDFLAGS -multiply_defined suppress"
# AC_TRY_COMPILE(,,AC_MSG_RESULT(yes),[
# LDFLAGS="$OLDLDFLAGS"
# AC_MSG_RESULT(no)])
dnl Check if the linker accepts -single_module; necessary on Mac OS X
AC_MSG_CHECKING(if the linker accepts -single_module)
OLDLDFLAGS="$TORSOCKSLDFLAGS"
SHLIB_EXT="so"
LDPRELOAD="LD_PRELOAD"
TORSOCKSLDFLAGS="$TORSOCKSLDFLAGS -single_module"
AC_TRY_COMPILE(,,
[
SHLIB_EXT="dylib"
LDPRELOAD="DYLD_INSERT_LIBRARIES"
AC_MSG_RESULT(yes)
],
[
TORSOCKSLDFLAGS="$OLDLDFLAGS"
AC_MSG_RESULT(no)
]
)
;;
*)
SHLIB_EXT="so"
LDPRELOAD="LD_PRELOAD"
;;
esac
AC_SUBST(SHLIB_EXT)
AC_SUBST(LDPRELOAD)
AC_SUBST(TORSOCKSLDFLAGS)
##############################################################################
# 7. Determine where the install should write the default configuration
# file and where libtorsocks should read it from by default.
##############################################################################
if test "x$prefix" = "xNONE"; then
prefix=$ac_default_prefix
fi
if test "x$CONFDIR" = "x"; then
CONFDIR=`eval echo $sysconfdir`
fi
AC_SUBST(CONFDIR)
AH_TEMPLATE([CONFDIR],[torsocks configuration directory])
AC_DEFINE_UNQUOTED(CONFDIR,"$CONFDIR")
AC_ARG_WITH(conf,
[ --with-conf=<file> location of configuration file (${CONFDIR}/torsocks.conf default)],[
if test "${withval}" = "yes" ; then
AC_MSG_ERROR("--with-conf requires the location of the configuration file as an argument")
else
AC_DEFINE_UNQUOTED([CONF_FILE], ["${withval}"],[Description])
fi
], [
AC_DEFINE_UNQUOTED([CONF_FILE], ["${CONFDIR}/torsocks.conf"],[Description])
])
##############################################################################
# 8. Clean up and create some supporting scripts from their *.in files
##############################################################################
AC_LANG_C
AC_PROG_CC
AC_LIBTOOL_DLOPEN
AC_PROG_LIBTOOL
AC_SUBST(LIBTOOL_DEPS)
AC_ENABLE_SHARED
AC_ENABLE_STATIC
DEFAULT_INCLUDES="-I\$(top_srcdir) -I\$(top_builddir) -I\$(top_builddir)/src -I\$(top_builddir)/include -include config.h"
AC_SUBST(DEFAULT_INCLUDES)
AC_CONFIG_FILES([
Makefile
extras/Makefile
src/Makefile
src/bin/Makefile
src/bin/torsocks
src/common/Makefile
src/lib/Makefile
tests/Makefile
tests/unit/Makefile
tests/utils/Makefile
tests/utils/tap/Makefile
doc/Makefile
])
AC_OUTPUT
|