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

include mkfiles


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

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



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

CPPOBJECTS =$(CPPOBJS:%= $(OBJDIR)/%)
CPPOBJECTSS =$(CPPOBJS2:%= $(OBJDIR)/%)
CCOBJECTS =$(CCOBJS:%= $(OBJDIR)/%)
CPPOBJECTS2 =$(CPPOBJS:%= $(OBJDIR2)/%)
CPPOBJECTSS2 =$(CPPOBJS2:%= $(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  = libwsmysqld$(VERSION).dll
LIBDLL2 = libwsmysql$(VERSION).dll
LIBST   = $(LIBNAME2).d
LIBST2  = $(LIBNAME2)
LIBDIR  = ../../bin

#all: $(LIBDIR)/$(LIBDLL) $(LIBDIR)/$(LIBDLL2) $(LIBDIR)/$(LIBST) $(LIBDIR)/$(LIBST2)
all: $(LIBDIR)/$(LIBDLL2)
debug: $(LIBDIR)/$(LIBDLL)

$(LIBDIR)/$(LIBDLL): $(CPPOBJECTS) $(CCOBJECTS) $(CPPOBJECTSS)
	dllwrap -o $(LIBDIR)/libwsmysqld$(VERSION).dll $(CPPOBJECTS) $(CCOBJECTS) $(CPPOBJECTSS) --export-all-symbols -L../../../others/mysql -lmysql $(LIBDIR)/libwsd$(VERSION).dll --output-def libwsmysqld$(VERSION).def --driver-name g++
	dlltool --def libwsmysqld$(VERSION).def --dllname libwsmysqld$(VERSION).dll --output-lib ../../lib/libwsmysqld.a
#	g++ -shared -o $(LIBDIR)/libwsmysqld$(VERSION).dll $(CPPOBJECTS) $(CCOBJECTS) $(CPPOBJECTSS) -Wl,--out-implib,../../lib/libwsmysqld.a -Wl,--export-all-symbols

$(LIBDIR)/$(LIBDLL2): $(CPPOBJECTS2) $(CCOBJECTS2) $(CPPOBJECTSS2)
	dllwrap -o $(LIBDIR)/libwsmysql$(VERSION).dll $(CPPOBJECTS2) $(CCOBJECTS2) $(CPPOBJECTSS2) --export-all-symbols -L../../../others/mysql -lmysql $(LIBDIR)/libws$(VERSION).dll --output-def libwsmysql$(VERSION).def --driver-name g++
	dlltool --def libwsmysql$(VERSION).def --dllname libwsmysql$(VERSION).dll --output-lib ../../lib/libwsmysql.a

#	g++ -shared -o $(LIBDIR)/libwsmysql$(VERSION).dll $(CPPOBJECTS2) $(CCOBJECTS2) $(CPPOBJECTSS2) -Wl,--out-implib,../../lib/libwsmysql.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
	sjisfix $(*F).cpp _$(*F).cpp
	$(CC) $(C++FLAGS) -c _$(*F).cpp -o $(OBJDIR)/$*.o
	rm.exe -f _$(*F).cpp
$(OBJDIR)/%.o:%.c
	sjisfix $(*F).c _$(*F).c
	$(CC1) $(C++FLAGS) -c _tmp.c   -o $(OBJDIR)/$*.o
	rm.exe -f _$(*F).c
$(OBJDIR2)/%.o:%.cpp
	sjisfix $(*F).cpp _$(*F).cpp
	$(CC) $(C++FLAGS2) -c _$(*F).cpp -o $(OBJDIR2)/$*.o
	rm.exe -f _$(*F).cpp
$(OBJDIR2)/%.o:%.c
	sjisfix $(*F).c _$(*F).c
	$(CC1) $(C++FLAGS2) -c _tmp.c   -o $(OBJDIR2)/$*.o
	rm.exe -f _$(*F).c

#$(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 *~
	rm.exe -f $(CPPOBJECTSS) $(CPPOBJECTSS2)
	rm.exe -f $(LIBDIR)/$(LIBDLL)  $(LIBDIR)/$(LIBDLL2) $(LIBDIR)/$(LIBST) $(LIBDIR)/$(LIBST2)

