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