aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvgeny Grin (Karlson2k) <k2k@narod.ru>2022-04-13 20:53:21 +0300
committerEvgeny Grin (Karlson2k) <k2k@narod.ru>2022-04-16 13:37:52 +0300
commit9b1865f6918057e6600ff6b455bb8486a016fce1 (patch)
treeffdd46232704ffcf53e7b240677ef6b5b74036ab
parentfff6d80c4bfa70a1d3368c9135b67eae2716a4b5 (diff)
downloadlibmicrohttpd-9b1865f6918057e6600ff6b455bb8486a016fce1.tar.gz
libmicrohttpd-9b1865f6918057e6600ff6b455bb8486a016fce1.zip
configure: added --enable-build-type=TYPE
Useful to quickly define settings combination. Individual settings still could be overridden by individual parameters. Added autoconf macros for compiler and linker flags
-rw-r--r--configure.ac231
-rw-r--r--m4/mhd_check_add_cc_cflag.m463
-rw-r--r--m4/mhd_check_add_cc_cflags.m439
-rw-r--r--m4/mhd_check_add_cc_ldflag.m434
-rw-r--r--m4/mhd_check_add_cc_ldflags.m439
-rw-r--r--m4/mhd_check_cc_cflag.m4 (renamed from m4/mhd_check_cc_flag.m4)138
-rw-r--r--m4/mhd_check_cc_ldflag.m443
-rw-r--r--m4/mhd_find_add_cc_cflag.m470
-rw-r--r--m4/mhd_find_add_cc_ldflag.m439
9 files changed, 599 insertions, 97 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 [
diff --git a/m4/mhd_check_add_cc_cflag.m4 b/m4/mhd_check_add_cc_cflag.m4
new file mode 100644
index 00000000..0d110e8c
--- /dev/null
+++ b/m4/mhd_check_add_cc_cflag.m4
@@ -0,0 +1,63 @@
1# SYNOPSIS
2#
3# MHD_CHECK_ADD_CC_CFLAG([FLAG-TO-TEST], [VARIABLE-TO-EXTEND],
4# [ACTION-IF-SUPPORTED], [ACTION-IF-NOT-SUPPORTED])
5#
6# DESCRIPTION
7#
8# This macro checks whether the specific compiler flag is supported.
9# The check is performing by appending FLAG-TO-TEST to the value of
10# VARIABLE-TO-EXTEND (CFLAGS if not specified), then prepending result to
11# CFLAGS (unless VARIABLE-TO-EXTEND is CFLAGS), and then performing compile
12# and link test. If test succeed without warnings, then the flag is added to
13# VARIABLE-TO-EXTEND. Otherwise, if compile and link without test flag cannot
14# be done without any warning, the flag is considered to be unsuppoted.
15#
16# Example usage:
17#
18# MHD_CHECK_ADD_CC_CFLAG([-Wshadow], [additional_CFLAGS])
19#
20#
21# LICENSE
22#
23# Copyright (c) 2022 Karlson2k (Evgeny Grin) <k2k@narod.ru>
24#
25# Copying and distribution of this file, with or without modification, are
26# permitted in any medium without royalty provided the copyright notice
27# and this notice are preserved. This file is offered as-is, without any
28# warranty.
29
30#serial 1
31
32AC_DEFUN([MHD_CHECK_ADD_CC_CFLAG],[dnl
33_MHD_CHECK_ADD_CC_XFLAG([$1],[$2],[$3],[$4],[[CFLAGS]])dnl
34])
35
36
37# SYNOPSIS
38#
39# _MHD_CHECK_ADD_CC_XFLAG([FLAG-TO-TEST], [VARIABLE-TO-EXTEND],
40# [ACTION-IF-SUPPORTED], [ACTION-IF-NOT-SUPPORTED],
41# [CFLAGS|LDFLAGS])
42#
43AC_DEFUN([_MHD_CHECK_ADD_CC_XFLAG],[dnl
44 AC_PREREQ([2.64])dnl for AS_VAR_IF, m4_ifnblank, m4_default
45 AC_LANG_ASSERT([C])dnl
46 m4_ifblank([$1], [m4_fatal([First macro argument must not be empty])])dnl
47 m4_bmatch(_mhd_norm_expd([$1]), [\s],dnl
48 [m4_fatal([First macro argument must not contain whitespaces])])dnl
49 m4_bmatch(_mhd_norm_expd([$2]), [\s],dnl
50 [m4_fatal([Second macro argument must not contain whitespaces])])dnl
51 m4_bmatch([$1], [\$], [m4_fatal([$0: First macro argument must not contain '$'])])dnl
52 m4_bmatch([$2], [\$], [m4_fatal([$0: Second macro argument must not contain '$'])])dnl
53 m4_bmatch(_mhd_norm_expd([$5]), [^\(CFLAGS\|LDFLAGS\)$],[],dnl
54 [m4_fatal([$0: Fifth macro argument must be either 'CFLAGS' or 'LDFLAGS; ']_mhd_norm_expd([$5])[' is not supported])])dnl
55 m4_ifnblank([$2],
56 [_MHD_CHECK_CC_XFLAG([$1], [$2],
57 [MHD_APPEND_FLAG_TO_VAR(_mhd_norm_expd([$2]),_mhd_norm_expd([$1]))
58 $3],[$4],[$5])],
59 [_MHD_CHECK_CC_XFLAG([$1],_mhd_norm_expd([$5]),
60 [MHD_APPEND_FLAG_TO_VAR(_mhd_norm_expd([$5]),_mhd_norm_expd([$1]))
61 $3],[$4],[$5])]
62 )
63])
diff --git a/m4/mhd_check_add_cc_cflags.m4 b/m4/mhd_check_add_cc_cflags.m4
new file mode 100644
index 00000000..2f13192d
--- /dev/null
+++ b/m4/mhd_check_add_cc_cflags.m4
@@ -0,0 +1,39 @@
1# SYNOPSIS
2#
3# MHD_CHECK_ADD_CC_CFLAGS([FLAGS-TO-TEST], [VARIABLE-TO-EXTEND])
4#
5# DESCRIPTION
6#
7# This macro checks whether the specific compiler flags are supported.
8# The FLAGS-TO-TEST parameter is whitespace-separated flagto to test.
9# The flags are tested one-by-one, all supported flags are added to the
10# VARIABLE-TO-EXTEND.
11# Every flag check is performing by appending one flag to the value of
12# VARIABLE-TO-EXTEND (CFLAGS if not specified), then prepending result to
13# CFLAGS (unless VARIABLE-TO-EXTEND is CFLAGS), and then performing compile
14# and link test. If test succeed without warnings, then the flag is added to
15# VARIABLE-TO-EXTEND. Otherwise, if compile and link without test flag cannot
16# be done without any warning, the flag is considered to be unsuppoted.
17#
18# Example usage:
19#
20# MHD_CHECK_ADD_CC_CFLAGS([-Wshadow -Walloc-zero -Winit-self],
21# [additional_CFLAGS])
22#
23#
24# LICENSE
25#
26# Copyright (c) 2022 Karlson2k (Evgeny Grin) <k2k@narod.ru>
27#
28# Copying and distribution of this file, with or without modification, are
29# permitted in any medium without royalty provided the copyright notice
30# and this notice are preserved. This file is offered as-is, without any
31# warranty.
32
33#serial 1
34
35AC_DEFUN([MHD_CHECK_ADD_CC_CFLAGS],[dnl
36m4_foreach_w([test_flag],[$1],
37[MHD_CHECK_ADD_CC_CFLAG([test_flag],[$2])
38])dnl
39])
diff --git a/m4/mhd_check_add_cc_ldflag.m4 b/m4/mhd_check_add_cc_ldflag.m4
new file mode 100644
index 00000000..132d33ab
--- /dev/null
+++ b/m4/mhd_check_add_cc_ldflag.m4
@@ -0,0 +1,34 @@
1# SYNOPSIS
2#
3# MHD_CHECK_ADD_CC_LDFLAG([FLAG-TO-TEST], [VARIABLE-TO-EXTEND],
4# [ACTION-IF-SUPPORTED], [ACTION-IF-NOT-SUPPORTED])
5#
6# DESCRIPTION
7#
8# This macro checks whether the specific compiler flag is supported.
9# The check is performing by appending FLAG-TO-TEST to the value of
10# VARIABLE-TO-EXTEND (LDFLAGS if not specified), then prepending result to
11# LDFLAGS (unless VARIABLE-TO-EXTEND is LDFLAGS), and then performing compile
12# and link test. If test succeed without warnings, then the flag is added to
13# VARIABLE-TO-EXTEND. Otherwise, if compile and link without test flag cannot
14# be done without any warning, the flag is considered to be unsuppoted.
15#
16# Example usage:
17#
18# MHD_CHECK_ADD_CC_LDFLAG([-pie], [additional_LDFLAGS])
19#
20#
21# LICENSE
22#
23# Copyright (c) 2022 Karlson2k (Evgeny Grin) <k2k@narod.ru>
24#
25# Copying and distribution of this file, with or without modification, are
26# permitted in any medium without royalty provided the copyright notice
27# and this notice are preserved. This file is offered as-is, without any
28# warranty.
29
30#serial 1
31
32AC_DEFUN([MHD_CHECK_ADD_CC_LDFLAG],[dnl
33_MHD_CHECK_ADD_CC_XFLAG([$1],[$2],[$3],[$4],[[LDFLAGS]])dnl
34])
diff --git a/m4/mhd_check_add_cc_ldflags.m4 b/m4/mhd_check_add_cc_ldflags.m4
new file mode 100644
index 00000000..5b013f29
--- /dev/null
+++ b/m4/mhd_check_add_cc_ldflags.m4
@@ -0,0 +1,39 @@
1# SYNOPSIS
2#
3# MHD_CHECK_ADD_CC_LDFLAGS([FLAGS-TO-TEST], [VARIABLE-TO-EXTEND])
4#
5# DESCRIPTION
6#
7# This macro checks whether the specific compiler flags are supported.
8# The FLAGS-TO-TEST parameter is whitespace-separated flagto to test.
9# The flags are tested one-by-one, all supported flags are added to the
10# VARIABLE-TO-EXTEND.
11# Every flag check is performing by appending one flag to the value of
12# VARIABLE-TO-EXTEND (LDFLAGS if not specified), then prepending result to
13# LDFLAGS (unless VARIABLE-TO-EXTEND is LDFLAGS), and then performing compile
14# and link test. If test succeed without warnings, then the flag is added to
15# VARIABLE-TO-EXTEND. Otherwise, if compile and link without test flag cannot
16# be done without any warning, the flag is considered to be unsuppoted.
17#
18# Example usage:
19#
20# MHD_CHECK_ADD_CC_LDFLAGS([-W,--strip-all -Wl,--fatal-warnings],
21# [additional_LDFLAGS])
22#
23#
24# LICENSE
25#
26# Copyright (c) 2022 Karlson2k (Evgeny Grin) <k2k@narod.ru>
27#
28# Copying and distribution of this file, with or without modification, are
29# permitted in any medium without royalty provided the copyright notice
30# and this notice are preserved. This file is offered as-is, without any
31# warranty.
32
33#serial 1
34
35AC_DEFUN([MHD_CHECK_ADD_CC_LDFLAGS],[dnl
36m4_foreach_w([test_flag],[$1],
37[MHD_CHECK_ADD_CC_LDFLAG([test_flag],[$2])
38])dnl
39])
diff --git a/m4/mhd_check_cc_flag.m4 b/m4/mhd_check_cc_cflag.m4
index e6ba38f6..f387495b 100644
--- a/m4/mhd_check_cc_flag.m4
+++ b/m4/mhd_check_cc_cflag.m4
@@ -1,7 +1,7 @@
1# SYNOPSIS 1# SYNOPSIS
2# 2#
3# MHD_CHECK_CC_FLAG([FLAG-TO-TEST], [VARIABLE-TO-PREPEND-CFLAGS], 3# MHD_CHECK_CC_CFLAG([FLAG-TO-TEST], [VARIABLE-TO-PREPEND-CFLAGS],
4# [ACTION-IF-SUPPORTED], [ACTION-IF-NOT-SUPPORTED]) 4# [ACTION-IF-SUPPORTED], [ACTION-IF-NOT-SUPPORTED])
5# 5#
6# DESCRIPTION 6# DESCRIPTION
7# 7#
@@ -15,14 +15,14 @@
15# 15#
16# Example usage: 16# Example usage:
17# 17#
18# MHD_CHECK_CC_FLAG([-Wshadow], [additional_CFLAGS], 18# MHD_CHECK_CC_CFLAG([-Wshadow], [additional_CFLAGS],
19# [additional_CFLAGS="${additional_CFLAGS} -Wshadow"]) 19# [additional_CFLAGS="${additional_CFLAGS} -Wshadow"])
20# 20#
21# Defined cache variable used in check so if any test will not work 21# Defined cache variable used in check so if any test will not work
22# correctly on some platform, user may simply fix it by giving cache 22# correctly on some platform, user may simply fix it by giving cache
23# variable in configure parameters, for example: 23# variable in configure parameters, for example:
24# 24#
25# ./configure mhd_cv_cc_fl_supp__wshadow=no 25# ./configure mhd_cv_cc_fl_supp__Wshadow=no
26# 26#
27# This simplify building from source on exotic platforms as patching 27# This simplify building from source on exotic platforms as patching
28# of configure.ac is not required to change results of tests. 28# of configure.ac is not required to change results of tests.
@@ -36,9 +36,19 @@
36# and this notice are preserved. This file is offered as-is, without any 36# and this notice are preserved. This file is offered as-is, without any
37# warranty. 37# warranty.
38 38
39#serial 1 39#serial 2
40 40
41AC_DEFUN([MHD_CHECK_CC_FLAG],[dnl 41AC_DEFUN([MHD_CHECK_CC_CFLAG],[dnl
42_MHD_CHECK_CC_XFLAG([$1],[$2],[$3],[$4],[[CFLAGS]])dnl
43])
44
45# SYNOPSIS
46#
47# _MHD_CHECK_CC_XFLAG([FLAG-TO-TEST], [VARIABLE-TO-PREPEND-CFLAGS],
48# [ACTION-IF-SUPPORTED], [ACTION-IF-NOT-SUPPORTED],
49# [CFLAGS|LDFLAGS])
50#
51AC_DEFUN([_MHD_CHECK_CC_XFLAG],[dnl
42 AC_PREREQ([2.64])dnl for AS_VAR_IF, m4_ifnblank 52 AC_PREREQ([2.64])dnl for AS_VAR_IF, m4_ifnblank
43 AC_LANG_ASSERT([C])dnl 53 AC_LANG_ASSERT([C])dnl
44 AC_REQUIRE([AC_PROG_CC])dnl 54 AC_REQUIRE([AC_PROG_CC])dnl
@@ -49,18 +59,20 @@ AC_DEFUN([MHD_CHECK_CC_FLAG],[dnl
49 [m4_fatal([$0: Second macro argument must not contain whitespaces])])dnl 59 [m4_fatal([$0: Second macro argument must not contain whitespaces])])dnl
50 m4_bmatch([$1], [\$], [m4_fatal([$0: First macro argument must not contain '$'])])dnl 60 m4_bmatch([$1], [\$], [m4_fatal([$0: First macro argument must not contain '$'])])dnl
51 m4_bmatch([$2], [\$], [m4_fatal([$0: Second macro argument must not contain '$'])])dnl 61 m4_bmatch([$2], [\$], [m4_fatal([$0: Second macro argument must not contain '$'])])dnl
52 AC_REQUIRE([MHD_FIND_CC_FLAG_WARNPARAMS])dnl sets 'mhd_CFLAGS_params_warn' variable 62 AC_REQUIRE([MHD_FIND_CC_XFLAG_WARNPARAMS])dnl sets 'mhd_xFLAGS_params_warn' variable
53 _MHD_CHECK_CC_FLAG_BODY([$1],[$2],[$3],[$4],[mhd_CFLAGS_params_warn])dnl 63 m4_bmatch(_mhd_norm_expd([$5]), [^\(CFLAGS\|LDFLAGS\)$],[],dnl
64 [m4_fatal([$0: Fifth macro argument must be either 'CFLAGS' or 'LDFLAGS; ']_mhd_norm_expd([$5])[' is not supported])])dnl
65 _MHD_CHECK_CC_XFLAG_BODY([$1],[$2],[$3],[$4],[mhd_xFLAGS_params_warn],[$5])dnl
54]) 66])
55 67
56 68
57# SYNOPSIS 69# SYNOPSIS
58# 70#
59# _MHD_CHECK_CC_FLAG_BODY([FLAG-TO-TEST], [VARIABLE-TO-PREPEND-CFLAGS], 71# _MHD_CHECK_CC_XFLAG_BODY([FLAG-TO-TEST], [VARIABLE-TO-PREPEND-CFLAGS],
60# [ACTION-IF-SUPPORTED], [ACTION-IF-NOT-SUPPORTED], 72# [ACTION-IF-SUPPORTED], [ACTION-IF-NOT-SUPPORTED],
61# [VARIABLE-TO-ENABLE-WARNS]) 73# [VARIABLE-TO-ENABLE-WARNS], [CFLAGS|LDFLAGS])
62# 74#
63AC_DEFUN([_MHD_CHECK_CC_FLAG_BODY],[dnl 75AC_DEFUN([_MHD_CHECK_CC_XFLAG_BODY],[dnl
64 AC_LANG_ASSERT([C])dnl 76 AC_LANG_ASSERT([C])dnl
65 m4_ifblank([$1], [m4_fatal([$0: First macro argument must not be empty])])dnl 77 m4_ifblank([$1], [m4_fatal([$0: First macro argument must not be empty])])dnl
66 m4_bmatch(_mhd_norm_expd([$1]), [\s],dnl 78 m4_bmatch(_mhd_norm_expd([$1]), [\s],dnl
@@ -71,18 +83,22 @@ AC_DEFUN([_MHD_CHECK_CC_FLAG_BODY],[dnl
71 m4_bmatch([$2], [\$], [m4_fatal([$0: Second macro argument must not contain '$'])])dnl 83 m4_bmatch([$2], [\$], [m4_fatal([$0: Second macro argument must not contain '$'])])dnl
72 m4_ifblank([$5], [m4_fatal([$0: Fifth macro argument must not be empty])])dnl 84 m4_ifblank([$5], [m4_fatal([$0: Fifth macro argument must not be empty])])dnl
73 m4_bmatch([$5], [\$], [m4_fatal([$0: Fifth macro argument must not contain '$'])])dnl 85 m4_bmatch([$5], [\$], [m4_fatal([$0: Fifth macro argument must not contain '$'])])dnl
74 AS_VAR_PUSHDEF([cv_Var], [mhd_cv_cc_fl_supp_]m4_bpatsubst(m4_tolower(_mhd_norm_expd([$1])),[[^a-z0-9]],[_]))dnl 86 m4_bmatch(_mhd_norm_expd([$6]), [^\(CFLAGS\|LDFLAGS\)$],[],dnl
75 dnl 87 [m4_fatal([$0: Sixth macro argument must be either 'CFLAGS' or 'LDFLAGS; ']_mhd_norm_expd([$6])[' is not supported])])dnl
88 m4_pushdef([XFLAGS],_mhd_norm_expd([$6]))dnl
89 dnl Keep uppercase letters to avoid clashes for parameters like -fPIE and -fpie
90 AS_VAR_PUSHDEF([cv_Var],[mhd_cv_cc_]m4_tolower(m4_substr(_mhd_norm_expd([$6]),0,1))[fl_supp_]m4_bpatsubst(_mhd_norm_expd([$1]),[[^a-zA-Z0-9]],[_]))dnl
91
76 AC_CACHE_CHECK([whether $[]CC supports _mhd_norm_expd([$1]) flag], cv_Var, 92 AC_CACHE_CHECK([whether $[]CC supports _mhd_norm_expd([$1]) flag], cv_Var,
77 [dnl 93 [dnl
78 AS_VAR_PUSHDEF([save_CFLAGS_Var], [mhd_check_cc_flag_save_CFLAGS])dnl 94 AS_VAR_PUSHDEF([save_xFLAGS_Var], [mhd_check_cc_flag_save_]XFLAGS)dnl
79 AS_VAR_SET([save_CFLAGS_Var],["${CFLAGS}"]) 95 AS_VAR_SET([save_xFLAGS_Var],["${XFLAGS}"])
80 m4_ifnblank([$2],[dnl 96 m4_ifnblank([$2],[dnl
81 m4_if(_mhd_norm_expd([$2]),[CFLAGS], 97 m4_if(_mhd_norm_expd([$2]),[XFLAGS],
82 [CFLAGS="${save_CFLAGS_Var} _mhd_norm_expd([$1]) $[]{_mhd_norm_expd([$5])}"], 98 [XFLAGS="${save_xFLAGS_Var} _mhd_norm_expd([$1]) $[]{_mhd_norm_expd([$5])}"],
83 [CFLAGS="$[]{_mhd_norm_expd([$2])} _mhd_norm_expd([$1]) ${save_CFLAGS_Var} $[]{_mhd_norm_expd([$5])}"]) 99 [XFLAGS="$[]{_mhd_norm_expd([$2])} _mhd_norm_expd([$1]) ${save_xFLAGS_Var} $[]{_mhd_norm_expd([$5])}"])
84 ],[dnl 100 ],[dnl
85 CFLAGS="_mhd_norm_expd([$1]) $[]CFLAGS $[]{_mhd_norm_expd([$5])}" 101 XFLAGS="_mhd_norm_expd([$1]) $[]XFLAGS $[]{_mhd_norm_expd([$5])}"
86 ])dnl 102 ])dnl
87 mhd_check_cc_flag_save_c_werror_flag="$ac_c_werror_flag" 103 mhd_check_cc_flag_save_c_werror_flag="$ac_c_werror_flag"
88 ac_c_werror_flag=yes 104 ac_c_werror_flag=yes
@@ -95,23 +111,23 @@ int main(void)
95 ]])]) 111 ]])])
96 AC_LINK_IFELSE([], 112 AC_LINK_IFELSE([],
97 [AS_VAR_SET([cv_Var],["yes"])], 113 [AS_VAR_SET([cv_Var],["yes"])],
98 [ [#] Compile and link failed if test flag added 114 [ [#] Compile and link failed with test flag added
99 m4_ifnblank([$2],[dnl 115 m4_ifnblank([$2],[dnl
100 m4_if(_mhd_norm_expd([$2]),[CFLAGS], 116 m4_if(_mhd_norm_expd([$2]),[XFLAGS],
101 [CFLAGS="${save_CFLAGS_Var} $[]{_mhd_norm_expd([$5])}"], 117 [XFLAGS="${save_xFLAGS_Var} $[]{_mhd_norm_expd([$5])}"],
102 [CFLAGS="$[]{_mhd_norm_expd([$2])} ${save_CFLAGS_Var} $[]{_mhd_norm_expd([$5])}"]) 118 [XFLAGS="$[]{_mhd_norm_expd([$2])} ${save_xFLAGS_Var} $[]{_mhd_norm_expd([$5])}"])
103 ],[dnl 119 ],[dnl
104 CFLAGS="${save_CFLAGS_Var} $[]{_mhd_norm_expd([$5])}" 120 XFLAGS="${save_xFLAGS_Var} $[]{_mhd_norm_expd([$5])}"
105 ])dnl 121 ])dnl
106 AC_LINK_IFELSE([], 122 AC_LINK_IFELSE([],
107 [AS_VAR_SET([cv_Var],["no"])], 123 [AS_VAR_SET([cv_Var],["no"])],
108 [ [#] Compile and link failed if test flag removed as well 124 [ [#] Compile and link failed with test flag removed as well
109 m4_ifnblank([$2],[dnl 125 m4_ifnblank([$2],[dnl
110 m4_if(_mhd_norm_expd([$2]),[CFLAGS], 126 m4_if(_mhd_norm_expd([$2]),[XFLAGS],
111 [CFLAGS="${save_CFLAGS_Var} _mhd_norm_expd([$1])"], 127 [XFLAGS="${save_xFLAGS_Var} _mhd_norm_expd([$1])"],
112 [CFLAGS="$[]{_mhd_norm_expd([$2])} _mhd_norm_expd([$1]) ${save_CFLAGS_Var}"]) 128 [XFLAGS="$[]{_mhd_norm_expd([$2])} _mhd_norm_expd([$1]) ${save_xFLAGS_Var}"])
113 ],[dnl 129 ],[dnl
114 CFLAGS="_mhd_norm_expd([$1]) ${save_CFLAGS_Var}" 130 XFLAGS="_mhd_norm_expd([$1]) ${save_xFLAGS_Var}"
115 ])dnl 131 ])dnl
116 ac_c_werror_flag="$mhd_check_cc_flag_save_c_werror_flag" 132 ac_c_werror_flag="$mhd_check_cc_flag_save_c_werror_flag"
117 AC_LINK_IFELSE([], 133 AC_LINK_IFELSE([],
@@ -123,72 +139,58 @@ int main(void)
123 ] 139 ]
124 ) 140 )
125 ac_c_werror_flag="$mhd_check_cc_flag_save_c_werror_flag" 141 ac_c_werror_flag="$mhd_check_cc_flag_save_c_werror_flag"
126 AS_VAR_SET([CFLAGS],["${save_CFLAGS_Var}"]) 142 AS_VAR_SET([XFLAGS],["${save_xFLAGS_Var}"])
127 AS_UNSET(save_CFLAGS_Var) 143 AS_UNSET(save_xFLAGS_Var)
128 AS_VAR_POPDEF([save_CFLAGS_Var])dnl 144 AS_VAR_POPDEF([save_xFLAGS_Var])dnl
129 ] 145 ]
130 ) 146 )
131 m4_ifnblank([$3$4],[dnl 147 m4_ifnblank([$3$4],[dnl
132 AS_VAR_IF([cv_Var], ["yes"], [$3], m4_default_nblank([$4])) 148 AS_VAR_IF([cv_Var], ["yes"], [$3], m4_default_nblank([$4]))
133 ])dnl 149 ])dnl
134 AS_VAR_POPDEF([cv_Var])dnl 150 AS_VAR_POPDEF([cv_Var])dnl
151 m4_popdef([XFLAGS])dnl
135]) 152])
136 153
137 154
138# 155#
139# SYNOPSIS 156# SYNOPSIS
140# 157#
141# MHD_FIND_CC_FLAG_WARNPARAMS() 158# MHD_FIND_CC_XFLAG_WARNPARAMS()
142# 159#
143AC_DEFUN([MHD_FIND_CC_FLAG_WARNPARAMS],[dnl 160AC_DEFUN([MHD_FIND_CC_XFLAG_WARNPARAMS],[dnl
144 AC_LANG_ASSERT([C])dnl 161 AC_LANG_ASSERT([C])dnl
145 AC_REQUIRE([MHD_FIND_CC_FLAG_WWARN])dnl 162 AC_REQUIRE([MHD_FIND_CC_CFLAG_WWARN])dnl
146 mhd_CFLAGS_params_warn='' 163 mhd_xFLAGS_params_warn=''
147 _MHD_CHECK_CC_FLAG_BODY([-Wunused-command-line-argument],[], 164 _MHD_CHECK_CC_XFLAG_BODY([-Wunused-command-line-argument],[],
148 [ 165 [
149 AS_IF([test -z "$mhd_CFLAGS_params_warn"], 166 MHD_APPEND_FLAG_TO_VAR([mhd_xFLAGS_params_warn],[-Wunused-command-line-argument])
150 [mhd_CFLAGS_params_warn='-Wunused-command-line-argument'], 167 ],[],[mhd_cv_cc_flag_Wwarn],[[CFLAGS]]
151 [mhd_CFLAGS_params_warn="$mhd_CFLAGS_params_warn -Wunused-command-line-argument"]
152 )
153 ],[],[mhd_cv_cc_flag_Wwarn]
154 ) 168 )
155 _MHD_CHECK_CC_FLAG_BODY([-Wignored-optimization-argument],[], 169 _MHD_CHECK_CC_XFLAG_BODY([-Wignored-optimization-argument],[],
156 [ 170 [
157 AS_IF([test -z "$mhd_CFLAGS_params_warn"], 171 MHD_APPEND_FLAG_TO_VAR([mhd_xFLAGS_params_warn],[-Wignored-optimization-argument])
158 [mhd_CFLAGS_params_warn='-Wignored-optimization-argument'], 172 ],[],[mhd_cv_cc_flag_Wwarn],[[CFLAGS]]
159 [mhd_CFLAGS_params_warn="$mhd_CFLAGS_params_warn -Wignored-optimization-argument"]
160 )
161 ],[],[mhd_cv_cc_flag_Wwarn]
162 ) 173 )
163 _MHD_CHECK_CC_FLAG_BODY([-Winvalid-command-line-argument],[], 174 _MHD_CHECK_CC_XFLAG_BODY([-Winvalid-command-line-argument],[],
164 [ 175 [
165 AS_IF([test -z "$mhd_CFLAGS_params_warn"], 176 MHD_APPEND_FLAG_TO_VAR([mhd_xFLAGS_params_warn],[-Winvalid-command-line-argument])
166 [mhd_CFLAGS_params_warn='-Winvalid-command-line-argument'], 177 ],[],[mhd_cv_cc_flag_Wwarn],[[CFLAGS]]
167 [mhd_CFLAGS_params_warn="$mhd_CFLAGS_params_warn -Winvalid-command-line-argument"]
168 )
169 ],[],[mhd_cv_cc_flag_Wwarn]
170 ) 178 )
171 _MHD_CHECK_CC_FLAG_BODY([-Wunknown-argument],[], 179 _MHD_CHECK_CC_XFLAG_BODY([-Wunknown-argument],[],
172 [ 180 [
173 AS_IF([test -z "$mhd_CFLAGS_params_warn"], 181 MHD_APPEND_FLAG_TO_VAR([mhd_xFLAGS_params_warn],[-Wunknown-argument])
174 [mhd_CFLAGS_params_warn='-Wunknown-argument'], 182 ],[],[mhd_cv_cc_flag_Wwarn],[[CFLAGS]]
175 [mhd_CFLAGS_params_warn="$mhd_CFLAGS_params_warn -Wunknown-argument"]
176 )
177 ],[],[mhd_cv_cc_flag_Wwarn]
178 )
179 AS_IF([test -z "$mhd_CFLAGS_params_warn"],
180 [mhd_CFLAGS_params_warn="$mhd_cv_cc_flag_Wwarn"],
181 [mhd_CFLAGS_params_warn="$mhd_cv_cc_flag_Wwarn $mhd_CFLAGS_params_warn"]
182 ) 183 )
184 MHD_PREPEND_FLAG_TO_VAR([mhd_xFLAGS_params_warn],[$mhd_cv_cc_flag_Wwarn])
183]) 185])
184 186
185 187
186# 188#
187# SYNOPSIS 189# SYNOPSIS
188# 190#
189# MHD_FIND_CC_FLAG_WWARN() 191# MHD_FIND_CC_CFLAG_WWARN()
190# 192#
191AC_DEFUN([MHD_FIND_CC_FLAG_WWARN],[dnl 193AC_DEFUN([MHD_FIND_CC_CFLAG_WWARN],[dnl
192 AC_PREREQ([2.64])dnl for AS_VAR_IF, m4_ifnblank 194 AC_PREREQ([2.64])dnl for AS_VAR_IF, m4_ifnblank
193 AC_REQUIRE([AC_PROG_CC])dnl 195 AC_REQUIRE([AC_PROG_CC])dnl
194 AC_LANG_ASSERT([C])dnl 196 AC_LANG_ASSERT([C])dnl
diff --git a/m4/mhd_check_cc_ldflag.m4 b/m4/mhd_check_cc_ldflag.m4
new file mode 100644
index 00000000..e5f57953
--- /dev/null
+++ b/m4/mhd_check_cc_ldflag.m4
@@ -0,0 +1,43 @@
1# SYNOPSIS
2#
3# MHD_CHECK_CC_LDFLAG([FLAG-TO-TEST], [VARIABLE-TO-PREPEND-LDFLAGS],
4# [ACTION-IF-SUPPORTED], [ACTION-IF-NOT-SUPPORTED])
5#
6# DESCRIPTION
7#
8# This macro checks whether the specific compiler flag is supported.
9# The check is performing by prepending FLAG-TO-TEST to LDFLAGS, then
10# prepending value of VARIABLE-TO-PREPEND-LDFLAGS (if any) to LDFLAGS, and
11# then performing compile and link test. If test succeed without warnings,
12# then the flag is considered to be suppoted. Otherwise, if compile and link
13# without test flag can be done without any warning, the flag is considered
14# to be unsuppoted.
15#
16# Example usage:
17#
18# MHD_CHECK_CC_LDFLAG([-pie], [additional_LDFLAGS],
19# [additional_LDFLAGS="${additional_LDFLAGS} -pie"])
20#
21# Defined cache variable used in check so if any test will not work
22# correctly on some platform, user may simply fix it by giving cache
23# variable in configure parameters, for example:
24#
25# ./configure mhd_cv_cc_fl_supp__wshadow=no
26#
27# This simplify building from source on exotic platforms as patching
28# of configure.ac is not required to change results of tests.
29#
30# LICENSE
31#
32# Copyright (c) 2022 Karlson2k (Evgeny Grin) <k2k@narod.ru>
33#
34# Copying and distribution of this file, with or without modification, are
35# permitted in any medium without royalty provided the copyright notice
36# and this notice are preserved. This file is offered as-is, without any
37# warranty.
38
39#serial 1
40
41AC_DEFUN([MHD_CHECK_CC_LDFLAG],[dnl
42_MHD_CHECK_CC_XFLAG([$1],[$2],[$3],[$4],[[LDFLAGS]])dnl
43])
diff --git a/m4/mhd_find_add_cc_cflag.m4 b/m4/mhd_find_add_cc_cflag.m4
new file mode 100644
index 00000000..7afc0f39
--- /dev/null
+++ b/m4/mhd_find_add_cc_cflag.m4
@@ -0,0 +1,70 @@
1# SYNOPSIS
2#
3# MHD_FIND_ADD_CC_CFLAG([VARIABLE-TO-EXTEND],
4# [FLAG1-TO-TEST], [FLAG2-TO-TEST], ...)
5#
6# DESCRIPTION
7#
8# This macro checks whether the specific compiler flags are supported.
9# The flags are checked one-by-one. The checking is stopped when the first
10# supported flag found.
11# The checks are performing by appending FLAGx-TO-TEST to the value of
12# VARIABLE-TO-EXTEND (CFLAGS if not specified), then prepending result to
13# CFLAGS (unless VARIABLE-TO-EXTEND is CFLAGS), and then performing compile
14# and link test. If test succeed without warnings, then the flag is added to
15# VARIABLE-TO-EXTEND and next flags are not checked. If compile-link cycle
16# cannot be performed without warning with all tested flags, no flag is
17# added to the VARIABLE-TO-EXTEND.
18#
19# Example usage:
20#
21# MHD_CHECK_CC_CFLAG([additional_CFLAGS],
22# [-ggdb3], [-g3], [-ggdb], [-g])
23#
24# Note: Unlike others MHD_CHECK_*CC_CFLAG* macro, this macro uses another
25# order of parameters.
26#
27# LICENSE
28#
29# Copyright (c) 2022 Karlson2k (Evgeny Grin) <k2k@narod.ru>
30#
31# Copying and distribution of this file, with or without modification, are
32# permitted in any medium without royalty provided the copyright notice
33# and this notice are preserved. This file is offered as-is, without any
34# warranty.
35
36#serial 1
37
38AC_DEFUN([MHD_FIND_ADD_CC_CFLAG],[dnl
39_MHD_FIND_ADD_CC_XFLAG([[CFLAGS]],$@)])
40
41
42# SYNOPSIS
43#
44# _MHD_FIND_ADD_CC_XFLAG([CFLAGS|LDFLAGS],
45# [VARIABLE-TO-EXTEND],
46# [FLAG1-TO-TEST], [FLAG2-TO-TEST], ...)
47#
48AC_DEFUN([_MHD_FIND_ADD_CC_XFLAG],[dnl
49 AC_PREREQ([2.64])dnl for m4_ifnblank
50 AC_LANG_ASSERT([C])dnl
51 m4_if(m4_eval([$# >= 3]), [0], [m4_fatal([$0: Macro must have at least three parameters])])dnl
52 m4_ifblank([$3],[m4_fatal([$0: Third macro argument must not be empty])])dnl
53 m4_bmatch(_mhd_norm_expd([$1]), [^\(CFLAGS\|LDFLAGS\)$],[],dnl
54 [m4_fatal([$0: First macro argument must be either 'CFLAGS' or 'LDFLAGS; ']_mhd_norm_expd([$5])[' is not supported])])dnl
55 m4_ifnblank([$2],[_MHD_FIND_ADD_CC_XFLAG_BODY($@)],dnl
56 [_MHD_FIND_ADD_CC_XFLAG_BODY([$1],[$1],m4_shift2($@))])dnl
57])
58
59
60m4_define([_MHD_FIND_ADD_CC_XFLAG_BODY],[dnl
61m4_version_prereq([2.64])dnl for m4_ifnblank
62m4_if([$#],[0],[m4_fatal([$0: no parameters])])dnl
63m4_bmatch(_mhd_norm_expd([$1]),[^\(CFLAGS\|LDFLAGS\)$],[],dnl
64[m4_fatal([$0: First macro argument must be either 'CFLAGS' or 'LDFLAGS; ']_mhd_norm_expd([$5])[' is not supported])])dnl
65m4_if([$#],[1],[m4_fatal([$0: not enough parameters])])dnl
66m4_if([$#],[2],[m4_fatal([$0: not enough parameters])])dnl
67m4_if([$#],[3],[m4_ifnblank([$3],[_MHD_CHECK_ADD_CC_XFLAG([$3],[$2],[],[],[$1])])],
68[m4_ifnblank([$3],[_MHD_CHECK_ADD_CC_XFLAG([$3],[$2],[],[$0([$1],[$2],m4_shift3($@))],[$1])],
69[$0([$1],[$2],m4_shift3($@))])])dnl
70])
diff --git a/m4/mhd_find_add_cc_ldflag.m4 b/m4/mhd_find_add_cc_ldflag.m4
new file mode 100644
index 00000000..224a4e29
--- /dev/null
+++ b/m4/mhd_find_add_cc_ldflag.m4
@@ -0,0 +1,39 @@
1# SYNOPSIS
2#
3# MHD_FIND_ADD_CC_LDFLAG([VARIABLE-TO-EXTEND],
4# [FLAG1-TO-TEST], [FLAG2-TO-TEST], ...)
5#
6# DESCRIPTION
7#
8# This macro checks whether the specific compiler flags are supported.
9# The flags are checked one-by-one. The checking is stopped when the first
10# supported flag found.
11# The checks are performing by appending FLAGx-TO-TEST to the value of
12# VARIABLE-TO-EXTEND (LDFLAGS if not specified), then prepending result to
13# LDFLAGS (unless VARIABLE-TO-EXTEND is LDFLAGS), and then performing compile
14# and link test. If test succeed without warnings, then the flag is added to
15# VARIABLE-TO-EXTEND and next flags are not checked. If compile-link cycle
16# cannot be performed without warning with all tested flags, no flag is
17# added to the VARIABLE-TO-EXTEND.
18#
19# Example usage:
20#
21# MHD_CHECK_CC_LDFLAG([additional_LDFLAGS],
22# [-Wl,--strip-all], [-Wl,--strip-debug])
23#
24# Note: Unlike others MHD_CHECK_*CC_LDFLAG* macro, this macro uses another
25# order of parameters.
26#
27# LICENSE
28#
29# Copyright (c) 2022 Karlson2k (Evgeny Grin) <k2k@narod.ru>
30#
31# Copying and distribution of this file, with or without modification, are
32# permitted in any medium without royalty provided the copyright notice
33# and this notice are preserved. This file is offered as-is, without any
34# warranty.
35
36#serial 1
37
38AC_DEFUN([MHD_FIND_ADD_CC_LDFLAG],[dnl
39_MHD_FIND_ADD_CC_XFLAG([[LDFLAGS]],$@)])