libixp

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

compile (1566B)


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