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