# This creates a PDOS-generic app (hence the "p" in "yap"),
# suitable for running under PdAndro etc.
# It uses the gcc built with aarch64-mingw64
# The output is a PE/COFF, but the subsystem is 0, ie neither
# UEFI nor Win64 - since it is neither.
# But the function calling convention is the same.

# long is 32-bit with this compiler, so it properly matches
# the pseudobios built with Visual C.

# You should build makecomm.pa6 with tools=mingw64 first to get
# the PDOS-generic dependencies in PDPCLIB built.


CC=gcc
COPTS=-S -I../src -D__ARM__ -I. -U__WIN32__ -D__PDPCLIB_DLL \
    -D__ARMGEN__ -D__PDOSGEN__ \
    -O2 -U__gnu_linux__ \
    -D__64BIT__ -nostdlib -nostdinc \
    -D__NODECLSPEC__ \
    -fno-stack-protector --no-pie -fno-builtin -fno-common \
    -I. -I../../pdos/pdpclib -I../../pdos/generic \
    -DNO_QUICK -DARM -I../../pdos/src -ansi

AR=ar
LD=pdld --oformat coff --no-insert-timestamp --subsystem 0
#LD=ld
AS=as

all: clean tobruk.exe

tobruk.exe: tobruk.o seenby.o dtsplit.o getopts.o \
     faddr.o mailproc.o error.o prseaddr.o strinl.o \
     stritr.o estdio.o estdlib.o dtfido.o trav.o \
     exists.o reform.o patmat.o pkt.o repo.o repofile.o \
     findkblk.o slidwin.o dtsplitm.o route.o mbase.o \
     dostime.o
  rm -f temp.a
  $(AR) r temp.a seenby.o dtsplit.o getopts.o
  $(AR) r temp.a faddr.o mailproc.o error.o prseaddr.o strinl.o
  $(AR) r temp.a stritr.o estdio.o estdlib.o dtfido.o trav.o
  $(AR) r temp.a exists.o reform.o patmat.o pkt.o repo.o repofile.o
  $(AR) r temp.a findkblk.o slidwin.o dtsplitm.o route.o mbase.o
  $(AR) r temp.a dostime.o
  $(LD) -s -o tobruk.exe ../../pdos/pdpclib/pgastart.o tobruk.o temp.a ../../pdos/pdpclib/string.o ../../pdos/pdpclib/a64supa.o

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

.asm.o:
  $(AS) --defsym LINUX=0 --defsym ELF=0 --defsym STACKPARM=0 -o $@ $<

clean:
  rm -f *.o tobruk.exe
