]> git.meshlink.io Git - meshlink/blob - configure.ac
Use AX_PTHREAD to set the proper pthread flags.
[meshlink] / configure.ac
1 dnl Process this file with autoconf to produce a configure script.
2
3 AC_PREREQ(2.61)
4 AC_INIT([MeshLink], [0.1])
5 AM_INIT_AUTOMAKE([std-options subdir-objects nostdinc silent-rules -Wall])
6 AC_CONFIG_HEADERS([config.h])
7 AC_CONFIG_MACRO_DIR([m4])
8 AC_CONFIG_SUBDIRS([catta])
9 AM_SILENT_RULES([yes])
10
11 # Enable GNU extensions.
12 # Define this here, not in acconfig's @TOP@ section, since definitions
13 # in the latter don't make it into the configure-time tests.
14 AC_GNU_SOURCE
15 AC_DEFINE([__USE_BSD], 1, [Enable BSD extensions])
16
17 dnl Checks for programs.
18 AM_PROG_CC_C_O
19 AM_PROG_AR
20 AC_PROG_CC_C99
21 AC_PROG_CXX
22 AC_PROG_CPP
23 AC_PROG_INSTALL
24 AC_PROG_LN_S
25 AC_PROG_LIBTOOL
26 AX_PTHREAD
27
28 dnl Check and set OS
29
30 AC_CANONICAL_HOST
31
32 case $host_os in
33   *linux*)
34     linux=true
35     AC_DEFINE(HAVE_LINUX, 1, [Linux])
36   ;;
37   *mingw*)
38     mingw=true
39     AC_DEFINE(HAVE_MINGW, 1, [MinGW])
40     LIBS="$LIBS -lws2_32 -lgdi32 -lcrypt32"
41   ;;
42 esac
43
44 AM_CONDITIONAL(LINUX, test "$linux" = true)
45 AM_CONDITIONAL(MINGW, test "$mingw" = true)
46
47 AC_CACHE_SAVE
48
49 if test -d /sw/include ; then
50   CPPFLAGS="$CPPFLAGS -I/sw/include"
51 fi
52 if test -d /sw/lib ; then
53   LIBS="$LIBS -L/sw/lib"
54 fi
55
56 dnl Compiler hardening flags
57 dnl No -fstack-protector-all because it doesn't work on all platforms or architectures.
58
59 AC_ARG_ENABLE([hardening], AS_HELP_STRING([--disable-hardening], [disable compiler and linker hardening flags]))
60 AS_IF([test "x$enable_hardening" != "xno"],
61   [AX_CHECK_COMPILE_FLAG([-DFORTIFY_SOURCE=2], [CPPFLAGS="$CPPFLAGS -DFORITFY_SOURCE=2"])
62    AX_CHECK_COMPILE_FLAG([-fno-strict-overflow], [CPPFLAGS="$CPPFLAGS -fno-strict-overflow"])
63    AX_CHECK_COMPILE_FLAG([-fwrapv], [CPPFLAGS="$CPPFLAGS -fwrapv"])
64    case $host_os in
65      *mingw*)
66        AX_CHECK_LINK_FLAG([-Wl,--dynamicbase], [LDFLAGS="$LDFLAGS -Wl,--dynamicbase"])
67        AX_CHECK_LINK_FLAG([-Wl,--nxcompat], [LDFLAGS="$LDFLAGS -Wl,--nxcompat"])
68        ;;
69      *)
70        AX_CHECK_COMPILE_FLAG([-fPIE], [CPPFLAGS="$CPPFLAGS -fPIE"])
71        AX_CHECK_COMPILE_FLAG([-fPIC], [CPPFLAGS="$CPPFLAGS -fPIC"])
72        AX_CHECK_LINK_FLAG([-pie], [LDFLAGS="$LDFLAGS -pie"])
73        ;;
74    esac
75    AX_CHECK_LINK_FLAG([-Wl,-z,relro], [LDFLAGS="$LDFLAGS -Wl,-z,relro"])
76    AX_CHECK_LINK_FLAG([-Wl,-z,now], [LDFLAGS="$LDFLAGS -Wl,-z,now"])
77   ]
78 );
79
80 dnl UTCP debug flags
81 AC_ARG_ENABLE([utcp_debug], AS_HELP_STRING([--enable-utcp-debug], [compile utcp with debug output]))
82 AS_IF([test "x$enable_utcp_debug" = "xyes"],
83   [AX_CHECK_COMPILE_FLAG([-DUTCP_DEBUG], [CPPFLAGS="$CPPFLAGS -DUTCP_DEBUG"])
84   ]
85 );
86
87 dnl Install test binaries
88 AC_ARG_ENABLE([install_tests],
89   [AS_HELP_STRING([--enable-install-tests], [include test binaries in installation])],
90   [AS_IF([test "x$enable_install_tests" = "xyes"], [install_tests=true], [install_tests=false])],
91   [install_tests=false]
92 )
93
94 AM_CONDITIONAL(INSTALL_TESTS, test "$install_tests" = true)
95
96 dnl Checks for header files.
97 dnl We do this in multiple stages, because unlike Linux all the other operating systems really suck and don't include their own dependencies.
98
99 AC_CHECK_HEADERS([syslog.h sys/file.h sys/param.h sys/resource.h sys/socket.h sys/time.h sys/un.h sys/wait.h netdb.h arpa/inet.h dirent.h])
100
101 dnl Checks for typedefs, structures, and compiler characteristics.
102 MeshLink_ATTRIBUTE(__malloc__)
103 MeshLink_ATTRIBUTE(__warn_unused_result__)
104
105 AC_CHECK_TYPES([socklen_t, struct addrinfo, struct sockaddr_in6], , ,
106   [#include "$srcdir/src/have.h"]
107 )
108
109 AC_CHECK_TYPES([struct sockaddr_storage], ,AC_MSG_ERROR([System must support struct sockaddr_storage.]),
110   [#include "$srcdir/src/have.h"]
111 )
112
113 dnl Checks for library functions.
114 AC_TYPE_SIGNAL
115 AC_CHECK_FUNCS([asprintf fchmod fork gettimeofday random select strdup usleep],
116   [], [], [#include "$srcdir/src/have.h"]
117 )
118
119 dnl Support for SunOS
120
121 AC_CHECK_FUNC(socket, [], [
122   AC_CHECK_LIB(socket, connect)
123 ])
124 AC_CHECK_FUNC(gethostbyname, [], [
125   AC_CHECK_LIB(nsl, gethostbyname)
126 ])
127
128 AC_CHECK_DECLS([freeaddrinfo, gai_strerror, getaddrinfo, getnameinfo],
129   [], [], [#include "$srcdir/src/have.h"]
130 )
131
132 AC_CACHE_SAVE
133
134 AC_CONFIG_FILES([Makefile src/Makefile doc/Makefile test/Makefile examples/Makefile])
135
136 AC_OUTPUT