blob: a19c7378cabdb4d6246ccf0daef210d9c285aa70 [file] [log] [blame]
rscdbd7b9a2003-11-23 18:29:08 +00001#!/bin/sh
2
rsceea5f6a2005-01-17 20:57:57 +00003test -f $PLAN9/config && . $PLAN9/config
rscdbd7b9a2003-11-23 18:29:08 +00004usegcc()
5{
6 cc=gcc
rsc8f314992004-03-02 17:34:15 +00007 ngflags=" \
rscdbd7b9a2003-11-23 18:29:08 +00008 -O2 \
rscdbd7b9a2003-11-23 18:29:08 +00009 -c \
rscdbd7b9a2003-11-23 18:29:08 +000010 -Wall \
11 -Wno-parentheses \
12 -Wno-missing-braces \
13 -Wno-switch \
rscd51419b2004-02-09 19:33:05 +000014 -Wno-comment \
rsc37652832003-11-25 02:36:46 +000015 -Wno-sign-compare \
wkj115d4c02004-05-03 17:26:17 +000016 -Wno-unknown-pragmas \
rscbe36ff62004-04-29 17:13:24 +000017 -fno-omit-frame-pointer \
rscdbd7b9a2003-11-23 18:29:08 +000018 "
rscbe36ff62004-04-29 17:13:24 +000019 # want to put -fno-optimize-sibling-calls here but
20 # that option only works with gcc3+ it seems
rscdc9d0ff2004-03-02 19:29:39 +000021 cflags="$ngflags -ggdb"
rscdbd7b9a2003-11-23 18:29:08 +000022}
23
rsc8f314992004-03-02 17:34:15 +000024tag="${SYSNAME:-`uname`}-${OBJTYPE:-`uname -m`}-${CC9:-cc}"
rscdbd7b9a2003-11-23 18:29:08 +000025case "$tag" in
rsc7033e492004-12-28 23:14:43 +000026*BSD*) usegcc ;;
rsc53dbac92004-03-02 16:58:49 +000027*Darwin*) usegcc
rsc8f314992004-03-02 17:34:15 +000028 cflags="$ngflags -g3 -no-cpp-precomp" ;;
rscdbd7b9a2003-11-23 18:29:08 +000029*HP-UX*) cc=cc; cflags="-g -O -c -Ae" ;;
rsc282c88f2004-09-17 22:09:31 +000030*Linux*) usegcc
rsc3b8f0b72005-07-22 18:56:31 +000031 case "${CC9:-gcc}" in
32 tcc)
33 cc=tcc
34 cflags="-c -g"
35 ;;
36 esac
rscead3e312005-01-04 21:13:58 +000037 case "${SYSVERSION:-`uname -r`}" in
rscfa267622004-12-24 07:12:30 +000038 2.6.*)
rsc282c88f2004-09-17 22:09:31 +000039 cflags="$cflags -D__Linux26__"
40 ;;
41 esac
42 ;;
rscdbd7b9a2003-11-23 18:29:08 +000043*OSF1*) cc=cc; cflags="-g -O -c" ;;
rsc0f192bb2004-03-26 05:01:11 +000044*SunOS*-cc) cc=cc;
rsc9e863cf2005-01-07 07:16:53 +000045 cflags="-mt -g -O -c -xCC -D__sun__"
rsc0f192bb2004-03-26 05:01:11 +000046 u=`uname`
rsc1b431b12004-03-26 05:05:33 +000047 v=`uname -r`
48 s=`echo $u$v | tr '. ' '__'`
rsc4fc1f5f2005-01-19 16:45:27 +000049 cflags="$cflags -D__${s}__"
rsc0f192bb2004-03-26 05:01:11 +000050 ;;
51*SunOS*-gcc) usegcc
52 u=`uname`
rsc1b431b12004-03-26 05:05:33 +000053 v=`uname -r`
54 s=`echo $u$v | tr '. ' '__'`
rsc78802e62004-04-24 04:52:49 +000055 cflags="$ngflags -g"
rsc4fc1f5f2005-01-19 16:45:27 +000056 cflags="$cflags -D__${s}__"
rsc0f192bb2004-03-26 05:01:11 +000057 ;;
rscdbd7b9a2003-11-23 18:29:08 +000058*)
59 echo 9c does not know how to compile on "$tag" 1>&2
60 exit 1
61esac
62
rscead3e312005-01-04 21:13:58 +000063# N.B. Must use temp file to avoid pipe; pipe loses status.
rsceacba192005-03-18 19:32:06 +000064# The uniq at the end is for gcc's strcmp/etc. built-in nonsense,
65# which multiplies single errors as a result of its expansion.
rscead3e312005-01-04 21:13:58 +000066xtmp=/tmp/9c.$$.$USER.out
rsc593ac8b2005-07-22 12:37:20 +000067$cc -DPLAN9PORT -I$PLAN9/include $cflags "$@" 2>$xtmp
rscd756dc52005-01-07 07:15:31 +000068status=$?
69grep -v '__p9l_autolib_' $xtmp |
rsc746d2e12006-02-14 19:38:15 +000070egrep -v ': error: .Each undeclared identifier|: error: for each function it appears|is dangerous, better use|is almost always misused|: In function |: At top level:' |
rsceacba192005-03-18 19:32:06 +000071sed 's/ .first use in this function.$//; s/\"\([^\"][^\"]*\)\", line \([0-9][0-9]*\)/\1:\2/g' |
rsc3b8f0b72005-07-22 18:56:31 +000072uniq 1>&2
rscd756dc52005-01-07 07:15:31 +000073rm -f $xtmp $xtmp.status
rscead3e312005-01-04 21:13:58 +000074exit $status