# This builds the OS/2 32-bit version
# You will need to build PDPCLIB with makefile.sos first
# And you will need to use the USE_MEMMGR option because
# this program apparently does lots of small memory requests

VPATH=src;src/bytearray;src/hashtab
CC=gccwin
CFLAGS=-O2
#CFLAGS=-O2 -DNO_LONG_LONG -ansi -pedantic-errors
LD=pdld
LDFLAGS=-s --no-insert-timestamp -nostdlib --oformat lx \
    --stub ../pdpclib/needpdos.exe
AS=pdas --oformat coff
COPTS=-S $(CFLAGS) -Wall -fno-common \
    -I./src -I./src/bytearray -I./src/hashtab -I../pdpclib \
    -U__WIN32__ -D__NOBIVA__ -D__HAVESYS__=_System \
    -D__OS2__ -D__32BIT__

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

TARGET=pdld.exe

all: clean $(TARGET)

$(TARGET): $(OBJS)
  $(LD) $(LDFLAGS) -o $(TARGET) ../pdpclib/os2strt.obj $(OBJS) ../pdpclib/pdpos2.lib ../pdpclib/os2.lib

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

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

BOOTSTRAP_AS=aswin
BOOTSTRAP_LD=ldwin

bootstrap: set_bootstrap all

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