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 $(which uniq) 1>&2 # avoid built-in uniq on SunOS
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-x86_64*) usegcc
74 cflags="$ngflags -g3 -no-cpp-precomp -m64" ;;
75 *Darwin*) usegcc
76 cflags="$ngflags -g3 -no-cpp-precomp -m32" ;;
77 *HP-UX*) cc=${CC9:-cc}; cflags="-g -O -c -Ae" ;;
78 *Linux*) usegcc
79 case "${CC9:-gcc}" in
80 tcc)
81 cc=tcc
82 cflags="-c -g"
83 ;;
84 esac
85 case "${SYSVERSION:-`uname -r`}" in
86 2.4.*)
87 cflags="$cflags -D__Linux24__"
88 ;;
89 2.6.*)
90 cflags="$cflags -D__Linux26__"
91 ;;
92 esac
93 ;;
94 *OSF1*) cc=${CC9:-cc}; cflags="-g -O -c" ;;
95 *SunOS*-cc) cc=cc;
96 cflags="-mt -g -O -c -xCC -D__sun__"
97 u=`uname`
98 v=`uname -r`
99 s=`echo $u$v | tr '. ' '__'`
100 cflags="$cflags -D__${s}__"
101 ;;
102 *SunOS*-gcc) usegcc
103 u=`uname`
104 v=`uname -r`
105 s=`echo $u$v | tr '. ' '__'`
106 cflags="$ngflags -g"
107 cflags="$cflags -D__sun__ -D__${s}__"
108 ;;
109 *AIX*) usegcc
110 cflags="$ngflags -g -D__AIX__"
111 ;;
112 *)
113 echo 9c does not know how to compile on "$tag" 1>&2
114 exit 1
115 esac
117 # N.B. Must use temp file to avoid pipe; pipe loses status.
118 xtmp=/tmp/9c.$$.$USER.out
119 $cc -DPLAN9PORT -I$PLAN9/include $cflags "$@" 2>$xtmp
120 status=$?
121 quiet $xtmp
122 rm -f $xtmp
123 exit $status