# Produces Linux x64 executable capable of running
# certain Win64 executables
# You should have built pdpclib with makefile.lc6 first

ifeq "$(tools)" "mcc"
CPP=pdcc
else
CPP=pdcc -D__CC64__ -Dconst=
endif

ifeq "$(tools)" "mcc"
CC=mcc
else
CC=cc64
endif

CFLAGS=
COPTS=$(CFLAGS) -D__gnu_linux__ \
    -I . -I ../pdpclib -I../src -I../bios \
    -DNEED_MZ -DNOUNDMAIN -DXUSE_MEMMGR \
    -DNO_DLLENTRY -DGENSHELL -D__W64SHELL__ \
    -D__64BIT__ -DHAVE_DIR -DLINDIR -DTARGET_64BIT \
    -DWINNEWMOD

AR=xar
AS=pdas --oformat coff --64
LD=pdld --no-insert-timestamp
LDFLAGS=

all: clean bios

bios: bios.obj list.obj ../src/patmat.obj ../bios/exeload.obj
  $(LD) -s --oformat elf -e ___pdpstart --image-base 0x400000 -nostdlib -o bios.exe ../pdpclib/linstart.obj bios.obj list.obj ../src/patmat.obj ../bios/exeload.obj ../pdpclib/pdpwin64.lib

.c.obj:
  $(CPP) -E $(COPTS) -o $*.i $<
ifeq "$(tools)" "mcc"
  $(CC) -o:$*.s $*.i
else
  $(CC) -q -c -out:$@ $*.i
endif
  rm -f $*.i
ifeq "$(tools)" "mcc"
  $(AS) -o $@ $*.s
  rm -f $*.s
endif

clean:
  rm -f *.o bios.exe
