[CA Integration] Pass connectivity type on which response is received
[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 BUILD    := release
26 PLATFORM := linux
27
28 # override with `make PLATFORM=arduinomega ARDUINOWIFI=1` to enable Arduino WiFi shield
29 ARDUINOWIFI := 0
30 CA_INT_DTLS := 0
31
32 ifeq ($(ROOT_DIR), )
33 ROOT_DIR        = ./
34 endif
35
36 PLATFORM_TYPE = linux
37
38 ifeq ($(PLATFORM),linux)
39     CXX=g++
40     CC=gcc
41     AR=ar
42     RANLIB=ranlib
43     CFLAGS_PLATFORM = -DWITH_POSIX -std=c99
44     PLATFORM_TYPE=linux
45 else ifeq ($(PLATFORM),arduinomega)
46     include local.properties
47     include $(PLATFORM).properties
48     CC=$(ARDUINO_TOOLS_DIR)/avr-g++
49     ifeq ($(wildcard $(ARDUINO_DIR)/libraries/Time/Time/),)
50         $(error Arduino Time library needs to be moved from <ARDUINO_DIR>/libraries/Time \
51         to <ARDUINO_DIR>/libraries/Time/Time. You may need to create \
52         <ARDUINO_DIR>/libraries/Time/Time directory. Please refer to the wiki or readme \
53         for more information)
54     endif
55     PLATFORM_TYPE=arduino
56 else ifeq ($(PLATFORM),arduinodue)
57     include local.properties
58     include $(PLATFORM).properties
59     CC=$(ARDUINO_TOOLS_DIR)/arm-none-eabi-g++
60     PLATFORM_TYPE=arduino
61 else
62     $(error Wrong value for PLATFORM !!)
63 endif
64
65 ifeq ($(PLATFORM_TYPE),arduino)
66     ifeq ($(ARDUINOWIFI),0)
67     ARDUINO_SHIELD_TYPE := "/ethernet_shield"
68     else ifeq ($(ARDUINOWIFI), 1)
69     ARDUINO_SHIELD_TYPE := "/wifi_shield"
70     endif
71     PLATFORM_SPECIFIC_BACKOUT:= ../../../../
72 else
73     PLATFORM_SPECIFIC_BACKOUT := ../../../
74 endif
75
76 ifeq ($(OUT_DIR), )
77 OUT_DIR = $(PLATFORM)$(ARDUINO_SHIELD_TYPE)/$(BUILD)
78 endif
79
80 ifeq ($(OBJ_DIR), )
81 OBJ_DIR = $(OUT_DIR)/obj
82 endif
83
84 OCLOGGER_DIR            = logger
85 OC_LOG_DIR              = ../oc_logger
86 OCRANDOM_DIR            = ocrandom
87 OCSOCKET_DIR            = ocsocket
88 LCOAP_DIR               = libcoap-4.1.1
89 OCCOAP_DIR              = occoap
90 OCTBSTACK_DIR           = stack
91 OCMALLOC_DIR            = ocmalloc
92 EXTLIBS_DIR             = ../../extlibs
93 CJSON_DIR               = $(EXTLIBS_DIR)/cjson
94 TINYDTLS_DIR    = $(EXTLIBS_DIR)/tinydtls
95 CONNECTIVITY_DIR        = connectivity
96
97 OCCOAP_SRC              = $(OCCOAP_DIR)/src
98 OCTBSTACK_SRC           = $(OCTBSTACK_DIR)/src
99 OCMALLOC_SRC            = $(OCMALLOC_DIR)/src
100 CJSON_SRC               = $(CJSON_DIR)
101 CONNECTIVITY_SRC        = $(CONNECTIVITY_DIR)
102
103 OCLOGGER_INC            = $(OCLOGGER_DIR)/include
104 OC_LOG_INC              = $(OC_LOG_DIR)/include
105 OCRANDOM_INC            = $(OCRANDOM_DIR)/include
106 OCSOCKET_INC            = $(OCSOCKET_DIR)/include
107 LCOAP_INC               = $(LCOAP_DIR)
108 OCCOAP_INC              = $(OCCOAP_DIR)/include
109 OCTBSTACK_INC           = $(OCTBSTACK_DIR)/include
110 OCMALLOC_INC            = $(OCMALLOC_DIR)/include
111 CJSON_INC               = $(CJSON_DIR)
112 CONNECTIVITY_INC        = $(CONNECTIVITY_DIR)/inc
113
114 INC_DIRS        := -I$(OCLOGGER_INC)
115 INC_DIRS        += -I$(OC_LOG_INC)
116 INC_DIRS        += -I$(OCRANDOM_INC)
117 INC_DIRS        += -I$(OCSOCKET_INC)
118 INC_DIRS        += -I$(LCOAP_INC)
119 INC_DIRS        += -I$(OCCOAP_INC)
120 INC_DIRS        += -I$(OCMALLOC_INC)
121 INC_DIRS        += -I$(OCTBSTACK_INC)
122 INC_DIRS        += -I$(OCTBSTACK_INC)/internal
123 INC_DIRS        += -I$(CJSON_INC)
124 INC_DIRS        += -I$(CONNECTIVITY_INC)
125 INC_DIRS        += -I$(CONNECTIVITY_DIR)/api
126
127 # TODO-CA Remove -fstack-protector-all before merging to master
128 # TODO-CA Remove CA_INT flag after CA merging is finalized
129 CC_FLAGS.debug          := -O0 -g3 -Wall -fstack-protector-all -c -fmessage-length=0 -pedantic -fpic -DTB_LOG -DCA_INT
130 # TODO-CA Remove -fstack-protector-all before merging to master
131 CC_FLAGS.release        := -Os -Wall -fstack-protector-all -c -fmessage-length=0 -fpic -DCA_INT
132
133 CFLAGS          += $(CC_FLAGS.$(BUILD)) $(INC_DIRS) $(CFLAGS_PLATFORM) $(INC_DIR_PLATFORM)
134 LDLIBS          += -lcoap
135
136 CJSON_SOURCES           := $(CJSON_SRC)/cJSON.c
137
138 OCCOAP_SOURCES          := $(OCCOAP_SRC)/occoap.c
139 OCCOAP_SOURCES          += $(OCCOAP_SRC)/occoaphelper.c
140
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       += $(OCTBSTACK_SRC)/ocsecurity.c
149
150 SOURCES                 := $(CJSON_SOURCES)
151 SOURCES                 += $(OCCOAP_SOURCES)
152 SOURCES                 += $(OCTBSTACK_SOURCES)
153
154 all:    make_lcoap objdirs obj_build ca liboctbstack.a
155
156 buildScript_all: objdirs obj_build ca liboctbstack.a
157
158 make_lcoap:
159         @echo "Building $@"
160         $(MAKE) -C $(LCOAP_DIR) "BUILD=$(BUILD)" "PLATFORM=$(PLATFORM)" "ARDUINOWIFI=$(ARDUINOWIFI)" "CA_INT_DTLS=$(CA_INT_DTLS)"
161
162 objdirs:
163         mkdir -p $(PLATFORM)
164         mkdir -p $(PLATFORM)/$(ARDUINO_SHIELD_TYPE)
165         mkdir -p $(OUT_DIR)
166         mkdir -p $(OBJ_DIR)
167
168 obj_build:
169         @echo "Building $@"
170         # Output all *.o files to $(OUT_DIR)/$(BUILD)/$(OBJ_DIR)
171         $(foreach source,$(SOURCES), $(CC) $(CFLAGS) $(source) -o $(patsubst %.c, %.o, $(patsubst %, $(OBJ_DIR)/%, $(notdir $(source))));)
172
173 ca:
174         @echo "Building $@"
175         @cd $(CONNECTIVITY_SRC)/lib/libcoap-4.1.1 && $(MAKE)
176         @cd $(CONNECTIVITY_SRC)/build/linux && $(MAKE)
177         @cd $(CONNECTIVITY_SRC)/samples/linux && $(MAKE)
178
179 liboctbstack.a:
180         @echo "Building $@"
181         # Unpackage libcoap.a to $(OBJ_DIR)/$(BUILD). The output objects from OCStack and OCCoap are already at this location
182         @cd $(OBJ_DIR) && $(AR) -x $(PLATFORM_SPECIFIC_BACKOUT)$(LCOAP_DIR)/$(PLATFORM)$(ARDUINO_SHIELD_TYPE)/$(BUILD)/libcoap.a
183         # Repackage all the objects at this location into a single archive. This is OCStack, OCCoap, and LibCoap (LibCoap contains OCRandom, OCLogger, and OCSocket.).
184         $(AR) -r $(OUT_DIR)/$@ $(OBJ_DIR)/*.o
185
186     ifeq ($(CA_INT_DTLS),0)
187      ifeq ($(PLATFORM),linux)
188       ifneq ($(wildcard $(TINYDTLS_DIR)/libtinydtls.a),)
189                         $(info "Building liboctbstack with DTLS support")
190                         mkdir -p $(OBJ_DIR)/tinydtls
191                         @cd $(OBJ_DIR)/tinydtls && $(AR) -x ../$(PLATFORM_SPECIFIC_BACKOUT)$(TINYDTLS_DIR)/libtinydtls.a
192                         $(AR) -q $(OUT_DIR)/$@ $(OBJ_DIR)/tinydtls/*.o
193       endif
194      endif
195     endif
196
197 .PHONY: clean print_vars
198
199 clean: legacy_clean
200         -rm -rf linux
201         -rm -rf arduinomega
202         -rm -rf arduinodue
203
204 deepclean: legacy_deepclean
205         -rm -rf linux
206         -rm -rf arduinomega
207         -rm -rf arduinodue
208
209 legacy_clean:
210         @echo "Cleaning all."
211         rm -f $(OBJ_DIR)/$(BUILD)/*.o
212         rm -f $(ROOT_DIR)/$(BUILD)/liboctbstack.a
213         cd $(CONNECTIVITY_SRC)/lib/libcoap-4.1.1 && $(MAKE) clean
214         cd $(CONNECTIVITY_SRC)/build/linux && $(MAKE) clean
215         cd $(CONNECTIVITY_SRC)/samples/linux && $(MAKE) clean
216         rm -rf $(OBJ_DIR)
217         rm -rf release
218         rm -rf debug
219
220 legacy_deepclean:
221         @echo "Deep-Cleaning all."
222         rm -f $(OBJ_DIR)/$(BUILD)/*.o
223         rm -f $(ROOT_DIR)/liboctbstack.a
224         cd $(CONNECTIVITY_SRC)/lib/libcoap-4.1.1 && $(MAKE) clean
225         cd $(CONNECTIVITY_SRC)/build/linux && $(MAKE) clean
226         cd $(CONNECTIVITY_SRC)/samples/linux && $(MAKE) clean
227         rm -rf $(OBJ_DIR)
228         $(MAKE) clean -C $(LCOAP_DIR)
229         rm -rf release
230         rm -rf debug