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