# You need to have run makefile.n64 in pdpclib first

# Note that we need to link with x64supa.obj because we
# need the routines to support cc64-compiled programs,
# and that is not in the library itself. But you will
# get an error at run-time, not link time, if you don't
# include it, due to cc64 limitations.

VPATH=src;src/bytearray;src/hashtab;src/ftebc
CPP=pdcc
ifeq "$(tools)" "mcc"
CC=mcc
CFLAGS=
else
CC=cc64
CFLAGS=-D__CC64__ -Dconst=
endif
CFLAGS=
LD=pdld
LDFLAGS=-s -nostdlib --no-insert-timestamp --image-base 0x400000
AS=pdas --oformat coff --64
AR=xar
# cc64 goes haywire if const is used in some places, so we kill it
COPTS=-I./src -I./src/bytearray -I./src/hashtab -I./src/ftebc -I../pdpclib \
    -D__WIN32__ -D__NOBIVA__ -D__64BIT__ $(CFLAGS)

OBJS=aout.obj aout_bytearray.obj atari.obj atari_bytearray.obj binary.obj bytearray.obj \
    cms.obj coff.obj coff_bytearray.obj elf.obj \
    elf_bytearray.obj error.obj febc.obj hashtab.obj hunk.obj \
    ld.obj libld.obj link.obj lx.obj lx_bytearray.obj \
    mainframe.obj map.obj mts.obj musicsp.obj omf.obj \
    read.obj sections.obj \
    symbols.obj tebc.obj xmalloc.obj \
    vse.obj xmit.obj z390.obj \
    coff_implib_compat.obj macho.obj macho_bytearray.obj omf.obj

TARGET=pdld.exe

all: clean $(TARGET)

$(TARGET): $(OBJS)
  $(AR) s temp.lib
  $(LD) $(LDFLAGS) -o $(TARGET) ../pdpclib/w32start.obj temp.lib ../pdpclib/x64supa.obj ../pdpclib/msvcrt.lib

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

.asm.obj:
  $(AS) -o $@ $<

clean:
  rm -f $(OBJS) $(TARGET)
  rm -f temp.lib
