iotivity 0.9.0
[platform/upstream/iotivity.git] / resource / csdk / ocrandom / test / linux / 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 debug build
23 BUILD := debug
24 PLATFORM := linux
25
26 # You must create the file "local.propertiessudo" on your local machine which contains any local paths, etc
27 # local_settings.mk should NOT be committed to repo
28 ROOT_DIR = ../../..
29 include $(ROOT_DIR)/local.properties
30 # GTEST_DIR contains the path to Google Test libs and must be defined in local.properties
31 #  Example:
32 #  GTEST_DIR := /home/johndoe/utils/gtest-1.7.0
33
34 # NOTE:  to run app, make sure that LD_LIBRARY_PATH env variable
35 #        contains $(GTEST_DIR)/lib/.libs
36                                 
37 CC := gcc
38 CXX     := g++
39
40 PROG := randomtest
41
42 SRC_DIR := ../../src
43 TEST_DIR:= ../../test/linux
44 INC_DIR := ../../include
45
46 CC_FLAGS.debug := -O0 -g3 -Wall -c -fmessage-length=0 -pedantic -std=c99 -fpic -D TB_LOG
47 CC_FLAGS.release := -O0 -g3 -Wall -c -fmessage-length=0 -std=c99 -fpic 
48 CC_FLAGS := $(CC_FLAGS.$(BUILD))
49
50 CXX_FLAGS.debug := -O0 -g3 -Wall -c -fmessage-length=0 -pedantic -std=c++0x -fpic -D TB_LOG
51 CXX_FLAGS.release := -O0 -g3 -Wall -c -fmessage-length=0 -std=c++0x -fpic 
52 CXX_FLAGS := $(CXX_FLAGS.$(BUILD))
53
54 INC     := -I$(SRC_DIR)  
55 INC += -I$(TEST_DIR)
56 INC += -I$(INC_DIR)
57 INC += -I$(GTEST_DIR)/include
58
59
60 # using make's computed variables to select object and bin folders
61 # depending on the build type
62 OBJ_DIR.debug := ./obj/debug
63 OBJ_DIR.release := ./obj/release
64 OBJ_DIR := $(OBJ_DIR.$(BUILD))
65
66 BIN_DIR.debug := ./bin/debug
67 BIN_DIR.release := ./bin/release
68 BIN_DIR := $(BIN_DIR.$(BUILD))
69
70 C_FILES := $(wildcard $(SRC_DIR)/*.c)
71 #CPP_FILES := $(wildcard $(SRC_DIR)/*.cpp)
72 CPP_FILES := $(wildcard $(TEST_DIR)/*.cpp)
73 OBJ_FILES := $(addprefix $(OBJ_DIR)/,$(notdir $(CPP_FILES:.cpp=.o) $(C_FILES:.c=.o)))
74 H_FILES := $(wildcard $(TEST_DIR)/*.h)
75 H_FILES += $(wildcard $(INC_DIR)/*.h)
76 LD_FLAGS := -L/usr/lib
77 LD_FLAGS += -L$(GTEST_DIR)/lib/.libs
78
79
80 LIBS := -lpthread
81 LIBS += -lgtest
82 LIBS += -lgtest_main
83
84
85 all: $(PROG)
86         
87 $(PROG): $(OBJ_FILES)  
88         mkdir -p $(BIN_DIR)
89         $(CXX) -o $@ $^ $(LD_FLAGS) $(LIBS)     
90 #       $(CXX) -o $@ $^ $(GTEST_DIR)/make/gtest_main.a -lpthread
91         mv ./$(PROG) ./$(BIN_DIR)
92
93 #$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c $(SRC_DIR)/%.h $(H_FILES)
94 #       $(CC) $(CC_FLAGS) $(INC) -c -o $@ $<
95
96 $(OBJ_DIR)/%.o: $(SRC_DIR)/%.c $(INC_DIR)/%.h $(H_FILES)
97         mkdir -p $(OBJ_DIR)
98         $(CC) $(CC_FLAGS) $(INC) -c -o $@ $<
99
100 $(OBJ_DIR)/%.o: $(TEST_DIR)/%.cpp $(H_FILES)
101         mkdir -p $(OBJ_DIR)
102         $(CXX) $(CXX_FLAGS) $(INC) -c -o $@ $<
103
104         
105 .PHONY: clean
106 clean :
107         rm -rf ./obj/debug/*
108         rm -rf ./obj/release/*
109         rm -rf ./lib/debug/*
110         rm -rf ./lib/release/*
111         rm -rf ./bin/debug/*
112         rm -rf ./bin/release/*
113         rm -rf ./test/tst_*.txt
114
115
116 .PHONY: print_vars
117
118 print_vars:
119         @echo ""
120         @echo 'BUILD     = '$(value BUILD)
121         @echo 'INC       = '$(value INC)
122         @echo 'CPP_FILES = '$(value CPP_FILES)
123         @echo 'LIBS      = '$(value LIBS)
124         
125