Made changes to support Arduino 1.5.8 with Connectivity Abstraction.
[platform/upstream/iotivity.git] / resource / 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 # default to ETHERNET for transport
26 BUILD    := release
27 PLATFORM := linux
28 TRANSPORT := ETHERNET
29
30 # override with `make PLATFORM=arduinomega ARDUINOWIFI=1` to enable Arduino WiFi shield
31 ARDUINOWIFI := 0
32 CA_INT_DTLS := 0
33
34 ifeq ($(ROOT_DIR), )
35 ROOT_DIR        = ./
36 endif
37
38 PLATFORM_TYPE = linux
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     PLATFORM_TYPE=linux
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 \
55         for more information)
56     endif
57     PLATFORM_TYPE=arduino
58 else ifeq ($(PLATFORM),arduinodue)
59     include local.properties
60     include $(PLATFORM).properties
61     CC=$(ARDUINO_TOOLS_DIR)/arm-none-eabi-g++
62     PLATFORM_TYPE=arduino
63 else
64     $(error Wrong value for PLATFORM !!)
65 endif
66
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"
72     endif
73     PLATFORM_SPECIFIC_BACKOUT:= ../../../../
74 else
75     PLATFORM_SPECIFIC_BACKOUT := ../../../
76 endif
77
78 ifeq ($(OUT_DIR), )
79 OUT_DIR = $(PLATFORM)$(ARDUINO_SHIELD_TYPE)/$(BUILD)
80 endif
81
82 ifeq ($(OBJ_DIR), )
83 OBJ_DIR = $(OUT_DIR)/obj
84 endif
85
86 OCLOGGER_DIR            = logger
87 OC_LOG_DIR              = ../oc_logger
88 OCRANDOM_DIR            = ocrandom
89 OCSOCKET_DIR            = ocsocket
90 LCOAP_DIR               = libcoap-4.1.1
91 OCCOAP_DIR              = occoap
92 OCTBSTACK_DIR           = stack
93 OCMALLOC_DIR            = ocmalloc
94 OCSECURITY_DIR  = security
95 EXTLIBS_DIR             = ../../extlibs
96 CJSON_DIR               = $(EXTLIBS_DIR)/cjson
97 TINYDTLS_DIR    = $(EXTLIBS_DIR)/tinydtls
98 CONNECTIVITY_DIR        = connectivity
99
100 OCCOAP_SRC              = $(OCCOAP_DIR)/src
101 OCTBSTACK_SRC           = $(OCTBSTACK_DIR)/src
102 OCMALLOC_SRC            = $(OCMALLOC_DIR)/src
103 OCSECURITY_SRC    = $(OCSECURITY_DIR)/src
104 CJSON_SRC               = $(CJSON_DIR)
105 CONNECTIVITY_SRC        = $(CONNECTIVITY_DIR)
106 OCLOGGER_SRC            = $(OCLOGGER_DIR)/src
107 OCSOCKET_SRC            = $(OCSOCKET_DIR)/src
108 OCRANDOM_SRC            = $(OCRANDOM_DIR)/src
109
110 OCLOGGER_INC            = $(OCLOGGER_DIR)/include
111 OC_LOG_INC              = $(OC_LOG_DIR)/include
112 OCRANDOM_INC            = $(OCRANDOM_DIR)/include
113 OCSOCKET_INC            = $(OCSOCKET_DIR)/include
114 LCOAP_INC               = $(LCOAP_DIR)
115 OCCOAP_INC              = $(OCCOAP_DIR)/include
116 OCTBSTACK_INC           = $(OCTBSTACK_DIR)/include
117 OCMALLOC_INC            = $(OCMALLOC_DIR)/include
118 OCSECURITY_INC  = $(OCSECURITY_DIR)/include
119 CJSON_INC               = $(CJSON_DIR)
120 CONNECTIVITY_INC        = $(CONNECTIVITY_DIR)/inc
121
122 INC_DIRS        := -I$(OCLOGGER_INC)
123 INC_DIRS        += -I$(OC_LOG_INC)
124 INC_DIRS        += -I$(OCRANDOM_INC)
125 INC_DIRS        += -I$(OCSOCKET_INC)
126 INC_DIRS        += -I$(LCOAP_INC)
127 INC_DIRS        += -I$(OCCOAP_INC)
128 INC_DIRS        += -I$(OCMALLOC_INC)
129 INC_DIRS        += -I$(OCSECURITY_INC)
130 INC_DIRS        += -I$(OCSECURITY_INC)/internal
131 INC_DIRS        += -I$(OCTBSTACK_INC)
132 INC_DIRS        += -I$(OCTBSTACK_INC)/internal
133 INC_DIRS        += -I$(CJSON_INC)
134 INC_DIRS        += -I$(CONNECTIVITY_INC)
135 INC_DIRS        += -I$(CONNECTIVITY_DIR)/api
136
137 # TODO-CA Remove -fstack-protector-all before merging to master
138 CC_FLAGS.debug          := -O0 -g3 -Wall -fstack-protector-all -c -fmessage-length=0 -pedantic -fpic -DTB_LOG
139 # TODO-CA Remove -fstack-protector-all before merging to master
140 CC_FLAGS.release        := -Os -Wall -fstack-protector-all -c -fmessage-length=0 -fpic
141
142 CFLAGS          += $(CC_FLAGS.$(BUILD)) $(INC_DIRS) $(CFLAGS_PLATFORM) $(INC_DIR_PLATFORM)
143 LDLIBS          += -lcoap
144
145 CJSON_SOURCES           := $(CJSON_SRC)/cJSON.c
146
147 OCCOAP_SOURCES          := $(OCCOAP_SRC)/occoap.c
148 OCCOAP_SOURCES          += $(OCCOAP_SRC)/occoaphelper.c
149
150 OCTBSTACK_SOURCES       := $(OCTBSTACK_SRC)/ocstack.c
151 OCTBSTACK_SOURCES       += $(OCTBSTACK_SRC)/occlientcb.c
152 OCTBSTACK_SOURCES       += $(OCTBSTACK_SRC)/ocresource.c
153 OCTBSTACK_SOURCES       += $(OCTBSTACK_SRC)/ocobserve.c
154 OCTBSTACK_SOURCES       += $(OCTBSTACK_SRC)/ocserverrequest.c
155 OCTBSTACK_SOURCES       += $(OCTBSTACK_SRC)/occollection.c
156 OCTBSTACK_SOURCES       += $(OCTBSTACK_SRC)/oicgroup.c
157 OCTBSTACK_SOURCES       += $(OCSECURITY_SRC)/ocsecurity.c
158 OCTBSTACK_SOURCES       += $(OCMALLOC_SRC)/ocmalloc.c
159 OCTBSTACK_SOURCES       += $(OCLOGGER_SRC)/logger.c
160 OCTBSTACK_SOURCES       += $(OCRANDOM_SRC)/ocrandom.c
161
162 ifeq ($(PLATFORM_TYPE),arduino)
163     ifeq ($(ARDUINOWIFI),1)
164         OCTBSTACK_SOURCES += $(OCSOCKET_SRC)/ocsocket_arduino_wifi.c
165     else
166         OCTBSTACK_SOURCES += $(OCSOCKET_SRC)/ocsocket_arduino.c
167     endif
168 else
169     OCTBSTACK_SOURCES += $(OCSOCKET_SRC)/ocsocket.c
170 endif
171
172 SOURCES                 := $(CJSON_SOURCES)
173 SOURCES                 += $(OCCOAP_SOURCES)
174 SOURCES                 += $(OCTBSTACK_SOURCES)
175
176 all:    objdirs obj_build ca liboctbstack.a
177
178 buildScript_all: objdirs obj_build ca liboctbstack.a
179
180 objdirs:
181         mkdir -p $(PLATFORM)
182         mkdir -p $(PLATFORM)/$(ARDUINO_SHIELD_TYPE)
183         mkdir -p $(OUT_DIR)
184         mkdir -p $(OBJ_DIR)
185
186 obj_build:
187         @echo "Building $@"
188         # Output all *.o files to $(OUT_DIR)/$(BUILD)/$(OBJ_DIR)
189         $(foreach source,$(SOURCES), $(CC) $(CFLAGS) $(source) -o $(patsubst %.c, %.o, $(patsubst %, $(OBJ_DIR)/%, $(notdir $(source))));)
190
191 ca:
192         @echo "Building $@"
193         ifeq ($(PLATFORM),linux)
194             @cd $(CONNECTIVITY_SRC)/lib/libcoap-4.1.1 && $(MAKE)
195             @cd $(CONNECTIVITY_SRC)/build/linux && $(MAKE) "BUILD=$(BUILD)" "PLATFORM=linux"
196             @cd $(CONNECTIVITY_SRC)/samples/linux && $(MAKE)
197         else
198             @cd $(CONNECTIVITY_SRC)/build/ && $(MAKE) "PLATFORM=$(PLATFORM)" "ARDUINO_DIR=$(ARDUINO_DIR)" "TRANSPORT=$(TRANSPORT)"
199         endif
200 liboctbstack.a:
201         @echo "Building $@"
202         $(AR) -r $(OUT_DIR)/$@ $(OBJ_DIR)/*.o
203
204     ifeq ($(CA_INT_DTLS),0)
205      ifeq ($(PLATFORM),linux)
206       ifneq ($(wildcard $(TINYDTLS_DIR)/libtinydtls.a),)
207                         $(info "Building liboctbstack with DTLS support")
208                         mkdir -p $(OBJ_DIR)/tinydtls
209                         @cd $(OBJ_DIR)/tinydtls && $(AR) -x ../$(PLATFORM_SPECIFIC_BACKOUT)$(TINYDTLS_DIR)/libtinydtls.a
210                         $(AR) -q $(OUT_DIR)/$@ $(OBJ_DIR)/tinydtls/*.o
211       endif
212      endif
213     endif
214
215 .PHONY: clean print_vars
216
217 clean: legacy_clean
218         -rm -rf linux
219         -rm -rf arduinomega
220         -rm -rf arduinodue
221         @cd $(CONNECTIVITY_SRC)/build/ && $(MAKE) clean "PLATFORM=arduinomega"
222         @cd $(CONNECTIVITY_SRC)/samples/linux && $(MAKE) "clean"
223
224 deepclean: legacy_deepclean
225         -rm -rf linux
226         -rm -rf arduinomega
227         -rm -rf arduinodue
228
229 legacy_clean:
230         @echo "Cleaning all."
231         rm -f $(OBJ_DIR)/$(BUILD)/*.o
232         rm -f $(ROOT_DIR)/$(BUILD)/liboctbstack.a
233         cd $(CONNECTIVITY_SRC)/lib/libcoap-4.1.1 && $(MAKE) clean
234         cd $(CONNECTIVITY_SRC)/build/linux && $(MAKE) clean
235         cd $(CONNECTIVITY_SRC)/samples/linux && $(MAKE) clean
236         rm -rf $(OBJ_DIR)
237         rm -rf release
238         rm -rf debug
239
240 legacy_deepclean:
241         @echo "Deep-Cleaning all."
242         rm -f $(OBJ_DIR)/$(BUILD)/*.o
243         rm -f $(ROOT_DIR)/liboctbstack.a
244         cd $(CONNECTIVITY_SRC)/lib/libcoap-4.1.1 && $(MAKE) clean
245         cd $(CONNECTIVITY_SRC)/build/linux && $(MAKE) clean
246         cd $(CONNECTIVITY_SRC)/samples/linux && $(MAKE) clean
247         rm -rf $(OBJ_DIR)
248         rm -rf release
249         rm -rf debug