load arg

sysroot=/Developer/SDKs/MacOSX10.4u.sdk
min=10.4

fn awk {
	os awk $*
}

fn 9c {
	load arg
	args := $*
	flags=''
	(arg
		I+ {flags = $flags  -I ^ `{file2root $arg}}
		D+ {flags = $flags -$opt ^ $arg}
		'*' {echo unknown option $opt}
		- $args
	)
	cwd=`{echo $emuroot ^ `pwd}
	cc='cc -arch i386'
	cflags=(
		-O2
		-c
		-Wall
		-Wno-parentheses
		-Wno-missing-braces
		-Wno-switch
		-Wno-comment
		-Wno-sign-compare
		-Wno-unknown-pragmas
		-fno-omit-frame-pointer
		-I$cwd
		-I$emuroot/sys/MacOSX/386/include
		-I$emuroot/sys/include
		-I$emuroot/sys/libinterp
		-I$emuroot/sys/emu/port
		-isysroot $sysroot
		'-mmacosx-version-min='^$min
		)
	file=$1
	ofile = `{basename $file .c}
	ofile = `{basename $ofile .s}
	ofile = `{basename $ofile .S}
	ofile = `{echo $emuroot ^ `{cleanname -d `pwd $ofile^.o}}
	file=`{cleanname -d `pwd $file}
	file=`{echo $emuroot ^ $file}
#	echo $cc -o $ofile $cflags $flags $file
	os `{echo $cc -o $ofile $cflags $flags $file}
}

fn 9l {
	ld=$cc
	ldflags= (
		-multiply_defined suppress
		-isysroot $sysroot
		'-mmacosx-version-min='^$min
		)
	syslibs=()
	args = $*
#	echo $ld $ldflags  `{file2root $args} $syslibs
	os `{echo $ld $ldflags  `{file2root $args} $syslibs }
}

fn file2root {
	args = $*
	for (i in $args) {
		(if {~ $i '-*' } { # exclude libraries
 			echo $i
		}
		{! ~ $i '*.*'} { # and their arguments (names w/o dots -- i.e. -framework CoreFoundation, etc) 
			echo $i
		}
		{
			i = `{cleanname -d `pwd $i}
			echo $emuroot ^ $i
		})
	}
}

fn 9ar {
	ar=ar
	cwd=`{echo $emuroot ^ `pwd }
	arflags=(-r -s)
	file=$1
	file=`{cleanname -d `pwd $file}
	file=`{echo $emuroot ^ $file }
	args = ${tl $*}
#	echo $ar $arflags $file  `{file2root $args}
	os `{echo $ar $arflags $file `{file2root $args}}
}

fn svn {
	args = ${tl $*}
	os svn $1 `{file2root $args}
}
bind /sys/MacOSX/386/mkconfig /sys/mkconfig
