summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormidipix <writeonce@midipix.org>2018-12-22 10:41:59 -0500
committermidipix <writeonce@midipix.org>2018-12-22 19:18:08 -0500
commite0398c7ac19765f10a0298a1bb67c1f63c5c9e4c (patch)
tree7c7311af265d876d23af0f58683df2a6daf8e671
parentf3ded2b2a12a85af58493f0d0e827b32782882e3 (diff)
downloadsbpython2-e0398c7ac19765f10a0298a1bb67c1f63c5c9e4c.tar.bz2
sbpython2-e0398c7ac19765f10a0298a1bb67c1f63c5c9e4c.tar.xz
sofort: cfgtest.sh: added cfgtest_type_size(), cfgtest_unit_type_size().
-rw-r--r--sofort/cfgtest.sh57
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
+}