scc

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

cc.sh (839B)


      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 [-o outfile][-r root][-a abi][-s sys] file
     26 		exit 1
     27 		;;
     28 	esac
     29 done
     30 
     31 sys=${sys:-`uname | tr 'A-Z' 'a-z'`}
     32 abi=${abi:-amd64}
     33 out=${out:-a.out}
     34 root=${root:-$SCCPREFIX}
     35 inc=$root/include
     36 arch_inc=$inc/bits/$abi
     37 sys_inc=$inc/bits/$sys
     38 lib=$root/lib/scc/${abi}-${sys}
     39 crt=$root/lib/scc/${abi}-${sys}/crt.o
     40 obj=${1%.c}.o
     41 cc=${CROSS_COMPILE}gcc
     42 ld=${CROSS_COMPILE}ld
     43 
     44 includes="-nostdinc -I$inc -I$arch_inc -I$sys_inc"
     45 flags="-std=c99 -g -w -fno-stack-protector --freestanding -static"
     46 
     47 if ! ${cc} -nopie 2>&1 | grep unrecogn >/dev/null
     48 then
     49 	pie=-no-pie
     50 fi
     51 
     52 ${cc} $flags $pie $includes -c $1
     53 ${ld} -g -z nodefaultlib -static -L$lib $obj $crt -lc -lcrt -o $out