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
This commit is contained in:
Evgeny Grin (Karlson2k)
2022-04-16 13:37:52 +03:00
parent fff6d80c4b
commit 9b1865f691
9 changed files with 599 additions and 97 deletions
+202 -29
View File
@@ -28,6 +28,7 @@ AC_CONFIG_AUX_DIR([build-aux])
AM_INIT_AUTOMAKE([gnu] [check-news] [filename-length-max=99] [tar-v7] [silent-rules] [subdir-objects])
AC_CONFIG_HEADERS([MHD_config.h])
AC_CONFIG_MACRO_DIR([m4])
m4_pattern_forbid([^_?MHD_[A-Z_]+_CC_])dnl
LIB_VERSION_CURRENT=72
LIB_VERSION_REVISION=0
@@ -71,6 +72,33 @@ AS_IF([test -z "$CC" && test -z "$CPP"], [
)
])
AC_MSG_CHECKING([for build type])
AC_ARG_ENABLE([build-type],
[AS_HELP_STRING([[--enable-build-type=TYPE]],
[enable build TYPE, a set of configuration parameters; individual settings ]
[(asserts, sanitizers, compiler and linker flags) can be overriden by ]
[additional configure parameters (debug, neutral, release, release-compact, ]
[release-hardened) [neutral]])],
[], [enable_build_type=neutral])
AS_IF([test "x${enable_build_type}" = "x"], [enable_build_type="neutral"])
AS_VAR_IF([enable_build_type], ["no"], [enable_build_type="neutral"])
AS_VAR_IF([enable_build_type], ["yes"], [AC_MSG_ERROR([[Missing TYPE for --enable-build-type=]])])
AS_CASE([${enable_build_type}],
[debug], [AC_MSG_RESULT([debug: enable asserts, sanitizers (if any supported), debug information, compiler optimisation for debugging])],
[neutral], [AC_MSG_RESULT([neutral: use only user-specified compiler and linker flags])],
[release], [AC_MSG_RESULT([release: disable asserts, enable compiler optimisations])],
[release-compact], [AC_MSG_RESULT([release-compact: disable asserts, enable compiler optimisations for size, enable compact code])],
[release-hardened], [AC_MSG_RESULT([release-hardened: disable asserts, enable compiler optimisations, enable linker and compiler hardening])],
[AC_MSG_ERROR([[Unknown build type: ${enable_build_type}]])]
)
AS_VAR_IF([enable_build_type], ["neutral"], [:],
[
# For all non-neutreal build types do not use automatic "-g -O2" for CFLAGS
AS_IF([test -z "${CFLAGS}"], [CFLAGS=""])
]
)
# Checks for programs.
AC_PROG_AWK
AC_PROG_GREP
@@ -109,6 +137,86 @@ CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS}"
LT_INIT([win32-dll])
LT_LANG([Windows Resource])
CFLAGS="${user_CFLAGS}"
# Compiler options to always enable (if supported)
MHD_CHECK_ADD_CC_CFLAG([-fno-strict-aliasing], [CFLAGS_ac])
AS_VAR_IF([enable_build_type],["neutral"],[],
[ # Any non-neutral build types
MHD_CHECK_ADD_CC_CFLAGS([-Wall -Wnull-dereference -Wdeclaration-after-statement], [CFLAGS_ac])
MHD_CHECK_ADD_CC_CFLAGS([-Wredundant-decls -Wtrampolines -Wunsafe-loop-optimizations], [CFLAGS_ac])
CFLAGS="${CFLAGS_ac} ${user_CFLAGS}"
LDFLAGS="${user_LDFLAGS}"
MHD_CHECK_ADD_CC_LDFLAG([-Wl,--warn-common], [LDFLAGS_ac])
LDFLAGS="${LDFLAGS_ac} ${user_LDFLAGS}"
]
)
AS_VAR_IF([enable_build_type],["debug"],
[ # Debug build
CFLAGS="${user_CFLAGS}"
MHD_FIND_ADD_CC_CFLAG([CFLAGS_ac], [-Og], [-O0])
MHD_FIND_ADD_CC_CFLAG([CFLAGS_ac], [-ggdb3], [-g3], [-ggdb], [-g])
MHD_CHECK_ADD_CC_CFLAGS([-Wextra -Wdouble-promotion -Wformat=2 -Wformat-overflow=2 -Wformat-truncation=2], [CFLAGS_ac])
MHD_CHECK_ADD_CC_CFLAGS([-Wmissing-include-dirs -Wshift-overflow=2 -Wstringop-overflow=4 -Walloc-zero], [CFLAGS_ac])
MHD_CHECK_ADD_CC_CFLAGS([-Wduplicated-branches -Wduplicated-cond -Wfloat-equal -Wshadow -Wpointer-arith], [CFLAGS_ac])
MHD_CHECK_ADD_CC_CFLAGS([-Wbad-function-cast -Wcast-qual -Wcast-align=strict -Wwrite-strings -Wconversion], [CFLAGS_ac])
MHD_CHECK_ADD_CC_CFLAGS([-Wjump-misses-init -Wlogical-op -Waggregate-return -Wstrict-prototypes], [CFLAGS_ac])
MHD_CHECK_ADD_CC_CFLAGS([-Wold-style-definition -Wmissing-prototypes -Wformat-security -Wshift-negative-value], [CFLAGS_ac])
CFLAGS="${CFLAGS_ac} ${user_CFLAGS}"
LDFLAGS="${user_LDFLAGS}"
MHD_CHECK_ADD_CC_LDFLAG([-Wl,--enable-long-section-names], [LDFLAGS_ac])
LDFLAGS="${LDFLAGS_ac} ${user_LDFLAGS}"
]
)
AS_CASE([${enable_build_type}],[release|release-*],
[ # All release types
CFLAGS="${user_CFLAGS}"
AS_VAR_IF([enable_build_type],
[release-compact],
[
AC_CHECK_DECL([MHD_FAVOR_SMALL_CODE],[],
[AC_CHECK_DECL([MHD_FAVOR_FAST_CODE],[],
[MHD_APPEND_FLAG_TO_VAR([CPPFLAGS_ac],[-DMHD_FAVOR_SMALL_CODE=1])],
[/* no includes */])],[/* no includes */])
CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS}"
MHD_FIND_ADD_CC_CFLAG([CFLAGS_ac], [-Oz], [-Os], [-O])
],
[ # All non-compact release types
AC_CHECK_DECL([MHD_FAVOR_SMALL_CODE],[],
[AC_CHECK_DECL([MHD_FAVOR_FAST_CODE],[],
[MHD_APPEND_FLAG_TO_VAR([CPPFLAGS_ac],[-DMHD_FAVOR_FAST_CODE=1])],
[/* no includes */])],[/* no includes */])
CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS}"
MHD_FIND_ADD_CC_CFLAG([CFLAGS_ac], [-O2], [-O])
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
MHD_CHECK_ADD_CC_CFLAGS([-ftree-partial-pre -fgcse-after-reload -fipa-pta], [CFLAGS_ac])
MHD_CHECK_ADD_CC_CFLAGS([-fisolate-erroneous-paths-attribute -ffinite-loops -floop-nest-optimize], [CFLAGS_ac])
MHD_CHECK_ADD_CC_CFLAGS([-fpredictive-commoning -frename-registers], [CFLAGS_ac])
MHD_CHECK_ADD_CC_CFLAGS([-ftree-loop-distribute-patterns -fpeel-loops -fsplit-loops -ftree-vectorize], [CFLAGS_ac])
]
)
AS_VAR_IF([enable_build_type],
[release-hardened],
[
MHD_CHECK_ADD_CC_CFLAGS([-Wformat-security -Wstack-protector], [CFLAGS_ac])
]
)
AS_VAR_IF([enable_build_type],
[ # Flags are not suitable for 'compact' and for 'hardened'
MHD_CHECK_ADD_CC_CFLAGS([-ffast-math -fno-trapping-math], [CFLAGS_ac])
]
)
CFLAGS="${CFLAGS_ac} ${user_CFLAGS}"
# W32-specific
LDFLAGS="${user_LDFLAGS}"
MHD_CHECK_ADD_CC_LDFLAG([-Wl,--disable-long-section-names], [LDFLAGS_ac])
LDFLAGS="${LDFLAGS_ac} ${user_LDFLAGS}"
]
)
CFLAGS="${CFLAGS_ac} ${user_CFLAGS}"
# Check for headers that are ALWAYS required
AC_CHECK_HEADERS_ONCE([stdio.h string.h stdint.h errno.h limits.h fcntl.h], [],
[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], [], [],
]]
)
# Adam shostack suggests the following for Windows:
# -D_FORTIFY_SOURCE=2 -fstack-protector-all
AC_ARG_ENABLE([gcc-hardening],
[AS_HELP_STRING([--enable-gcc-hardening], [enable compiler security checks])],
[AS_IF([test x$enableval = xyes],[
CFLAGS_ac="${CFLAGS_ac} -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -fstack-protector-all"
CFLAGS_ac="${CFLAGS_ac} -fwrapv -fPIE -Wstack-protector"
CFLAGS_ac="${CFLAGS_ac} --param ssp-buffer-size=1"
AC_ARG_ENABLE([compiler-hardening],
[AS_HELP_STRING([--enable-compiler-hardening], [enable compiler security checks])],
[],
[AS_CASE([${enable_build_type}],[*-hardened],
[enable_compiler_hardening='yes'],[enable_compiler_hardening='no'])]
)
AS_VAR_IF([enable_compiler_hardening],["yes"],
[
CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS}"
AC_CHECK_DECL([_FORTIFY_SOURCE],
[MHD_APPEND_FLAG_TO_VAR([CPPFLAGS_ac],[-U_FORTIFY_SOURCE])],
[],[/* no includes */])
MHD_APPEND_FLAG_TO_VAR([CPPFLAGS_ac],[-D_FORTIFY_SOURCE=2])
CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS}"
CFLAGS="${user_CFLAGS}"
MHD_FIND_ADD_CC_CFLAG([CFLAGS_ac],[-fstack-protector-strong],[-fstack-protector-all],[-fstack-protector])
MHD_CHECK_ADD_CC_CFLAGS([-fstack-clash-protection -ftrivial-auto-var-init=pattern],[CFLAGS_ac])
CFLAGS="${CFLAGS_ac} ${user_CFLAGS}"
AS_VAR_IF([pic_mode],["no"],[],
[
AS_VAR_IF([enable_shared],["yes"],[],
[
# PIE cannot be used for shared lib
# PIE static lib can be used within non-PIE application, but
# PIE static lib cannot be used in non-PIE shared lib. Let's assume
# that static lib will not be used in shared lib
CFLAGS="${user_CFLAGS}"
# Perform tests with "-pie" enabled
LDFLAGS="${LDFLAGS_ac} -pie ${user_LDFLAGS}"
MHD_CHECK_ADD_CC_CFLAG([-fPIE],[CFLAGS_ac],
[
MHD_APPEND_FLAG_TO_VAR([LDFLAGS_ac],[-pie])
],
[
MHD_CHECK_CC_CFLAG([-fpie],[CFLAGS_ac],
[
MHD_APPEND_FLAG_TO_VAR([LDFLAGS_ac],[-pie])
]
)
]
)
CFLAGS="${CFLAGS_ac} ${user_CFLAGS}"
LDFLAGS="${LDFLAGS_ac} ${user_LDFLAGS}"
]
)
]
)
CFLAGS="${CFLAGS_ac} ${user_CFLAGS}"
LDFLAGS_ac="${LDFLAGS_ac} -pie"
LDFLAGS="${LDFLAGS_ac} ${user_LDFLAGS}"
])])
]
)
# Linker hardening options
# Currently these options are ELF specific - you can't use this with MacOSX
# Currently these options are ELF specific, they don't work on Darwin and W32
AC_ARG_ENABLE([linker-hardening],
[AS_HELP_STRING([--enable-linker-hardening], [enable linker security fixups])],
[AS_IF([test x$enableval = xyes],
[LDFLAGS_ac="${LDFLAGS_ac} -z relro -z now"])])
LDFLAGS="${LDFLAGS_ac} ${user_LDFLAGS}"
[],
[AS_CASE([${enable_build_type}],[*-hardened],
[enable_linker_hardening='yes'],[enable_linker_hardening='no'])]
)
AS_VAR_IF([enable_linker_hardening],["yes"],
[
CFLAGS="${CFLAGS_ac} ${user_CFLAGS}"
LDFLAGS="${user_LDFLAGS}"
MHD_CHECK_ADD_CC_LDFLAG([-Wl,-z,relro],[LDFLAGS_ac],
[MHD_CHECK_ADD_CC_LDFLAG([-Wl,-z,now],[LDFLAGS_ac])])
# Actually should be "noexec" by default, but let's try to enforce it.
MHD_CHECK_ADD_CC_LDFLAG([-Wl,-z,noexecstack],[LDFLAGS_ac])
# W32-specific. Some are enabled by default, but they will be enfored to be sure.
MHD_CHECK_ADD_CC_LDFLAGS([-Wl,--large-address-aware -Wl,--enable-auto-image-base],[LDFLAGS_ac])
MHD_CHECK_ADD_CC_LDFLAGS([-Wl,--dynamicbase -Wl,--nxcompat -Wl,--high-entropy-va],[LDFLAGS_ac])
LDFLAGS="${LDFLAGS_ac} ${user_LDFLAGS}"
]
)
AH_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"
AC_SEARCH_LIBS([sendmsg], [socket], [AC_DEFINE([HAVE_SENDMSG],[1],[Define if your platform supports sendmsg])])
AC_CHECK_FUNCS([writev])
# set GCC options
# use '-fno-strict-aliasing', but only if the compiler
# and linker can take it
AX_CHECK_LINK_FLAG([-fno-strict-aliasing],
[AX_APPEND_COMPILE_FLAGS([-fno-strict-aliasing], [CFLAGS_ac])])
CFLAGS="${CFLAGS_ac} ${user_CFLAGS}"
AC_C_BIGENDIAN
AC_C_VARARRAYS
@@ -1971,7 +2126,7 @@ MHD_CHECK_FUNC([[nanosleep]], [[#include <time.h>]], [[struct timespec ts2, ts1
HIDDEN_VISIBILITY_CFLAGS=""
AH_TEMPLATE([_MHD_EXTERN],[defines how to decorate public symbols w][hile building the library])
CFLAGS="${user_CFLAGS}"
MHD_CHECK_CC_FLAG([-fvisibility=hidden],[CFLAGS_ac],
MHD_CHECK_CC_CFLAG([-fvisibility=hidden],[CFLAGS_ac],
[
# NOTE: require setting of errattr_CFLAGS above
CFLAGS="${CFLAGS_ac} -fvisibility=hidden ${user_CFLAGS} ${errattr_CFLAGS}"
@@ -2893,9 +3048,12 @@ AC_MSG_RESULT([$CPU_COUNT])
AC_MSG_CHECKING([[whether to enable debug asserts]])
AC_ARG_ENABLE([[asserts]],
AS_HELP_STRING([[--enable-asserts]],
[enable test build with debug asserts]),
[], [[enable_asserts='no']])
[AS_HELP_STRING([[--enable-asserts]],
[enable test build with debug asserts])],
[],
[AS_CASE([${enable_build_type}],[*-hardened],
[enable_compiler_hardening='yes'],[enable_compiler_hardening='no'])]
)
AS_CASE([[$enable_asserts]], [[yes]], [[:]], [[no]], [[:]], [[enable_asserts='no']])
AC_MSG_RESULT([[$enable_asserts]])
@@ -2956,10 +3114,25 @@ AS_IF([test "x${enable_sanitizers}" = "xno"],
],
[test "x${enable_sanitizers}" = "xauto" || test "x${enable_sanitizers}" = "xauto-optional"],
[
enable_san_address="auto"
enable_san_undef="auto"
enable_san_leak="auto"
enable_san_upoison="auto"
AS_VAR_IF([enable_compiler_hardening],["yes"],
[
AS_VAR_IF([enable_sanitizers],["auto"],
[AC_MSG_ERROR([sanitizers cannot be enabled with compiler hardnening])],
[AC_MSG_WARN([sanitizers cannot be enabled with compiler hardnening])]
)
enable_sanitizers="no"
enable_san_address="no"
enable_san_undef="no"
enable_san_leak="no"
enable_san_upoison="no"
],
[
enable_san_address="auto"
enable_san_undef="auto"
enable_san_leak="auto"
enable_san_upoison="auto"
]
)
],
[test "x${enable_sanitizers}" = "xauto-fallback"],
[
+63
View File
@@ -0,0 +1,63 @@
# SYNOPSIS
#
# MHD_CHECK_ADD_CC_CFLAG([FLAG-TO-TEST], [VARIABLE-TO-EXTEND],
# [ACTION-IF-SUPPORTED], [ACTION-IF-NOT-SUPPORTED])
#
# DESCRIPTION
#
# This macro checks whether the specific compiler flag is supported.
# The check is performing by appending FLAG-TO-TEST to the value of
# VARIABLE-TO-EXTEND (CFLAGS if not specified), then prepending result to
# CFLAGS (unless VARIABLE-TO-EXTEND is CFLAGS), and then performing compile
# and link test. If test succeed without warnings, then the flag is added to
# VARIABLE-TO-EXTEND. Otherwise, if compile and link without test flag cannot
# be done without any warning, the flag is considered to be unsuppoted.
#
# Example usage:
#
# MHD_CHECK_ADD_CC_CFLAG([-Wshadow], [additional_CFLAGS])
#
#
# LICENSE
#
# Copyright (c) 2022 Karlson2k (Evgeny Grin) <k2k@narod.ru>
#
# Copying and distribution of this file, with or without modification, are
# permitted in any medium without royalty provided the copyright notice
# and this notice are preserved. This file is offered as-is, without any
# warranty.
#serial 1
AC_DEFUN([MHD_CHECK_ADD_CC_CFLAG],[dnl
_MHD_CHECK_ADD_CC_XFLAG([$1],[$2],[$3],[$4],[[CFLAGS]])dnl
])
# SYNOPSIS
#
# _MHD_CHECK_ADD_CC_XFLAG([FLAG-TO-TEST], [VARIABLE-TO-EXTEND],
# [ACTION-IF-SUPPORTED], [ACTION-IF-NOT-SUPPORTED],
# [CFLAGS|LDFLAGS])
#
AC_DEFUN([_MHD_CHECK_ADD_CC_XFLAG],[dnl
AC_PREREQ([2.64])dnl for AS_VAR_IF, m4_ifnblank, m4_default
AC_LANG_ASSERT([C])dnl
m4_ifblank([$1], [m4_fatal([First macro argument must not be empty])])dnl
m4_bmatch(_mhd_norm_expd([$1]), [\s],dnl
[m4_fatal([First macro argument must not contain whitespaces])])dnl
m4_bmatch(_mhd_norm_expd([$2]), [\s],dnl
[m4_fatal([Second macro argument must not contain whitespaces])])dnl
m4_bmatch([$1], [\$], [m4_fatal([$0: First macro argument must not contain '$'])])dnl
m4_bmatch([$2], [\$], [m4_fatal([$0: Second macro argument must not contain '$'])])dnl
m4_bmatch(_mhd_norm_expd([$5]), [^\(CFLAGS\|LDFLAGS\)$],[],dnl
[m4_fatal([$0: Fifth macro argument must be either 'CFLAGS' or 'LDFLAGS; ']_mhd_norm_expd([$5])[' is not supported])])dnl
m4_ifnblank([$2],
[_MHD_CHECK_CC_XFLAG([$1], [$2],
[MHD_APPEND_FLAG_TO_VAR(_mhd_norm_expd([$2]),_mhd_norm_expd([$1]))
$3],[$4],[$5])],
[_MHD_CHECK_CC_XFLAG([$1],_mhd_norm_expd([$5]),
[MHD_APPEND_FLAG_TO_VAR(_mhd_norm_expd([$5]),_mhd_norm_expd([$1]))
$3],[$4],[$5])]
)
])
+39
View File
@@ -0,0 +1,39 @@
# SYNOPSIS
#
# MHD_CHECK_ADD_CC_CFLAGS([FLAGS-TO-TEST], [VARIABLE-TO-EXTEND])
#
# DESCRIPTION
#
# This macro checks whether the specific compiler flags are supported.
# The FLAGS-TO-TEST parameter is whitespace-separated flagto to test.
# The flags are tested one-by-one, all supported flags are added to the
# VARIABLE-TO-EXTEND.
# Every flag check is performing by appending one flag to the value of
# VARIABLE-TO-EXTEND (CFLAGS if not specified), then prepending result to
# CFLAGS (unless VARIABLE-TO-EXTEND is CFLAGS), and then performing compile
# and link test. If test succeed without warnings, then the flag is added to
# VARIABLE-TO-EXTEND. Otherwise, if compile and link without test flag cannot
# be done without any warning, the flag is considered to be unsuppoted.
#
# Example usage:
#
# MHD_CHECK_ADD_CC_CFLAGS([-Wshadow -Walloc-zero -Winit-self],
# [additional_CFLAGS])
#
#
# LICENSE
#
# Copyright (c) 2022 Karlson2k (Evgeny Grin) <k2k@narod.ru>
#
# Copying and distribution of this file, with or without modification, are
# permitted in any medium without royalty provided the copyright notice
# and this notice are preserved. This file is offered as-is, without any
# warranty.
#serial 1
AC_DEFUN([MHD_CHECK_ADD_CC_CFLAGS],[dnl
m4_foreach_w([test_flag],[$1],
[MHD_CHECK_ADD_CC_CFLAG([test_flag],[$2])
])dnl
])
+34
View File
@@ -0,0 +1,34 @@
# SYNOPSIS
#
# MHD_CHECK_ADD_CC_LDFLAG([FLAG-TO-TEST], [VARIABLE-TO-EXTEND],
# [ACTION-IF-SUPPORTED], [ACTION-IF-NOT-SUPPORTED])
#
# DESCRIPTION
#
# This macro checks whether the specific compiler flag is supported.
# The check is performing by appending FLAG-TO-TEST to the value of
# VARIABLE-TO-EXTEND (LDFLAGS if not specified), then prepending result to
# LDFLAGS (unless VARIABLE-TO-EXTEND is LDFLAGS), and then performing compile
# and link test. If test succeed without warnings, then the flag is added to
# VARIABLE-TO-EXTEND. Otherwise, if compile and link without test flag cannot
# be done without any warning, the flag is considered to be unsuppoted.
#
# Example usage:
#
# MHD_CHECK_ADD_CC_LDFLAG([-pie], [additional_LDFLAGS])
#
#
# LICENSE
#
# Copyright (c) 2022 Karlson2k (Evgeny Grin) <k2k@narod.ru>
#
# Copying and distribution of this file, with or without modification, are
# permitted in any medium without royalty provided the copyright notice
# and this notice are preserved. This file is offered as-is, without any
# warranty.
#serial 1
AC_DEFUN([MHD_CHECK_ADD_CC_LDFLAG],[dnl
_MHD_CHECK_ADD_CC_XFLAG([$1],[$2],[$3],[$4],[[LDFLAGS]])dnl
])
+39
View File
@@ -0,0 +1,39 @@
# SYNOPSIS
#
# MHD_CHECK_ADD_CC_LDFLAGS([FLAGS-TO-TEST], [VARIABLE-TO-EXTEND])
#
# DESCRIPTION
#
# This macro checks whether the specific compiler flags are supported.
# The FLAGS-TO-TEST parameter is whitespace-separated flagto to test.
# The flags are tested one-by-one, all supported flags are added to the
# VARIABLE-TO-EXTEND.
# Every flag check is performing by appending one flag to the value of
# VARIABLE-TO-EXTEND (LDFLAGS if not specified), then prepending result to
# LDFLAGS (unless VARIABLE-TO-EXTEND is LDFLAGS), and then performing compile
# and link test. If test succeed without warnings, then the flag is added to
# VARIABLE-TO-EXTEND. Otherwise, if compile and link without test flag cannot
# be done without any warning, the flag is considered to be unsuppoted.
#
# Example usage:
#
# MHD_CHECK_ADD_CC_LDFLAGS([-W,--strip-all -Wl,--fatal-warnings],
# [additional_LDFLAGS])
#
#
# LICENSE
#
# Copyright (c) 2022 Karlson2k (Evgeny Grin) <k2k@narod.ru>
#
# Copying and distribution of this file, with or without modification, are
# permitted in any medium without royalty provided the copyright notice
# and this notice are preserved. This file is offered as-is, without any
# warranty.
#serial 1
AC_DEFUN([MHD_CHECK_ADD_CC_LDFLAGS],[dnl
m4_foreach_w([test_flag],[$1],
[MHD_CHECK_ADD_CC_LDFLAG([test_flag],[$2])
])dnl
])
@@ -1,7 +1,7 @@
# SYNOPSIS
#
# MHD_CHECK_CC_FLAG([FLAG-TO-TEST], [VARIABLE-TO-PREPEND-CFLAGS],
# [ACTION-IF-SUPPORTED], [ACTION-IF-NOT-SUPPORTED])
# MHD_CHECK_CC_CFLAG([FLAG-TO-TEST], [VARIABLE-TO-PREPEND-CFLAGS],
# [ACTION-IF-SUPPORTED], [ACTION-IF-NOT-SUPPORTED])
#
# DESCRIPTION
#
@@ -15,14 +15,14 @@
#
# Example usage:
#
# MHD_CHECK_CC_FLAG([-Wshadow], [additional_CFLAGS],
# [additional_CFLAGS="${additional_CFLAGS} -Wshadow"])
# MHD_CHECK_CC_CFLAG([-Wshadow], [additional_CFLAGS],
# [additional_CFLAGS="${additional_CFLAGS} -Wshadow"])
#
# Defined cache variable used in check so if any test will not work
# correctly on some platform, user may simply fix it by giving cache
# variable in configure parameters, for example:
#
# ./configure mhd_cv_cc_fl_supp__wshadow=no
# ./configure mhd_cv_cc_fl_supp__Wshadow=no
#
# This simplify building from source on exotic platforms as patching
# of configure.ac is not required to change results of tests.
@@ -36,9 +36,19 @@
# and this notice are preserved. This file is offered as-is, without any
# warranty.
#serial 1
#serial 2
AC_DEFUN([MHD_CHECK_CC_FLAG],[dnl
AC_DEFUN([MHD_CHECK_CC_CFLAG],[dnl
_MHD_CHECK_CC_XFLAG([$1],[$2],[$3],[$4],[[CFLAGS]])dnl
])
# SYNOPSIS
#
# _MHD_CHECK_CC_XFLAG([FLAG-TO-TEST], [VARIABLE-TO-PREPEND-CFLAGS],
# [ACTION-IF-SUPPORTED], [ACTION-IF-NOT-SUPPORTED],
# [CFLAGS|LDFLAGS])
#
AC_DEFUN([_MHD_CHECK_CC_XFLAG],[dnl
AC_PREREQ([2.64])dnl for AS_VAR_IF, m4_ifnblank
AC_LANG_ASSERT([C])dnl
AC_REQUIRE([AC_PROG_CC])dnl
@@ -49,18 +59,20 @@ AC_DEFUN([MHD_CHECK_CC_FLAG],[dnl
[m4_fatal([$0: Second macro argument must not contain whitespaces])])dnl
m4_bmatch([$1], [\$], [m4_fatal([$0: First macro argument must not contain '$'])])dnl
m4_bmatch([$2], [\$], [m4_fatal([$0: Second macro argument must not contain '$'])])dnl
AC_REQUIRE([MHD_FIND_CC_FLAG_WARNPARAMS])dnl sets 'mhd_CFLAGS_params_warn' variable
_MHD_CHECK_CC_FLAG_BODY([$1],[$2],[$3],[$4],[mhd_CFLAGS_params_warn])dnl
AC_REQUIRE([MHD_FIND_CC_XFLAG_WARNPARAMS])dnl sets 'mhd_xFLAGS_params_warn' variable
m4_bmatch(_mhd_norm_expd([$5]), [^\(CFLAGS\|LDFLAGS\)$],[],dnl
[m4_fatal([$0: Fifth macro argument must be either 'CFLAGS' or 'LDFLAGS; ']_mhd_norm_expd([$5])[' is not supported])])dnl
_MHD_CHECK_CC_XFLAG_BODY([$1],[$2],[$3],[$4],[mhd_xFLAGS_params_warn],[$5])dnl
])
# SYNOPSIS
#
# _MHD_CHECK_CC_FLAG_BODY([FLAG-TO-TEST], [VARIABLE-TO-PREPEND-CFLAGS],
# [ACTION-IF-SUPPORTED], [ACTION-IF-NOT-SUPPORTED],
# [VARIABLE-TO-ENABLE-WARNS])
# _MHD_CHECK_CC_XFLAG_BODY([FLAG-TO-TEST], [VARIABLE-TO-PREPEND-CFLAGS],
# [ACTION-IF-SUPPORTED], [ACTION-IF-NOT-SUPPORTED],
# [VARIABLE-TO-ENABLE-WARNS], [CFLAGS|LDFLAGS])
#
AC_DEFUN([_MHD_CHECK_CC_FLAG_BODY],[dnl
AC_DEFUN([_MHD_CHECK_CC_XFLAG_BODY],[dnl
AC_LANG_ASSERT([C])dnl
m4_ifblank([$1], [m4_fatal([$0: First macro argument must not be empty])])dnl
m4_bmatch(_mhd_norm_expd([$1]), [\s],dnl
@@ -71,18 +83,22 @@ AC_DEFUN([_MHD_CHECK_CC_FLAG_BODY],[dnl
m4_bmatch([$2], [\$], [m4_fatal([$0: Second macro argument must not contain '$'])])dnl
m4_ifblank([$5], [m4_fatal([$0: Fifth macro argument must not be empty])])dnl
m4_bmatch([$5], [\$], [m4_fatal([$0: Fifth macro argument must not contain '$'])])dnl
AS_VAR_PUSHDEF([cv_Var], [mhd_cv_cc_fl_supp_]m4_bpatsubst(m4_tolower(_mhd_norm_expd([$1])),[[^a-z0-9]],[_]))dnl
dnl
m4_bmatch(_mhd_norm_expd([$6]), [^\(CFLAGS\|LDFLAGS\)$],[],dnl
[m4_fatal([$0: Sixth macro argument must be either 'CFLAGS' or 'LDFLAGS; ']_mhd_norm_expd([$6])[' is not supported])])dnl
m4_pushdef([XFLAGS],_mhd_norm_expd([$6]))dnl
dnl Keep uppercase letters to avoid clashes for parameters like -fPIE and -fpie
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
AC_CACHE_CHECK([whether $[]CC supports _mhd_norm_expd([$1]) flag], cv_Var,
[dnl
AS_VAR_PUSHDEF([save_CFLAGS_Var], [mhd_check_cc_flag_save_CFLAGS])dnl
AS_VAR_SET([save_CFLAGS_Var],["${CFLAGS}"])
AS_VAR_PUSHDEF([save_xFLAGS_Var], [mhd_check_cc_flag_save_]XFLAGS)dnl
AS_VAR_SET([save_xFLAGS_Var],["${XFLAGS}"])
m4_ifnblank([$2],[dnl
m4_if(_mhd_norm_expd([$2]),[CFLAGS],
[CFLAGS="${save_CFLAGS_Var} _mhd_norm_expd([$1]) $[]{_mhd_norm_expd([$5])}"],
[CFLAGS="$[]{_mhd_norm_expd([$2])} _mhd_norm_expd([$1]) ${save_CFLAGS_Var} $[]{_mhd_norm_expd([$5])}"])
m4_if(_mhd_norm_expd([$2]),[XFLAGS],
[XFLAGS="${save_xFLAGS_Var} _mhd_norm_expd([$1]) $[]{_mhd_norm_expd([$5])}"],
[XFLAGS="$[]{_mhd_norm_expd([$2])} _mhd_norm_expd([$1]) ${save_xFLAGS_Var} $[]{_mhd_norm_expd([$5])}"])
],[dnl
CFLAGS="_mhd_norm_expd([$1]) $[]CFLAGS $[]{_mhd_norm_expd([$5])}"
XFLAGS="_mhd_norm_expd([$1]) $[]XFLAGS $[]{_mhd_norm_expd([$5])}"
])dnl
mhd_check_cc_flag_save_c_werror_flag="$ac_c_werror_flag"
ac_c_werror_flag=yes
@@ -95,23 +111,23 @@ int main(void)
]])])
AC_LINK_IFELSE([],
[AS_VAR_SET([cv_Var],["yes"])],
[ [#] Compile and link failed if test flag added
[ [#] Compile and link failed with test flag added
m4_ifnblank([$2],[dnl
m4_if(_mhd_norm_expd([$2]),[CFLAGS],
[CFLAGS="${save_CFLAGS_Var} $[]{_mhd_norm_expd([$5])}"],
[CFLAGS="$[]{_mhd_norm_expd([$2])} ${save_CFLAGS_Var} $[]{_mhd_norm_expd([$5])}"])
m4_if(_mhd_norm_expd([$2]),[XFLAGS],
[XFLAGS="${save_xFLAGS_Var} $[]{_mhd_norm_expd([$5])}"],
[XFLAGS="$[]{_mhd_norm_expd([$2])} ${save_xFLAGS_Var} $[]{_mhd_norm_expd([$5])}"])
],[dnl
CFLAGS="${save_CFLAGS_Var} $[]{_mhd_norm_expd([$5])}"
XFLAGS="${save_xFLAGS_Var} $[]{_mhd_norm_expd([$5])}"
])dnl
AC_LINK_IFELSE([],
[AS_VAR_SET([cv_Var],["no"])],
[ [#] Compile and link failed if test flag removed as well
[ [#] Compile and link failed with test flag removed as well
m4_ifnblank([$2],[dnl
m4_if(_mhd_norm_expd([$2]),[CFLAGS],
[CFLAGS="${save_CFLAGS_Var} _mhd_norm_expd([$1])"],
[CFLAGS="$[]{_mhd_norm_expd([$2])} _mhd_norm_expd([$1]) ${save_CFLAGS_Var}"])
m4_if(_mhd_norm_expd([$2]),[XFLAGS],
[XFLAGS="${save_xFLAGS_Var} _mhd_norm_expd([$1])"],
[XFLAGS="$[]{_mhd_norm_expd([$2])} _mhd_norm_expd([$1]) ${save_xFLAGS_Var}"])
],[dnl
CFLAGS="_mhd_norm_expd([$1]) ${save_CFLAGS_Var}"
XFLAGS="_mhd_norm_expd([$1]) ${save_xFLAGS_Var}"
])dnl
ac_c_werror_flag="$mhd_check_cc_flag_save_c_werror_flag"
AC_LINK_IFELSE([],
@@ -123,72 +139,58 @@ int main(void)
]
)
ac_c_werror_flag="$mhd_check_cc_flag_save_c_werror_flag"
AS_VAR_SET([CFLAGS],["${save_CFLAGS_Var}"])
AS_UNSET(save_CFLAGS_Var)
AS_VAR_POPDEF([save_CFLAGS_Var])dnl
AS_VAR_SET([XFLAGS],["${save_xFLAGS_Var}"])
AS_UNSET(save_xFLAGS_Var)
AS_VAR_POPDEF([save_xFLAGS_Var])dnl
]
)
m4_ifnblank([$3$4],[dnl
AS_VAR_IF([cv_Var], ["yes"], [$3], m4_default_nblank([$4]))
])dnl
AS_VAR_POPDEF([cv_Var])dnl
m4_popdef([XFLAGS])dnl
])
#
# SYNOPSIS
#
# MHD_FIND_CC_FLAG_WARNPARAMS()
# MHD_FIND_CC_XFLAG_WARNPARAMS()
#
AC_DEFUN([MHD_FIND_CC_FLAG_WARNPARAMS],[dnl
AC_DEFUN([MHD_FIND_CC_XFLAG_WARNPARAMS],[dnl
AC_LANG_ASSERT([C])dnl
AC_REQUIRE([MHD_FIND_CC_FLAG_WWARN])dnl
mhd_CFLAGS_params_warn=''
_MHD_CHECK_CC_FLAG_BODY([-Wunused-command-line-argument],[],
AC_REQUIRE([MHD_FIND_CC_CFLAG_WWARN])dnl
mhd_xFLAGS_params_warn=''
_MHD_CHECK_CC_XFLAG_BODY([-Wunused-command-line-argument],[],
[
AS_IF([test -z "$mhd_CFLAGS_params_warn"],
[mhd_CFLAGS_params_warn='-Wunused-command-line-argument'],
[mhd_CFLAGS_params_warn="$mhd_CFLAGS_params_warn -Wunused-command-line-argument"]
)
],[],[mhd_cv_cc_flag_Wwarn]
MHD_APPEND_FLAG_TO_VAR([mhd_xFLAGS_params_warn],[-Wunused-command-line-argument])
],[],[mhd_cv_cc_flag_Wwarn],[[CFLAGS]]
)
_MHD_CHECK_CC_FLAG_BODY([-Wignored-optimization-argument],[],
_MHD_CHECK_CC_XFLAG_BODY([-Wignored-optimization-argument],[],
[
AS_IF([test -z "$mhd_CFLAGS_params_warn"],
[mhd_CFLAGS_params_warn='-Wignored-optimization-argument'],
[mhd_CFLAGS_params_warn="$mhd_CFLAGS_params_warn -Wignored-optimization-argument"]
)
],[],[mhd_cv_cc_flag_Wwarn]
MHD_APPEND_FLAG_TO_VAR([mhd_xFLAGS_params_warn],[-Wignored-optimization-argument])
],[],[mhd_cv_cc_flag_Wwarn],[[CFLAGS]]
)
_MHD_CHECK_CC_FLAG_BODY([-Winvalid-command-line-argument],[],
_MHD_CHECK_CC_XFLAG_BODY([-Winvalid-command-line-argument],[],
[
AS_IF([test -z "$mhd_CFLAGS_params_warn"],
[mhd_CFLAGS_params_warn='-Winvalid-command-line-argument'],
[mhd_CFLAGS_params_warn="$mhd_CFLAGS_params_warn -Winvalid-command-line-argument"]
)
],[],[mhd_cv_cc_flag_Wwarn]
MHD_APPEND_FLAG_TO_VAR([mhd_xFLAGS_params_warn],[-Winvalid-command-line-argument])
],[],[mhd_cv_cc_flag_Wwarn],[[CFLAGS]]
)
_MHD_CHECK_CC_FLAG_BODY([-Wunknown-argument],[],
_MHD_CHECK_CC_XFLAG_BODY([-Wunknown-argument],[],
[
AS_IF([test -z "$mhd_CFLAGS_params_warn"],
[mhd_CFLAGS_params_warn='-Wunknown-argument'],
[mhd_CFLAGS_params_warn="$mhd_CFLAGS_params_warn -Wunknown-argument"]
)
],[],[mhd_cv_cc_flag_Wwarn]
)
AS_IF([test -z "$mhd_CFLAGS_params_warn"],
[mhd_CFLAGS_params_warn="$mhd_cv_cc_flag_Wwarn"],
[mhd_CFLAGS_params_warn="$mhd_cv_cc_flag_Wwarn $mhd_CFLAGS_params_warn"]
MHD_APPEND_FLAG_TO_VAR([mhd_xFLAGS_params_warn],[-Wunknown-argument])
],[],[mhd_cv_cc_flag_Wwarn],[[CFLAGS]]
)
MHD_PREPEND_FLAG_TO_VAR([mhd_xFLAGS_params_warn],[$mhd_cv_cc_flag_Wwarn])
])
#
# SYNOPSIS
#
# MHD_FIND_CC_FLAG_WWARN()
# MHD_FIND_CC_CFLAG_WWARN()
#
AC_DEFUN([MHD_FIND_CC_FLAG_WWARN],[dnl
AC_DEFUN([MHD_FIND_CC_CFLAG_WWARN],[dnl
AC_PREREQ([2.64])dnl for AS_VAR_IF, m4_ifnblank
AC_REQUIRE([AC_PROG_CC])dnl
AC_LANG_ASSERT([C])dnl
+43
View File
@@ -0,0 +1,43 @@
# SYNOPSIS
#
# MHD_CHECK_CC_LDFLAG([FLAG-TO-TEST], [VARIABLE-TO-PREPEND-LDFLAGS],
# [ACTION-IF-SUPPORTED], [ACTION-IF-NOT-SUPPORTED])
#
# DESCRIPTION
#
# This macro checks whether the specific compiler flag is supported.
# The check is performing by prepending FLAG-TO-TEST to LDFLAGS, then
# prepending value of VARIABLE-TO-PREPEND-LDFLAGS (if any) to LDFLAGS, and
# then performing compile and link test. If test succeed without warnings,
# then the flag is considered to be suppoted. Otherwise, if compile and link
# without test flag can be done without any warning, the flag is considered
# to be unsuppoted.
#
# Example usage:
#
# MHD_CHECK_CC_LDFLAG([-pie], [additional_LDFLAGS],
# [additional_LDFLAGS="${additional_LDFLAGS} -pie"])
#
# Defined cache variable used in check so if any test will not work
# correctly on some platform, user may simply fix it by giving cache
# variable in configure parameters, for example:
#
# ./configure mhd_cv_cc_fl_supp__wshadow=no
#
# This simplify building from source on exotic platforms as patching
# of configure.ac is not required to change results of tests.
#
# LICENSE
#
# Copyright (c) 2022 Karlson2k (Evgeny Grin) <k2k@narod.ru>
#
# Copying and distribution of this file, with or without modification, are
# permitted in any medium without royalty provided the copyright notice
# and this notice are preserved. This file is offered as-is, without any
# warranty.
#serial 1
AC_DEFUN([MHD_CHECK_CC_LDFLAG],[dnl
_MHD_CHECK_CC_XFLAG([$1],[$2],[$3],[$4],[[LDFLAGS]])dnl
])
+70
View File
@@ -0,0 +1,70 @@
# SYNOPSIS
#
# MHD_FIND_ADD_CC_CFLAG([VARIABLE-TO-EXTEND],
# [FLAG1-TO-TEST], [FLAG2-TO-TEST], ...)
#
# DESCRIPTION
#
# This macro checks whether the specific compiler flags are supported.
# The flags are checked one-by-one. The checking is stopped when the first
# supported flag found.
# The checks are performing by appending FLAGx-TO-TEST to the value of
# VARIABLE-TO-EXTEND (CFLAGS if not specified), then prepending result to
# CFLAGS (unless VARIABLE-TO-EXTEND is CFLAGS), and then performing compile
# and link test. If test succeed without warnings, then the flag is added to
# VARIABLE-TO-EXTEND and next flags are not checked. If compile-link cycle
# cannot be performed without warning with all tested flags, no flag is
# added to the VARIABLE-TO-EXTEND.
#
# Example usage:
#
# MHD_CHECK_CC_CFLAG([additional_CFLAGS],
# [-ggdb3], [-g3], [-ggdb], [-g])
#
# Note: Unlike others MHD_CHECK_*CC_CFLAG* macro, this macro uses another
# order of parameters.
#
# LICENSE
#
# Copyright (c) 2022 Karlson2k (Evgeny Grin) <k2k@narod.ru>
#
# Copying and distribution of this file, with or without modification, are
# permitted in any medium without royalty provided the copyright notice
# and this notice are preserved. This file is offered as-is, without any
# warranty.
#serial 1
AC_DEFUN([MHD_FIND_ADD_CC_CFLAG],[dnl
_MHD_FIND_ADD_CC_XFLAG([[CFLAGS]],$@)])
# SYNOPSIS
#
# _MHD_FIND_ADD_CC_XFLAG([CFLAGS|LDFLAGS],
# [VARIABLE-TO-EXTEND],
# [FLAG1-TO-TEST], [FLAG2-TO-TEST], ...)
#
AC_DEFUN([_MHD_FIND_ADD_CC_XFLAG],[dnl
AC_PREREQ([2.64])dnl for m4_ifnblank
AC_LANG_ASSERT([C])dnl
m4_if(m4_eval([$# >= 3]), [0], [m4_fatal([$0: Macro must have at least three parameters])])dnl
m4_ifblank([$3],[m4_fatal([$0: Third macro argument must not be empty])])dnl
m4_bmatch(_mhd_norm_expd([$1]), [^\(CFLAGS\|LDFLAGS\)$],[],dnl
[m4_fatal([$0: First macro argument must be either 'CFLAGS' or 'LDFLAGS; ']_mhd_norm_expd([$5])[' is not supported])])dnl
m4_ifnblank([$2],[_MHD_FIND_ADD_CC_XFLAG_BODY($@)],dnl
[_MHD_FIND_ADD_CC_XFLAG_BODY([$1],[$1],m4_shift2($@))])dnl
])
m4_define([_MHD_FIND_ADD_CC_XFLAG_BODY],[dnl
m4_version_prereq([2.64])dnl for m4_ifnblank
m4_if([$#],[0],[m4_fatal([$0: no parameters])])dnl
m4_bmatch(_mhd_norm_expd([$1]),[^\(CFLAGS\|LDFLAGS\)$],[],dnl
[m4_fatal([$0: First macro argument must be either 'CFLAGS' or 'LDFLAGS; ']_mhd_norm_expd([$5])[' is not supported])])dnl
m4_if([$#],[1],[m4_fatal([$0: not enough parameters])])dnl
m4_if([$#],[2],[m4_fatal([$0: not enough parameters])])dnl
m4_if([$#],[3],[m4_ifnblank([$3],[_MHD_CHECK_ADD_CC_XFLAG([$3],[$2],[],[],[$1])])],
[m4_ifnblank([$3],[_MHD_CHECK_ADD_CC_XFLAG([$3],[$2],[],[$0([$1],[$2],m4_shift3($@))],[$1])],
[$0([$1],[$2],m4_shift3($@))])])dnl
])
+39
View File
@@ -0,0 +1,39 @@
# SYNOPSIS
#
# MHD_FIND_ADD_CC_LDFLAG([VARIABLE-TO-EXTEND],
# [FLAG1-TO-TEST], [FLAG2-TO-TEST], ...)
#
# DESCRIPTION
#
# This macro checks whether the specific compiler flags are supported.
# The flags are checked one-by-one. The checking is stopped when the first
# supported flag found.
# The checks are performing by appending FLAGx-TO-TEST to the value of
# VARIABLE-TO-EXTEND (LDFLAGS if not specified), then prepending result to
# LDFLAGS (unless VARIABLE-TO-EXTEND is LDFLAGS), and then performing compile
# and link test. If test succeed without warnings, then the flag is added to
# VARIABLE-TO-EXTEND and next flags are not checked. If compile-link cycle
# cannot be performed without warning with all tested flags, no flag is
# added to the VARIABLE-TO-EXTEND.
#
# Example usage:
#
# MHD_CHECK_CC_LDFLAG([additional_LDFLAGS],
# [-Wl,--strip-all], [-Wl,--strip-debug])
#
# Note: Unlike others MHD_CHECK_*CC_LDFLAG* macro, this macro uses another
# order of parameters.
#
# LICENSE
#
# Copyright (c) 2022 Karlson2k (Evgeny Grin) <k2k@narod.ru>
#
# Copying and distribution of this file, with or without modification, are
# permitted in any medium without royalty provided the copyright notice
# and this notice are preserved. This file is offered as-is, without any
# warranty.
#serial 1
AC_DEFUN([MHD_FIND_ADD_CC_LDFLAG],[dnl
_MHD_FIND_ADD_CC_XFLAG([[LDFLAGS]],$@)])