# makefile for module rocrail with mingw

# ------------------------------------------------------------
MOUNTPOINT=..
OUTDIR=..\winbin
GENDIR=..\wingen
TMPOUTDIR=$(GENDIR)\rocrail\bin
DEBUG=-g

CPP=gcc
LNK=gcc
INCL_PATH=$(MOUNTPOINT)
CC_FLAGS=-c $(DEBUG) -I$(INCL_PATH) -I$(GENDIR)
LNK_FLAGS=
LIBS=$(OUTDIR)\libwrapper.a $(OUTDIR)\librocs.a -liphlpapi -lwsock32 -lmpr -ladvapi32 -lwinmm

OBJS=$(patsubst impl/%.c,$(TMPOUTDIR)/%.o,$(wildcard impl/*.c))
WEBOBJS=$(patsubst impl/web/%.c,$(TMPOUTDIR)/%.o,$(wildcard impl/web/*.c))
WOBJS=$(patsubst $(GENDIR)/rocrail/wrapper/impl/%.c,$(GENDIR)/rocrail/wrapper/bin/%.o,$(wildcard $(GENDIR)/rocrail/wrapper/impl/*.c))

LIBOBJS=$(TMPOUTDIR)\rcon.o

TARGET=$(OUTDIR)\rocrail.exe

all: $(TARGET)
#	-del /Q $(OUTDIR)\*.o

$(TARGET): $(WOBJS) $(OBJS) $(WEBOBJS) $(OUTDIR)\librocs.a $(OUTDIR)\librocrail.a $(OUTDIR)\libwrapper.a
	$(LNK) $(LNK_FLAGS) -o $(TARGET) $(OBJS) $(WEBOBJS) $(LIBS)

# ------------------------------------------------------------
# The client connection archive.
# ------------------------------------------------------------
$(OUTDIR)\librocrail.a: $(LIBOBJS)
	ar rcs $(OUTDIR)\librocrail.a $(LIBOBJS)

# ------------------------------------------------------------
# The wrapper archive.
# ------------------------------------------------------------
$(OUTDIR)\libwrapper.a: $(WOBJS)
	ar rcs $(OUTDIR)\libwrapper.a $(WOBJS)

# ------------------------------------------------------------
# The RocRail objects.
# ------------------------------------------------------------
$(TMPOUTDIR)/%.o: impl/%.c $(GENDIR)/rocrail/wrapper/public/wrapper.h
	$(CPP) $(CC_FLAGS) $< -o $@

$(TMPOUTDIR)/%.o: impl/web/%.c $(GENDIR)/rocrail/wrapper/public/wrapper.h
	$(CPP) $(CC_FLAGS) $< -o $@

$(GENDIR)/rocrail/wrapper/bin/%.o: $(GENDIR)/rocrail/wrapper/impl/%.c
	$(CPP) $(CC_FLAGS) $< -o $@

clean:
	-mkdir $(OUTDIR)
	-mkdir $(TMPOUTDIR)
	-mkdir $(GENDIR)\rocrail
	-del /Q $(OUTDIR)\*.o
	-del /Q $(OUTDIR)\libwrapper.a
	-del /Q $(GENDIR)\rocrail\wrapper\public\*.*
	-del /Q $(GENDIR)\rocrail\wrapper\impl\*.*
	-del /Q $(GENDIR)\rocrail\wrapper\bin\*.*
	-del /Q $(GENDIR)\rocrail\wrapper\doc\*.*
	cd $(GENDIR)\rocrail & ..\$(OUTDIR)\ogen.exe ..\..\rocrail\rocrail.xml ..\\
	cd $(GENDIR)\rocrail & ..\$(OUTDIR)\wgen.exe ..\..\rocrail\public\wrapper.xml
	cd $(GENDIR)\rocrail & ..\$(OUTDIR)\xml2cstr.exe ..\..\rocrail\public\wrapper.xml wrapper\impl\wrapperinfo.c wrapperinfo
	cd $(GENDIR)\rocrail & ..\$(OUTDIR)\xml2cstr.exe wrapper\doc\wrapper-en.html wrapper\impl\rocrail_doc.c rocrail_doc
	cd $(GENDIR)\rocrail & ..\$(OUTDIR)\xml2cstr.exe ..\..\common\version.xml wrapper\impl\version.c svnLog

rocrail:
	cd ..\rocs & make -f makefile-mingw clean & make -f makefile-mingw all DEBUG=$(DEBUG)
	cd ..\rocint & make -f makefile-mingw clean & make -f makefile-mingw all DEBUG=$(DEBUG)
	make -f makefile-mingw clean & make -f makefile-mingw all DEBUG=$(DEBUG)
	cd ..\rocdigs & make -f makefile-mingw clean & make -f makefile-mingw all DEBUG=$(DEBUG)
	cd ..\roclcdr & make -f makefile-mingw clean & make -f makefile-mingw all DEBUG=$(DEBUG)
	cd ..\rocgui & make -f makefile-mingw clean & make -f makefile-mingw all DEBUG=$(DEBUG)

unicode:
	cd ..\rocs & make -f makefile-mingw clean & make -f makefile-mingw all DEBUG=$(DEBUG)
	cd ..\rocint & make -f makefile-mingw clean & make -f makefile-mingw all DEBUG=$(DEBUG)
	make -f makefile-mingw clean & make -f makefile-mingw all DEBUG=$(DEBUG)
	cd ..\rocdigs & make -f makefile-mingw clean & make -f makefile-mingw all DEBUG=$(DEBUG)
	cd ..\roclcdr & make -f makefile-mingw clean & make -f makefile-mingw all DEBUG=$(DEBUG)
	cd ..\rocgui & make -f makefile-mingw clean & make -f makefile-mingw unicode DEBUG=$(DEBUG)

ansi:
	cd ..\rocs & make -f makefile-mingw clean & make -f makefile-mingw all DEBUG=$(DEBUG)
	cd ..\rocint & make -f makefile-mingw clean & make -f makefile-mingw all DEBUG=$(DEBUG)
	make -f makefile-mingw clean & make -f makefile-mingw all DEBUG=$(DEBUG)
	cd ..\rocdigs & make -f makefile-mingw clean & make -f makefile-mingw all DEBUG=$(DEBUG)
	cd ..\roclcdr & make -f makefile-mingw clean & make -f makefile-mingw all DEBUG=$(DEBUG)
	cd ..\rocgui & make -f makefile-mingw clean & make -f makefile-mingw ansi DEBUG=$(DEBUG)
