]> git.meshlink.io Git - meshlink/blob - configure.ac
Fix a compile error on macOS when using an older version of autoconf.
[meshlink] / configure.ac
1 dnl Process this file with autoconf to produce a configure script.
2
3 AC_PREREQ(2.69)
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_USE_SYSTEM_EXTENSIONS
16 AC_DEFINE([__USE_BSD], 1, [Enable BSD extensions])
17 AC_DEFINE([_POSIX_C_SOURCE], 200809L, [Enable POSIX features])
18 AC_DEFINE([_DARWIN_C_SOURCE], 1, [Enable Darwin features])
19
20 dnl Checks for programs.
21 AM_PROG_CC_C_O
22 AM_PROG_AR
23 AC_PROG_CC
24 AC_PROG_CXX
25 AC_PROG_CPP
26 AC_PROG_INSTALL
27 AC_PROG_LN_S
28 LT_INIT
29 AX_PTHREAD
30
31 dnl Check and set OS
32
33 AC_CANONICAL_HOST
34
35 case $host_os in
36   *linux*)
37     linux=true
38     AC_DEFINE(HAVE_LINUX, 1, [Linux])
39   ;;
40   *mingw*)
41     mingw=true
42     AC_DEFINE(HAVE_MINGW, 1, [MinGW])
43     LIBS="$LIBS -lws2_32 -lgdi32 -lcrypt32"
44   ;;
45   *darwin* | *ios*)
46     LIBS="$LIBS -framework Foundation -framework SystemConfiguration"
47   ;;
48 esac
49
50 AM_CONDITIONAL(LINUX, test "$linux" = true)
51 AM_CONDITIONAL(MINGW, test "$mingw" = true)
52
53 AC_CACHE_SAVE
54
55 if test -d /sw/include ; then
56   CPPFLAGS="$CPPFLAGS -I/sw/include"
57 fi
58 if test -d /sw/lib ; then
59   LIBS="$LIBS -L/sw/lib"
60 fi
61
62 AX_CHECK_COMPILE_FLAG([-std=c11], [CFLAGS="$CFLAGS -std=c11"])
63
64 dnl Compiler hardening flags
65 dnl No -fstack-protector-all because it doesn't work on all platforms or architectures.
66
67 AC_ARG_ENABLE([hardening], AS_HELP_STRING([--disable-hardening], [disable compiler and linker hardening flags]))
68 AS_IF([test "x$enable_hardening" != "xno"],
69   [CPPFLAGS="$CPPFLAGS -Wall -W -pedantic"
70    AX_CHECK_COMPILE_FLAG([-DFORTIFY_SOURCE=2], [CPPFLAGS="$CPPFLAGS -DFORITFY_SOURCE=2"])
71    AX_CHECK_COMPILE_FLAG([-fwrapv], [CPPFLAGS="$CPPFLAGS -fwrapv"],
72      [AX_CHECK_COMPILE_FLAG([-fno-strict-overflow], [CPPFLAGS="$CPPFLAGS -fno-strict-overflow"])]
73    )
74    case $host_os in
75      *mingw*)
76        AX_CHECK_LINK_FLAG([-Wl,--dynamicbase], [LDFLAGS="$LDFLAGS -Wl,--dynamicbase"])
77        AX_CHECK_LINK_FLAG([-Wl,--nxcompat], [LDFLAGS="$LDFLAGS -Wl,--nxcompat"])
78        ;;
79      *)
80        AX_CHECK_COMPILE_FLAG([-fPIC], [CPPFLAGS="$CPPFLAGS -fPIC"])
81        ;;
82    esac
83    AX_CHECK_LINK_FLAG([-Wl,-z,relro], [LDFLAGS="$LDFLAGS -Wl,-z,relro"])
84    AX_CHECK_LINK_FLAG([-Wl,-z,now], [LDFLAGS="$LDFLAGS -Wl,-z,now"])
85    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], [CPPFLAGS="$CPPFLAGS -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"])
86   ]
87 );
88
89 dnl UTCP debug flags
90 AC_ARG_ENABLE([utcp_debug], AS_HELP_STRING([--enable-utcp-debug], [compile utcp with debug output]))
91 AS_IF([test "x$enable_utcp_debug" = "xyes"],
92   [AX_CHECK_COMPILE_FLAG([-DUTCP_DEBUG], [CPPFLAGS="$CPPFLAGS -DUTCP_DEBUG"])
93   ]
94 );
95
96 dnl Blackbox test suite
97 PKG_CHECK_MODULES([CMOCKA], [cmocka >= 1.1.0], [cmocka=true], [cmocka=false])
98 PKG_CHECK_MODULES([LXC], [lxc >= 2.0.0], [lxc=true], [lxc=false])
99 AM_CONDITIONAL(BLACKBOX_TESTS, test "$cmocka" = true -a "$lxc" = true)
100
101
102 dnl Additional example code
103 PKG_CHECK_MODULES([NCURSES], [ncurses >= 5], [curses=true], [curses=false])
104 AC_ARG_ENABLE([monitor_code], 
105         [AS_HELP_STRING([--enable-monitor-code], [Add monitor example code to the build])],
106   [AS_IF([test "x$enable_monitor_code" = "xyes"], [monitor_code=true], [monitor_code=false])],
107   [monitor_code=false]
108 )
109 AM_CONDITIONAL(MONITOR, test "$monitor_code" = true)
110
111 dnl Install test binaries
112 AC_ARG_ENABLE([install_tests],
113   [AS_HELP_STRING([--enable-install-tests], [include test binaries in installation])],
114   [AS_IF([test "x$enable_install_tests" = "xyes"], [install_tests=true], [install_tests=false])],
115   [install_tests=false]
116 )
117
118 AM_CONDITIONAL(INSTALL_TESTS, test "$install_tests" = true)
119
120 dnl Checks for header files.
121 dnl We do this in multiple stages, because unlike Linux all the other operating systems really suck and don't include their own dependencies.
122
123 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 stdatomic.h])
124
125 dnl Checks for typedefs, structures, and compiler characteristics.
126 MeshLink_ATTRIBUTE(__malloc__)
127 MeshLink_ATTRIBUTE(__warn_unused_result__)
128
129 dnl Checks for library functions.
130 AC_CHECK_FUNCS([asprintf fchmod fork gettimeofday random pselect select setns strdup usleep getifaddrs freeifaddrs],
131   [], [], [#include "$srcdir/src/have.h"]
132 )
133
134 dnl Support for SunOS
135
136 AC_CHECK_FUNC(socket, [], [
137   AC_CHECK_LIB(socket, connect)
138 ])
139
140 AC_CACHE_SAVE
141
142 AC_CONFIG_FILES([
143          Makefile
144          src/Makefile
145          test/Makefile
146          test/blackbox/Makefile
147          test/blackbox/run_blackbox_tests/Makefile
148          test/blackbox/test_case_channel_conn_01/Makefile
149          test/blackbox/test_case_channel_conn_02/Makefile
150          test/blackbox/test_case_channel_conn_03/Makefile
151          test/blackbox/test_case_channel_conn_04/Makefile
152          test/blackbox/test_case_channel_conn_05/Makefile
153          test/blackbox/test_case_channel_conn_06/Makefile
154          test/blackbox/test_case_channel_conn_07/Makefile
155          test/blackbox/test_case_channel_conn_08/Makefile
156          test/blackbox/test_case_meta_conn_01/Makefile
157          test/blackbox/test_case_meta_conn_02/Makefile
158          test/blackbox/test_case_meta_conn_03/Makefile
159          test/blackbox/test_case_meta_conn_04/Makefile
160          test/blackbox/test_case_meta_conn_05/Makefile
161          test/blackbox/test_cases_submesh01/Makefile
162          test/blackbox/test_cases_submesh02/Makefile
163          test/blackbox/test_cases_submesh03/Makefile
164          test/blackbox/test_cases_submesh04/Makefile
165          examples/Makefile
166 ])
167
168 AC_OUTPUT