scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | README | LICENSE

cc.sh (762B)


      1 #!/bin/sh
      2 
      3 set -e
      4 
      5 for i
      6 do
      7 	case "$i" in
      8 	-r)
      9 		root=$2
     10 		shift 2
     11 		;;
     12 	-a)
     13 		abi=$2
     14 		shift 2
     15 		;;
     16 	-s)
     17 		sys=$2
     18 		shift 2
     19 		;;
     20 	-o)
     21 		out=$2
     22 		shift 2
     23 		;;
     24 	-*)
     25 		echo usage: cc.sh [-t target] file
     26 		exit 1
     27 		;;
     28 	esac
     29 done
     30 
     31 sys=${sys:-`uname | tr 'A-Z' 'a-z'`}
     32 abi=${abi:-amd64-sysv}
     33 out=${out:-a.out}
     34 root=${root:-$SCCPREFIX}
     35 inc=$root/include/scc
     36 arch_inc=$root/include/scc/bits/$abi
     37 sys_inc=$root/include/scc/bits/$sys
     38 lib=$root/lib/scc/${abi}-${sys}
     39 obj=${1%.c}.o
     40 
     41 includes="-nostdinc -I$inc -I$arch_inc -I$sys_inc"
     42 flags="-std=c99 -g -w -fno-stack-protector --freestanding -static"
     43 
     44 if ! gcc -nopie 2>&1 | grep unrecogn >/dev/null
     45 then
     46 	pie=-nopie
     47 fi
     48 
     49 gcc $flags $pie $includes -c $1
     50 ld -g $pie -z nodefaultlib -static -L$lib $lib/crt.o $obj -lc -o $out