diff options
author | midipix <writeonce@midipix.org> | 2021-05-26 02:08:52 +0000 |
---|---|---|
committer | midipix <writeonce@midipix.org> | 2021-05-26 14:37:21 +0000 |
commit | 3efe2d9e30a62a92a68eb39762a3a9400e4f1e08 (patch) | |
tree | 72cc00b3cba790fdfb7e46140a9786dc60fee6de | |
parent | 53eaf3f602d625aa16a6fcc805a7085c97fc9f85 (diff) | |
download | apimagic-3efe2d9e30a62a92a68eb39762a3a9400e4f1e08.tar.bz2 apimagic-3efe2d9e30a62a92a68eb39762a3a9400e4f1e08.tar.xz |
build system: cfgtest framework: added cfgtest_compiler_switch().
-rw-r--r-- | sofort/cfgtest/cfgtest.sh | 62 |
1 files changed, 62 insertions, 0 deletions
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' |