| From f411b502222c8fe442d7b3beb00b530c9e16b7a2 Mon Sep 17 00:00:00 2001 |
| From: "Van Bemten, Lionel (Nokia - BE/Antwerp)" <lionel.van_bemten@nokia.com> |
| Date: Sun, 29 Apr 2018 19:53:40 +0200 |
| Subject: [PATCH] No runtime tests for type sizes |
| |
| Replace build and execution of runtime test programs for determining |
| some type sizes of the target with compile time test programs. |
| |
| This improves support for cross-compilation. |
| |
| Signed-off-by: "Van Bemten, Lionel (Nokia - BE/Antwerp)" <lionel.van_bemten@nokia.com> |
| Signed-off-by: Eric Le Bihan <eric.le.bihan.dev@free.fr> |
| --- |
| configure | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++------------- |
| 1 file changed, 60 insertions(+), 15 deletions(-) |
| |
| diff --git a/configure b/configure |
| index 434eec8..c09e9c8 100755 |
| --- a/configure |
| +++ b/configure |
| @@ -155,23 +155,69 @@ choose () { |
| fi |
| } |
| |
| +findtypesize () { |
| + typ=$1 |
| + abbr=$2 |
| + r=false |
| + type_size=0 |
| + while true; do |
| + cat>trysizeof${abbr}.c<<EOF |
| +#include <sys/types.h> |
| + |
| +int main(void) |
| +{ |
| + static int v = 1 / !!((sizeof($typ) == $type_size)); |
| + return 0; |
| +} |
| +EOF |
| + if $CC_AUTO $CPPFLAGS_AUTO $CPPFLAGS $CPPFLAGS_POST $CFLAGS_AUTO $CFLAGS $CFLAGS_POST $LDFLAGS_AUTO $LDFLAGS $LDFLAGS_POST -o trysizeof${abbr} trysizeof${abbr}.c 2>/dev/null; then |
| + r=true |
| + break |
| + fi |
| + type_size=$(expr $type_size + 1) |
| + test $type_size -le 16 || break |
| + done |
| + rm -f trysizeof${abbr} trysizeof${abbr}.c |
| + test $r = true || fail "$0: unable to determine size of $typ" |
| + caps=$(echo "sizeof${abbr}" | tr a-z A-Z) |
| + echo "#define ${package_macro_name}_${caps} $type_size" >> $sysdeps/sysdeps.h |
| + echo "sizeof${abbr}: $type_size" >> $sysdeps/sysdeps |
| +} |
| + |
| +findtypesign () { |
| + typ=$1 |
| + abbr=$2 |
| + caps=$(echo "signed${abbr}" | tr a-z A-Z) |
| + cat>trysignof${abbr}.c<<EOF |
| +#include <sys/types.h> |
| + |
| +int main(void) |
| +{ |
| + static int v = 1 / !!(((($typ) -1) < 0)); |
| + return 0; |
| +} |
| +EOF |
| + if $CC_AUTO $CPPFLAGS_AUTO $CPPFLAGS $CPPFLAGS_POST $CFLAGS_AUTO $CFLAGS $CFLAGS_POST $LDFLAGS_AUTO $LDFLAGS $LDFLAGS_POST -o trysignof${abbr} trysignof${abbr}.c 2>/dev/null; then |
| + echo "#define ${package_macro_name}_HAS${caps}" >> $sysdeps/sysdeps.h |
| + echo "#undef ${package_macro_name}_HASUN${caps}" >> $sysdeps/sysdeps.h |
| + echo "signed${abbr}: yes" >> $sysdeps/sysdeps |
| + else |
| + echo "#undef ${package_macro_name}_HAS${caps}" >> $sysdeps/sysdeps.h |
| + echo "#define ${package_macro_name}_HASUN${caps}" >> $sysdeps/sysdeps.h |
| + echo "signed${abbr}: no" >> $sysdeps/sysdeps |
| + fi |
| + rm -f trysignof${abbr} trysignof${abbr}.c |
| +} |
| + |
| trytypes () { |
| echo "Checking size and signedness of standard types..." |
| - $CC_AUTO $CPPFLAGS_AUTO $CPPFLAGS $CPPFLAGS_POST $CFLAGS_AUTO $CFLAGS $CFLAGS_POST $LDFLAGS_AUTO $LDFLAGS $LDFLAGS_POST -o output-types src/sysdeps/output-types.c |
| - ./output-types >> $sysdeps/sysdeps |
| - ./output-types | grep -F sizeof | while read key value ; do |
| - caps=$(echo $key | sed s/:\$// | tr a-z A-Z) |
| - echo "#define ${package_macro_name}_${caps} $value" >> $sysdeps/sysdeps.h |
| + for t in "unsigned short" "unsigned int" "unsigned long"; do |
| + abbr=$(echo "$t" | sed -e 's/nsigned //') |
| + findtypesize "$t" "${abbr}" |
| done |
| - ./output-types | grep -F signed | while read key value ; do |
| - caps=$(echo $key | sed s/:\$// | tr a-z A-Z) |
| - if test $value = yes ; then |
| - echo "#define ${package_macro_name}_HAS${caps}" |
| - echo "#undef ${package_macro_name}_HASUN${caps}" |
| - else |
| - echo "#undef ${package_macro_name}_HAS${caps}" |
| - echo "#define ${package_macro_name}_HASUN${caps}" |
| - fi >> $sysdeps/sysdeps.h |
| + for t in size uid gid pid time dev ino; do |
| + findtypesize "${t}_t" "$t" |
| + findtypesign "${t}_t" "$t" |
| done |
| rm -f output-types |
| echo " ... done" |
| @@ -548,7 +594,6 @@ EOF |
| choose cl itimer ITIMER 'setitimer()' |
| choose cl namespaces NAMESPACES 'namespaces' |
| choose cl nsgetparent NSGETPARENT 'NS_GET_PARENT' |
| - choose cl explicit_bzero EXPLICIT_BZERO 'explicit_bzero()' |
| |
| echo '#endif' >> $sysdeps/sysdeps.h |
| fi |
| -- |
| 2.14.3 |
| |