# This is the makefile for Linux to build pdpclib for ARM64 UEFI using
# the gcc compiler and pdld.

# Probably want to add -ffixed-x18 if Windows or MacOS are involved, to
# stop that register from being used

ifeq "$(tools)" "macwin"
CC=aarch64-none-elf-gcc -D__LONG64__
AR=aarch64-none-elf-ar
AS=aarch64-none-elf-as
ASPARM=--defsym ELF=1

else ifeq "$(tools)" "mingw64"
CC=gcc -U__WIN32__ -D__GENSHELL__ -DWINNEWMOD \
    -D__USEBIVA__ -D__NOSPECBIVA__
AR=ar
AS=as
ASPARM=

else
CC=gcc -D__LONG64__
AR=ar
AS=as
ASPARM=--defsym ELF=1
endif

COPTS=--no-pie -D__EFI__ -D__EFIBIOS__ -c -O2 \
  -D__ARM__ -fno-builtin -D__64BIT__ -I . -fno-stack-protector \
  -U__gnu_linux__ -D__GENSHELL__


pdptest: efistart.o a64supa.o pdptest.o stdio.o string.o stdlib.o \
       start.o time.o errno.o assert.o signal.o locale.o \
       ctype.o math.o __memmgr.o
	rm -f pdpefi.a
	$(AR) r pdpefi.a efistart.o a64supa.o stdio.o string.o stdlib.o
	$(AR) r pdpefi.a start.o time.o errno.o assert.o signal.o
	$(AR) r pdpefi.a locale.o ctype.o math.o __memmgr.o
	pdld --no-insert-timestamp -o pdptest.efi -e efimain --oformat coff --subsystem 10 efistart.o pdptest.o pdpefi.a

.c.o:
	$(CC) $(COPTS) $<

a64supa.o: a64supa.asm
	$(AS) --defsym STACKPARM=0 $(ASPARM) -o $@ $*.asm
