Initial merge-commit of the OIC code. Should successfully do discovery for single...
[platform/upstream/iotivity.git] / csdk / ubstack / makefile
1 # override with `make BUILD=release`
2 # default to debug build
3 BUILD := debug
4
5 # You must create the file "local.properties" on your local machine which contains any local paths, etc
6 # local_settings.mk should NOT be committed to repo
7 include ./local.properties
8 # GTEST_DIR contains the path to Google Test libs and must be defined in local.properties
9 #  Example:
10 #  GTEST_DIR := /home/johndoe/utils/gtest-1.7.0
11
12 # NOTE:  to run app, make sure that LD_LIBRARY_PATH env variable
13 #        contains $(GTEST_DIR)/lib/.libs
14                                 
15 CC := gcc
16 CXX     := g++
17
18 PROG := ubstacktest
19
20 SRC_DIR := ./src
21 TEST_DIR:= ./test
22 INC_DIR := ./include
23 LOG_DIR := ../logger
24 COAP_DIR := ../occoap
25 STACK_DIR := ../stack
26
27 CC_FLAGS.debug := -O0 -g3 -Wall -c -fmessage-length=0 -pedantic -std=c99 -fpic -D TB_LOG
28 CC_FLAGS.release := -O0 -g3 -Wall -c -fmessage-length=0 -std=c99 -fpic 
29 CC_FLAGS := $(CC_FLAGS.$(BUILD))
30
31 CXX_FLAGS.debug := -O0 -g3 -Wall -c -fmessage-length=0 -pedantic -std=c++0x -fpic -D TB_LOG
32 CXX_FLAGS.release := -O0 -g3 -Wall -c -fmessage-length=0 -std=c++0x -fpic 
33 CXX_FLAGS := $(CXX_FLAGS.$(BUILD))
34
35 INC     := -I$(SRC_DIR)  
36 INC += -I$(TEST_DIR)
37 INC += -I$(INC_DIR)
38 INC += -I$(LOG_DIR)/include
39 INC += -I$(COAP_DIR)/include
40 INC += -I$(STACK_DIR)/include
41 INC += -I$(STACK_DIR)/include/internal
42 INC += -I$(GTEST_DIR)/include
43
44
45 # using make's computed variables to select object and bin folders
46 # depending on the build type
47 OBJ_DIR.debug := ./obj/debug
48 OBJ_DIR.release := ./obj/release
49 OBJ_DIR := $(OBJ_DIR.$(BUILD))
50
51 BIN_DIR.debug := ./bin/debug
52 BIN_DIR.release := ./bin/release
53 BIN_DIR := $(BIN_DIR.$(BUILD))
54
55 C_FILES := $(wildcard $(LOG_DIR)/src/*.c)
56 C_FILES += $(wildcard $(COAP_DIR)/src/*.c)
57 C_FILES += $(wildcard $(STACK_DIR)/src/*.c)
58 CPP_FILES := $(wildcard $(SRC_DIR)/*.cpp)
59 CPP_FILES += $(wildcard $(TEST_DIR)/*.cpp)
60 CPP_FILES += $(wildcard $(TEST_DIR)/*.cpp)
61
62 OBJ_FILES := $(addprefix $(OBJ_DIR)/,$(notdir $(CPP_FILES:.cpp=.o) $(C_FILES:.c=.o)))
63 H_FILES := $(wildcard $(TEST_DIR)/*.h)
64 H_FILES += $(wildcard $(INC_DIR)/*.h)
65 H_FILES += $(wildcard $(LOG_DIR)/include/*.h)
66 LD_FLAGS := -L/usr/lib
67 LD_FLAGS += -L$(GTEST_DIR)/lib/.libs
68
69
70 LIBS := -lpthread
71 LIBS += -lgtest
72 LIBS += -lgtest_main
73
74
75 all: $(PROG)
76         mkdir -p ./$(OBJ_DIR)
77         mkdir -p ./$(BIN_DIR)
78
79         
80 $(PROG): $(OBJ_FILES)
81         $(CXX) -o $@ $^ $(LD_FLAGS) $(LIBS) 
82         mkdir -p ./$(BIN_DIR)   
83         mv ./$(PROG) ./$(BIN_DIR)
84
85 # UB Stack
86 $(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp $(SRC_DIR)/%.h $(H_FILES)
87         mkdir -p ./$(OBJ_DIR)
88         $(CXX) $(CXX_FLAGS) $(INC) -c -o $@ $<
89
90 # UB Stack
91 $(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp $(INC_DIR)/%.h $(H_FILES)
92         mkdir -p ./$(OBJ_DIR)
93         $(CXX) $(CXX_FLAGS) $(INC) -c -o $@ $<
94
95 # UB Stack unit test
96 $(OBJ_DIR)/%.o: $(TEST_DIR)/%.cpp $(H_FILES)
97         mkdir -p ./$(OBJ_DIR)
98         $(CXX) $(CXX_FLAGS) $(INC) -c -o $@ $<
99
100 # Logger        
101 $(OBJ_DIR)/%.o: $(LOG_DIR)/src/%.c $(LOG_DIR)/include/%.h $(H_FILES)
102         mkdir -p ./$(OBJ_DIR)
103         $(CC) $(CC_FLAGS) $(INC) -c -o $@ $<    
104
105 # Stack 
106 $(OBJ_DIR)/%.o: $(STACK_DIR)/src/%.c $(STACK_DIR)/include/%.h $(H_FILES)
107         mkdir -p ./$(OBJ_DIR)
108         $(CC) $(CC_FLAGS) $(INC) -c -o $@ $<    
109
110 # OCCoAP        
111 $(OBJ_DIR)/%.o: $(COAP_DIR)/src/%.c $(COAP_DIR)/include/%.h $(H_FILES)
112         mkdir -p ./$(OBJ_DIR)
113         $(CC) $(CC_FLAGS) $(INC) -c -o $@ $<    
114         
115 .PHONY: clean
116 clean :
117         rm -rf ./obj/debug/*
118         rm -rf ./obj/release/*
119         rm -rf ./lib/*
120         rm -rf ./bin/debug/*
121         rm -rf ./bin/release/*
122
123
124 .PHONY: print_vars
125
126 print_vars:
127         @echo ""
128         @echo 'BUILD     = '$(value BUILD)
129         @echo 'INC       = '$(value INC)
130         @echo 'CPP_FILES = '$(value CPP_FILES)
131         @echo 'LIBS      = '$(value LIBS)
132         
133