sztest: Use bash specifically.
[utils.git] / sztest
... / ...
CommitLineData
1#!/bin/bash
2
3if [ $# -lt 1 ]; then
4 echo "usage: sztest [-H SYS-HEADER] [-L LOCAL-HEADER] TYPE [CCFLAGS...]" >&2
5 exit 1
6fi
7
8sheaders=
9lheaders=
10while [ "${1:0:1}" = "-" ]; do
11 opt="$1"
12 shift
13 case "$opt" in
14 "-H")
15 sheaders="$sheaders $1"
16 shift
17 ;;
18 "-L")
19 lheaders="$lheaders $1"
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
34for header in $sheaders; do
35 echo "#include <$header>" >>"$file.c"
36done
37for header in $lheaders; do
38 echo "#include \"$header\"" >>"$file.c"
39done
40cat >>"$file.c" <<EOF
41int main(int argc, char **argv)
42{
43 printf("%zi\n", sizeof($type));
44 return(0);
45}
46EOF
47
48if ! gcc "$@" -iquote. -g -Wall -o "$file" "$file.c"; then
49 rm -f "$file" "$file.c"
50 exit 1
51fi
52"$file"
53rm "$file" "$file.c"