# 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 64-bit EFI uemacs.efi

# Links against pdpclib created with makefile.es6

CC=x86_64-w64-mingw32-gcc
CFLAGS=-O2
LD=pdld
LDFLAGS=--no-insert-timestamp -s
AS=pdas --64 --oformat coff
AR=ar

COPTS=$(CFLAGS) -DC90 -S -mno-red-zone -D__64BIT__ -D__EFI__ -U__WIN32__ -I. -I../pdos/pdpclib -fno-builtin -fno-common -ansi -Wno-builtin-declaration-mismatch

TARGET=uemacs.efi
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) --no-insert-timestamp -s -subsystem 10 -e efimain -o $(TARGET) ../pdos/pdpclib/efistart.obj main.obj $(TEMP_ARCHIVE) ../pdos/pdpclib/pdpefi.lib
  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)
