+# override with `make BUILD=release`
+# default to release build
+BUILD := release
+CXX := g++
+#CXX := clang
+OUT_DIR := $(PWD)/$(BUILD)
+OBJ_DIR := $(OUT_DIR)/obj
+SAMPLES_OUT_DIR := $(OUT_DIR)/samples
-CXX=g++
-#CXX=clang
-CXX_FLAGS=-std=c++11 -Wall -pthread
-CXX_INC=-I./include/ -I./csdk/stack/include -I./csdk/ocsocket/include -I./csdk/ocrandom/include -I./csdk/logger/include
+CXX_FLAGS.debug := -g3 -std=c++11 -Wall -pthread
+
+CXX_FLAGS.release := -std=c++11 -Wall -pthread
+
+CXX_INC := -I./include/
+CXX_INC += -I./csdk/stack/include
+CXX_INC += -I./csdk/ocsocket/include
+CXX_INC += -I./csdk/ocrandom/include
+CXX_INC += -I./csdk/logger/include
# Force metatargets to build:
-.PHONY: c_sdk simpleserver simpleclient
+.PHONY: prep_dirs c_sdk simpleserver simpleclient
+
+all: .PHONY
-all: .PHONY
+prep_dirs:
+ -mkdir $(OUT_DIR)
+ -mkdir $(OBJ_DIR)
+ -mkdir $(SAMPLES_OUT_DIR)
c_sdk:
- cd csdk && $(MAKE)
+ cd csdk && $(MAKE) "BUILD=$(BUILD)"
examples:
- cd examples && $(MAKE)
+ cd examples && $(MAKE) "BUILD=$(BUILD)"
-simpleserver: OCLib.a simpleserver.o
- $(CXX) $(CXX_FLAGS) -o simpleserver simpleserver.o OCLib.a csdk/liboctbstack.a
+simpleserver: OCLib.a
+ $(CXX) $(CXX_FLAGS.$(BUILD)) -o $(SAMPLES_OUT_DIR)/$@ examples/simpleserver.cpp $(CXX_INC) $(OBJ_DIR)/OCLib.a csdk/liboctbstack.a
-simpleclient: OCLib.a simpleclient.o
- $(CXX) $(CXX_FLAGS) -o simpleclient simpleclient.o OCLib.a csdk/liboctbstack.a
+simpleclient: OCLib.a
+ $(CXX) $(CXX_FLAGS.$(BUILD)) -o $(SAMPLES_OUT_DIR)/$@ examples/simpleclient.cpp $(CXX_INC) $(OBJ_DIR)/OCLib.a csdk/liboctbstack.a
OCLib.a: OCPlatform.o OCResource.o OCReflect.o InProcServerWrapper.o InProcClientWrapper.o
- ar -cvq OCLib.a OCPlatform.o OCResource.o OCReflect.o InProcServerWrapper.o InProcClientWrapper.o
+ ar -cvq $(OBJ_DIR)/OCLib.a $(OBJ_DIR)/OCPlatform.o $(OBJ_DIR)/OCResource.o $(OBJ_DIR)/OCReflect.o $(OBJ_DIR)/InProcServerWrapper.o $(OBJ_DIR)/InProcClientWrapper.o
OCReflect.o: OCLib/OCReflect.cpp
- $(CXX) $(CXX_FLAGS) -c OCLib/OCReflect.cpp $(CXX_INC)
+ $(CXX) $(CXX_FLAGS.$(BUILD)) -o $(OBJ_DIR)/$@ -c OCLib/OCReflect.cpp $(CXX_INC)
OCPlatform.o: OCLib/OCPlatform.cpp
- $(CXX) $(CXX_FLAGS) -c OCLib/OCPlatform.cpp $(CXX_INC)
+ $(CXX) $(CXX_FLAGS.$(BUILD)) -o $(OBJ_DIR)/$@ -c OCLib/OCPlatform.cpp $(CXX_INC)
OCResource.o: OCLib/OCResource.cpp
- $(CXX) $(CXX_FLAGS) -c OCLib/OCResource.cpp $(CXX_INC)
+ $(CXX) $(CXX_FLAGS.$(BUILD)) -o $(OBJ_DIR)/$@ -c OCLib/OCResource.cpp $(CXX_INC)
InProcServerWrapper.o: OCLib/InProcServerWrapper.cpp
- $(CXX) $(CXX_FLAGS) -c OCLib/InProcServerWrapper.cpp $(CXX_INC)
+ $(CXX) $(CXX_FLAGS.$(BUILD)) -o $(OBJ_DIR)/$@ -c OCLib/InProcServerWrapper.cpp $(CXX_INC)
InProcClientWrapper.o: OCLib/InProcClientWrapper.cpp
- $(CXX) $(CXX_FLAGS) -c OCLib/InProcClientWrapper.cpp $(CXX_INC)
-
-simpleserver.o : examples/simpleserver.cpp
- $(CXX) $(CXX_FLAGS) -c examples/simpleserver.cpp $(CXX_INC)
-
-simpleclient.o : examples/simpleclient.cpp
- $(CXX) $(CXX_FLAGS) -c examples/simpleclient.cpp $(CXX_INC)
+ $(CXX) $(CXX_FLAGS.$(BUILD)) -o $(OBJ_DIR)/$@ -c OCLib/InProcClientWrapper.cpp $(CXX_INC)
-clean:
- rm -f -v OCLib.a *.o simpleserver simpleclient
+clean: clean_legacy
+ -rm -rf release
+ -rm -rf debug
cd csdk && $(MAKE) clean
cd csdk && $(MAKE) deepclean
+clean_legacy:
+ -rm -f -v OCLib.a *.o simpleserver simpleclient
Builds with g++ 4.6, 4.8, 4.9.
-Run "make" to build OCLib.a and the examples.
+Run "make" to build OCLib.a, the examples, and TBStack in RELEASE mode.
+
+Run "make BUILD=debug" to build OCLib.a, the examples, and TBStack in DEBUG mode.
OCProject/
├── csdk
-CXX=g++ -g -O0
+# override with `make BUILD=release`
+# default to release build
+BUILD := release
+CXX := g++
#CXX=clang -lstdc++ -g -O0
+OUT_DIR := $(PWD)/$(BUILD)
+OBJ_DIR := $(OUT_DIR)/obj
-CXX_FLAGS=-std=c++11 -Wall -pthread
+CXX_FLAGS.debug := -g3 -std=c++11 -Wall -pthread
-CXX_INC=-I../include/ -I./client/ -I../csdk/stack/include -I../csdk/ocsocket/include -I../csdk/ocrandom/include -I../csdk/logger/include
+CXX_FLAGS.release := -std=c++11 -Wall -pthread
-# LIB_SRC0=../OCLib/OCReflect.cpp ../OCLib/OCProperties.cpp ../OCLib/OCObserver.cpp ../OCLib/OCResource.cpp ./client/MyObserverHandler.cpp ../OCLib/OCServer.cpp
-LIB_SRC0=../OCLib/OCReflect.cpp ../OCLib/OCProperties.cpp ../OCLib/OCObserver.cpp ../OCLib/OCResource.cpp ../OCLib/OCServer.cpp
+CXX_INC := -I../include/
+CXX_INC += -I./client/
+CXX_INC += -I../csdk/stack/include
+CXX_INC += -I../csdk/ocsocket/include
+CXX_INC += -I../csdk/ocrandom/include
+CXX_INC += -I../csdk/logger/include
-LIB_SRC1=../OCLib/OCReflect.cpp ../OCLib/OCObserver.cpp ./client/MyObserverHandler.cpp ../OCLib/OCResource.cpp ../OCLib/OCSecurityModel.cpp ../OCLib/InProcClientWrapper.cpp ../OCLib/OCPlatform.cpp ../OCLib/InProcServerWrapper.cpp ../csdk/liboctbstack.a ../OCLib/OCServer.cpp
+LIB_SRC0 := ../OCLib/OCReflect.cpp
+LIB_SRC0 += ../OCLib/OCProperties.cpp
+LIB_SRC0 += ../OCLib/OCObserver.cpp
+LIB_SRC0 += ../OCLib/OCResource.cpp
+LIB_SRC0 += ../OCLib/OCServer.cpp
-CXX_LIBS=-lboost_regex
+LIB_SRC1 := ../OCLib/OCReflect.cpp
+LIB_SRC1 += ../OCLib/OCObserver.cpp
+LIB_SRC1 += ./client/MyObserverHandler.cpp
+LIB_SRC1 += ../OCLib/OCResource.cpp
+LIB_SRC1 += ../OCLib/OCSecurityModel.cpp
+LIB_SRC1 += ../OCLib/InProcClientWrapper.cpp
+LIB_SRC1 += ../OCLib/OCPlatform.cpp
+LIB_SRC1 += ../OCLib/InProcServerWrapper.cpp
+LIB_SRC1 += ../csdk/liboctbstack.a
+LIB_SRC1 += ../OCLib/OCServer.cpp
-.PHONY: ocreflect test_OCReflect test_OCClient test_properties
+CXX_LIBS := -Lboost_regex
+
+.PHONY: prep_dirs ocreflect test_OCReflect test_OCClient test_properties
all: .PHONY
+prep_dirs:
+ -mkdir $(OUT_DIR)
+ -mkdir $(OBJ_DIR)
+
ocreflect: test_properties test_OCClient
test_properties:
-
- $(CXX) $(CXX_FLAGS) -o test_properties reflect/test_properties.cpp $(LIB_SRC0) $(CXX_INC) $(CXX_LIBS)
+ $(CXX) $(CXX_FLAGS.$(BUILD)) -o $(OUT_DIR)/$@ reflect/test_properties.cpp $(LIB_SRC0) $(CXX_INC) $(CXX_LIBS)
test_OCReflect:
- $(CXX) $(CXX_FLAGS) -o test_OCReflect reflect/test_OCReflect.cpp ../OCLib/OCReflect.cpp ../OCLib/OCProperties.cpp ../OCLib/OCServer.cpp $(CXX_INC) $(CXX_LIBS)
+ $(CXX) $(CXX_FLAGS.$(BUILD)) -o $(OUT_DIR)/$@ reflect/test_OCReflect.cpp ../OCLib/OCReflect.cpp ../OCLib/OCProperties.cpp ../OCLib/OCServer.cpp $(CXX_INC) $(CXX_LIBS)
test_OCClient:
- $(CXX) $(CXX_FLAGS) -o test_OCClient reflect/test_OCClient.cpp $(LIB_SRC0) $(CXX_INC) $(CXX_LIBS)
+ $(CXX) $(CXX_FLAGS.$(BUILD)) -o $(OUT_DIR)/$@ reflect/test_OCClient.cpp $(LIB_SRC0) $(CXX_INC) $(CXX_LIBS)
-clean:
- rm -f -v test_properties test_OCReflect test_OCClient
+clean: clean_legacy
+ -rm -rf release/*
+ -rm -rf release/obj/*.o
+ -rm -rf release/obj/*.a
+ -rmdir release
+ -rm -rf debug/*
+ -rm -rf debug/obj/*.o
+ -rm -rf debug/obj/*.a
+ -rmdir debug
+clean_legacy:
+ -rm -f -v test_properties test_OCReflect test_OCClient