CFLAGS=-g -O2
CXXFLAGS=-g -O2

all : dlltest.exe test.o test2.o test3.o mkdlllib.exe autotest.exe

autotest.exe : autotest
	coff2exe autotest

autotest : autotest.o grinit.o dll.o libgrdll.o
	gcc $^ -o autotest

libgrdll.o : libgrdll.s
	as $^ -o $@

libgrdll.s : mkdlllib.exe libgr.o
	mkdlllib.exe libgr.o libgrdll.s

libgr.o : mkdlo.bat
	mkdlo /111/lib/libgr.a libgr.o

test.o : test.c
	gcc -O2 -c test.c

test2.o : test2.cc
	gcc -O2 -c test2.cc

test3.o : test3.s
	as test3.s -o test3.o

dlltest.exe : dlltest
	coff2exe dlltest
	
dlltest : dlltest.o dll.o
	gcc -o $@ $^

gccdll.h : mkdll.exe
	nm $(LIBRARY_PATH)/libgcc.a | sort -u | mkdll > gccdll.h

grdll.h : mkdll.exe libgr.o
	nm libgr.o | mkdll -u > grdll.h
	
mkdll.exe : mkdll
	coff2exe mkdll

mkdll : mkdll.o
	gcc -o $@ $^

mkdlllib.exe : mkdlllib
	coff2exe mkdlllib

mkdlllib : mkdlllib.o
	gcc -o $@ $^

clean:
	-rm *.o *.exe mkdll dlltest gccdll.h autotest mkdlllib
	-rm libgrdll.s grdll.h

# DEPENDENCIES

test.o : dll.h

dlltest.o : dll.h

dll.o : dll.h gccdll.h

grinit.o : grdll.h
