1 # //******************************************************************
3 # // Copyright 2014 Intel Mobile Communications GmbH All Rights Reserved.
5 # //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
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
11 # // http://www.apache.org/licenses/LICENSE-2.0
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.
19 # //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
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 # default to ETHERNET for transport
30 # override with `make PLATFORM=arduinomega ARDUINOWIFI=1` to enable Arduino WiFi shield
40 ifeq ($(PLATFORM),linux)
45 CFLAGS_PLATFORM = -DWITH_POSIX -std=gnu99
47 else ifeq ($(PLATFORM),arduinomega)
48 include local.properties
49 include $(PLATFORM).properties
50 CC=$(ARDUINO_TOOLS_DIR)/avr-g++
51 ifeq ($(wildcard $(ARDUINO_DIR)/libraries/Time/Time/),)
52 $(error Arduino Time library needs to be moved from <ARDUINO_DIR>/libraries/Time \
53 to <ARDUINO_DIR>/libraries/Time/Time. You may need to create \
54 <ARDUINO_DIR>/libraries/Time/Time directory. Please refer to the wiki or readme \
58 else ifeq ($(PLATFORM),arduinodue)
59 include local.properties
60 include $(PLATFORM).properties
61 CC=$(ARDUINO_TOOLS_DIR)/arm-none-eabi-g++
64 $(error Wrong value for PLATFORM !!)
67 ifeq ($(PLATFORM_TYPE),arduino)
68 ifeq ($(ARDUINOWIFI),0)
69 ARDUINO_SHIELD_TYPE := "/ethernet_shield"
70 else ifeq ($(ARDUINOWIFI), 1)
71 ARDUINO_SHIELD_TYPE := "/wifi_shield"
73 PLATFORM_SPECIFIC_BACKOUT:= ../../../../
75 PLATFORM_SPECIFIC_BACKOUT := ../../../
79 OUT_DIR = $(PLATFORM)$(ARDUINO_SHIELD_TYPE)/$(BUILD)
83 OBJ_DIR = $(OUT_DIR)/obj
87 OC_LOG_DIR = ../oc_logger
88 OCRANDOM_DIR = ocrandom
89 OCSOCKET_DIR = ocsocket
91 OCMALLOC_DIR = ocmalloc
92 OCSECURITY_DIR = security
93 EXTLIBS_DIR = ../../extlibs
94 CJSON_DIR = $(EXTLIBS_DIR)/cjson
95 TINYDTLS_DIR = $(EXTLIBS_DIR)/tinydtls
96 CONNECTIVITY_DIR = connectivity
98 OCTBSTACK_SRC = $(OCTBSTACK_DIR)/src
99 OCMALLOC_SRC = $(OCMALLOC_DIR)/src
100 OCSECURITY_SRC = $(OCSECURITY_DIR)/src
101 CJSON_SRC = $(CJSON_DIR)
102 CONNECTIVITY_SRC = $(CONNECTIVITY_DIR)
103 OCLOGGER_SRC = $(OCLOGGER_DIR)/src
104 OCSOCKET_SRC = $(OCSOCKET_DIR)/src
105 OCRANDOM_SRC = $(OCRANDOM_DIR)/src
107 OCLOGGER_INC = $(OCLOGGER_DIR)/include
108 OC_LOG_INC = $(OC_LOG_DIR)/include
109 OCRANDOM_INC = $(OCRANDOM_DIR)/include
110 OCSOCKET_INC = $(OCSOCKET_DIR)/include
111 OCTBSTACK_INC = $(OCTBSTACK_DIR)/include
112 OCMALLOC_INC = $(OCMALLOC_DIR)/include
113 OCSECURITY_INC = $(OCSECURITY_DIR)/include
114 CJSON_INC = $(CJSON_DIR)
115 CONNECTIVITY_INC = $(CONNECTIVITY_DIR)/inc
116 LIBCOAP_INC = $(CONNECTIVITY_DIR)/lib/libcoap-4.1.1
118 INC_DIRS := -I$(OCLOGGER_INC)
119 INC_DIRS += -I$(OC_LOG_INC)
120 INC_DIRS += -I$(OCRANDOM_INC)
121 INC_DIRS += -I$(OCSOCKET_INC)
122 INC_DIRS += -I$(OCMALLOC_INC)
123 INC_DIRS += -I$(OCSECURITY_INC)
124 INC_DIRS += -I$(OCSECURITY_INC)/internal
125 INC_DIRS += -I$(OCTBSTACK_INC)
126 INC_DIRS += -I$(OCTBSTACK_INC)/internal
127 INC_DIRS += -I$(CJSON_INC)
128 INC_DIRS += -I$(CONNECTIVITY_INC)
129 INC_DIRS += -I$(CONNECTIVITY_DIR)/api
130 INC_DIRS += -I$(LIBCOAP_INC)
132 # TODO-CA Remove -fstack-protector-all before merging to master
133 CC_FLAGS.debug := -O0 -g3 -Wall -fstack-protector-all -c -fmessage-length=0 -pedantic -fpic -DTB_LOG
134 # TODO-CA Remove -fstack-protector-all before merging to master
135 CC_FLAGS.release := -Os -Wall -fstack-protector-all -c -fmessage-length=0 -fpic
137 CFLAGS += $(CC_FLAGS.$(BUILD)) $(INC_DIRS) $(CFLAGS_PLATFORM) $(INC_DIR_PLATFORM)
139 CJSON_SOURCES := $(CJSON_SRC)/cJSON.c
141 OCTBSTACK_SOURCES := $(OCTBSTACK_SRC)/ocstack.c
142 OCTBSTACK_SOURCES += $(OCTBSTACK_SRC)/occlientcb.c
143 OCTBSTACK_SOURCES += $(OCTBSTACK_SRC)/ocresource.c
144 OCTBSTACK_SOURCES += $(OCTBSTACK_SRC)/ocobserve.c
145 OCTBSTACK_SOURCES += $(OCTBSTACK_SRC)/ocserverrequest.c
146 OCTBSTACK_SOURCES += $(OCTBSTACK_SRC)/occollection.c
147 OCTBSTACK_SOURCES += $(OCTBSTACK_SRC)/oicgroup.c
148 OCTBSTACK_SOURCES += $(OCSECURITY_SRC)/ocsecurity.c
149 OCTBSTACK_SOURCES += $(OCMALLOC_SRC)/ocmalloc.c
150 OCTBSTACK_SOURCES += $(OCLOGGER_SRC)/logger.c
151 OCTBSTACK_SOURCES += $(OCRANDOM_SRC)/ocrandom.c
153 ifeq ($(PLATFORM_TYPE),arduino)
154 ifeq ($(ARDUINOWIFI),1)
155 OCTBSTACK_SOURCES += $(OCSOCKET_SRC)/ocsocket_arduino_wifi.c
157 OCTBSTACK_SOURCES += $(OCSOCKET_SRC)/ocsocket_arduino.c
160 OCTBSTACK_SOURCES += $(OCSOCKET_SRC)/ocsocket.c
163 SOURCES := $(CJSON_SOURCES)
164 SOURCES += $(OCTBSTACK_SOURCES)
166 all: objdirs obj_build ca liboctbstack.a
168 buildScript_all: objdirs obj_build ca liboctbstack.a
172 mkdir -p $(PLATFORM)/$(ARDUINO_SHIELD_TYPE)
178 # Output all *.o files to $(OUT_DIR)/$(BUILD)/$(OBJ_DIR)
179 $(foreach source,$(SOURCES), $(CC) $(CFLAGS) $(source) -o $(patsubst %.c, %.o, $(patsubst %, $(OBJ_DIR)/%, $(notdir $(source))));)
183 ifeq ($(PLATFORM),linux)
184 @cd $(CONNECTIVITY_SRC)/lib/libcoap-4.1.1 && $(MAKE)
185 @cd $(CONNECTIVITY_SRC)/build/linux && $(MAKE) "BUILD=$(BUILD)" "PLATFORM=linux"
186 @cd $(CONNECTIVITY_SRC)/samples/linux && $(MAKE)
188 @cd $(CONNECTIVITY_SRC)/build/ && $(MAKE) "PLATFORM=$(PLATFORM)" "ARDUINO_DIR=$(ARDUINO_DIR)" "TRANSPORT=$(TRANSPORT)"
192 $(AR) -r $(OUT_DIR)/$@ $(OBJ_DIR)/*.o
194 ifeq ($(CA_INT_DTLS),0)
195 ifeq ($(PLATFORM),linux)
196 ifneq ($(wildcard $(TINYDTLS_DIR)/libtinydtls.a),)
197 $(info "Building liboctbstack with DTLS support")
198 mkdir -p $(OBJ_DIR)/tinydtls
199 @cd $(OBJ_DIR)/tinydtls && $(AR) -x ../$(PLATFORM_SPECIFIC_BACKOUT)$(TINYDTLS_DIR)/libtinydtls.a
200 $(AR) -q $(OUT_DIR)/$@ $(OBJ_DIR)/tinydtls/*.o
205 .PHONY: clean print_vars
211 @cd $(CONNECTIVITY_SRC)/build/ && $(MAKE) clean "PLATFORM=arduinomega"
212 @cd $(CONNECTIVITY_SRC)/samples/linux && $(MAKE) "clean"
214 deepclean: legacy_deepclean
220 @echo "Cleaning all."
221 rm -f $(OBJ_DIR)/$(BUILD)/*.o
222 rm -f $(ROOT_DIR)/$(BUILD)/liboctbstack.a
223 cd $(CONNECTIVITY_SRC)/lib/libcoap-4.1.1 && $(MAKE) clean
224 cd $(CONNECTIVITY_SRC)/build/linux && $(MAKE) clean
225 cd $(CONNECTIVITY_SRC)/samples/linux && $(MAKE) clean
231 @echo "Deep-Cleaning all."
232 rm -f $(OBJ_DIR)/$(BUILD)/*.o
233 rm -f $(ROOT_DIR)/liboctbstack.a
234 cd $(CONNECTIVITY_SRC)/lib/libcoap-4.1.1 && $(MAKE) clean
235 cd $(CONNECTIVITY_SRC)/build/linux && $(MAKE) clean
236 cd $(CONNECTIVITY_SRC)/samples/linux && $(MAKE) clean