Commit | Line | Data |
---|---|---|
1c2fdcc2 FT |
1 | #!/bin/sh |
2 | ||
3 | if [ $# -lt 1 ]; then | |
c5f010d4 | 4 | echo "usage: sztest [-H SYS-HEADER] [-L LOCAL-HEADER] TYPE [CCFLAGS...]" >&2 |
1c2fdcc2 FT |
5 | exit 1 |
6 | fi | |
7 | ||
c5f010d4 FT |
8 | sheaders= |
9 | lheaders= | |
1c2fdcc2 FT |
10 | while [ "${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 | |
23 | done | |
24 | type="$1" | |
25 | shift | |
26 | file="$(mktemp /tmp/sztestXXXXXX)" | |
27 | cat >"$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> | |
33 | EOF | |
c5f010d4 | 34 | for header in $sheaders; do |
1c2fdcc2 FT |
35 | echo "#include <$header>" >>"$file.c" |
36 | done | |
c5f010d4 FT |
37 | for header in $lheaders; do |
38 | echo "#include \"$header\"" >>"$file.c" | |
39 | done | |
1c2fdcc2 FT |
40 | cat >>"$file.c" <<EOF |
41 | int main(int argc, char **argv) | |
42 | { | |
43 | printf("%zi\n", sizeof($type)); | |
44 | return(0); | |
45 | } | |
46 | EOF | |
47 | ||
c5f010d4 | 48 | if ! gcc "$@" -iquote. -g -Wall -o "$file" "$file.c"; then |
1c2fdcc2 FT |
49 | rm -f "$file" "$file.c" |
50 | exit 1 | |
51 | fi | |
52 | "$file" | |
53 | rm "$file" "$file.c" |