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