#!/bin/sh
# Make all combinations of binaries
# Assumes GCC, GNU Make and DASM 2.02 with Olaf Seibert's modifications.

build8bit=TRUE
buildlinux=TRUE

while [ $# -gt 0 ]
do
	case "$1" in
	except8bit)
		build8bit=FALSE
		;;
	exceptlinux)
		buildlinux=FALSE
		;;
	*)
		echo "$0: unrecognized option '$1'."
	esac
	shift
done

BINDIR=../bin

### First make all 8-bitter .prgs:

if [ $build8bit = TRUE ]
then
	rm -f *.prg

	for target in pet3001 pet4001 vic20 c64 c128
	do
		# First make all binaries for the prlink cable:

		mkdir -p $BINDIR/$target/prlink
		make TARGET=$target RAMEXP=none CABLE=prlink prprgs
		mv prserver.prg $BINDIR/$target/prlink
		mv *.prg $BINDIR/$target

		# Then make prserver binaries for the rest of the cables
		# except transnib and prlink88, which are Amiga specific:

		for cable in pc64 c64net # transnib prlink88
		do
			make TARGET=$target RAMEXP=none CABLE=$cable \
			     cleanchosen prserver.prg
			mkdir $BINDIR/$target/$cable
			mv prserver.prg $BINDIR/$target/$cable
		done
	done

	# Make binaries with memory expansion support

	for target in c64 c128
	do
		for exp in pia reu piareu
		do
			if [ "$exp" = "piareu" ]; then
				expopt="piaexp | reuexp"
			else
				expopt=$exp"exp"
			fi

			for cable in prlink pc64 c64net # transnib prlink88
			do
				make TARGET=$target RAMEXP=$expopt \
				     CABLE=$cable cleanchosen prserver.prg
				mv prserver.prg \
				   $BINDIR/$target/$cable/pr$exp.prg
			done
		done
	done

	# Make the C128 boot sector

	make TARGET=c128 RAMEXP=none cleanchosen bootsect.bin
	mv bootsect.bin $BINDIR/$target/bootsect.std
	make TARGET=c128 RAMEXP=piaexp cleanchosen bootsect.bin
	mv bootsect.bin $BINDIR/$target/bootsect.pia
fi

if [ $buildlinux = TRUE ]
then
	mkdir -p $BINDIR/linux
	for cable in 8 4 2
	do
		rm -f prmain
		make CLIENT=Linux CABLEOBJ=prtrans$cable.o OPTIONS=-DWRAP_AROUND \
		     prmain
		mv prmain $BINDIR/linux/prmain$cable
	done
	make reallyclean
fi
