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
28 # override with `make PLATFORM=arduinomega ARDUINOWIFI=1` to enable Arduino WiFi shield
37 ifeq ($(PLATFORM),linux)
42 CFLAGS_PLATFORM = -DWITH_POSIX -std=c99
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 \
55 else ifeq ($(PLATFORM),arduinodue)
56 include local.properties
57 include $(PLATFORM).properties
58 CC=$(ARDUINO_TOOLS_DIR)/arm-none-eabi-g++
61 $(error Wrong value for PLATFORM !!)
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"
70 PLATFORM_SPECIFIC_BACKOUT:= ../../../../
72 PLATFORM_SPECIFIC_BACKOUT := ../../../
76 OUT_DIR = $(PLATFORM)$(ARDUINO_SHIELD_TYPE)/$(BUILD)
80 OBJ_DIR = $(OUT_DIR)/obj
84 OC_LOG_DIR = ../oc_logger
85 OCRANDOM_DIR = ocrandom
86 OCSOCKET_DIR = ocsocket
87 LCOAP_DIR = libcoap-4.1.1
90 OCMALLOC_DIR = ocmalloc
91 EXTLIBS_DIR = ../../extlibs
92 CJSON_DIR = $(EXTLIBS_DIR)/cjson
93 TINYDTLS_DIR = $(EXTLIBS_DIR)/tinydtls
95 OCCOAP_SRC = $(OCCOAP_DIR)/src
96 OCTBSTACK_SRC = $(OCTBSTACK_DIR)/src
97 OCMALLOC_SRC = $(OCMALLOC_DIR)/src
98 CJSON_SRC = $(CJSON_DIR)
100 OCLOGGER_INC = $(OCLOGGER_DIR)/include
101 OC_LOG_INC = $(OC_LOG_DIR)/include
102 OCRANDOM_INC = $(OCRANDOM_DIR)/include
103 OCSOCKET_INC = $(OCSOCKET_DIR)/include
104 LCOAP_INC = $(LCOAP_DIR)
105 OCCOAP_INC = $(OCCOAP_DIR)/include
106 OCTBSTACK_INC = $(OCTBSTACK_DIR)/include
107 OCMALLOC_INC = $(OCMALLOC_DIR)/include
108 CJSON_INC = $(CJSON_DIR)
110 INC_DIRS := -I$(OCLOGGER_INC)
111 INC_DIRS += -I$(OC_LOG_INC)
112 INC_DIRS += -I$(OCRANDOM_INC)
113 INC_DIRS += -I$(OCSOCKET_INC)
114 INC_DIRS += -I$(LCOAP_INC)
115 INC_DIRS += -I$(OCCOAP_INC)
116 INC_DIRS += -I$(OCMALLOC_INC)
117 INC_DIRS += -I$(OCTBSTACK_INC)
118 INC_DIRS += -I$(OCTBSTACK_INC)/internal
119 INC_DIRS += -I$(CJSON_INC)
121 CC_FLAGS.debug := -O0 -g3 -Wall -c -fmessage-length=0 -pedantic -fpic -DTB_LOG
122 CC_FLAGS.release := -Os -Wall -c -fmessage-length=0 -fpic
124 CFLAGS += $(CC_FLAGS.$(BUILD)) $(INC_DIRS) $(CFLAGS_PLATFORM) $(INC_DIR_PLATFORM)
127 CJSON_SOURCES := $(CJSON_SRC)/cJSON.c
129 OCCOAP_SOURCES := $(OCCOAP_SRC)/occoap.c
130 OCCOAP_SOURCES += $(OCCOAP_SRC)/occoaphelper.c
132 OCTBSTACK_SOURCES := $(OCTBSTACK_SRC)/ocstack.c
133 OCTBSTACK_SOURCES += $(OCTBSTACK_SRC)/occlientcb.c
134 OCTBSTACK_SOURCES += $(OCTBSTACK_SRC)/ocresource.c
135 OCTBSTACK_SOURCES += $(OCTBSTACK_SRC)/ocobserve.c
136 OCTBSTACK_SOURCES += $(OCTBSTACK_SRC)/ocserverrequest.c
137 OCTBSTACK_SOURCES += $(OCTBSTACK_SRC)/occollection.c
138 OCTBSTACK_SOURCES += $(OCTBSTACK_SRC)/oicgroup.c
139 OCTBSTACK_SOURCES += $(OCTBSTACK_SRC)/ocsecurity.c
141 SOURCES := $(CJSON_SOURCES)
142 SOURCES += $(OCCOAP_SOURCES)
143 SOURCES += $(OCTBSTACK_SOURCES)
145 all: make_lcoap objdirs obj_build liboctbstack.a
147 buildScript_all: objdirs obj_build liboctbstack.a
150 $(MAKE) -C $(LCOAP_DIR) "BUILD=$(BUILD)" "PLATFORM=$(PLATFORM)" "ARDUINOWIFI=$(ARDUINOWIFI)"
154 mkdir -p $(PLATFORM)/$(ARDUINO_SHIELD_TYPE)
160 # Output all *.o files to $(OUT_DIR)/$(BUILD)/$(OBJ_DIR)
161 $(foreach source,$(SOURCES), $(CC) $(CFLAGS) $(source) -o $(patsubst %.c, %.o, $(patsubst %, $(OBJ_DIR)/%, $(notdir $(source))));)
163 liboctbstack.a: obj_build
165 # Unpackage libcoap.a to $(OBJ_DIR)/$(BUILD). The output objects from OCStack and OCCoap are already at this location
166 @cd $(OBJ_DIR) && $(AR) -x $(PLATFORM_SPECIFIC_BACKOUT)$(LCOAP_DIR)/$(PLATFORM)$(ARDUINO_SHIELD_TYPE)/$(BUILD)/libcoap.a
167 # Repackage all the objects at this location into a single archive. This is OCStack, OCCoap, and LibCoap (LibCoap contains OCRandom, OCLogger, and OCSocket.).
168 $(AR) -r $(OUT_DIR)/$@ $(OBJ_DIR)/*.o
170 ifeq ($(PLATFORM),linux)
171 ifneq ($(wildcard $(TINYDTLS_DIR)/libtinydtls.a),)
172 $(info "Building liboctbstack with DTLS support")
173 mkdir -p $(OBJ_DIR)/tinydtls
174 @cd $(OBJ_DIR)/tinydtls && $(AR) -x ../$(PLATFORM_SPECIFIC_BACKOUT)$(TINYDTLS_DIR)/libtinydtls.a
175 $(AR) -q $(OUT_DIR)/$@ $(OBJ_DIR)/tinydtls/*.o
179 .PHONY: clean print_vars
186 deepclean: legacy_deepclean
192 @echo "Cleaning all."
193 rm -f $(OBJ_DIR)/$(BUILD)/*.o
194 rm -f $(ROOT_DIR)/$(BUILD)/liboctbstack.a
200 @echo "Deep-Cleaning all."
201 rm -f $(OBJ_DIR)/$(BUILD)/*.o
202 rm -f $(ROOT_DIR)/liboctbstack.a
204 $(MAKE) clean -C $(LCOAP_DIR)