wmii

git clone git://oldgit.suckless.org/wmii/
Log | Files | Refs | README | LICENSE

compile (1648B)


      1 #!/bin/sh -f
      2 
      3 CC=$1
      4 PACKAGES=$2
      5 CFLAGS=$3; shift 3
      6 
      7 [ -n "$PACKAGES" ] && CFLAGS="$CFLAGS $(pkg-config --cflags $PACKAGES)"
      8 
      9 outfile="$1"; shift
     10 bin="$(echo $0 | sed 's,/[^/]*$,,')"
     11 xtmp=/tmp/cc.$$.$USER.out
     12 
     13 # Derived from Russ Cox's 9c in plan9port.
     14 
     15 echo CC $($bin/cleanname ${BASE}$outfile)
     16 [ -n "$noisycc" ] && echo $CC -o $outfile $CFLAGS $@
     17 eval '$CC -o $outfile '"$CFLAGS"' $@ >$xtmp 2>&1'
     18 status=$?
     19 [ $status -eq 0 ] || echo $CC -o $outfile $CFLAGS $@ >&2
     20 
     21 base=$(echo $BASE | sed 's/,/\\,/g')
     22 re='\([^[:space:]/][^[:space:]]*\..:[0-9]\)'
     23 
     24 undup() { # GCC is crap.
     25 	awk '
     26 	function shift() {
     27 		for(n=1; n<=3; n++)
     28 			if(2*n <= nl)
     29 			for(i=1; i<=n; i++) {
     30 				if(l[i] != l[i+n])
     31 					break;
     32 				if(i == n) {
     33 					for(i=1; i<=n; i++)
     34 						print l[i]
     35 					nl -= 2*n;
     36 					for(i=1; i<=nl; i++)
     37 						l[i] = l[i+2*n];
     38 					return;
     39 				}
     40 			}
     41 		if(nl == 0)
     42 			return
     43 		print l[1]
     44 		for(i=1; i<nl; i++)
     45 			l[i] = l[i+1]
     46 		nl--
     47 	}
     48 	BEGIN{
     49 		nl=0
     50 		maxl=6
     51 	}
     52 	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/ {
     53 		next
     54 	}
     55 	$1 == "warning:" {
     56 		t = $2 " " $1
     57 		sub(/^[^ ]+ [^ ]+ /, "")
     58 		$0 = t " " $0
     59 	}
     60 	{
     61 		sub(/\[/, ": [", $1)
     62 		if(nl == maxl)
     63 			shift()
     64 		l[++nl] = $0
     65 	}
     66 	END{
     67 		while(nl > 0)
     68 			shift();
     69 	}'
     70 }
     71 
     72 cat $xtmp | sed "s,^$re,$base&,g; s,\([[:space:]]\)$re,\1$base\2,g" |
     73 	sed 's/ .first use in this function.$//; s/\"\([^\"][^\"]*\)\", line \([0-9][0-9]*\)/\1:\2/g' |
     74 	undup >&2
     75 rm -f $xtmp
     76 exit $status
     77