### choose client system type

#CLIENT = AmigaDOS
CLIENT = Linux

## choose the default printer port (0 to 3, PC only)
DEFAULT_PORT = 0

### choose the server options

## server type
#TARGET = c128   	# Commodore 128
TARGET = c64    	# Commodore 64
#TARGET = vic20  	# Commodore VIC-20
#TARGET = pet3001	# Commodore PET 3001 series
#TARGET = pet4001	# Commodore PET 4001/8001 series

## memory expansion type
RAMEXP = none
#RAMEXP = piaexp	# the PIA-based expansion for the C64 and the 128
#RAMEXP = reuexp	# see also the actionreuplay definition in prserver.a65
#RAMEXP = piaexp | reuexp	# both of the above
#RAMEXP = pet96 	# PET 8096 memory expansion

## cables
CABLE = prlink		# the default 8-bit/4-bit cable (Amiga and PC)
#CABLE = iec		# IEC bus using the X1541 or Disk64e cables
#CABLE = prlink88	# (Amiga) the full 8-bit option of the Amiga cable
#CABLE = transnib	# (Amiga) the TransNib cable.
			# A 6-wire subset of the above.
#CABLE = pc64		# (PC) the 4-bit/4-bit PC64 cable
#CABLE = c64net		# (PC) the 4-bit/2-bit 64NET cable


### automatically choose the cable object for the clients

ifeq ($(CLIENT),AmigaDOS) ## Amiga
  CABLEOBJS = pramiga.o

  CABLEOBJ = pramiga.o	# the Amiga cable

  ifeq ($(CABLE),prlink88)
    OPTIONS = -DPRLINK88	# allow full 8-bit transfer
  endif
  ifeq ($(CABLE),transnib)
    OPTIONS = -DTRANSNIB	# use the TransNib cable (Amiga only)
  endif
  ifeq ($(CABLE),iec)
    OPTIONS = -DX1541		# X1541 cable for the IEC bus (slowest)
  endif
endif

ifeq ($(CLIENT),Linux) ## PC/Linux
  CABLEOBJS = prtrans8.o prtrans4.o prtrans2.o prtrans1.o

  OPTIONS = -DDEFAULT_PORT=$(DEFAULT_PORT)	# default printer port

  ifeq ($(CABLE),prlink)
    CABLEOBJ = prtrans8.o	# the 8-bit/4-bit cable
  endif
  ifeq ($(CABLE),pc64)
    CABLEOBJ = prtrans4.o	# the 4-bit/4-bit PC64 cable
  endif
  ifeq ($(CABLE),c64net)
    CABLEOBJ = prtrans2.o	# the 64NET cable (slow)
  endif
  ifeq ($(CABLE),iec)
    CABLEOBJ = prtrans1.o	# X1541 cable for the IEC bus (slowest)
  endif
endif

### choose the compiler and flags

CC = gcc
CFLAGS = -Wall -O6 $(OPTIONS)

ifdef DEBUG
  CFLAGS += -ggdb
  LDFLAGS += -ggdb
endif

ifdef NO_ASM
  OPTIONS += -DNO_ASM
endif

ifdef FIXED
  OPTIONS += -D__MAIN_C__
endif

ifdef DISK64E
  OPTIONS += -DDISK64E
endif

TARGETS = prload prsave prrfile prwfile prcart prdisk
MAINOBJ = prload.o prsave.o prrfile.o prwfile.o prdisk.o prcart.o \
	  prcommon.o
PRTARGETS = prserver.prg prrfile.prg prwfile.prg prdisk.prg
PRUTILS = tod.prg playtune.prg fastload.prg

ifeq ($(TARGET),c128)
  PRTARGETS += bootsect.pia bootsect.std
endif

all: clients prprgs

clients: $(TARGETS)

prmain: prmain.o $(MAINOBJ) $(CABLEOBJS)
	$(CC) $(LDFLAGS) -o $@ $^
ifeq ($(CLIENT),Linux)
	chown root $@
	chmod u+s $@
endif

ifdef FIXED
%: %.o prcommon.o $(CABLEOBJ)
	$(CC) $(LDFLAGS) -o $@ $^
ifeq ($(CLIENT),Linux)
	chown root $@
	chmod u+s $@
endif
else
$(TARGETS): prmain
	ln -sf prmain $@
endif

%.o: %.c prtrans.h prtransd.h
	$(CC) $(CFLAGS) -c $< -o $@

prprgs: $(PRTARGETS)

prutils: $(PRUTILS)

prserver.prg: prtrans.inc

%.prg: %.a65 options.inc
	dasm $< -o$@ -Mtarget="$(strip $(TARGET))" \
	-Mramexp="$(strip $(RAMEXP))" -Mcable="$(strip $(CABLE))"

bootsect.pia: bootsect.a65
	dasm $< -o$@ -f3 -Mramexp=piaexp -Mtarget=c128

bootsect.std: bootsect.a65
	dasm $< -o$@ -f3 -Mramexp=none -Mtarget=c128

clean:
	rm -f *.o *.bak *.lst a.out *~

reallyclean: clean
	rm -f prmain $(TARGETS) $(PRTARGETS) $(PRUTILS)
