aboutsummaryrefslogtreecommitdiff
path: root/configure.ac
diff options
context:
space:
mode:
Diffstat (limited to 'configure.ac')
-rw-r--r--configure.ac231
1 files changed, 202 insertions, 29 deletions
diff --git a/configure.ac b/configure.ac
index ef7424be..c497145e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -28,6 +28,7 @@ AC_CONFIG_AUX_DIR([build-aux])
28AM_INIT_AUTOMAKE([gnu] [check-news] [filename-length-max=99] [tar-v7] [silent-rules] [subdir-objects]) 28AM_INIT_AUTOMAKE([gnu] [check-news] [filename-length-max=99] [tar-v7] [silent-rules] [subdir-objects])
29AC_CONFIG_HEADERS([MHD_config.h]) 29AC_CONFIG_HEADERS([MHD_config.h])
30AC_CONFIG_MACRO_DIR([m4]) 30AC_CONFIG_MACRO_DIR([m4])
31m4_pattern_forbid([^_?MHD_[A-Z_]+_CC_])dnl
31 32
32LIB_VERSION_CURRENT=72 33LIB_VERSION_CURRENT=72
33LIB_VERSION_REVISION=0 34LIB_VERSION_REVISION=0
@@ -71,6 +72,33 @@ AS_IF([test -z "$CC" && test -z "$CPP"], [
71 ) 72 )
72]) 73])
73 74
75
76AC_MSG_CHECKING([for build type])
77AC_ARG_ENABLE([build-type],
78 [AS_HELP_STRING([[--enable-build-type=TYPE]],
79 [enable build TYPE, a set of configuration parameters; individual settings ]
80 [(asserts, sanitizers, compiler and linker flags) can be overriden by ]
81 [additional configure parameters (debug, neutral, release, release-compact, ]
82 [release-hardened) [neutral]])],
83 [], [enable_build_type=neutral])
84AS_IF([test "x${enable_build_type}" = "x"], [enable_build_type="neutral"])
85AS_VAR_IF([enable_build_type], ["no"], [enable_build_type="neutral"])
86AS_VAR_IF([enable_build_type], ["yes"], [AC_MSG_ERROR([[Missing TYPE for --enable-build-type=]])])
87AS_CASE([${enable_build_type}],
88 [debug], [AC_MSG_RESULT([debug: enable asserts, sanitizers (if any supported), debug information, compiler optimisation for debugging])],
89 [neutral], [AC_MSG_RESULT([neutral: use only user-specified compiler and linker flags])],
90 [release], [AC_MSG_RESULT([release: disable asserts, enable compiler optimisations])],
91 [release-compact], [AC_MSG_RESULT([release-compact: disable asserts, enable compiler optimisations for size, enable compact code])],
92 [release-hardened], [AC_MSG_RESULT([release-hardened: disable asserts, enable compiler optimisations, enable linker and compiler hardening])],
93 [AC_MSG_ERROR([[Unknown build type: ${enable_build_type}]])]
94)
95AS_VAR_IF([enable_build_type], ["neutral"], [:],
96 [
97 # For all non-neutreal build types do not use automatic "-g -O2" for CFLAGS
98 AS_IF([test -z "${CFLAGS}"], [CFLAGS=""])
99 ]
100)
101
74# Checks for programs. 102# Checks for programs.
75AC_PROG_AWK 103AC_PROG_AWK
76AC_PROG_GREP 104AC_PROG_GREP
@@ -109,6 +137,86 @@ CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS}"
109LT_INIT([win32-dll]) 137LT_INIT([win32-dll])
110LT_LANG([Windows Resource]) 138LT_LANG([Windows Resource])
111 139
140
141CFLAGS="${user_CFLAGS}"
142# Compiler options to always enable (if supported)
143MHD_CHECK_ADD_CC_CFLAG([-fno-strict-aliasing], [CFLAGS_ac])
144
145AS_VAR_IF([enable_build_type],["neutral"],[],
146 [ # Any non-neutral build types
147 MHD_CHECK_ADD_CC_CFLAGS([-Wall -Wnull-dereference -Wdeclaration-after-statement], [CFLAGS_ac])
148 MHD_CHECK_ADD_CC_CFLAGS([-Wredundant-decls -Wtrampolines -Wunsafe-loop-optimizations], [CFLAGS_ac])
149 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}"
150 LDFLAGS="${user_LDFLAGS}"
151 MHD_CHECK_ADD_CC_LDFLAG([-Wl,--warn-common], [LDFLAGS_ac])
152 LDFLAGS="${LDFLAGS_ac} ${user_LDFLAGS}"
153 ]
154)
155AS_VAR_IF([enable_build_type],["debug"],
156 [ # Debug build
157 CFLAGS="${user_CFLAGS}"
158 MHD_FIND_ADD_CC_CFLAG([CFLAGS_ac], [-Og], [-O0])
159 MHD_FIND_ADD_CC_CFLAG([CFLAGS_ac], [-ggdb3], [-g3], [-ggdb], [-g])
160 MHD_CHECK_ADD_CC_CFLAGS([-Wextra -Wdouble-promotion -Wformat=2 -Wformat-overflow=2 -Wformat-truncation=2], [CFLAGS_ac])
161 MHD_CHECK_ADD_CC_CFLAGS([-Wmissing-include-dirs -Wshift-overflow=2 -Wstringop-overflow=4 -Walloc-zero], [CFLAGS_ac])
162 MHD_CHECK_ADD_CC_CFLAGS([-Wduplicated-branches -Wduplicated-cond -Wfloat-equal -Wshadow -Wpointer-arith], [CFLAGS_ac])
163 MHD_CHECK_ADD_CC_CFLAGS([-Wbad-function-cast -Wcast-qual -Wcast-align=strict -Wwrite-strings -Wconversion], [CFLAGS_ac])
164 MHD_CHECK_ADD_CC_CFLAGS([-Wjump-misses-init -Wlogical-op -Waggregate-return -Wstrict-prototypes], [CFLAGS_ac])
165 MHD_CHECK_ADD_CC_CFLAGS([-Wold-style-definition -Wmissing-prototypes -Wformat-security -Wshift-negative-value], [CFLAGS_ac])
166 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}"
167 LDFLAGS="${user_LDFLAGS}"
168 MHD_CHECK_ADD_CC_LDFLAG([-Wl,--enable-long-section-names], [LDFLAGS_ac])
169 LDFLAGS="${LDFLAGS_ac} ${user_LDFLAGS}"
170 ]
171)
172AS_CASE([${enable_build_type}],[release|release-*],
173 [ # All release types
174 CFLAGS="${user_CFLAGS}"
175 AS_VAR_IF([enable_build_type],
176 [release-compact],
177 [
178 AC_CHECK_DECL([MHD_FAVOR_SMALL_CODE],[],
179 [AC_CHECK_DECL([MHD_FAVOR_FAST_CODE],[],
180 [MHD_APPEND_FLAG_TO_VAR([CPPFLAGS_ac],[-DMHD_FAVOR_SMALL_CODE=1])],
181 [/* no includes */])],[/* no includes */])
182 CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS}"
183 MHD_FIND_ADD_CC_CFLAG([CFLAGS_ac], [-Oz], [-Os], [-O])
184 ],
185 [ # All non-compact release types
186 AC_CHECK_DECL([MHD_FAVOR_SMALL_CODE],[],
187 [AC_CHECK_DECL([MHD_FAVOR_FAST_CODE],[],
188 [MHD_APPEND_FLAG_TO_VAR([CPPFLAGS_ac],[-DMHD_FAVOR_FAST_CODE=1])],
189 [/* no includes */])],[/* no includes */])
190 CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS}"
191 MHD_FIND_ADD_CC_CFLAG([CFLAGS_ac], [-O2], [-O])
192 MHD_CHECK_ADD_CC_CFLAGS([-fsched-pressure -fira-loop-pressure -fmerge-all-constants], [CFLAGS_ac]) # These flags may improve size, recheck with LTO and linker garbage collection
193 MHD_CHECK_ADD_CC_CFLAGS([-ftree-partial-pre -fgcse-after-reload -fipa-pta], [CFLAGS_ac])
194 MHD_CHECK_ADD_CC_CFLAGS([-fisolate-erroneous-paths-attribute -ffinite-loops -floop-nest-optimize], [CFLAGS_ac])
195 MHD_CHECK_ADD_CC_CFLAGS([-fpredictive-commoning -frename-registers], [CFLAGS_ac])
196 MHD_CHECK_ADD_CC_CFLAGS([-ftree-loop-distribute-patterns -fpeel-loops -fsplit-loops -ftree-vectorize], [CFLAGS_ac])
197 ]
198 )
199
200 AS_VAR_IF([enable_build_type],
201 [release-hardened],
202 [
203 MHD_CHECK_ADD_CC_CFLAGS([-Wformat-security -Wstack-protector], [CFLAGS_ac])
204 ]
205 )
206 AS_VAR_IF([enable_build_type],
207 [ # Flags are not suitable for 'compact' and for 'hardened'
208 MHD_CHECK_ADD_CC_CFLAGS([-ffast-math -fno-trapping-math], [CFLAGS_ac])
209 ]
210 )
211 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}"
212 # W32-specific
213 LDFLAGS="${user_LDFLAGS}"
214 MHD_CHECK_ADD_CC_LDFLAG([-Wl,--disable-long-section-names], [LDFLAGS_ac])
215 LDFLAGS="${LDFLAGS_ac} ${user_LDFLAGS}"
216 ]
217)
218CFLAGS="${CFLAGS_ac} ${user_CFLAGS}"
219
112# Check for headers that are ALWAYS required 220# Check for headers that are ALWAYS required
113AC_CHECK_HEADERS_ONCE([stdio.h string.h stdint.h errno.h limits.h fcntl.h], [], 221AC_CHECK_HEADERS_ONCE([stdio.h string.h stdint.h errno.h limits.h fcntl.h], [],
114 [AC_MSG_ERROR([Compiling libmicrohttpd requires standard POSIX headers files])], [AC_INCLUDES_DEFAULT]) 222 [AC_MSG_ERROR([Compiling libmicrohttpd requires standard POSIX headers files])], [AC_INCLUDES_DEFAULT])
@@ -189,26 +297,80 @@ AC_CHECK_HEADERS([sys/sysctl.h netinet/ip_icmp.h netinet/icmp_var.h], [], [],
189 ]] 297 ]]
190) 298)
191 299
192# Adam shostack suggests the following for Windows: 300AC_ARG_ENABLE([compiler-hardening],
193# -D_FORTIFY_SOURCE=2 -fstack-protector-all 301 [AS_HELP_STRING([--enable-compiler-hardening], [enable compiler security checks])],
194AC_ARG_ENABLE([gcc-hardening], 302 [],
195 [AS_HELP_STRING([--enable-gcc-hardening], [enable compiler security checks])], 303 [AS_CASE([${enable_build_type}],[*-hardened],
196[AS_IF([test x$enableval = xyes],[ 304 [enable_compiler_hardening='yes'],[enable_compiler_hardening='no'])]
197 CFLAGS_ac="${CFLAGS_ac} -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -fstack-protector-all" 305)
198 CFLAGS_ac="${CFLAGS_ac} -fwrapv -fPIE -Wstack-protector" 306AS_VAR_IF([enable_compiler_hardening],["yes"],
199 CFLAGS_ac="${CFLAGS_ac} --param ssp-buffer-size=1" 307 [
308 CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS}"
309 AC_CHECK_DECL([_FORTIFY_SOURCE],
310 [MHD_APPEND_FLAG_TO_VAR([CPPFLAGS_ac],[-U_FORTIFY_SOURCE])],
311 [],[/* no includes */])
312 MHD_APPEND_FLAG_TO_VAR([CPPFLAGS_ac],[-D_FORTIFY_SOURCE=2])
313 CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS}"
314 CFLAGS="${user_CFLAGS}"
315 MHD_FIND_ADD_CC_CFLAG([CFLAGS_ac],[-fstack-protector-strong],[-fstack-protector-all],[-fstack-protector])
316 MHD_CHECK_ADD_CC_CFLAGS([-fstack-clash-protection -ftrivial-auto-var-init=pattern],[CFLAGS_ac])
317 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}"
318 AS_VAR_IF([pic_mode],["no"],[],
319 [
320 AS_VAR_IF([enable_shared],["yes"],[],
321 [
322 # PIE cannot be used for shared lib
323 # PIE static lib can be used within non-PIE application, but
324 # PIE static lib cannot be used in non-PIE shared lib. Let's assume
325 # that static lib will not be used in shared lib
326 CFLAGS="${user_CFLAGS}"
327 # Perform tests with "-pie" enabled
328 LDFLAGS="${LDFLAGS_ac} -pie ${user_LDFLAGS}"
329 MHD_CHECK_ADD_CC_CFLAG([-fPIE],[CFLAGS_ac],
330 [
331 MHD_APPEND_FLAG_TO_VAR([LDFLAGS_ac],[-pie])
332 ],
333 [
334 MHD_CHECK_CC_CFLAG([-fpie],[CFLAGS_ac],
335 [
336 MHD_APPEND_FLAG_TO_VAR([LDFLAGS_ac],[-pie])
337 ]
338 )
339 ]
340 )
341 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}"
342 LDFLAGS="${LDFLAGS_ac} ${user_LDFLAGS}"
343 ]
344 )
345 ]
346 )
200 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}" 347 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}"
201 LDFLAGS_ac="${LDFLAGS_ac} -pie"
202 LDFLAGS="${LDFLAGS_ac} ${user_LDFLAGS}" 348 LDFLAGS="${LDFLAGS_ac} ${user_LDFLAGS}"
203 ])]) 349 ]
350)
204 351
205# Linker hardening options 352# Linker hardening options
206# Currently these options are ELF specific - you can't use this with MacOSX 353# Currently these options are ELF specific, they don't work on Darwin and W32
207AC_ARG_ENABLE([linker-hardening], 354AC_ARG_ENABLE([linker-hardening],
208 [AS_HELP_STRING([--enable-linker-hardening], [enable linker security fixups])], 355 [AS_HELP_STRING([--enable-linker-hardening], [enable linker security fixups])],
209[AS_IF([test x$enableval = xyes], 356 [],
210 [LDFLAGS_ac="${LDFLAGS_ac} -z relro -z now"])]) 357 [AS_CASE([${enable_build_type}],[*-hardened],
211LDFLAGS="${LDFLAGS_ac} ${user_LDFLAGS}" 358 [enable_linker_hardening='yes'],[enable_linker_hardening='no'])]
359)
360AS_VAR_IF([enable_linker_hardening],["yes"],
361 [
362 CFLAGS="${CFLAGS_ac} ${user_CFLAGS}"
363 LDFLAGS="${user_LDFLAGS}"
364 MHD_CHECK_ADD_CC_LDFLAG([-Wl,-z,relro],[LDFLAGS_ac],
365 [MHD_CHECK_ADD_CC_LDFLAG([-Wl,-z,now],[LDFLAGS_ac])])
366 # Actually should be "noexec" by default, but let's try to enforce it.
367 MHD_CHECK_ADD_CC_LDFLAG([-Wl,-z,noexecstack],[LDFLAGS_ac])
368 # W32-specific. Some are enabled by default, but they will be enfored to be sure.
369 MHD_CHECK_ADD_CC_LDFLAGS([-Wl,--large-address-aware -Wl,--enable-auto-image-base],[LDFLAGS_ac])
370 MHD_CHECK_ADD_CC_LDFLAGS([-Wl,--dynamicbase -Wl,--nxcompat -Wl,--high-entropy-va],[LDFLAGS_ac])
371 LDFLAGS="${LDFLAGS_ac} ${user_LDFLAGS}"
372 ]
373)
212 374
213 375
214AH_TEMPLATE([[HAVE_STDBOOL_H]], [Define to 1 i][f you have the <stdbool.h> header file and <stdbool.h> defines 'bool' type.]) 376AH_TEMPLATE([[HAVE_STDBOOL_H]], [Define to 1 i][f you have the <stdbool.h> header file and <stdbool.h> defines 'bool' type.])
@@ -1059,13 +1221,6 @@ AM_CONDITIONAL([HAVE_LISTEN_SHUTDOWN], [test "x$mhd_cv_host_shtdwn_trgr_select"
1059AC_SEARCH_LIBS([sendmsg], [socket], [AC_DEFINE([HAVE_SENDMSG],[1],[Define if your platform supports sendmsg])]) 1221AC_SEARCH_LIBS([sendmsg], [socket], [AC_DEFINE([HAVE_SENDMSG],[1],[Define if your platform supports sendmsg])])
1060AC_CHECK_FUNCS([writev]) 1222AC_CHECK_FUNCS([writev])
1061 1223
1062# set GCC options
1063# use '-fno-strict-aliasing', but only if the compiler
1064# and linker can take it
1065AX_CHECK_LINK_FLAG([-fno-strict-aliasing],
1066 [AX_APPEND_COMPILE_FLAGS([-fno-strict-aliasing], [CFLAGS_ac])])
1067CFLAGS="${CFLAGS_ac} ${user_CFLAGS}"
1068
1069AC_C_BIGENDIAN 1224AC_C_BIGENDIAN
1070AC_C_VARARRAYS 1225AC_C_VARARRAYS
1071 1226
@@ -1971,7 +2126,7 @@ MHD_CHECK_FUNC([[nanosleep]], [[#include <time.h>]], [[struct timespec ts2, ts1
1971HIDDEN_VISIBILITY_CFLAGS="" 2126HIDDEN_VISIBILITY_CFLAGS=""
1972AH_TEMPLATE([_MHD_EXTERN],[defines how to decorate public symbols w][hile building the library]) 2127AH_TEMPLATE([_MHD_EXTERN],[defines how to decorate public symbols w][hile building the library])
1973CFLAGS="${user_CFLAGS}" 2128CFLAGS="${user_CFLAGS}"
1974MHD_CHECK_CC_FLAG([-fvisibility=hidden],[CFLAGS_ac], 2129MHD_CHECK_CC_CFLAG([-fvisibility=hidden],[CFLAGS_ac],
1975 [ 2130 [
1976 # NOTE: require setting of errattr_CFLAGS above 2131 # NOTE: require setting of errattr_CFLAGS above
1977 CFLAGS="${CFLAGS_ac} -fvisibility=hidden ${user_CFLAGS} ${errattr_CFLAGS}" 2132 CFLAGS="${CFLAGS_ac} -fvisibility=hidden ${user_CFLAGS} ${errattr_CFLAGS}"
@@ -2893,9 +3048,12 @@ AC_MSG_RESULT([$CPU_COUNT])
2893 3048
2894AC_MSG_CHECKING([[whether to enable debug asserts]]) 3049AC_MSG_CHECKING([[whether to enable debug asserts]])
2895AC_ARG_ENABLE([[asserts]], 3050AC_ARG_ENABLE([[asserts]],
2896 AS_HELP_STRING([[--enable-asserts]], 3051 [AS_HELP_STRING([[--enable-asserts]],
2897 [enable test build with debug asserts]), 3052 [enable test build with debug asserts])],
2898 [], [[enable_asserts='no']]) 3053 [],
3054 [AS_CASE([${enable_build_type}],[*-hardened],
3055 [enable_compiler_hardening='yes'],[enable_compiler_hardening='no'])]
3056)
2899AS_CASE([[$enable_asserts]], [[yes]], [[:]], [[no]], [[:]], [[enable_asserts='no']]) 3057AS_CASE([[$enable_asserts]], [[yes]], [[:]], [[no]], [[:]], [[enable_asserts='no']])
2900AC_MSG_RESULT([[$enable_asserts]]) 3058AC_MSG_RESULT([[$enable_asserts]])
2901 3059
@@ -2956,10 +3114,25 @@ AS_IF([test "x${enable_sanitizers}" = "xno"],
2956 ], 3114 ],
2957 [test "x${enable_sanitizers}" = "xauto" || test "x${enable_sanitizers}" = "xauto-optional"], 3115 [test "x${enable_sanitizers}" = "xauto" || test "x${enable_sanitizers}" = "xauto-optional"],
2958 [ 3116 [
2959 enable_san_address="auto" 3117 AS_VAR_IF([enable_compiler_hardening],["yes"],
2960 enable_san_undef="auto" 3118 [
2961 enable_san_leak="auto" 3119 AS_VAR_IF([enable_sanitizers],["auto"],
2962 enable_san_upoison="auto" 3120 [AC_MSG_ERROR([sanitizers cannot be enabled with compiler hardnening])],
3121 [AC_MSG_WARN([sanitizers cannot be enabled with compiler hardnening])]
3122 )
3123 enable_sanitizers="no"
3124 enable_san_address="no"
3125 enable_san_undef="no"
3126 enable_san_leak="no"
3127 enable_san_upoison="no"
3128 ],
3129 [
3130 enable_san_address="auto"
3131 enable_san_undef="auto"
3132 enable_san_leak="auto"
3133 enable_san_upoison="auto"
3134 ]
3135 )
2963 ], 3136 ],
2964 [test "x${enable_sanitizers}" = "xauto-fallback"], 3137 [test "x${enable_sanitizers}" = "xauto-fallback"],
2965 [ 3138 [