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

include mkfiles.win
include ../../sys/config/version-def

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

DEBUG = -O3 -DMSW  -Wall -Wno-format
DEBUG2 = -g -ggdb -DMSW  -Wall -Wno-format -DWS_DEBUG
#DEBUG = -O3 -DLINUX  -Wall -Wno-format
#DEBUG2 = -ggdb -g -DLINUX  -Wall -Wno-format -fPIC
OBJDIR = ./runtime
OBJDIR2 = ./debug
C++FLAGS = $(DEBUG) -DFUNCPROTO -DXTFUNCPROTO $(INCLUDE)
C++FLAGS2 = $(DEBUG2) -DFUNCPROTO -DXTFUNCPROTO $(INCLUDE)
RANLIB = ranlib
RANLIB = ranlib
LIBS = ../../lib/libws.a ../../lib/libwsc.a ../../lib/libwsb.a ../../lib/libwsad.a ../../lib/libwswin.a
LIBSD = ../../lib/libwsd.a ../../lib/libwscd.a ../../lib/libwsbd.a ../../lib/libwsadd.a ../../lib/libwswind.a
#LIBSD = ../../bin/libwsd$(VERSION).dll ../../bin/libwsadd$(VERSION).dll ../../bin/libwswind$(VERSION).dll


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

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
#

TARGET1 = $(TARGET).exe
TARGET2 = $(TARGETD).exe

#all: $(BINDIR)/$(TARGET1) $(BINDIR)/$(TARGET2)
all: $(BINDIR)/$(TARGET1)
debug: $(BINDIR)/$(TARGET2)

$(BINDIR)/$(TARGET1): $(CPPOBJECTS) $(CCOBJECTS)
	$(CC) $(C++FLAGS) -o $(BINDIR)/$(TARGET1) $(CPPOBJECTS) $(CCOBJECTS) $(LIBS) -mwindows

$(BINDIR)/$(TARGET2): $(CPPOBJECTS2) $(CCOBJECTS2)
	$(CC) $(C++FLAGS2) -o $(BINDIR)/$(TARGET2) $(CPPOBJECTS2) $(CCOBJECTS2) $(LIBSD)



$(OBJDIR)/wsres.o:wsres.rc
	windres --include-dir ../.. -I rc -i wsres.rc -o $(OBJDIR)/wsres.o
$(OBJDIR2)/wsres.o:wsres.rc
	windres --include-dir ../.. -I rc -i wsres.rc -o $(OBJDIR2)/wsres.o

$(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 _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 $(BINDIR)/$(TARGET1)  $(BINDIR)/$(TARGET2)

