iotivity 0.9.0
[platform/upstream/iotivity.git] / resource / csdk / stack / test / arduino / 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 BUILD    := release
22 PLATFORM := arduinomega
23
24 ROOT_DIR = ../../..
25 include $(ROOT_DIR)/local.properties
26 LIBCOAP_DIR = $(ROOT_DIR)/libcoap-4.1.1
27 OCSOCK_DIR = $(ROOT_DIR)/ocsocket
28 OCCOAP_DIR = $(ROOT_DIR)/occoap
29 LOGGER_DIR = $(ROOT_DIR)/logger
30 RANDOM_DIR = $(ROOT_DIR)/ocrandom
31 JSON_DIR = $(ROOT_DIR)/../../extlibs/cjson
32 OCSTACK_DIR = $(ROOT_DIR)/stack
33 BIN_DIR = $(OCSTACK_DIR)/bin/arduino/
34 OBJ_DIR = $(OCSTACK_DIR)/obj/arduino/
35
36 #Source directories
37 SDIR_ARD_CORE = $(ARDUINO_DIR)/hardware/arduino/cores/arduino
38 SDIR_ARD_SPI = $(ARDUINO_DIR)/libraries/SPI
39 SDIR_ARD_ETH = $(ARDUINO_DIR)/libraries/Ethernet
40 SDIR_ARD_ETH_UTIL = $(ARDUINO_DIR)/libraries/Ethernet/utility
41 SDIR_ARD_TIME = $(ARDUINO_DIR)/libraries/Time
42
43 VPATH = $(SDIR_ARD_CORE):$(SDIR_ARD_SPI):$(SDIR_ARD_ETH):$(SDIR_ARD_ETH_UTIL):$(SDIR_ARD_TIME):$(RANDOM_DIR)/src:$(OCSTACK_DIR)/src:$(OCCOAP_DIR)/src:$(JSON_DIR)
44
45 #include directories
46 IDIR_ARD_CORE = $(ARDUINO_DIR)/hardware/arduino/cores/arduino
47 IDIR_ARD_VARIANT = $(ARDUINO_DIR)/hardware/arduino/variants/mega
48 IDIR_ARD_SPI = $(ARDUINO_DIR)/libraries/SPI
49 IDIR_ARD_ETH = $(ARDUINO_DIR)/libraries/Ethernet
50 IDIR_ARD_ETH_UTIL = $(ARDUINO_DIR)/libraries/Ethernet/utility
51 IDIR_ARD_TIME = $(ARDUINO_DIR)/libraries/Time
52
53 INC_DIRS = -I$(IDIR_ARD_CORE) -I$(IDIR_ARD_VARIANT) -I$(IDIR_ARD_SPI) \
54         -I$(IDIR_ARD_ETH) -I$(IDIR_ARD_ETH_UTIL) -I$(IDIR_ARD_TIME) \
55         -I$(OCSOCK_DIR)/include -I$(LOGGER_DIR)/include -I$(RANDOM_DIR)/include \
56         -I$(OCSTACK_DIR)/include -I$(OCSTACK_DIR)/include/internal \
57          -I$(LIBCOAP_DIR)/ -I$(OCCOAP_DIR)/include -I$(JSON_DIR)
58
59 #Compiler/Linker flags
60 COPTIONS_ARDUINO = -mmcu=atmega2560 -DF_CPU=16000000L -DARDUINO=156 -DARDUINO_AVR_MEGA2560 -DARDUINO_ARCH_AVR -MMD -DNDEBUG
61 CFLAGS += -c -Os -Wall -Wno-write-strings -ffunction-sections -fdata-sections -fno-exceptions -felide-constructors -std=c++0x -DATMEGA2560 -DTB_LOG -DWITH_ARDUINO
62
63 #Compilers
64 CXX=avr-g++
65 CC=avr-gcc
66 AR=avr-ar
67 RANLIB=avr-ranlib
68
69 TESTAPP = ocserver
70
71 CORE_COBJ = WInterrupts.o wiring.o wiring_digital.o
72 CORE_CPPOBJ = main.o Stream.o WMath.o WString.o HardwareSerial.o Print.o SPI.o IPAddress.o wiring_analog.o
73 ETH_CPPOBJ = Dhcp.o Dns.o Ethernet.o EthernetUdp.o
74 ETH_UTIL_CPPOBJ = socket.o w5100.o
75 OCSTACK_CPPOBJ = ocrandom.o ocresource.o occollection.o ocobserve.o ocserverrequest.o ocstack.o occoaphelper.o occoap.o occlientcb.o
76 OCDEPENDENT_CPPOBJ = wiring_analog.o
77 CJSON_COBJ = cJSON.o
78
79 all: core.a $(TESTAPP).o $(TESTAPP).elf $(TESTAPP).hex
80         mkdir -p $(BIN_DIR)
81         cp $(TESTAPP).hex $(BIN_DIR)
82         mkdir -p $(OBJ_DIR)
83         cp *.o $(OBJ_DIR)
84         cp *.elf $(OBJ_DIR)
85
86 # Note for Arduino: The C files are compiled using C++ compiler since Arduino
87 # build includes Time.h header file which has C++ style definitions.
88 %.o: %.c
89         $(CXX) $(CFLAGS) $(COPTIONS_ARDUINO) $(INC_DIRS) $< -o $@
90
91 %.o: %.cpp
92         $(CXX) $(CFLAGS) $(COPTIONS_ARDUINO) $(INC_DIRS) $< -o $@
93
94 core.a: $(CORE_COBJ) $(CORE_CPPOBJ) $(ETH_CPPOBJ) $(ETH_UTIL_CPPOBJ) $(LIBCOAP_DIR)/$(BUILD)/libcoap.a
95         $(AR) rcs $@ $^
96         $(RANLIB) $@
97
98 $(TESTAPP).elf: $(TESTAPP).o core.a $(OCSTACK_CPPOBJ) $(OCDEPENDENT_CPPOBJ) $(LIBCOAP_DIR)/$(BUILD)/libcoap.a $(CJSON_COBJ)
99         $(CC) -Os -Wl,--gc-sections,--relax $(COPTIONS_ARDUINO) $^ -lm -o $@
100
101 $(TESTAPP).hex: $(TESTAPP).elf
102         avr-objcopy -O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0 $< $(TESTAPP).eep
103         avr-objcopy -O ihex -R .eeprom $< $@
104
105 install: all
106         avrdude -C$(ARDUINO_DIR)/hardware/tools/avrdude.conf -v -v -v -v -patmega2560 -cstk500v2 -P/dev/ttyACM0 -b115200 -D -Uflash:w:$(TESTAPP).hex:i
107
108 .PHONY: clean
109
110 clean:
111         rm -f *.o *.d *.elf *.eep *.a *.hex *-
112         rm -fr $(BIN_DIR)
113         rm -fr $(OBJ_DIR)
114