# This builds pdpclib with pdcc for 80386

CC=pdcc
AR=xar
AS=pdas --oformat coff
LD=pdld
COPTS=-D__NODECLSPEC__ -D__WIN32__ -D__PDPCLIB_DLL \
    -D__NOBIVA__ -I . -I ../src -DOLDWIN -D__NOSTDCALL__

DLLNAME=msvcrt

all: pdptest.exe

pdptest.exe: w32start.obj pdptest.obj stdio.obj string.obj stdlib.obj \
       start.obj time.obj errno.obj assert.obj signal.obj locale.obj \
       ctype.obj setjmp.obj math.obj dllcrt.obj winsupa.obj
  rm -f temp.lib
  $(AR) r temp.lib stdio.obj string.obj stdlib.obj winsupa.obj
  $(AR) r temp.lib start.obj time.obj errno.obj assert.obj signal.obj
  $(AR) r temp.lib locale.obj ctype.obj setjmp.obj math.obj
  $(AR) s temp.lib
  $(LD) -s --implib-compat --no-insert-timestamp -o $(DLLNAME).dll --shared --out-implib $(DLLNAME).lib dllcrt.obj temp.lib ../src/kernel32.lib
  rm -f temp.lib
  $(LD) -s -nostdlib --no-insert-timestamp -o pdptest.exe w32start.obj pdptest.obj $(DLLNAME).lib winsupa.obj setjmp.obj

w32start.obj: w32start.c
  $(CC) -D__NODECLSPEC__ -D__WIN32__ -I . -I ../src -o $*.s $*.c
  $(AS) -o $*.obj $*.s
  rm -f $*.s

pdptest.obj: pdptest.c
  $(CC) -D__NODECLSPEC__ -D__WIN32__ -I . -I ../src -o $*.s $*.c
  $(AS) -o $*.obj $*.s
  rm -f $*.s

dllcrt.obj: dllcrt.c
  $(CC) $(COPTS) -D__EXPORT__ -DNEED_START -o $*.s $*.c
  $(AS) -o $*.obj $*.s
  rm -f $*.s

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

.asm.obj:
  as86 -o $@ -f coff $<
#  sasm -o $@ -f coff $<

clean:
  rm -f *.obj
  rm -f pdptest.exe
