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