Implemented libcoap's tinyDTLS interface
[contrib/iotivity.git] / resource / csdk / libcoap-4.1.1 / 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 #other options are arduinomega, arduinodue
27 PLATFORM=linux
28 #other options are arduino
29 PLATFORM_TYPE=linux
30 # override with `make PLATFORM=arduinomega ARDUINOWIFI=1` to enable Arduino WiFi shield
31 ARDUINOWIFI := 0
32
33 ifeq ($(ROOT_DIR), )
34         ROOT_DIR = ..
35 endif
36 ifeq ($(PLATFORM), "")
37         PLATFORM := "linux"
38 endif
39
40 OCSOCK_DIR    = $(ROOT_DIR)/ocsocket
41 OC_LOG_DIR    = $(ROOT_DIR)/../oc_logger
42 LOGGER_DIR    = $(ROOT_DIR)/logger
43 RANDOM_DIR    = $(ROOT_DIR)/ocrandom
44 STACK_DIR     = $(ROOT_DIR)/stack
45 OCMALLOC_DIR  = $(ROOT_DIR)/ocmalloc
46 INC_DIRS      = -I$(OCSOCK_DIR)/include/ -I$(LOGGER_DIR)/include -I$(RANDOM_DIR)/include \
47                 -I$(OCMALLOC_DIR)/include -I$(OC_LOG_DIR)/include 
48
49 # Note for Arduino: The CC flag is set to the C++ compiler since Arduino build 
50 # includes Time.h header file which has C++ style definitions.
51 ifeq ($(PLATFORM),android)
52     CXX=arm-linux-androideabi-g++
53     CC=arm-linux-androideabi-gcc
54     AR=arm-linux-androideabi-ar
55     RANLIB=arm-linux-androideabi-ranlib
56     CFLAGS_PLATFORM =  -DWITH_POSIX -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16
57     LDFLAGS_PLATFORM = -march=armv7-a -Wl,--fix-cortex-a8 -llog
58 else ifeq ($(PLATFORM),linux)
59     PLATFORM_TYPE:=linux
60     CXX=g++
61     CC=gcc
62     AR=ar
63     RANLIB=ranlib
64     CFLAGS_PLATFORM = -std=gnu99 -DWITH_POSIX
65 else ifeq ($(PLATFORM),arduinomega)
66     PLATFORM_TYPE:=arduino
67     include $(ROOT_DIR)/local.properties
68     include $(ROOT_DIR)/$(PLATFORM).properties
69     CC=$(ARDUINO_TOOLS_DIR)/avr-g++
70 else ifeq ($(PLATFORM),arduinodue)
71     PLATFORM_TYPE:=arduino
72     include $(ROOT_DIR)/local.properties
73     include $(ROOT_DIR)/$(PLATFORM).properties
74     CC=$(ARDUINO_TOOLS_DIR)/arm-none-eabi-g++
75 else
76    $(error Wrong value for PLATFORM !!)
77 endif
78
79 ifeq ($(PLATFORM_TYPE),arduino)
80     ifeq ($(ARDUINOWIFI),1)
81         SOURCES += ocsocket_arduino_wifi.c
82         ARDUINO_SHIELD_TYPE := "/wifi_shield"
83     else
84         SOURCES += ocsocket_arduino.c
85         ARDUINO_SHIELD_TYPE := "/ethernet_shield"
86     endif
87     SOURCESCPP:= Time.cpp
88     OBJECTSCPP:= $(patsubst %.cpp, %.o, $(SOURCESCPP))
89     VPATH := $(SDIR_ARD_TIME)
90 else
91     SOURCES += ocsocket.c
92 endif
93
94 OUT_DIR   := ./$(PLATFORM)$(ARDUINO_SHIELD_TYPE)/$(BUILD)
95 OBJ_DIR   := $(OUT_DIR)/obj
96
97 CC_FLAGS.debug := -O0 -g3 -Wall -ffunction-sections -fdata-sections -fno-exceptions -pedantic \
98 -DTB_LOG
99 CC_FLAGS.release := -Os -Wall -ffunction-sections -fdata-sections -fno-exceptions
100
101 SOURCES+= pdu.c net.c debug.c encode.c uri.c coap_list.c hashkey.c \
102           str.c option.c async.c subscribe.c block.c logger.c ocrandom.c ocmalloc.c \
103                   oc_logger.c oc_console_logger.c
104 VPATH += $(OCSOCK_DIR)/src:$(LOGGER_DIR)/src:$(RANDOM_DIR)/src:$(OCMALLOC_DIR)/src\
105          :$(OC_LOG_DIR)/c
106
107 ifeq ($(PLATFORM),linux)
108 ifneq ($(wildcard $(ROOT_DIR)/tinydtls/libtinydtls.a),)
109     $(info "Building libcoap with DTLS support")
110         SOURCES += netdtls.c
111         VPATH += sec
112         TINYDTLS_DIR  = $(ROOT_DIR)/tinydtls
113         NETDTLS_DIR   = sec
114         INC_DIRS += -I$(TINYDTLS_DIR) -I$(NETDTLS_DIR) -I.
115         CC_FLAGS.debug += -DWITH_DTLS
116         CC_FLAGS.release += -DWITH_DTLS
117 endif
118 endif
119
120 OBJECTS:= $(patsubst %.c, %.o, $(SOURCES))
121
122 all: prep_dirs libcoap.a
123
124 prep_dirs:
125         -mkdir -p $(PLATFORM)
126         -mkdir -p $(OUT_DIR)
127         -mkdir -p $(OBJ_DIR)
128
129 %.o: %.c
130         $(CC) -c $(CC_FLAGS.$(BUILD)) $(CFLAGS_PLATFORM) $(INC_DIRS) $(INC_DIR_PLATFORM) $< -o $(OBJ_DIR)/$@
131
132 %.o: %.cpp
133         $(CXX) -c $(CC_FLAGS.$(BUILD)) $(CFLAGS_PLATFORM) $(INC_DIRS) $(INC_DIR_PLATFORM) $< -o $(OBJ_DIR)/$@
134
135 libcoap.a: $(OBJECTS) $(OBJECTSCPP)
136         $(AR) rcs $(OUT_DIR)/$@ $(addprefix $(OBJ_DIR)/,$^)
137         $(RANLIB) $(OUT_DIR)/$@
138
139 .PHONY: clean
140
141 clean:  legacy_clean
142         -rm -rf linux
143         -rm -rf arduinomega
144         -rm -rf arduinodue
145
146 legacy_clean:
147         rm -f *.o libcoap.a
148         rm -rf release
149         rm -rf debug
150