]> git.meshlink.io Git - meshlink/blob - configure.ac
Don't overwrite CFLAGS when adding -std=c11.
[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 DX_PS_FEATURE(OFF)
6 DX_INIT_DOXYGEN([MeshLink], [$(top_srcdir)/Doxyfile])
7 AM_INIT_AUTOMAKE([std-options subdir-objects nostdinc silent-rules -Wall])
8 AC_CONFIG_HEADERS([config.h])
9 AC_CONFIG_MACRO_DIR([m4])
10 AM_SILENT_RULES([yes])
11
12 # Enable GNU extensions.
13 # Define this here, not in acconfig's @TOP@ section, since definitions
14 # in the latter don't make it into the configure-time tests.
15 AC_GNU_SOURCE
16 AC_DEFINE([__USE_BSD], 1, [Enable BSD extensions])
17
18 dnl Checks for programs.
19 AM_PROG_CC_C_O
20 AM_PROG_AR
21 AC_PROG_CC_C99
22 AC_PROG_CXX
23 AC_PROG_CPP
24 AC_PROG_INSTALL
25 AC_PROG_LN_S
26 AC_PROG_LIBTOOL
27 AX_PTHREAD
28
29 dnl Check and set OS
30
31 AC_CANONICAL_HOST
32
33 case $host_os in
34   *linux*)
35     linux=true
36     AC_DEFINE(HAVE_LINUX, 1, [Linux])
37   ;;
38   *mingw*)
39     mingw=true
40     AC_DEFINE(HAVE_MINGW, 1, [MinGW])
41     LIBS="$LIBS -lws2_32 -lgdi32 -lcrypt32"
42   ;;
43 esac
44
45 AM_CONDITIONAL(LINUX, test "$linux" = true)
46 AM_CONDITIONAL(MINGW, test "$mingw" = true)
47
48 AC_CACHE_SAVE
49
50 if test -d /sw/include ; then
51   CPPFLAGS="$CPPFLAGS -I/sw/include"
52 fi
53 if test -d /sw/lib ; then
54   LIBS="$LIBS -L/sw/lib"
55 fi
56
57 AX_CHECK_COMPILE_FLAG([-std=c11], [CFLAGS="$CFLAGS -std=c11"])
58
59 dnl Compiler hardening flags
60 dnl No -fstack-protector-all because it doesn't work on all platforms or architectures.
61
62 AC_ARG_ENABLE([hardening], AS_HELP_STRING([--disable-hardening], [disable compiler and linker hardening flags]))
63 AS_IF([test "x$enable_hardening" != "xno"],
64   [CPPFLAGS="$CPPFLAGS -Wall -W -pedantic"
65    AX_CHECK_COMPILE_FLAG([-DFORTIFY_SOURCE=2], [CPPFLAGS="$CPPFLAGS -DFORITFY_SOURCE=2"])
66    AX_CHECK_COMPILE_FLAG([-fwrapv], [CPPFLAGS="$CPPFLAGS -fwrapv"],
67      [AX_CHECK_COMPILE_FLAG([-fno-strict-overflow], [CPPFLAGS="$CPPFLAGS -fno-strict-overflow"])]
68    )
69    case $host_os in
70      *mingw*)
71        AX_CHECK_LINK_FLAG([-Wl,--dynamicbase], [LDFLAGS="$LDFLAGS -Wl,--dynamicbase"])
72        AX_CHECK_LINK_FLAG([-Wl,--nxcompat], [LDFLAGS="$LDFLAGS -Wl,--nxcompat"])
73        ;;
74      *)
75        AX_CHECK_COMPILE_FLAG([-fPIC], [CPPFLAGS="$CPPFLAGS -fPIC"])
76        ;;
77    esac
78    AX_CHECK_LINK_FLAG([-Wl,-z,relro], [LDFLAGS="$LDFLAGS -Wl,-z,relro"])
79    AX_CHECK_LINK_FLAG([-Wl,-z,now], [LDFLAGS="$LDFLAGS -Wl,-z,now"])
80    AX_CHECK_COMPILE_FLAG([-Wextra -pedantic -Wreturn-type -Wold-style-definition -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wredundant-decls -Wshadow -Wbad-function-cast -Wwrite-strings -fdiagnostics-show-option -fstrict-aliasing -Wmissing-noreturn], [
81      CPPFLAGS="$CPPFLAGS -Wextra -pedantic -Wreturn-type -Wmissing-declarations -Wredundant-decls -Wshadow -Wwrite-strings -fdiagnostics-show-option -fstrict-aliasing -Wmissing-noreturn"
82      CFLAGS="$CFLAGS -Wold-style-definition -Wmissing-prototypes -Wstrict-prototypes -Wbad-function-cast"
83    ])
84   ]
85 );
86
87 dnl Allow building without Catta
88 AC_ARG_ENABLE([catta], AS_HELP_STRING([--disable-catta], [disable linking with the Catta library]))
89 AS_IF([test "x$enable_catta" != "xno"],
90   AC_DEFINE(HAVE_CATTA, 1, [Link with Catta])
91   AC_CONFIG_SUBDIRS([catta])
92 )
93 AM_CONDITIONAL(CATTA, test "x$enable_catta" != "xno")
94
95 dnl UTCP debug flags
96 AC_ARG_ENABLE([utcp_debug], AS_HELP_STRING([--enable-utcp-debug], [compile utcp with debug output]))
97 AS_IF([test "x$enable_utcp_debug" = "xyes"],
98   [AX_CHECK_COMPILE_FLAG([-DUTCP_DEBUG], [CPPFLAGS="$CPPFLAGS -DUTCP_DEBUG"])
99   ]
100 );
101
102 dnl Blackbox test suite
103 PKG_CHECK_MODULES([CMOCKA], [cmocka >= 1.1.0], [cmocka=true], [cmocka=false])
104 PKG_CHECK_MODULES([LXC], [lxc >= 2.0.0], [lxc=true], [lxc=false])
105 AM_CONDITIONAL(BLACKBOX_TESTS, test "$cmocka" = true -a "$lxc" = true)
106
107
108 dnl Additional example code
109 PKG_CHECK_MODULES([NCURSES], [ncurses >= 5], [curses=true], [curses=false])
110 AC_ARG_ENABLE([monitor_code], 
111         [AS_HELP_STRING([--enable-monitor-code], [Add monitor example code to the build])],
112   [AS_IF([test "x$enable_monitor_code" = "xyes"], [monitor_code=true], [monitor_code=false])],
113   [monitor_code=false]
114 )
115 AM_CONDITIONAL(MONITOR, test "$monitor_code" = true)
116
117 dnl Install test binaries
118 AC_ARG_ENABLE([install_tests],
119   [AS_HELP_STRING([--enable-install-tests], [include test binaries in installation])],
120   [AS_IF([test "x$enable_install_tests" = "xyes"], [install_tests=true], [install_tests=false])],
121   [install_tests=false]
122 )
123
124 AM_CONDITIONAL(INSTALL_TESTS, test "$install_tests" = true)
125
126 dnl Checks for header files.
127 dnl We do this in multiple stages, because unlike Linux all the other operating systems really suck and don't include their own dependencies.
128
129 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 curses.h ifaddrs.h])
130
131 dnl Checks for typedefs, structures, and compiler characteristics.
132 MeshLink_ATTRIBUTE(__malloc__)
133 MeshLink_ATTRIBUTE(__warn_unused_result__)
134
135 dnl Checks for library functions.
136 AC_TYPE_SIGNAL
137 AC_CHECK_FUNCS([asprintf fchmod fork gettimeofday random pselect select setns strdup usleep getifaddrs freeifaddrs],
138   [], [], [#include "$srcdir/src/have.h"]
139 )
140
141 dnl Support for SunOS
142
143 AC_CHECK_FUNC(socket, [], [
144   AC_CHECK_LIB(socket, connect)
145 ])
146
147 AC_CACHE_SAVE
148
149 AC_CONFIG_FILES([
150          Makefile
151          src/Makefile
152          test/Makefile
153          test/blackbox/Makefile
154          test/blackbox/run_blackbox_tests/Makefile
155          test/blackbox/test_case_channel_conn_01/Makefile
156          test/blackbox/test_case_channel_conn_02/Makefile
157          test/blackbox/test_case_channel_conn_03/Makefile
158          test/blackbox/test_case_channel_conn_04/Makefile
159          test/blackbox/test_case_channel_conn_05/Makefile
160          test/blackbox/test_case_channel_conn_06/Makefile
161          test/blackbox/test_case_channel_conn_07/Makefile
162          test/blackbox/test_case_channel_conn_08/Makefile
163          test/blackbox/test_case_meta_conn_01/Makefile
164          test/blackbox/test_case_meta_conn_02/Makefile
165          test/blackbox/test_case_meta_conn_03/Makefile
166          test/blackbox/test_case_meta_conn_04/Makefile
167          test/blackbox/test_case_meta_conn_05/Makefile
168          test/blackbox/test_cases_submesh01/Makefile
169          test/blackbox/test_cases_submesh02/Makefile
170          test/blackbox/test_cases_submesh03/Makefile
171          test/blackbox/test_cases_submesh04/Makefile
172          examples/Makefile
173 ])
174
175 AC_OUTPUT