ANN: Fixed name detection bug in presence of "The".
[utils.git] / sztest
CommitLineData
1c2fdcc2
FT
1#!/bin/sh
2
3if [ $# -lt 1 ]; then
c5f010d4 4 echo "usage: sztest [-H SYS-HEADER] [-L LOCAL-HEADER] TYPE [CCFLAGS...]" >&2
1c2fdcc2
FT
5 exit 1
6fi
7
c5f010d4
FT
8sheaders=
9lheaders=
1c2fdcc2
FT
10while [ "${1:0:1}" = "-" ]; do
11 opt="$1"
12 shift
13 case "$opt" in
14 "-H")
c5f010d4
FT
15 sheaders="$sheaders $1"
16 shift
17 ;;
18 "-L")
19 lheaders="$lheaders $1"
1c2fdcc2
FT
20 shift
21 ;;
22 esac
23done
24type="$1"
25shift
26file="$(mktemp /tmp/sztestXXXXXX)"
27cat >"$file.c" <<EOF
28#include <stdio.h>
29#include <stdint.h>
30#include <sys/types.h>
31#include <unistd.h>
32#include <sys/stat.h>
33EOF
c5f010d4 34for header in $sheaders; do
1c2fdcc2
FT
35 echo "#include <$header>" >>"$file.c"
36done
c5f010d4
FT
37for header in $lheaders; do
38 echo "#include \"$header\"" >>"$file.c"
39done
1c2fdcc2
FT
40cat >>"$file.c" <<EOF
41int main(int argc, char **argv)
42{
43 printf("%zi\n", sizeof($type));
44 return(0);
45}
46EOF
47
c5f010d4 48if ! gcc "$@" -iquote. -g -Wall -o "$file" "$file.c"; then
1c2fdcc2
FT
49 rm -f "$file" "$file.c"
50 exit 1
51fi
52"$file"
53rm "$file" "$file.c"