# This is the makefile for Win64 to build pdpclib using
# the cc64 compiler and static linking. Use pdmake etc
# And using the new standard tools

# You need to have run makek32.n64 before using this

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

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

ifeq "$(tools)" "mcc"
AS=sasm -f win64
GAS=pdas --oformat coff --64
else
AS=sasm -f win64 -DCC64
endif

AR=xar

CFLAGS=
COPTS=$(CFLAGS) -D__WIN32__ -D__STATIC__ \
  -I . -I../src -D__64BIT__ -DNOUNDMAIN -D__GENSHELL__

#AS=sasm -f win64 -DCC64
#AS=pdas --oformat coff --64 --defsym PDAS=1 --defsym CC64=1 --no-pseudo-dot
#AS=ml64 -DCC64
LD=pdld

all: pdptest.exe

pdptest.exe: p32start.obj pdptest.obj stdio.obj string.obj stdlib.obj \
       start.obj time.obj errno.obj assert.obj signal.obj locale.obj \
       ctype.obj setjmp.obj math.obj __memmgr.obj x64supa.obj
  cmd /c if exist pdpwin64.lib del pdpwin64.lib
  $(AR) r pdpwin64.lib p32start.obj stdio.obj string.obj stdlib.obj x64supa.obj
  $(AR) r pdpwin64.lib start.obj time.obj errno.obj assert.obj signal.obj
  $(AR) r pdpwin64.lib locale.obj ctype.obj setjmp.obj math.obj __memmgr.obj
  $(AR) s pdpwin64.lib
  $(LD) -s --no-insert-timestamp --image-base 0x400000 -nostdlib -o pdptest.exe p32start.obj pdptest.obj pdpwin64.lib ../src/kernel32.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"
  $(GAS) -o $@ $*.s
  rm -f $*.s
endif

.asm.obj:
  $(AS) -o $@ $<
#  $(AS) -nologo -c -Fo$@ $<

clean:
  rm -rf *.obj
  rm -rf pdptest.exe
