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