From 185c8947e8a09bfc7f9fe357e681fd219d4d1503 Mon Sep 17 00:00:00 2001 From: midipix Date: Wed, 26 May 2021 02:08:52 +0000 Subject: build system: cfgtest framework: added cfgtest_compiler_switch(). --- sofort/cfgtest/cfgtest.sh | 62 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/sofort/cfgtest/cfgtest.sh b/sofort/cfgtest/cfgtest.sh index 87fb4f3..736abdd 100644 --- a/sofort/cfgtest/cfgtest.sh +++ b/sofort/cfgtest/cfgtest.sh @@ -109,6 +109,11 @@ cfgtest_epilog() printf '\n\ncfgtest: could not determine size of type `%s.\n' "${3}'" >&3 printf '%s\n' '------------------------' >&3 return 1 + elif [ "${1}" = 'switch' ] && [ "${2}" = '(error)' ]; then + printf '\n\ncfgtest: the switch `%s is not supported by the %s compiler.\n' \ + "${3}'" "$mb_cfgtest_cfgtype" >&3 + printf '%s\n' '------------------------' >&3 + return 1 elif [ "${2}" = '(error)' ]; then printf '\n\ncfgtest: %s `%s is not defined or cannot be used.\n' "${1}" "${3}'" >&3 printf '%s\n' '------------------------' >&3 @@ -194,27 +199,40 @@ cfgtest_common_init() cfgtest_fmt='%s -S -xc - -o -' fi + if [ "$cfgtest_type" = 'lib' ]; then cfgtest_cmd=$(printf "$cfgtest_fmt %s %s %s" \ "$mb_cfgtest_cc" \ "$mb_cfgtest_cflags" \ "$mb_cfgtest_ldflags" \ "$cfgtest_libs") + + elif [ "$cfgtest_type" = 'switch' ]; then + cfgtest_cmd=$(printf "$cfgtest_fmt %s %s" \ + "$mb_cfgtest_cc" \ + "$mb_cfgtest_cflags" \ + "$cfgtest_switches") else cfgtest_cmd=$(printf "$cfgtest_fmt %s" \ "$mb_cfgtest_cc" \ "$mb_cfgtest_cflags") fi + if [ -z "$mb_cfgtest_headers" ] || [ "$cfgtest_type" = 'lib' ]; then cfgtest_inc= cfgtest_src="$cfgtest_code_snippet" + + elif [ "$cfgtest_type" = 'switch' ]; then + cfgtest_inc= + cfgtest_src= else cfgtest_inc=$(printf '#include <%s>\n' $mb_cfgtest_headers) cfgtest_src=$(printf '%s\n_\n' "$cfgtest_inc" \ | m4 -D_="$cfgtest_code_snippet") fi + # config.log printf "$cfgtest_fmt" "$mb_cfgtest_cc" >&3 @@ -226,6 +244,11 @@ cfgtest_common_init() for cfgtest_lib in $cfgtest_libs; do printf ' \\\n\t%s' "$cfgtest_lib" >&3 done + + elif [ "$cfgtest_type" = 'switch' ]; then + for cfgtest_switch in $cfgtest_switches; do + printf ' \\\n\t%s' "$cfgtest_switch" >&3 + done fi printf ' \\\n' >&3 @@ -513,6 +536,45 @@ cfgtest_library_presence() } +cfgtest_compiler_switch() +{ + # init + cfgtest_switches= + cfgtest_spc= + + for cfgtest_switch in ${@}; do + cfgtest_switches="$cfgtest_switches$cfgtest_spc$cfgtest_switch" + cfgtest_spc=' ' + done + + if [ "${1}" = "$cfgtest_switches" ]; then + cfgtest_prolog 'compiler switch' "$cfgtest_switches" + else + cfgtest_prolog 'compiler switch combination' "$cfgtest_switches" + fi + + cfgtest_code_snippet= + + cfgtest_common_init 'switch' + + # execute + printf '%s' "$cfgtest_src" \ + | eval $(printf '%s' "$cfgtest_cmd") \ + > /dev/null 2>&3 \ + || cfgtest_epilog 'switch' '(error)' "$@" \ + || return 1 + + # result + printf 'cfgtest: the switch `%s was accepted by the compier.\n' \ + "$cfgtest_switches'" >&3 + printf '%s\n' '------------------------' >&3 + + cfgtest_epilog 'switch' '(accepted)' + + return 0 +} + + cfgtest_unit_header_presence() { cfgtest_internal_unit_test='unit_test' -- cgit v1.2.3