diff options
author | Andrew Shadura <andrew@shadura.me> | 2015-07-25 14:44:29 +0200 |
---|---|---|
committer | Andrew Shadura <andrew@shadura.me> | 2015-07-25 14:44:29 +0200 |
commit | aba913436a8521abe405a04ed71388989e1d646f (patch) | |
tree | 0e2fea8c3ccf06ae3b370806810e382ca51f4a98 /scripts/mkc_check_sizeof | |
parent | 1d3d0bb1e461a81bc1a9cd4520958bd2b1db4c7f (diff) |
Imported Upstream version 0.25.0
Diffstat (limited to 'scripts/mkc_check_sizeof')
-rwxr-xr-x | scripts/mkc_check_sizeof | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/scripts/mkc_check_sizeof b/scripts/mkc_check_sizeof new file mode 100755 index 0000000..5b35387 --- /dev/null +++ b/scripts/mkc_check_sizeof @@ -0,0 +1,108 @@ +#!/bin/sh + +############################################################ +# Copyright (c) 2009-2010 by Aleksey Cheusov +# +# See LICENSE file in the distribution. +############################################################ + +set -e + +LC_ALL=C +export LC_ALL + +################################################## +# options +usage (){ + cat <<EOF +mkc_check_sizeof detects sizeof(type) +by compiling a test program. +mkc_check_sizeof doesn't run a generated executable +and therefore is ready for cross-compiling. + +Usage: mkc_check_sizeof type [headers...] + +Examples: + mkc_check_sizeof 'void*' + mkc_check_sizeof long-long + mkc_check_sizeof size_t stdlib.h +EOF +} + +if test $# -eq 0; then + usage + exit 1 +fi +if test "_$1" = '_-h'; then + usage + exit 0 +fi + +################################################## +# initializing + +type=`echo $1 | tr ' -' ' '` +pathpart=sizeof_`echo $type | tr '* ' 'P~'` +shift + +. mkc_check_common.sh + +################################################## +# test + +try_it (){ + # succeedes if size is bad + # $1 - test size + # $2.. - #includes + sz=$1 + shift + + for f in $MKC_COMMON_HEADERS "$@"; do + echo "#include <$f>" + done > "$tmpc" + cat >> "$tmpc" <<EOF +int main () +{ + switch (0){ + case sizeof ($type): break; + case $sz: break; + } + return 0; +} +EOF + + if $CC -c -o "${tmpo}" $CPPFLAGS $CFLAGS "${tmpc}" 2>"${tmperr}"; then + return 0 + else + return 1 + fi +} + +check_itself (){ + if try_it 2147483647 "$@" + then + for sz in 4 8 2 1 16 12 3 5 6 7 9 10 11 13 14 15; do + if try_it $sz "$@" + then + : + else + echo $sz + return + fi + done + fi + echo failed +} + +check_and_cache "checking for sizeof ${type}" "$cache" "$@" + +################################################## +# clean-ups + +cleanup + +################################################## +# finishing + +printme "$ret\n" 1>&2 +echo $ret |