# Links against pdpclib created with makefile.es6

VPATH=src;src/bytearray;src/hashtab

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

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

OBJS=bytearray.obj coff.obj coff_bytearray.obj error.obj hashtab.obj ld.obj libld.obj link.obj map.obj sections.obj symbols.obj xmalloc.obj

TARGET=pdld.efi

all: clean $(TARGET)

$(TARGET): $(OBJS)
  $(LD) $(LDFLAGS) -subsystem 10 -e efimain -o $(TARGET) ../pdpclib/efistart.obj $(OBJS) ../pdpclib/pdpefi.lib

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

clean:
  rm -f $(OBJS) $(TARGET)

BOOTSTRAP_AS=x86_64-w64-mingw32-as
BOOTSTRAP_LD=x86_64-w64-mingw32-ld

bootstrap: set_bootstrap all

set_bootstrap:
  $(eval AS=$(BOOTSTRAP_AS))
  $(eval LD=$(BOOTSTRAP_LD))
