Blob


1 #!/bin/sh
3 test -f $PLAN9/config && . $PLAN9/config
4 usegcc()
5 {
6 cc=${CC9:-gcc}
7 ngflags=" \
8 -O2 \
9 -c \
10 -Wall \
11 -Wno-parentheses \
12 -Wno-missing-braces \
13 -Wno-switch \
14 -Wno-comment \
15 -Wno-sign-compare \
16 -Wno-unknown-pragmas \
17 -Wno-misleading-indentation \
18 -Wno-stringop-truncation \
19 -Wno-stringop-overflow \
20 -Wno-format-truncation \
21 -fno-omit-frame-pointer \
22 -fsigned-char \
23 "
24 # want to put -fno-optimize-sibling-calls here but
25 # that option only works with gcc3+ it seems
26 cflags="$ngflags -ggdb"
27 }
29 quiet()
30 {
31 # The uniq at the end is for gcc's strcmp/etc. built-in nonsense,
32 # which multiplies single errors as a result of its expansion.
33 # The "Cursor. is deprecated" kills off warnings from Apple
34 # about using SetCursor/InitCursor. (Okay, they're deprecated,
35 # but you could at least tell us what to use instead, Apple!)
37 ignore=': error: .Each undeclared identifier'
38 ignore=$ignore'|: error: for each function it appears'
39 ignore=$ignore'|is dangerous, better use'
40 ignore=$ignore'|is almost always misused'
41 ignore=$ignore'|: In function '
42 ignore=$ignore'|: At top level:'
43 ignore=$ignore'|support .long long.'
44 ignore=$ignore'|In file included from'
45 ignore=$ignore'| from'
46 ignore=$ignore'|use of C99 long long'
47 ignore=$ignore'|ISO C forbids conversion'
48 ignore=$ignore'|marked deprecated'
49 ignore=$ignore'|is deprecated'
50 ignore=$ignore'|warn_unused_result'
51 ignore=$ignore'|expanded from macro'
53 grep -v '__p9l_autolib_' $1 |
54 egrep -v "$ignore" |
55 sed 's/ .first use in this function.$//; s/\"\([^\"][^\"]*\)\", line \([0-9][0-9]*\)/\1:\2/g' |
56 $(which uniq) 1>&2 # avoid built-in uniq on SunOS
57 }
59 useclang()
60 {
61 cc=${CC9:-clang}
62 ngflags=" \
63 -O2 \
64 -c \
65 -Wall \
66 -Wno-parentheses \
67 -Wno-missing-braces \
68 -Wno-switch \
69 -Wno-comment \
70 -Wno-sign-compare \
71 -Wno-unknown-pragmas \
72 -Wno-empty-body \
73 -Wno-unused-value \
74 -Wno-array-bounds \
75 -Wno-gnu-designator \
76 -Wno-array-bounds \
77 -Wno-unneeded-internal-declaration \
78 -fsigned-char \
79 -fno-caret-diagnostics \
80 "
81 cflags="$ngflags -g"
82 }
84 tag="${SYSNAME:-`uname`}-${OBJTYPE:-`uname -m`}-${CC9:-cc}"
85 case "$tag" in
86 *DragonFly*gcc*|*BSD*gcc*) usegcc ;;
87 *DragonFly*clang|*BSD*clang*) useclang ;;
88 *Darwin-x86_64*)
89 useclang
90 cflags="$ngflags -g3 -m64"
91 ;;
92 *Darwin*clang*)
93 useclang
94 cflags="$ngflags -g3 -m32"
95 ;;
96 *Darwin*) usegcc
97 cflags="$ngflags -g3 -no-cpp-precomp -m32" ;;
98 *HP-UX*) cc=${CC9:-cc}; cflags="-g -O -c -Ae" ;;
99 *Linux*) usegcc
100 case "${CC9:-gcc}" in
101 tcc)
102 cc=tcc
103 cflags="-c -g"
104 ;;
105 esac
106 ;;
107 *OSF1*) cc=${CC9:-cc}; cflags="-g -O -c" ;;
108 *SunOS*-cc) cc=cc;
109 cflags="-mt -g -O -c -xCC -D__sun__"
110 u=`uname`
111 v=`uname -r`
112 s=`echo $u$v | tr '. ' '__'`
113 cflags="$cflags -D__${s}__"
114 ;;
115 *SunOS*-gcc) usegcc
116 u=`uname`
117 v=`uname -r`
118 s=`echo $u$v | tr '. ' '__'`
119 cflags="$ngflags -g"
120 cflags="$cflags -D__sun__ -D__${s}__"
121 ;;
122 *AIX*) usegcc
123 cflags="$ngflags -g -D__AIX__"
124 ;;
125 *)
126 echo 9c does not know how to compile on "$tag" 1>&2
127 exit 1
128 esac
130 # N.B. Must use temp file to avoid pipe; pipe loses status.
131 xtmp=${TMPDIR-/tmp}/9c.$$.$USER.out
132 $cc -DPLAN9PORT -I$PLAN9/include $cflags "$@" 2>$xtmp
133 status=$?
134 quiet $xtmp
135 rm -f $xtmp
136 exit $status