# This builds EFI executables for x86_64 using cc64

# At time of writing (2024-04-19), cc64 when used as a
# cross compiler (from 32-bit x86 to 64-bit x64) was
# buggy such that parameters don't work, and fgets from
# stdin doesn't work. So it needs to be run under either
# Win64 or UCX64, not Windows 2000

CC=cc64
AR=xar
LD=pdld --no-insert-timestamp
AS=sasm -f win64 -DCC64
#AS=pdas --oformat coff --64 --defsym PDAS=1 --defsym CC64=1 --no-pseudo-dot
#AS=ml64 -DCC64
COPTS=-D__64BIT__ -D__EFI__ -D__EFIBIOS__ -U__WIN32__ -I. \
    -D__CC64__ -D__CC64OS__ -D__NO_LONG_LONG__ -DWINNEWMOD

TARGET=pdptest.efi
OBJS=efistart.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 x64supa.obj

$(TARGET): clean pdptest.obj $(OBJS)
  rm -f pdpefi.lib
  $(AR) r pdpefi.lib $(OBJS)
  $(AR) s pdpefi.lib
  $(LD) -s -subsystem 10 -e efimain -nostdlib -o $(TARGET) pdptest.obj $(OBJS)

.c.obj:
  pdcc -E $(COPTS) -o $*.i $<
  $(CC) -q -c -out:$@ $*.i
  rm -f $*.i

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

clean:
  rm -f *.obj
  rm -f $(TARGET)
