CC=gcc
CFLAGS=-Wall -I. -DNDEBUG -O9
LIBMODULES = stdwin stdframe framectl stdfont
MODULES = $(LIBMODULES) test1 test2 test3
HEADERS = stdwin stdframe framectl stdfont
LIBDIR_BASE = /gcc2/lib
LIBDIR_STATIC = $(LIBDIR_BASE)/static
LIBDIR_DYNAMIC = $(LIBDIR_BASE)/dynamic
DLLDIR = /gcc2/dll
INCDIR = /gcc2/gccincl

LIBOBJS = $(addsuffix .obj, $(LIBMODULES)
DLLOBJ = $(addprefix $(LIBDIR_BASE)/, dllinit0.obj dllinit.obj) $(LIBOBJS)
OBJS = $(addsuffix .obj, $(MODULES))
SOURCE = $(addsuffix .cc, $(MODULES))
DEPS = $(addsuffix .d, $(MODULES))
HFILES = $(addsuffix .h, $(HEADERS))
DESTHFILES = $(addprefix $(INCDIR)/, $(HFILES))

%.obj %.d: %.cc
	$(CC) $(CFLAGS) -c -MD $<
$(INCDIR)/%.h: %.h
	rm -f $@
	cp $< $@

.PHONY: all clean depend default install tests

default: all
all: stdwin.lib stdwinx.lib

install: $(LIBDIR_STATIC)/stdwin.lib \
	$(LIBDIR_DYNAMIC)/stdwin.lib \
	$(DLLDIR)/stdwin.dll \
	$(DESTHFILES)

$(LIBDIR_STATIC)/stdwin.lib: stdwinx.lib
	rm -f $(LIBDIR_STATIC)/stdwin.lib
	cp stdwinx.lib $(LIBDIR_STATIC)/stdwin.lib
$(LIBDIR_DYNAMIC)/stdwin.lib: stdwin.lib
	rm -f $(LIBDIR_DYNAMIC)/stdwin.lib
	cp stdwin.lib $(LIBDIR_DYNAMIC)/stdwin.lib
$(DLLDIR)/stdwin.dll: stdwin.dll
	rm -f $(DLLDIR)/stdwin.dll
	cp stdwin.dll $(DLLDIR)
$(DESTHFILES):


tests: test1.exe test1x.exe test2.exe test2x.exe test3.exe test3x.exe

test1.exe: stdwin.lib test1.obj
	$(CC) -o test1.exe test1.obj stdwin.lib  -Xlinker -pm
test1x.exe: stdwinx.lib test1.obj
	$(CC) -o test1x.exe test1.obj stdwinx.lib -Xlinker -pm

test2.exe: stdwin.lib test2.obj
	$(CC) -o test2.exe test2.obj stdwin.lib -Xlinker -pm
test2x.exe: stdwinx.lib test2.obj
	$(CC) -o test2x.exe test2.obj stdwinx.lib -Xlinker -pm

test3.exe: stdwin.lib test3.obj
	$(CC) -o test3.exe test3.obj stdwin.lib -Xlinker -pm
test3x.exe: stdwin.lib test3.obj
	$(CC) -o test3x.exe test3.obj stdwinx.lib -Xlinker -pm

stdwinx.lib: $(LIBOBJS)
	rm -f stdwinx.lib
	glib stdwinx.lib $(addprefix -a , $(LIBOBJS))

stdwin.lib: stdwin.def stdwin.dll
	implib /NOI /NOL stdwin.lib stdwin.def
stdwin.dll: $(DLLOBJ) stdwin.def
	gcc -o stdwin.dll stdwin.def $(DLLOBJ)

stdwin.def: stdwin.de0 $(DLLOBJ)
	omfexp $(DLLOBJ) | gnusort -u | cat stdwin.de0 - > stdwin.def
	

clean:
	rm -f $(OBJS) *~ stdwin.lib stdwinx.lib stdwin.dll stdwin.def

depend: $(DEPS) $(OBJS)
	cat $(DEPS) > depend.mak

$(OBJS) $(DEPS):

include depend.mak
