f26ba0009663b5f9b3f719c8aca6c9930181f2a7
[platform/upstream/iotivity.git] / resource / csdk / stack / samples / arduino / SimpleClientServer / ocserver / 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
22 BUILD := release
23 PLATFORM := arduinomega
24 ARDUINO_PORT := ttyACM0
25
26 # override with `make PLATFORM=arduinomega ARDUINOWIFI=1` to enable Arduino WiFi shield
27 ARDUINOWIFI := 0
28
29 APP_NAME := ocserver
30
31 ROOT_DIR = ../../../../..
32 LOGGER_DIR = $(ROOT_DIR)/logger
33 OC_LOG_DIR = $(ROOT_DIR)/../oc_logger
34 TBSTACK_DIR = $(ROOT_DIR)/stack
35
36 include $(ROOT_DIR)/local.properties
37 include $(ROOT_DIR)/$(PLATFORM).properties
38
39 VPATH := $(SDIR_ARD_PLATFORM)
40
41 #include directories
42 LOGGER_DIR = $(ROOT_DIR)/logger
43 STACK_DIR  = $(ROOT_DIR)/stack
44 INC_DIRS = -I$(OCSOCK_DIR)/include/ -I$(OC_LOG_DIR)/include -I$(LOGGER_DIR)/include -I$(STACK_DIR)/include
45
46 CC_FLAGS.debug          := -O1 -g3 -Wall -c -fmessage-length=0 -pedantic -fpic
47 CC_FLAGS.release        := -Os -Wall -c -fmessage-length=0 -fpic
48
49 CFLAGS := $(CC_FLAGS.$(BUILD)) -DTB_LOG
50
51 ifeq ($(ARDUINOWIFI),1)
52         CFLAGS += -DARDUINOWIFI
53         ARDUINO_SHIELD_TYPE := "/wifi_shield"
54         TRANSPORT_OBJS = $(WIFI_COBJ)
55 else
56         ARDUINO_SHIELD_TYPE := "/ethernet_shield"
57         TRANSPORT_OBJS = $(ETH_CPPOBJ) $(ETH_UTIL_CPPOBJ)
58 endif
59
60 OUT_DIR := $(PLATFORM)$(ARDUINO_SHIELD_TYPE)/$(BUILD)
61
62 OBJ_DIR := $(OUT_DIR)/bin
63
64 all: prep_dirs core.a $(APP_NAME).o $(APP_NAME).elf $(APP_NAME).hex
65
66 core.a: $(PLATFORM_OBJS)
67         @cd $(OBJ_DIR) && $(AR) -x ../../../../$(ROOT_DIR)/$(PLATFORM)$(ARDUINO_SHIELD_TYPE)/$(BUILD)/liboctbstack.a
68         @cd $(OBJ_DIR) && $(AR) -x ../../../../$(ROOT_DIR)/connectivity/build/arduino/core.a
69         $(AR) rcs $(OBJ_DIR)/$@ $(foreach obj, $^, $(OBJ_DIR)/$(obj)) $(OBJ_DIR)/*.o
70         @cd $(OBJ_DIR) && $(RANLIB) $@
71
72 prep_dirs:
73         -mkdir $(PLATFORM)
74         -mkdir $(PLATFORM)/$(ARDUINO_SHIELD_TYPE)
75         -mkdir $(OUT_DIR)
76         -mkdir $(OBJ_DIR)
77
78 %.o: %.c
79         $(CC) $(CFLAGS) $(CFLAGS_PLATFORM) $(INC_DIRS) $(INC_DIR_PLATFORM) $< -o $(OBJ_DIR)/$@
80
81 %.o: %.cpp
82         $(CXX) $(CFLAGS) $(CFLAGS_PLATFORM) $(INC_DIRS) $(INC_DIR_PLATFORM) $< -o $(OBJ_DIR)/$@
83
84 $(APP_NAME).elf: $(APP_NAME).o core.a
85 ifeq ($(PLATFORM),arduinomega)
86         $(CC) -Os -Wl,--gc-sections,--relax $(CFLAGS_PLATFORM) $(foreach obj, $^, $(OBJ_DIR)/$(obj)) -lm -o $(OBJ_DIR)/$@
87 else ifeq ($(PLATFORM),arduinodue)
88         $(CXX) -Os -Wl,--gc-sections -mcpu=cortex-m3 -T/$(SDIR_ARD_CORE_3)/linker_scripts/gcc/flash.ld -Wl,-Map,$(APP_NAME).map -o $(OBJ_DIR)/$@ -lm -lgcc -mthumb -Wl,--cref -Wl,--check-sections -Wl,--gc-sections -Wl,--entry=Reset_Handler -Wl,--unresolved-symbols=report-all -Wl,--warn-common -Wl,--warn-section-align -Wl,--warn-unresolved-symbols -Wl,--start-group $(foreach obj, $(APP_NAME).o $(SYSCALLS_SAM3_OBJ) $(SPI_OBJ) $(TRANSPORT_OBJS) $(VARIANT_OBJ) core.a, $(OBJ_DIR)/$(obj)) $(SDIR_ARD_CORE_3)/libsam_sam3x8e_gcc_rel.a -Wl,--end-group
89 else
90         $(error Wrong value for PLATFORM !!)
91 endif
92
93 $(APP_NAME).hex: $(APP_NAME).elf
94 ifeq ($(PLATFORM),arduinomega)
95         $(AVR_OBJCOPY) -O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0 $(OBJ_DIR)/$< $(OBJ_DIR)/$(APP_NAME).eep
96         $(AVR_OBJCOPY) -O ihex -R .eeprom $(OBJ_DIR)/$< $(OUT_DIR)/$@
97 else ifeq ($(PLATFORM),arduinodue)
98         $(ARDUINO_TOOLS_DIR)/arm-none-eabi-objcopy -O binary $(OBJ_DIR)/$< $(OUT_DIR)/$@
99 else
100         $(error Wrong value for PLATFORM !!)
101 endif
102
103 install: all
104 ifeq ($(PLATFORM),arduinomega)
105         $(AVR_PROGRAMMER) -C$(ARDUINO_DIR)/hardware/tools/avr/etc/avrdude.conf -v -v -v -v -patmega2560 -cstk500v2 -P/dev/$(ARDUINO_PORT) -b115200 -D -Uflash:w:$(OUT_DIR)/$(APP_NAME).hex:i
106 else ifeq ($(PLATFORM),arduinodue)
107         stty -F /dev/$(ARDUINO_PORT) speed 1200 cs8 -cstopb -parenb
108         $(ARDUINO_DIR)/hardware/tools/bossac -i -d --port=$(ARDUINO_PORT) -U false -e -w -v -b $(OUT_DIR)/$(APP_NAME).hex -R
109 else
110         $(error Wrong value for PLATFORM !!)
111 endif
112
113 .PHONY: clean
114
115 clean: legacy_clean
116         rm -rf arduinomega
117         rm -rf arduinodue
118
119 legacy_clean:
120         @rm -rf bin
121         @rm -f *.o *.d *.elf *.eep *.a *.hex *.bin *.map *-
122