# This builds 32-bit Windows ARM (PE/coff) executables
# using Visual C and targeting msvcrt.dll

# run makek32.mar first

CC=cl
COPTS=-c -I../src -D__ARM__ -I. -D__WIN32__ -D__PDPCLIB_DLL \
    -DNOUNDMAIN -D__GENSHELL__ -D__MSC__ -nologo -GS- -Za -Zl -O2 -Oi-

AR=lib
LD=pdld --no-insert-timestamp
#LD=link
AS=armasm


TARGET=pdptest.exe
OBJS=w32start.obj stdio.obj string.obj stdlib.obj start.obj time.obj errno.obj \
    assert.obj signal.obj locale.obj ctype.obj math.obj fpfuncsa.obj dllcrt.obj \
    armsupb.obj

$(TARGET): clean pdptest.obj $(OBJS)
  rm -f temp.lib
  $(AR) -nologo -out:temp.lib $(OBJS)
  $(LD) -s -o msvcrt.dll --shared --out-implib msvcrt.lib dllcrt.obj temp.lib ../src/kernel32.lib
#  $(LD) -nologo -fixed:no -dll -out:msvcrt.dll dllcrt.obj temp.lib ../src/kernel32.lib
  rm -f temp.lib
  $(LD) -s -nostdlib -o pdptest.exe w32start.obj pdptest.obj msvcrt.lib armsupb.obj
#  $(LD) -nologo -fixed:no -out:pdptest.exe w32start.obj pdptest.obj msvcrt.lib

w32start.obj: w32start.c
  $(CC) $(COPTS) -U__PDPCLIB_DLL $*.c

pdptest.obj: pdptest.c
  $(CC) $(COPTS) -U__PDPCLIB_DLL $*.c

dllcrt.obj: dllcrt.c
  $(CC) $(COPTS) -D__EXPORT__ -DNEED_START $*.c

.c.obj:
  $(CC) $(COPTS) $<

armsupb.obj: armsupb.asm
# we don't need an explicit -16
  $(AS) -nologo -o armsupb.obj armsupb.asm

.asm.obj:
  $(AS) -nologo -o $@ $<

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