diff options
author | midipix <writeonce@midipix.org> | 2018-12-22 10:41:59 -0500 |
---|---|---|
committer | midipix <writeonce@midipix.org> | 2018-12-22 19:14:21 -0500 |
commit | c5ab4e4afe5175d38eb3718cf6955103e1bd70a0 (patch) | |
tree | 73ecfda2455bb39a8e2c5dcfc98580f7d2d7aae8 /sofort | |
parent | 7d043d68cc2da5ee9911e7f4685e7589b50565c8 (diff) | |
download | sbpython3-c5ab4e4afe5175d38eb3718cf6955103e1bd70a0.tar.bz2 sbpython3-c5ab4e4afe5175d38eb3718cf6955103e1bd70a0.tar.xz |
sofort: cfgtest.sh: added cfgtest_type_size(), cfgtest_unit_type_size().
Diffstat (limited to 'sofort')
-rw-r--r-- | sofort/cfgtest.sh | 57 |
1 files changed, 57 insertions, 0 deletions
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 +} |