# This is the makefile for 32-bit z/Linux to build pdpclib using
# the gcc390 compiler.
#
# Note that simply adding --64 to the LD command will force a
# 64-bit ELF to be created, so that you can use qemu-s390x
# But it will presumably fail if negative indexes are used.
# Which could be solved by mapping the 4 GiB to 8 GiB region
# on to 0 GiB to 4 GiB, to provide effective AM32.
# The executable also works on real z/Linux, and the 32-bit
# relocations are apparently accepted (or ignored).

# However, there is currently a failsafe in lz3supa.asm that
# deliberately does a negative index. So you'll need to disable
# that, and hope that the rest of your code doesn't generate
# negative indexes. They aren't very common, so there is a good
# chance your program will work fine.

#LDEXTRA=--64

CC=gcc390
AS=as390
LD=pdld $(LDEXTRA) --oformat elf --output-e-machine EM_S390 --entry __pdpent --emit-relocs
AR=xar

COPTS=-Os -fno-builtin -nostdlib -nostdinc -I . \
    -D__USEBIVA__ -fno-common


pdptest.exe: linstart.o lz3supa.o pdptest.o stdio.o string.o stdlib.o \
       start.o time.o errno.o assert.o signal.o locale.o \
       ctype.o setjmp.o math.o __memmgr.o
	rm -f pdplinux.a
	$(AR) r pdplinux.a linstart.o lz3supa.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 setjmp.o math.o __memmgr.o
        $(AR) s pdplinux.a
	$(LD) -nostdlib -o pdptest pdptest.o pdplinux.a

.c.o:
	$(CC) -S -o $*.s $(COPTS) $<
        $(AS) -o $@ $*.s
        rm -f $*.s

lz3supa.o: lz3supa.asm
	$(AS) -o $@ $*.asm
