H='
==========
makelink target
==========
produces a link script for TLINK using the named target project file.
==========
BUGS:
==========
*	files in the project file must have name of the form c:/path/name.suf
==========
'
TARGET=FUBAR
while	:
do
case $1 in
	-h)				clear;echo "$H";exit 0;;
	[a-zA-Z]*)		TARGET=$1;break;;
esac
case $# in
	0|1)	break;;
	*)		shift;;
esac
done
case $TARGET in
	FUBAR)	clear;echo "$H";exit 69;;
	*)		;;
esac
SEGS="/se:1024"
cat - > awk.tmp <<\TAIL
BEGIN{
	nlist = 0
	MAPF = "nul.map"
	turboc = "c:\\turboc\\lib\\"
	startr = "c0m.obj+"		# 	memory model sensitive
	emulib = "emu.lib+"
	mathlib = "mathm.lib+"
	baselib = "cm.lib"
	printf("%s%s\n",turboc,startr)
	}
	{
	source = $0
	gsub(" .*","",source)
	}
/\.c/{
	gsub(".*\/","",source)
	gsub("\.c$",".obj",source)
	}
	{
	#	some fuckup here - gives a line of length 1 but null
	gsub("\/","\\\\",source)
	}
	{
	if(length(source) >= 3) {
		crap[nlist] = source
		nlist += 1
		}
	}
END{
	ix = 0
	while(ix < nlist)	{
		printf("%s",crap[ix])
		ix += 1
		if(ix < nlist)	printf("+\n")
		else			printf("\n")
		}
	printf("%s\n",EXEC)
	printf("%s\n",MAPF)
	printf("%s%s\n",turboc,emulib)
	printf("%s%s\n",turboc,mathlib)
	printf("%s%s\n",turboc,baselib)
	printf("\n")
	}
TAIL
awk -f awk.tmp "EXEC=`basename $1 .prj`.exe" $1 > barf.tmp
vi +1 barf.tmp
tlink @barf.tmp
