Merge "Partial Implementation of US1574:"
[platform/upstream/iotivity.git] / csdk / ubstack / makefile
1 # //******************************************************************
2 # //
3 # // Copyright 2014 Intel Mobile Communications GmbH All Rights Reserved.
4 # //
5 # //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
6 # //
7 # // Licensed under the Apache License, Version 2.0 (the "License");
8 # // you may not use this file except in compliance with the License.
9 # // You may obtain a copy of the License at
10 # //
11 # //      http://www.apache.org/licenses/LICENSE-2.0
12 # //
13 # // Unless required by applicable law or agreed to in writing, software
14 # // distributed under the License is distributed on an "AS IS" BASIS,
15 # // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # // See the License for the specific language governing permissions and
17 # // limitations under the License.
18 # //
19 # //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
20 #
21 # override with `make BUILD=release`
22 # default to release build
23 BUILD := release
24
25 # You must create the file "local.properties" on your local machine which contains any local paths, etc
26 # local_settings.mk should NOT be committed to repo
27 include ./local.properties
28 # GTEST_DIR contains the path to Google Test libs and must be defined in local.properties
29 #  Example:
30 #  GTEST_DIR := /home/johndoe/utils/gtest-1.7.0
31
32 # NOTE:  to run app, make sure that LD_LIBRARY_PATH env variable
33 #        contains $(GTEST_DIR)/lib/.libs
34                                 
35 CC := gcc
36 CXX     := g++
37
38 PROG := ubstacktest
39
40 SRC_DIR := ./src
41 TEST_DIR:= ./test
42 INC_DIR := ./include
43 LOG_DIR := ../logger
44 COAP_DIR := ../occoap
45 STACK_DIR := ../stack
46
47 CC_FLAGS.debug := -O0 -g3 -Wall -c -fmessage-length=0 -pedantic -std=c99 -fpic -DTB_LOG
48 CC_FLAGS.release := -Os -Wall -c -fmessage-length=0 -std=c99 -fpic 
49 CC_FLAGS := $(CC_FLAGS.$(BUILD))
50
51 CXX_FLAGS.debug := -O0 -g3 -Wall -c -fmessage-length=0 -pedantic -std=c++0x -fpic -DTB_LOG
52 CXX_FLAGS.release := -Os -Wall -c -fmessage-length=0 -std=c++0x -fpic 
53 CXX_FLAGS := $(CXX_FLAGS.$(BUILD))
54
55 INC     := -I$(SRC_DIR)  
56 INC += -I$(TEST_DIR)
57 INC += -I$(INC_DIR)
58 INC += -I$(LOG_DIR)/include
59 INC += -I$(COAP_DIR)/include
60 INC += -I$(STACK_DIR)/include
61 INC += -I$(STACK_DIR)/include/internal
62 INC += -I$(GTEST_DIR)/include
63
64
65 # using make's computed variables to select object and bin folders
66 # depending on the build type
67 OBJ_DIR.debug := ./obj/debug
68 OBJ_DIR.release := ./obj/release
69 OBJ_DIR := $(OBJ_DIR.$(BUILD))
70
71 BIN_DIR.debug := ./bin/debug
72 BIN_DIR.release := ./bin/release
73 BIN_DIR := $(BIN_DIR.$(BUILD))
74
75 C_FILES := $(wildcard $(LOG_DIR)/src/*.c)
76 C_FILES += $(wildcard $(COAP_DIR)/src/*.c)
77 C_FILES += $(wildcard $(STACK_DIR)/src/*.c)
78 CPP_FILES := $(wildcard $(SRC_DIR)/*.cpp)
79 CPP_FILES += $(wildcard $(TEST_DIR)/*.cpp)
80 CPP_FILES += $(wildcard $(TEST_DIR)/*.cpp)
81
82 OBJ_FILES := $(addprefix $(OBJ_DIR)/,$(notdir $(CPP_FILES:.cpp=.o) $(C_FILES:.c=.o)))
83 H_FILES := $(wildcard $(TEST_DIR)/*.h)
84 H_FILES += $(wildcard $(INC_DIR)/*.h)
85 H_FILES += $(wildcard $(LOG_DIR)/include/*.h)
86 LD_FLAGS := -L/usr/lib
87 LD_FLAGS += -L$(GTEST_DIR)/lib/.libs
88
89
90 LIBS := -lpthread
91 LIBS += -lgtest
92 LIBS += -lgtest_main
93
94
95 all: $(PROG)
96         mkdir -p ./$(OBJ_DIR)
97         mkdir -p ./$(BIN_DIR)
98
99         
100 $(PROG): $(OBJ_FILES)
101         $(CXX) -o $@ $^ $(LD_FLAGS) $(LIBS) 
102         mkdir -p ./$(BIN_DIR)   
103         mv ./$(PROG) ./$(BIN_DIR)
104
105 # UB Stack
106 $(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp $(SRC_DIR)/%.h $(H_FILES)
107         mkdir -p ./$(OBJ_DIR)
108         $(CXX) $(CXX_FLAGS) $(INC) -c -o $@ $<
109
110 # UB Stack
111 $(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp $(INC_DIR)/%.h $(H_FILES)
112         mkdir -p ./$(OBJ_DIR)
113         $(CXX) $(CXX_FLAGS) $(INC) -c -o $@ $<
114
115 # UB Stack unit test
116 $(OBJ_DIR)/%.o: $(TEST_DIR)/%.cpp $(H_FILES)
117         mkdir -p ./$(OBJ_DIR)
118         $(CXX) $(CXX_FLAGS) $(INC) -c -o $@ $<
119
120 # Logger        
121 $(OBJ_DIR)/%.o: $(LOG_DIR)/src/%.c $(LOG_DIR)/include/%.h $(H_FILES)
122         mkdir -p ./$(OBJ_DIR)
123         $(CC) $(CC_FLAGS) $(INC) -c -o $@ $<    
124
125 # Stack 
126 $(OBJ_DIR)/%.o: $(STACK_DIR)/src/%.c $(STACK_DIR)/include/%.h $(H_FILES)
127         mkdir -p ./$(OBJ_DIR)
128         $(CC) $(CC_FLAGS) $(INC) -c -o $@ $<    
129
130 # OCCoAP        
131 $(OBJ_DIR)/%.o: $(COAP_DIR)/src/%.c $(COAP_DIR)/include/%.h $(H_FILES)
132         mkdir -p ./$(OBJ_DIR)
133         $(CC) $(CC_FLAGS) $(INC) -c -o $@ $<    
134         
135 .PHONY: clean
136 clean :
137         rm -rf ./obj/debug/*
138         rm -rf ./obj/release/*
139         rm -rf ./lib/*
140         rm -rf ./bin/debug/*
141         rm -rf ./bin/release/*
142
143
144 .PHONY: print_vars
145
146 print_vars:
147         @echo ""
148         @echo 'BUILD     = '$(value BUILD)
149         @echo 'INC       = '$(value INC)
150         @echo 'CPP_FILES = '$(value CPP_FILES)
151         @echo 'LIBS      = '$(value LIBS)
152         
153