wmii/util/compile

78 lines
1.6 KiB
Plaintext
Raw Permalink Normal View History

#!/bin/sh -f
2009-10-10 00:40:33 +04:00
CC=$1
PACKAGES=$2
CFLAGS=$3; shift 3
[ -n "$PACKAGES" ] && CFLAGS="$CFLAGS $(pkg-config --cflags $PACKAGES)"
2009-10-10 00:40:33 +04:00
outfile="$1"; shift
bin="$(echo $0 | sed 's,/[^/]*$,,')"
2010-07-27 22:28:04 +04:00
xtmp=/tmp/cc.$$.$USER.out
# Derived from Russ Cox's 9c in plan9port.
echo CC $($bin/cleanname ${BASE}$outfile)
2007-07-17 00:52:35 +04:00
[ -n "$noisycc" ] && echo $CC -o $outfile $CFLAGS $@
eval '$CC -o $outfile '"$CFLAGS"' $@ >$xtmp 2>&1'
status=$?
2010-05-27 11:58:02 +04:00
[ $status -eq 0 ] || echo $CC -o $outfile $CFLAGS $@ >&2
2007-07-02 01:43:27 +04:00
base=$(echo $BASE | sed 's/,/\\,/g')
re='\([^[:space:]/][^[:space:]]*\..:[0-9]\)'
undup() { # GCC is crap.
awk '
function shift() {
for(n=1; n<=3; n++)
if(2*n <= nl)
for(i=1; i<=n; i++) {
if(l[i] != l[i+n])
break;
if(i == n) {
for(i=1; i<=n; i++)
print l[i]
nl -= 2*n;
for(i=1; i<=nl; i++)
l[i] = l[i+2*n];
return;
}
}
if(nl == 0)
return
print l[1]
for(i=1; i<nl; i++)
l[i] = l[i+1]
nl--
}
BEGIN{
nl=0
maxl=6
}
2010-10-08 00:31:41 +04:00
tolower($0) ~ /: (error|note): .?each undeclared identifier|: error: for each function it appears|is dangerous, better use|is almost always misused|: in function |: at top level:|support .long long.|use of c99 long long|iso c forbids conversion|warning:.*warn_unused_result/ {
2010-07-27 22:28:04 +04:00
next
}
$1 == "warning:" {
t = $2 " " $1
sub(/^[^ ]+ [^ ]+ /, "")
$0 = t " " $0
}
{
2010-07-27 22:28:04 +04:00
sub(/\[/, ": [", $1)
if(nl == maxl)
shift()
l[++nl] = $0
}
END{
while(nl > 0)
shift();
}'
}
2007-07-02 01:43:27 +04:00
cat $xtmp | sed "s,^$re,$base&,g; s,\([[:space:]]\)$re,\1$base\2,g" |
sed 's/ .first use in this function.$//; s/\"\([^\"][^\"]*\)\", line \([0-9][0-9]*\)/\1:\2/g' |
2010-07-27 22:28:04 +04:00
undup >&2
rm -f $xtmp
exit $status