From e5f78aecc18f98288d14f568b052c8a8b35c0eff Mon Sep 17 00:00:00 2001 From: midipix Date: Sat, 22 Dec 2018 10:41:59 -0500 Subject: cfgtest.sh: added cfgtest_type_size(), cfgtest_unit_type_size(). --- sofort/cfgtest.sh | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/sofort/cfgtest.sh b/sofort/cfgtest.sh index caa000a..7f1555b 100644 --- a/sofort/cfgtest.sh +++ b/sofort/cfgtest.sh @@ -208,6 +208,55 @@ cfgtest_decl_presence() } +cfgtest_type_size() +{ + mb_internal_cflags='' + mb_internal_size='' + mb_internal_test='char x[(sizeof(%s) == %s) ? 1 : -1];' + + for mb_header in $mb_cfgtest_headers; do + mb_internal_cflags="$mb_internal_cflags --include=$mb_header" + done + + for mb_internal_guess in 8 4 2 1 16 32 64 128; do + if [ -z $mb_internal_size ]; then + mb_internal_type="$@" + + mb_internal_str=$(printf "$mb_internal_test" \ + "$mb_internal_type" \ + "$mb_internal_guess") + + printf '%s' "$mb_internal_str" \ + | $mb_cfgtest_cc -S -xc - -o - \ + $mb_cfgtest_cflags \ + $mb_internal_cflags \ + > /dev/null 2>/dev/null \ + && mb_internal_size=$mb_internal_guess + fi + done + + # unrecognized type, or type size not within range + if [ -z $mb_internal_size ]; then + return 1 + fi + + # -DSIZEOF_TYPE=SIZE + mb_internal_str=$(printf '%s%s=%s' '-DSIZEOF_' \ + "$mb_internal_type" \ + "$mb_internal_size" \ + | sed -e 's/\ /_/g' -e 's/*/P/g' \ + | tr "[:lower:]" "[:upper:]") + + if [ -z ${cfgtest_internal_unit_test:-} ]; then + cfgtest_cflags_append "$mb_internal_str" + else + cfgtest_makevar_append "$mb_internal_str" + fi + + return 0 +} + + cfgtest_library_presence() { printf 'int main(void){return 0;}' \ @@ -253,3 +302,11 @@ cfgtest_unit_decl_presence() cfgtest_decl_presence "$@" || return 1 return 0 } + + +cfgtest_unit_type_size() +{ + cfgtest_internal_unit_test='unit_test' + cfgtest_type_size "$@" || return 1 + return 0 +} -- cgit v1.2.3