Blob


1 #!/bin/sh
3 test -f $PLAN9/config && . $PLAN9/config
4 usegcc()
5 {
6 cc=${CC9:-gcc}
7 cflags=" \
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 -fcommon \
24 "
25 # want to put -fno-optimize-sibling-calls here but
26 # that option only works with gcc3+ it seems
27 cflags="$cflags -ggdb"
28 cflags="$cflags $CC9FLAGS"
29 case "$cflags" in
30 *sanitize=address*)
31 cflags="$cflags -DPLAN9PORT_ASAN"
32 esac
33 }
35 quiet()
36 {
37 # The uniq at the end is for gcc's strcmp/etc. built-in nonsense,
38 # which multiplies single errors as a result of its expansion.
39 # The "Cursor. is deprecated" kills off warnings from Apple
40 # about using SetCursor/InitCursor. (Okay, they're deprecated,
41 # but you could at least tell us what to use instead, Apple!)
43 ignore=': error: .Each undeclared identifier'
44 ignore=$ignore'|: error: for each function it appears'
45 ignore=$ignore'|is dangerous, better use'
46 ignore=$ignore'|is almost always misused'
47 ignore=$ignore'|: In function '
48 ignore=$ignore'|: At top level:'
49 ignore=$ignore'|support .long long.'
50 ignore=$ignore'|In file included from'
51 ignore=$ignore'| from'
52 ignore=$ignore'|use of C99 long long'
53 ignore=$ignore'|ISO C forbids conversion'
54 ignore=$ignore'|marked deprecated'
55 ignore=$ignore'|is deprecated'
56 ignore=$ignore'|warn_unused_result'
57 ignore=$ignore'|expanded from macro'
59 grep -v '__p9l_autolib_' $1 |
60 egrep -v "$ignore" |
61 sed 's/ .first use in this function.$//; s/\"\([^\"][^\"]*\)\", line \([0-9][0-9]*\)/\1:\2/g' |
62 $(which uniq) 1>&2 # avoid built-in uniq on SunOS
63 }
65 useclang()
66 {
67 cc=${CC9:-clang}
68 cflags=" \
69 -O2 \
70 -c \
71 -Wall \
72 -Wno-parentheses \
73 -Wno-missing-braces \
74 -Wno-switch \
75 -Wno-comment \
76 -Wno-sign-compare \
77 -Wno-unknown-pragmas \
78 -Wno-empty-body \
79 -Wno-unused-value \
80 -Wno-array-bounds \
81 -Wno-gnu-designator \
82 -Wno-array-bounds \
83 -Wno-unneeded-internal-declaration \
84 -fsigned-char \
85 -fno-caret-diagnostics \
86 "
87 cflags="$cflags -g"
88 cflags="$cflags $CC9FLAGS"
90 case "$cflags" in
91 *sanitize=address*)
92 cflags="$cflags -DPLAN9PORT_ASAN"
93 esac
94 }
96 usexlc()
97 {
98 cc=${CC9:-xlc_r}
99 cflags=" \
100 -c \
101 -O0 \
102 -qmaxmem=-1 \
103 -qsuppress=1506-236 \
104 -qsuppress=1506-358 \
105 -qsuppress=1500-010 \
106 -qsuppress=1506-224 \
107 -qsuppress=1506-1300 \
108 -qsuppress=1506-342 \
110 cflags="$cflags -g -qfullpath"
111 cflags="$cflags $CC9FLAGS"
114 tag="${SYSNAME:-`uname`}-${OBJTYPE:-`uname -m`}-${CC9:-cc}"
115 case "$tag" in
116 *DragonFly*gcc*|*BSD*gcc*) usegcc ;;
117 *DragonFly*clang|*BSD*clang*) useclang ;;
118 *Darwin-x86_64*)
119 useclang
120 cflags="$cflags -g3 -m64"
121 ;;
122 *Darwin*clang*)
123 useclang
124 cflags="$cflags -g3 -m32"
125 ;;
126 *Darwin*) usegcc
127 cflags="$cflags -g3 -no-cpp-precomp -m32" ;;
128 *HP-UX*) cc=${CC9:-cc}; cflags="-g -O -c -Ae" ;;
129 *Linux*) usegcc
130 case "${CC9:-gcc}" in
131 tcc)
132 cc=tcc
133 cflags="-c -g"
134 ;;
135 esac
136 ;;
137 *OSF1*) cc=${CC9:-cc}; cflags="-g -O -c" ;;
138 *SunOS*-cc) cc=cc;
139 cflags="-mt -g -O -c -xCC -D__sun__"
140 u=`uname`
141 v=`uname -r`
142 s=`echo $u$v | tr '. ' '__'`
143 cflags="$cflags -D__${s}__"
144 ;;
145 *SunOS*-gcc) usegcc
146 u=`uname`
147 v=`uname -r`
148 s=`echo $u$v | tr '. ' '__'`
149 cflags="$cflags -g"
150 cflags="$cflags -D__sun__ -D__${s}__"
151 ;;
152 *AIX*) usexlc
153 cflags="$cflags -g -D__AIX__"
154 ;;
155 *)
156 echo 9c does not know how to compile on "$tag" 1>&2
157 exit 1
158 esac
160 # N.B. Must use temp file to avoid pipe; pipe loses status.
161 xtmp=${TMPDIR-/tmp}/9c.$$.$USER.out
162 $cc -DPLAN9PORT -I$PLAN9/include $cflags "$@" 2>$xtmp
163 status=$?
164 quiet $xtmp
165 rm -f $xtmp
166 exit $status