# This is the makefile for Linux to build pdpclib using
# the gcc compiler for 64-bit LoongArch64.
#

CC=gcc
COPTS=-c -O2 -D__LOONG__ -nostdinc -nostdlib -fno-builtin \
    -D__64BIT__ -I . -fno-stack-protector --no-pie -D__USEBIVA__ \
    -D__NOSPECBIVA__ -D__LONG64__ -mdirect-extern-access \
    -D__GENSHELL__ -DWINNEWMOD
AS=as
AR=ar

# Can't combine -s and --emit-relocs with ld for some reason
STRIP=strip --strip-unneeded

# No need to use gcc to link anymore
####LD=gcc -nostdlib -static -e __pdpent -L,--emit-relocs
#LD=ld -nostdlib -static -e __pdpent --emit-relocs

LD=pdld --oformat elf -e __pdpent -s --emit-relocs


pdptest: linstart.o lg6supa.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 lg6supa.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
        $(AR) s pdplinux.a
	$(LD) -nostdlib -o pdptest linstart.o lg6supa.o pdptest.o pdplinux.a
	$(STRIP) pdptest

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

lg6supa.o: lg6supa.asm
	$(AS) --defsym LINUX=1 --defsym ELF=1 -o $@ $*.asm
