# This builds 64-bit Windows Loongarch64 (PE/coff) executables
# (if such a thing existed, and used 64-bit long)
# using gcc built targeting loongarch64-linux

# run makek32.wg6 first



CC=gcc
COPTS=-c -I../src -D__LOONG__ -I. -D__WIN32__ -D__PDPCLIB_DLL \
    -DNOUNDMAIN -D__GENSHELL__ -O2 -U__gnu_linux__ \
    -D__NOSTDCALL__ \
    -D__64BIT__ -nostdlib -nostdinc \
    -D__NODECLSPEC__ -D__LONG64__ \
    -fno-stack-protector --no-pie -fno-builtin \
    -mdirect-extern-access

AR=ar
LD=pdld --no-insert-timestamp
#LD=ld
AS=as


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 dllcrt.obj \
    lg6supa.obj

$(TARGET): clean pdptest.obj $(OBJS)
  rm -f temp.lib
  $(AR) r temp.lib $(OBJS)
  $(LD) --export-all-symbols -s --no-insert-timestamp -o msvcrt.dll --shared --out-implib msvcrt.lib dllcrt.obj temp.lib ../src/kernel32.lib
  rm -f temp.lib
  $(LD) -s -nostdlib -e mainCRTStartup --no-insert-timestamp -o pdptest.exe w32start.obj pdptest.obj msvcrt.lib

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

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

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

.c.obj:
  $(CC) -o $@ $(COPTS) $<

lg6supa.obj: lg6supa.asm
  $(AS) -o lg6supa.obj lg6supa.asm

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

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