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