# Released to the public domain.
#
# Anyone and anything may copy, edit, publish,
# use, compile, sell and distribute this work
# and all its parts in any form for any purpose,
# commercial and non-commercial, without any restrictions,
# without complying with any conditions
# and by any means.

# This makefile builds PE uemacs.exe for ARM64
# makecomm.pa6 in pdos/generic must be used before using this makefile

CC=gcc
CFLAGS=-O2
COPTS=$(CFLAGS) -S -D__PDOS386__ -D__PDOSGEN__ -D__ARMGEN__ \
    -I. -I../pdos/pdpclib -I../pdos/generic -DC90 \
    -ansi -fno-common -fno-builtin -D__64BIT__ -D__USEBIVA__ \
    -fno-stack-protector --no-pie -U__gnu_linux__
LD=pdld --no-insert-timestamp -s --emit-relocs
# Note that ld gives an error if you add -s
#LD=gcc -static -nostdlib -Wl,--emit-relocs
LDFLAGS=-e __crt0
AS=as
AR=ar

TARGET=uemacs.exe
TEMP_ARCHIVE=temp.lib
OBJS=		ansi.obj basic.obj bind.obj buffer.obj display.obj file.obj \
		fileio.obj line.obj lock.obj main.obj random.obj region.obj \
		search.obj spawn.obj termio.obj window.obj word.obj

all: clean $(TARGET)

$(TARGET): $(OBJS)
  $(AR) s $(TEMP_ARCHIVE)
  $(LD) $(LDFLAGS) -o $(TARGET) ../pdos/pdpclib/pgastart.o main.obj $(TEMP_ARCHIVE) ../pdos/pdpclib/a64supa.o
  rm -f $(TEMP_ARCHIVE)

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

clean:
  rm -f *.obj
  rm -f $(TARGET)
  rm -f $(TEMP_ARCHIVE)
