############################################################################## # 1. Initialize the autoconf build ############################################################################## # Process this file with autoconf to produce a configure script. AC_INIT([torsocks], [2.3.0],[dgoulet@torproject.org],[],[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.h file to store defines generated by configure AC_CONFIG_HEADER([include/config.h]) # Try to enable the POSIX extensions. AC_USE_SYSTEM_EXTENSIONS # Automake initialization AM_INIT_AUTOMAKE([foreign dist-xz 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|freebsd*], [ 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" 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= 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) ############################################################################## # 9. Test and add hardening flags ############################################################################## # 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"],[],[] ) 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"],[],[]) dnl Add glibc hardening CPPFLAGS="$CPPFLAGS -D_FORTIFY_SOURCE=2" ############################################################################## # 10. Finish up ############################################################################## 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