# 
# This make file is intended to build the code with
# MinGW.
#
# Start a DOS command shell (cmd.exe).
# Then make sure that your PATH variable FIRST contains the path to
# the MinGW bin directory.
# e.g.
# SET PATH=C:\MinGW\bin;C:\WINDOWS
#
# To create everything
#
# mingw32-make -f makefile.mingw32
#

BUILDDIR := mingw32
COPTS := -Wall -O2 -c

DLL1 := stm_print
OBJ1 := pipeproto stm_print mypipe

APP2 := create_fake_tpiu
OBJ2 := create_fake_tpiu twp

APP3 := pipe_read
OBJ3 := pipe_read mypipe

DLL4 := itm_print
OBJ4 := pipeproto itm_print mypipe

DLL5 := stpv1_print
OBJ5 := pipeproto stpv1_print mypipe


OBJ1 := $(patsubst %,$(BUILDDIR)/%.o,$(OBJ1))
DLL1 := $(patsubst %,$(BUILDDIR)/%.dll,$(DLL1))

OBJ2 := $(patsubst %,$(BUILDDIR)/%.o,$(OBJ2))
APP2 := $(patsubst %,$(BUILDDIR)/%.exe,$(APP2))

OBJ3 := $(patsubst %,$(BUILDDIR)/%.o,$(OBJ3))
APP3 := $(patsubst %,$(BUILDDIR)/%.exe,$(APP3))

OBJ4 := $(patsubst %,$(BUILDDIR)/%.o,$(OBJ4))
DLL4 := $(patsubst %,$(BUILDDIR)/%.dll,$(DLL4))

OBJ5 := $(patsubst %,$(BUILDDIR)/%.o,$(OBJ5))
DLL5 := $(patsubst %,$(BUILDDIR)/%.dll,$(DLL5))

all: $(DLL1) $(APP2) $(APP3) $(DLL4) $(DLL5)

$(OBJ1) $(OBJ2) $(OBJ3) $(OBJ4): | $(BUILDDIR)


$(BUILDDIR):
	mkdir $(BUILDDIR)


$(DLL1): $(OBJ1)
	gcc -shared -o $@ $^
	strip $@

$(APP2): $(OBJ2)
	gcc -o $@ $^
	strip $@

$(APP3): $(OBJ3)
	gcc -o $@ $^
	strip $@

$(DLL4): $(OBJ4)
	gcc -shared -o $@ $^
	strip $@

$(DLL5): $(OBJ5)
	gcc -shared -o $@ $^
	strip $@

$(BUILDDIR)/%.o: src/%.c
	gcc $(COPTS) -o $@ $<

clean:
	rmdir /S /Q $(BUILDDIR)
	
cleanmost:
	del /Q /F $(BUILDDIR)\*.o
