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