Use CXX for the variable containing the name of the C++ compiler
[platform/upstream/iotivity.git] / csdk / 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=debug`
22 # override with `make PLATFORM=arduinomega` or `make PLATFORM=arduinodue`
23 # default to release build
24 # default to build for linux
25 BUILD    := release
26 PLATFORM := linux
27
28 # override with `make PLATFORM=arduinomega ARDUINOWIFI=1` to enable Arduino WiFi shield
29 ARDUINOWIFI := 0
30
31 ifeq ($(ROOT_DIR), )
32 ROOT_DIR        = $(PWD)
33 endif
34
35 ifeq ($(OBJ_DIR), )
36 OBJ_DIR = obj
37 endif
38
39
40 ifeq ($(PLATFORM),linux)
41     CXX=g++
42     CC=gcc
43     AR=ar
44     RANLIB=ranlib
45     CFLAGS_PLATFORM = -DWITH_POSIX -std=c99
46 else ifeq ($(PLATFORM),arduinomega)
47     include local.properties
48     include $(PLATFORM).properties
49         CC=$(ARDUINO_TOOLS_DIR)/avr-g++
50         ifeq ($(wildcard $(ARDUINO_DIR)/libraries/Time/Time/),)
51         $(error Arduino Time library needs to be moved from <ARDUINO_DIR>/libraries/Time \
52         to <ARDUINO_DIR>/libraries/Time/Time. You may need to create \
53         <ARDUINO_DIR>/libraries/Time/Time directory. Please refer to the wiki or readme \
54         for more information)
55         endif
56 else ifeq ($(PLATFORM),arduinodue)
57     include local.properties
58     include $(PLATFORM).properties
59         CC=$(ARDUINO_TOOLS_DIR)/arm-none-eabi-g++
60 else
61    $(error Wrong value for PLATFORM !!)
62 endif
63
64 OCLOGGER_DIR    = $(ROOT_DIR)/logger
65 OCRANDOM_DIR    = $(ROOT_DIR)/ocrandom
66 OCSOCKET_DIR    = $(ROOT_DIR)/ocsocket
67 LCOAP_DIR       = $(ROOT_DIR)/libcoap-4.1.1
68 OCCOAP_DIR      = $(ROOT_DIR)/occoap
69 OCTBSTACK_DIR   = $(ROOT_DIR)/stack
70 UTILS_DIR       = $(ROOT_DIR)/../../oic-utilities/tb
71 CJSON_DIR       = $(UTILS_DIR)/cJSON
72
73 OCCOAP_SRC      = $(OCCOAP_DIR)/src
74 OCTBSTACK_SRC   = $(OCTBSTACK_DIR)/src
75 CJSON_SRC       = $(CJSON_DIR)
76
77 OCLOGGER_INC    = $(OCLOGGER_DIR)/include
78 OCRANDOM_INC    = $(OCRANDOM_DIR)/include
79 OCSOCKET_INC    = $(OCSOCKET_DIR)/include
80 LCOAP_INC       = $(LCOAP_DIR)
81 OCCOAP_INC      = $(OCCOAP_DIR)/include
82 OCTBSTACK_INC   = $(OCTBSTACK_DIR)/include
83 CJSON_INC       = $(CJSON_DIR)
84
85 INC_DIRS        := -I$(OCLOGGER_INC)
86 INC_DIRS        += -I$(OCRANDOM_INC)
87 INC_DIRS        += -I$(OCSOCKET_INC)
88 INC_DIRS        += -I$(LCOAP_INC)
89 INC_DIRS        += -I$(OCCOAP_INC)
90 INC_DIRS        += -I$(OCTBSTACK_INC)
91 INC_DIRS        += -I$(OCTBSTACK_INC)/internal
92 INC_DIRS        += -I$(CJSON_INC)
93
94 CC_FLAGS.debug          := -O0 -g3 -Wall -c -fmessage-length=0 -pedantic -fpic -DTB_LOG
95 CC_FLAGS.release        := -Os -Wall -c -fmessage-length=0 -fpic
96
97 CFLAGS          += $(CC_FLAGS.$(BUILD)) $(INC_DIRS) $(CFLAGS_PLATFORM) $(INC_DIR_PLATFORM)
98 LDLIBS          += -lcoap
99
100 CJSON_SOURCES           := $(CJSON_SRC)/cJSON.c
101
102 OCCOAP_SOURCES          := $(OCCOAP_SRC)/occoap.c
103 OCCOAP_SOURCES          += $(OCCOAP_SRC)/occoaphelper.c
104
105 OCTBSTACK_SOURCES       := $(OCTBSTACK_SRC)/ocstack.c
106 OCTBSTACK_SOURCES       += $(OCTBSTACK_SRC)/occlientcb.c
107 OCTBSTACK_SOURCES       += $(OCTBSTACK_SRC)/ocresource.c
108 OCTBSTACK_SOURCES       += $(OCTBSTACK_SRC)/ocobserve.c
109 OCTBSTACK_SOURCES       += $(OCTBSTACK_SRC)/occollection.c
110
111 SOURCES                 := $(CJSON_SOURCES)
112 SOURCES                 += $(OCCOAP_SOURCES)
113 SOURCES                 += $(OCTBSTACK_SOURCES)
114
115 all:    make_lcoap objdirs obj_build liboctbstack.a #print_vars
116
117 make_lcoap: 
118         $(MAKE) -C $(LCOAP_DIR) "BUILD=$(BUILD)" "PLATFORM=$(PLATFORM)" "ARDUINOWIFI=$(ARDUINOWIFI)"
119
120 objdirs: $(ROOT_DIR)
121         mkdir -p $(BUILD)
122         mkdir -p $(BUILD)/$(OBJ_DIR)
123
124 obj_build:
125         @echo "Building $@"
126         # Output all *.o files to $(OBJ_DIR)/$(BUILD)
127         $(foreach source,$(SOURCES), $(CC) $(CFLAGS) $(source) -o $(patsubst %.c, %.o, $(patsubst %, $(BUILD)/$(OBJ_DIR)/%, $(notdir $(source))));)
128
129 liboctbstack.a:
130         @echo "Building $@" 
131         # Unpackage libcoap.a to $(OBJ_DIR)/$(BUILD). The output objects from OCStack and OCCoap are already at this location
132         @cd $(BUILD)/$(OBJ_DIR) && $(AR) -x $(LCOAP_DIR)/$(BUILD)/libcoap.a
133         # Repackage all the objects at this location into a single archive. This is OCStack, OCCoap, and LibCoap (LibCoap contains OCRandom, OCLogger, and OCSocket.).
134         $(AR) -r $(BUILD)/$@ $(BUILD)/$(OBJ_DIR)/*.o
135
136 .PHONY: clean print_vars
137
138 clean: legacy_clean
139         -rm -rf release
140         -rm -rf debug
141
142 deepclean: legacy_deepclean
143         -rm -rf release
144         -rm -rf debug
145
146 legacy_clean:   $(ROOT_DIR)
147         @echo "Cleaning all."
148         rm -f $(OBJ_DIR)/$(BUILD)/*.o
149         rm -f $(ROOT_DIR)/$(BUILD)/liboctbstack.a
150         rm -rf $(OBJ_DIR)
151
152 legacy_deepclean: $(ROOT_DIR)
153         @echo "Deep-Cleaning all."
154         rm -f $(OBJ_DIR)/$(BUILD)/*.o
155         rm -f $(ROOT_DIR)/liboctbstack.a
156         rm -rf $(OBJ_DIR)
157         $(MAKE) clean -C $(LCOAP_DIR)
158
159 print_vars:
160         @echo ""
161         @echo 'INCLUDES ARE: '$(value INC_DIRS)
162         @echo ""
163         @echo 'SOURCE FILES ARE: '$(value SOURCES)
164         @echo ""
165         @echo 'OBJ_DIR/BUILD is: '$(OBJ_DIR)'/'$(BUILD)
166         @echo ""
167         @echo 'ROOT_DIR is: '$(ROOT_DIR)