CPP     = g++.exe
CC      = gcc.exe
JAVAC   = javac.exe
WINDRES = windres.exe

OPT = -Os

# 
# gcc hello.c -nostdlib -Os -s -lkernel32 -o hello.exe
# strip hello.exe
# 


.PHONY: all all-before all-after clean clean-custom

all: all-before exewrap.exe all-after

clean: clean-custom
	rm -f *.o *.exe *.res *.class *.img

exewrap.exe: exewrap.o image_console.img image_gui.img image_service.img exewrap.res
	$(CPP) -mthreads exewrap.o exewrap.res -s -o exewrap.exe -lversion
	bindres.exe exewrap.exe VERSION_INFO  versioninfo.bin
	bindres.exe exewrap.exe IMAGE_CONSOLE image_console.img
	bindres.exe exewrap.exe IMAGE_GUI     image_gui.img
	bindres.exe exewrap.exe IMAGE_SERVICE image_service.img

exewrap.res: exewrap.rc
	$(WINDRES) -i exewrap.rc -o exewrap.res -O coff
	
image_console.img: image_console.o image_console.res dde_connect.o jvm.o bindres.exe Loader.class Toolkit.class
	$(CPP) image_console.o image_console.res dde_connect.o jvm.o -s -o image_console.img
	bindres.exe image_console.img LOADER  Loader.class
	bindres.exe image_console.img TOOLKIT Toolkit.class

image_console.o: image_console.cpp
	$(CPP) -c image_console.cpp -o image_console.o $(OPT)

image_console.res: image_console.rc
	$(WINDRES) -i image_console.rc -o image_console.res -O coff 


image_gui.img: image_gui.o image_gui.res dde_connect.o jvm.o bindres.exe Loader.class Toolkit.class FileLogStream.class UncaughtHandler.class
	$(CPP) -mwindows image_gui.o image_gui.res dde_connect.o jvm.o -s -o image_gui.img
	bindres.exe image_gui.img LOADER  Loader.class
	bindres.exe image_gui.img TOOLKIT Toolkit.class
	bindres.exe image_gui.img FILELOG FileLogStream.class
	bindres.exe image_gui.img HANDLER UncaughtHandler.class

image_gui.o: image_gui.cpp
	$(CPP) -c image_gui.cpp -o image_gui.o $(OPT)

image_gui.res: image_gui.rc
	$(WINDRES) -i image_gui.rc -o image_gui.res -O coff 


image_service.img: image_service.o image_service.res service.o eventlog.o jvm.o bindres.exe Loader.class Toolkit.class EventLogStream.class
	$(CPP) image_service.o image_service.res service.o eventlog.o jvm.o -o image_service.img -lshlwapi
	bindres.exe image_service.img LOADER   Loader.class
	bindres.exe image_service.img TOOLKIT  Toolkit.class
	bindres.exe image_service.img EVENTLOG EventLogStream.class
	bindres.exe image_service.img HANDLER  UncaughtHandler.class

image_service.o: image_service.cpp
	$(CPP) -c image_service.cpp -o image_service.o $(OPT)

image_service.res: image_service.rc eventlog.bin
	$(WINDRES) -i image_service.rc -o image_service.res -O coff

service.o: service.c
	$(CC) -c service.c -o service.o $(OPT)

eventlog.o: eventlog.c
	$(CC) -c eventlog.c -o eventlog.o $(OPT)	

dde_connect.o: dde_connect.cpp
	$(CPP) -c dde_connect.cpp -o dde_connect.o $(OPT)

jvm.o: jvm.cpp
	$(CPP) -c jvm.cpp -o jvm.o $(OPT)

bindres.exe: bindres.o
	$(CPP) bindres.o -s -o bindres.exe $(OPT)

bindres.o: bindres.cpp
	$(CPP) -c bindres.cpp -o bindres.o $(OPT)


Loader.class: java\Loader.java
	$(JAVAC) -source 1.2 -target 1.2 -sourcepath java -d . java\Loader.java

Toolkit.class: java\Toolkit.java
	$(JAVAC) -source 1.2 -target 1.2 -sourcepath java -d . java\Toolkit.java

FileLogStream.class: java\FileLogStream.java
	$(JAVAC) -source 1.2 -target 1.2 -sourcepath java -d . java\FileLogStream.java

EventLogStream.class: java\EventLogStream.java
	$(JAVAC) -source 1.2 -target 1.2 -sourcepath java -d . java\EventLogStream.java

UncaughtHandler.class: java\UncaughtHandler.java
	$(JAVAC) -source 1.2 -target 1.2 -sourcepath java -d . java\UncaughtHandler.java
	