scc

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

gcc-scc.sh (1290B)


      1 #!/bin/sh
      2 
      3 set -e
      4 
      5 while getopts gr:a:s:o:c o
      6 do
      7 	case $o in
      8 	g)
      9 		g=-g
     10 		;;
     11 	r)
     12 		root=$OPTARG
     13 		;;
     14 	a)
     15 		abi=$OPTARG
     16 		;;
     17 	s)
     18 		sys=$OPTARG
     19 		;;
     20 	o)
     21 		out=$OPTARG
     22 		;;
     23 	c)
     24 		onlycc=1
     25 		;;
     26 	*)
     27 		echo >&2 "usage: gcc-scc [-o outfile] [-c] [-r root] [-a abi] [-s sys] file"
     28 		exit 1
     29 		;;
     30 	esac
     31 done
     32 shift $((OPTIND-1))
     33 
     34 sys=${sys:-`uname | tr 'A-Z' 'a-z'`}
     35 abi=${abi:-amd64}
     36 out=${out:-a.out}
     37 root=${root:-${SCCPREFIX:-`dirname $0`/..}}
     38 inc=$root/include/scc
     39 arch_inc=$inc/bits/$abi
     40 sys_inc=$inc/bits/$sys
     41 sys_arch_inc=$inc/bits/$sys/$abi
     42 lib=$root/lib/scc/${abi}-${sys}
     43 crt=$root/lib/scc/${abi}-${sys}/crt.o
     44 obj=${1%.c}.o
     45 cc=${CROSS_COMPILE}cc
     46 ld=${CROSS_COMPILE}ld
     47 
     48 case `uname` in
     49 OpenBSD)
     50 	nopie=-no-pie
     51 	;;
     52 esac
     53 
     54 includes="-nostdinc -I$inc -I$arch_inc -I$sys_inc -I$sys_arch_inc"
     55 cflags="-std=c99 -w -fno-pie -fno-stack-protector -ffreestanding -static"
     56 ldflags="-z nodefaultlib -static -L$lib"
     57 
     58 if test ${onlycc:-0} -eq 1
     59 then
     60 	$cc $cflags $includes -c "$@"
     61 else
     62 	for i
     63 	do
     64 		case $i in
     65 		*.c)
     66 			$cc $g $cflags $includes -c "$i"
     67 			;;
     68 		esac
     69 	done
     70 
     71 	# convert *.c args to *.o while correctly maintaing IFS chars
     72 	for i
     73 	do
     74 		shift
     75 		case $i in
     76 		*.c)
     77 			set -- "$@" "${i%c}o"
     78 			;;
     79 		*)
     80 			set -- "$@" "$i"
     81 			;;
     82 		esac
     83 	done
     84 
     85 	$ld $g $ldflags $nopie $crt "$@" -lc -lcrt -o "$out"
     86 fi