# Produces x64 EFI executable that is a shim to an
# x86 PE32 module running in CM32.
# Using cc64 as compiler

# We link with the library produced by makefile.ne6
# And we (don't) use makefile.p64 and makecomm.p64
# which are PE. Or makecomm.c64

# Define CM16 for a 16-bit version instead

# We need this executable to load below the 4 GiB mark.
# So we use the image-base keyword on the link step

# See makefile.h32 for more documentation

CC=cc64
AR=xar
LD=pdld --no-insert-timestamp
AS=pdas --64 --oformat coff
COPTS=-D__64BIT__ -D__EFI__ -D__EFIBIOS__ -U__WIN32__ -D__CC64__ \
    -I../pdpclib -I../bios -I. -I../src -DNEED_ELF -D__NO_LONG_LONG__ \
    -DTARGET_64BIT -DNEED_MZ -DNO_DLLENTRY -DW64EMUL -D__CC64OS__ \
    -DGENSHELL -DSHIMCM32 -DXCM16

all: clean bios.exe

OBJS=../bios/exeload.obj shimcm32.obj

bios.exe: bios.obj $(OBJS)
    $(LD) -s -subsystem 10 -e efimain -nostdlib --image-base 0x400000 -o bios.exe bios.obj $(OBJS) ../pdpclib/pdpefi.lib

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

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

clean:
    rm -f *.obj bios.exe
