# This is the makefile for Win32 to build msvcrt.dll using
# the gcc compiler, and using custom-built Windows tools.
#
# The makefile uses spaces, which are normal for Windows
# users, and Borland make, Microsoft nmake and others are
# happy to accept them. If you are using Cygwin or a make
# that unfortunately requires tabs, then simply edit this
# file, change all spaces to tabs, and it will work, even
# if the resultant file looks a bit silly.

# You will need to have built kernel32.a with makek32.w32
# prior to running this

CC=gccwin
AR=arwin
AS=aswin
LD=ldwin
COPTS=-S -fno-common -ansi -O2 -D__WIN32__ -D__PDPCLIB_DLL -D__NOBIVA__ -I . -I ../src

all: pdptest.exe

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

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

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

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

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

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

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