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