### 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 (suits for Amiga and PC)
#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
  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
endif

ifeq ($(CLIENT),Linux) ## PC/Linux
  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
endif

## generic
OPTIONS += -DWRAP_AROUND	# allow address wraparound in prsave

### choose the compiler and flags

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

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

TARGETS = prmain 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

all: $(TARGETS) prprgs

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

prload prsave prrfile prwfile prdisk prcart:
	ln -sf prmain $@

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

prprgs: cleanchosen $(PRTARGETS)

%.prg: %.a65 chosen.inc
	dasm $< -o$@

%.bin: %.a65 chosen.inc
	dasm $< -o$@ -f3

chosen.inc:
	echo target = "$(TARGET)" >  chosen.inc
	echo ramexp = "$(RAMEXP)" >> chosen.inc
	echo cable  = "$(CABLE)"  >> chosen.inc

cleanchosen:
	rm -f chosen.inc

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

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