summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormidipix <writeonce@midipix.org>2018-12-22 10:41:59 -0500
committermidipix <writeonce@midipix.org>2018-12-24 19:22:45 -0500
commite5f78aecc18f98288d14f568b052c8a8b35c0eff (patch)
tree3ea723dfc1d0af16ca453d605412cc3aae77ba6b
parent36f693fa6c3b28d16b866033fa4cf883d9308822 (diff)
downloadsofort-e5f78aecc18f98288d14f568b052c8a8b35c0eff.tar.bz2
sofort-e5f78aecc18f98288d14f568b052c8a8b35c0eff.tar.xz
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
+}