Merge "IOT-31: Add copyright info to all makefiles"
[platform/upstream/iotivity.git] / 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        = $(PWD)
33 endif
34
35 ifeq ($(OBJ_DIR), )
36 OBJ_DIR = obj
37 endif
38
39
40 ifeq ($(PLATFORM),linux)
41     CCPLUS=g++
42     CC=gcc
43     AR=ar
44     RANLIB=ranlib
45     CFLAGS_PLATFORM = -DWITH_POSIX -std=c99
46 else ifeq ($(PLATFORM),arduinomega)
47     include local.properties
48     include $(PLATFORM).properties
49         CC=$(ARDUINO_TOOLS_DIR)/avr-g++
50 else ifeq ($(PLATFORM),arduinodue)
51     include local.properties
52     include $(PLATFORM).properties
53         CC=$(ARDUINO_TOOLS_DIR)/arm-none-eabi-g++
54 else
55    $(error Wrong value for PLATFORM !!)
56 endif
57
58 OCLOGGER_DIR    = $(ROOT_DIR)/logger
59 OCRANDOM_DIR    = $(ROOT_DIR)/ocrandom
60 OCSOCKET_DIR    = $(ROOT_DIR)/ocsocket
61 LCOAP_DIR       = $(ROOT_DIR)/libcoap-4.1.1
62 OCCOAP_DIR      = $(ROOT_DIR)/occoap
63 OCTBSTACK_DIR   = $(ROOT_DIR)/stack
64 UTILS_DIR       = $(ROOT_DIR)/../../oic-utilities/tb
65 CJSON_DIR       = $(UTILS_DIR)/cJSON
66
67 OCCOAP_SRC      = $(OCCOAP_DIR)/src
68 OCTBSTACK_SRC   = $(OCTBSTACK_DIR)/src
69 CJSON_SRC       = $(CJSON_DIR)
70
71 OCLOGGER_INC    = $(OCLOGGER_DIR)/include
72 OCRANDOM_INC    = $(OCRANDOM_DIR)/include
73 OCSOCKET_INC    = $(OCSOCKET_DIR)/include
74 LCOAP_INC       = $(LCOAP_DIR)
75 OCCOAP_INC      = $(OCCOAP_DIR)/include
76 OCTBSTACK_INC   = $(OCTBSTACK_DIR)/include
77 CJSON_INC       = $(CJSON_DIR)
78
79 INC_DIRS        := -I$(OCLOGGER_INC)
80 INC_DIRS        += -I$(OCRANDOM_INC)
81 INC_DIRS        += -I$(OCSOCKET_INC)
82 INC_DIRS        += -I$(LCOAP_INC)
83 INC_DIRS        += -I$(OCCOAP_INC)
84 INC_DIRS        += -I$(OCTBSTACK_INC)
85 INC_DIRS        += -I$(OCTBSTACK_INC)/internal
86 INC_DIRS        += -I$(CJSON_INC)
87
88 CC_FLAGS.debug          := -O0 -g3 -Wall -c -fmessage-length=0 -pedantic -fpic -DTB_LOG
89 CC_FLAGS.release        := -Os -Wall -c -fmessage-length=0 -fpic
90
91 CFLAGS          += $(CC_FLAGS.$(BUILD)) $(INC_DIRS) $(CFLAGS_PLATFORM) $(INC_DIR_PLATFORM)
92 LDLIBS          += -lcoap
93
94 CJSON_SOURCES           := $(CJSON_SRC)/cJSON.c
95
96 OCCOAP_SOURCES          := $(OCCOAP_SRC)/occoap.c
97 OCCOAP_SOURCES          += $(OCCOAP_SRC)/occoaphelper.c
98
99 OCTBSTACK_SOURCES       := $(OCTBSTACK_SRC)/ocstack.c
100 OCTBSTACK_SOURCES       += $(OCTBSTACK_SRC)/occlientcb.c
101 OCTBSTACK_SOURCES       += $(OCTBSTACK_SRC)/ocresource.c
102 OCTBSTACK_SOURCES       += $(OCTBSTACK_SRC)/ocobserve.c
103 OCTBSTACK_SOURCES       += $(OCTBSTACK_SRC)/occollection.c
104
105 SOURCES                 := $(CJSON_SOURCES)
106 SOURCES                 += $(OCCOAP_SOURCES)
107 SOURCES                 += $(OCTBSTACK_SOURCES)
108
109 all:    make_lcoap objdirs obj_build liboctbstack.a #print_vars
110
111 make_lcoap: 
112         $(MAKE) -C $(LCOAP_DIR) "BUILD=$(BUILD)" "PLATFORM=$(PLATFORM)" "ARDUINOWIFI=$(ARDUINOWIFI)"
113
114 objdirs: $(ROOT_DIR)
115         mkdir -p $(BUILD)
116         mkdir -p $(BUILD)/$(OBJ_DIR)
117
118 obj_build:
119         @echo "Building $@"
120         # Output all *.o files to $(OBJ_DIR)/$(BUILD)
121         $(foreach source,$(SOURCES), $(CC) $(LDLIBS) $(CFLAGS) $(source) -o $(patsubst %.c, %.o, $(patsubst %, $(BUILD)/$(OBJ_DIR)/%, $(notdir $(source))));)
122
123 liboctbstack.a:
124         @echo "Building $@" 
125         # Unpackage libcoap.a to $(OBJ_DIR)/$(BUILD). The output objects from OCStack and OCCoap are already at this location
126         @cd $(BUILD)/$(OBJ_DIR) && $(AR) -x $(LCOAP_DIR)/$(BUILD)/libcoap.a
127         # Repackage all the objects at this location into a single archive. This is OCStack, OCCoap, and LibCoap (LibCoap contains OCRandom, OCLogger, and OCSocket.).
128         $(AR) -r $(BUILD)/$@ $(BUILD)/$(OBJ_DIR)/*.o
129
130 .PHONY: clean print_vars
131
132 clean: legacy_clean
133         -rm -rf release
134         -rm -rf debug
135
136 deepclean: legacy_deepclean
137         -rm -rf release
138         -rm -rf debug
139
140 legacy_clean:   $(ROOT_DIR)
141         @echo "Cleaning all."
142         rm -f $(OBJ_DIR)/$(BUILD)/*.o
143         rm -f $(ROOT_DIR)/$(BUILD)/liboctbstack.a
144         rm -rf $(OBJ_DIR)
145
146 legacy_deepclean: $(ROOT_DIR)
147         @echo "Deep-Cleaning all."
148         rm -f $(OBJ_DIR)/$(BUILD)/*.o
149         rm -f $(ROOT_DIR)/liboctbstack.a
150         rm -rf $(OBJ_DIR)
151         $(MAKE) clean -C $(LCOAP_DIR)
152
153 print_vars:
154         @echo ""
155         @echo 'INCLUDES ARE: '$(value INC_DIRS)
156         @echo ""
157         @echo 'SOURCE FILES ARE: '$(value SOURCES)
158         @echo ""
159         @echo 'OBJ_DIR/BUILD is: '$(OBJ_DIR)'/'$(BUILD)
160         @echo ""
161         @echo 'ROOT_DIR is: '$(ROOT_DIR)