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