.SUFFIXES: .o .C .c  .cpp
CC1 = cc
CC = g++

include mkfiles


##################################################################

DEBUG = -g -ggdb -DMSW -Wall -Wno-format -DWS_DEBUG
#DEBUG2 = -g -DMSW -Wall -Wno-format
DEBUG2 = -O3 -DMSW  -Wall -Wno-format -DHAVE_CONFIG_H
OBJDIR = ./debug
OBJDIR2 = ./runtime
C++FLAGS = $(DEBUG) -DFUNCPROTO -DXTFUNCPROTO $(INCLUDE)
RANLIB = ranlib
C++FLAGS2 = $(DEBUG2) -DFUNCPROTO -DXTFUNCPROTO $(INCLUDE)
RANLIB = ranlib


##################################################################

CPPOBJECTS =$(CPPOBJS:%= $(OBJDIR)/%)
CCOBJECTS =$(CCOBJS:%= $(OBJDIR)/%)
CPPOBJECTS2 =$(CPPOBJS:%= $(OBJDIR2)/%)
CCOBJECTS2 =$(CCOBJS:%= $(OBJDIR2)/%)

#.c.o:
#	$(CC1) $(C++FLAGS) -c $(*F).c  -o $(OBJDIR)/$*.o
#
#.C.o:
#	$(CC) $(C++FLAGS) -c $(*F).C   -o $(OBJDIR)/$*.o
#
#.cpp.o:
#	$(CC) $(C++FLAGS) -c $(*F).cpp -o $(OBJDIR)/$*.o
#

LIBDLLBASE  = $(LIBNAME)
#LIBDLL  = $(LIBNAME).$(VERSION).d
#LIBDLL2 = $(LIBNAME).$(VERSION)
LIBDLL  = libwswind$(VERSION).dll
LIBDLL2 = $(LIBNAME)
LIBST   = $(LIBNAME2).d
LIBST2  = $(LIBNAME2)

#all: $(LIBDIR)/$(LIBDLL) $(LIBDIR)/$(LIBDLL2) $(LIBDIR)/$(LIBST) $(LIBDIR)/$(LIBST2)
all: ../../lib/$(LIBDLL2)
debug: $(LIBDIR)/libwswind$(VERSION).dll


../../lib/$(LIBDLL2): $(CPPOBJECTS2) $(CCOBJECTS2)
	dllwrap -o _mpfcmodule.dll $(CPPOBJECTS2) $(CCOBJECTS2) -mwindows --export-all-symbols $(LIBDIR)/libws$(VERSION).dll $(LIBDIR)/libwsc$(VERSION).dll $(LIBDIR)/libwswin$(VERSION).dll $(LIBDIR)/libwsr$(VERSION).dll $(LIBDIR)/libwsb$(VERSION).dll $(LIBDIR)/libwssheet$(VERSION).dll $(LIBDIR)/libwsj3w$(VERSION).dll ../../../others/Python-2.2-mingw32/lib/libpython22.a -L../../../others/lib --output-def _mpfcmodule.def --driver-name g++
	dlltool --def _mpfcmodule.def --dllname _mpfcmodule.dll --output-lib ../../lib/_mpfcmodule.a 
	cp _mpfcmodule.dll ../../lib/
	cp _mpfcmodule.dll ../../lib/_mpfc.dll
	cp mpfc.py ../../lib/mpfc.py

#	g++ -shared -o $(LIBDIR)/libwswin$(VERSION).dll $(CPPOBJECTS2) $(CCOBJECTS2) ../../lib/libws$(VERSION).a -Wl,--out-implib,../../lib/libwswin.a -Wl,--export-all-symbols

$(LIBDIR)/$(LIBST): $(CPPOBJECTS) $(CCOBJECTS)
	ar -rv $(LIBDIR)/$(LIBST) $(CPPOBJECTS) $(CCOBJECTS)
	$(RANLIB) $(LIBDIR)/$(LIBST)

$(LIBDIR)/$(LIBST2): $(CPPOBJECTS2) $(CCOBJECTS2)
	ar -rv $(LIBDIR)/$(LIBST2) $(CPPOBJECTS2) $(CCOBJECTS2)
	$(RANLIB) $(LIBDIR)/$(LIBST2)

$(OBJDIR)/%.o:%.cpp
	$(CC) $(C++FLAGS) -c $(*F).cpp -o $(OBJDIR)/$*.o
$(OBJDIR)/%.o:%.c
	$(CC1) $(C++FLAGS) -c $(*F).c   -o $(OBJDIR)/$*.o
$(OBJDIR2)/%.o:%.cpp
	$(CC) $(C++FLAGS2) -c $(*F).cpp -o $(OBJDIR2)/$*.o
$(OBJDIR2)/%.o:%.c
	$(CC1) $(C++FLAGS2) -c $(*F).c   -o $(OBJDIR2)/$*.o

#$(CPPOBJECTS):
#	$(CC) $(C++FLAGS) -c $(*F).cpp -o $*.o
#
#$(CCOBJECTS):
#	$(CC) $(C++FLAGS) -c $(*F).c -o $*.o


clean:
	rm.exe -f $(CPPOBJECTS) $(CCOBJECTS) $(CPPOBJECTS2) $(CCOBJECTS2) *.bak *~ *.def _mpfcmodule.dll
	rm.exe -f $(LIBDIR)/$(LIBDLL)  $(LIBDIR)/$(LIBDLL2) $(LIBDIR)/$(LIBST) $(LIBDIR)/$(LIBST2)


