.SUFFIXES: .o .C .c  .cpp

include mkfiles


##################################################################
include ../../sys/config/mkflags


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

CPPOBJECTS =$(CPPOBJS:%= $(OBJDIR)/%)
CPPOBJECTSS =$(CPPOBJS2:%= $(OBJDIR2)/%)
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  = libwscd.dylib
LIBDLL2 = libwsc.dylib
LIBST   = $(LIBNAMED2)
LIBST2  = $(LIBNAME2)

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

$(LIBDIR)/$(LIBDLL): $(CPPOBJECTS) $(CCOBJECTS) $(CPPOBJECTSS)
	$(CC) -r -keep_private_externs -nostdlib -o debug/master_obj.o $(CPPOBJECTS) $(CCOBJECTS) $(CPPOBJECTSS)
	$(CC) -dynamiclib -current_version $(VERSION) -compatibility_version $(VERSION) -o $(LIBDLL) debug/master_obj.o $(CPPOBJECTSS) -lwsd
	cp $(LIBDLL) ../../lib/$(LIBDLL)
	cp $(LIBDLL) /usr/lib/$(LIBDLL)
#	cd $(LIBDIR);\rm -f $(LIBNAMED);\ln -s $(LIBDLL) $(LIBNAMED)
$(LIBDIR)/$(LIBDLL2): $(CPPOBJECTS2) $(CCOBJECTS2) $(CPPOBJECTSS)
	$(CC) -r -keep_private_externs -nostdlib -o runtime/master_obj.o $(CPPOBJECTS2) $(CCOBJECTS2) $(CPPOBJECTSS)
	$(CC) -dynamiclib -current_version $(VERSION) -compatibility_version $(VERSION) -o $(LIBDLL2) runtime/master_obj.o -lws
	$(CC) -bundle -undefined suppress -flat_namespace -o libwsc.bundle runtime/master_obj.o -lws
	cp $(LIBDLL2) ../../lib/$(LIBDLL2)
	cp $(LIBDLL2) /usr/lib/$(LIBDLL2)
	cp libwsc.bundle ../../lib/libwsc.bundle
	cp libwsc.bundle /usr/lib/libwsc.bundle
#	cd $(LIBDIR);\rm -f $(LIBNAME);\ln -s $(LIBDLL2) $(LIBNAME)

$(LIBDIR)/$(LIBST): $(CPPOBJECTS) $(CCOBJECTS)
	$(CC) -r -keep_private_externs -nostdlib -o debug/master_obj.o $(CPPOBJECTS) $(CCOBJECTS) $(CPPOBJECTSS)
	ar -rv $(LIBDIR)/$(LIBST) debug/master_obj.o
	$(RANLIB) $(LIBDIR)/$(LIBST)

$(LIBDIR)/$(LIBST2): $(CPPOBJECTS2) $(CCOBJECTS2)
	$(CC) -r -keep_private_externs -nostdlib -o runtime/master_obj.o $(CPPOBJECTS2) $(CCOBJECTS2) $(CPPOBJECTSS)
	ar -rv $(LIBDIR)/$(LIBST2) runtime/master_obj.o
	$(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 -f $(CPPOBJECTS) $(CPPOBJECTSS) $(CCOBJECTS) $(CPPOBJECTS2) $(CCOBJECTS2) $(CPPOBJECTSS) *.bak
	\rm -f $(LIBDIR)/$(LIBDLL)  $(LIBDIR)/$(LIBDLL2) $(LIBDIR)/$(LIBST) $(LIBDIR)/$(LIBST2)
	\rm -f $(LIBDIR)/$(LIBNAMED)
	\rm -f $(LIBDIR)/$(LIBNAME)
	\rm -f $(LIBDIR)/libwsc.bundle
	\rm -f libwsc.bundle
	\rm -f runtime/master_obj.o
	\rm -f runtime-st/master_obj.o
	\rm -f debug/master_obj.o     
	\rm -f debug-st/master_obj.o
	\rm -f $(LIBDLL) $(LIBDLL2)
