# This is the makefile for Linux to build pdpclib using
# the gcc compiler for ARM64.
#
# If using mingw64, add tools=mingw64
#

ifeq "$(tools)" "mingw64"
CC=gcc -U__WIN32__ -D__GENSHELL__ -DWINNEWMOD
ASPARM=
else
CC=gcc -D__LONG64__
ASPARM=--defsym ELF=1
endif

COPTS=-c -O2 -D__ARM__ -nostdinc -nostdlib -fno-builtin \
    -D__64BIT__ -I . -fno-stack-protector --no-pie -D__USEBIVA__ \
    -D__NOSPECBIVA__ -D__gnu_linux__

# We need to use ld until we have pdld available
# No need for gcc - we can use ld directly
###LD=gcc -static

ifeq "$(altld)" "ld"
LD=ld -s --emit-relocs -e __pdpent
else
LD=pdld --oformat elf --emit-relocs -e __pdpent
endif

pdptest: linstart.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 pdplinux.a
	ar r pdplinux.a linstart.o a64supa.o stdio.o string.o stdlib.o
	ar r pdplinux.a start.o time.o errno.o assert.o signal.o
	ar r pdplinux.a locale.o ctype.o math.o __memmgr.o
	$(LD) -s -nostdlib -o pdptest linstart.o a64supa.o pdptest.o pdplinux.a

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

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