.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)/%)
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  = libwsadd$(VERSION).dll
LIBDLL2 = libwsad$(VERSION).dll
LIBST   = $(LIBNAMED2)
LIBST2  = $(LIBNAME2)
LIBDIR  = ../../bin

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

$(LIBDIR)/libwsadd$(VERSION).dll: $(CPPOBJECTS) $(CCOBJECTS)
	dllwrap -o $(LIBDIR)/libwsadd$(VERSION).dll $(CPPOBJECTS) $(CCOBJECTS) -mwindows --export-all-symbols $(LIBDIR)/libwsed$(VERSION).dll $(LIBDIR)/libwsd$(VERSION).dll $(LIBDIR)/libwsbd$(VERSION).dll --output-def libwsadd$(VERSION).def --driver-name g++
	dlltool --def libwsadd$(VERSION).def --dllname libwsadd$(VERSION).dll --output-lib ../../lib/libwsadd.a

#	g++ -shared -o $(LIBDIR)/libwsadd$(VERSION).dll $(CPPOBJECTS) $(CCOBJECTS) $(LIBDIR)/libwsd$(VERSION).dll $(LIBDIR)/libwscd$(VERSION).dll -Wl,--out-implib,../../lib/libwsadd.a -Wl,--export-all-symbols

$(LIBDIR)/$(LIBDLL2): $(CPPOBJECTS2) $(CCOBJECTS2)
	dllwrap -o $(LIBDIR)/libwsad$(VERSION).dll $(CPPOBJECTS2) $(CCOBJECTS2) -mwindows --export-all-symbols $(LIBDIR)/libwse$(VERSION).dll $(LIBDIR)/libws$(VERSION).dll $(LIBDIR)/libwsc$(VERSION).dll $(LIBDIR)/libwsb$(VERSION).dll --output-def libwsad$(VERSION).def --driver-name g++
	dlltool --def libwsad$(VERSION).def --dllname libwsad$(VERSION).dll --output-lib ../../lib/libwsad.a

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

$(LIBDIR)/$(LIBST): $(CPPOBJECTS) $(CCOBJECTS)
	g++ -r -nostdlib -o $(OBJDIR)/master_obj.o $(CPPOBJECTS) $(CCOBJECTS)
	ar -rv ../../lib-st/$(LIBST) $(OBJDIR)/master_obj.o
	$(RANLIB) ../../lib-st/$(LIBST)

../../lib-st/$(LIBST2): $(CPPOBJECTS2) $(CCOBJECTS2)
	g++ -r -nostdlib -o $(OBJDIR2)/master_obj.o $(CPPOBJECTS2) $(CCOBJECTS2)
	ar -rv ../../lib-st/$(LIBST2) $(OBJDIR2)/master_obj.o
	$(RANLIB) ../../lib-st/$(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 _$(*F).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 _$(*F).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 *~ *.def
	rm.exe -f $(LIBDIR)/$(LIBDLL)  $(LIBDIR)/$(LIBDLL2) $(LIBDIR)/$(LIBST) $(LIBDIR)/$(LIBST2)
	rm.exe -f ../../lib-st/$(LIBST)
	rm.exe -f ../../lib-st/$(LIBST2)
	rm.exe -f $(OBJDIR)/master_obj.o
	rm.exe -f $(OBJDIR2)/master_obj.o

