#Source directories
SDIR_ARD_CORE_1 = $(ARDUINO_DIR)/hardware/arduino/sam/cores/arduino
SDIR_ARD_CORE_2 = $(ARDUINO_DIR)/hardware/arduino/sam/cores/arduino/USB
SDIR_ARD_CORE_3 = $(ARDUINO_DIR)/hardware/arduino/sam/variants/arduino_due_x
SDIR_ARD_CORE_4 = $(ARDUINO_DIR)/hardware/arduino/sam/cores/arduino/avr
SDIR_ARD_SPI = $(ARDUINO_DIR)/hardware/arduino/sam/libraries/SPI
SDIR_ARD_ETH = $(ARDUINO_DIR)/libraries/Ethernet/src
SDIR_ARD_ETH_UTIL = $(ARDUINO_DIR)/libraries/Ethernet/src/utility
SDIR_ARD_WIFI = $(ARDUINO_DIR)/libraries/WiFi/src
SDIR_ARD_WIFI_UTIL = $(ARDUINO_DIR)/libraries/WiFi/src/utility
SDIR_ARD_TIME = $(ARDUINO_DIR)/libraries/Time/Time

SDIR_ARD_PLATFORM = $(SDIR_ARD_CORE_1):$(SDIR_ARD_CORE_2):$(SDIR_ARD_CORE_3):$(SDIR_ARD_CORE_4):$(SDIR_ARD_SPI):\
                        $(SDIR_ARD_TIME)

#include directories
IDIR_ARD_CORE_1 = $(ARDUINO_DIR)/hardware/arduino/sam/cores/arduino
IDIR_ARD_CORE_2 = $(ARDUINO_DIR)/hardware/arduino/sam/system/libsam
IDIR_ARD_CORE_3 = $(ARDUINO_DIR)/hardware/arduino/sam/system/CMSIS/CMSIS/Include
IDIR_ARD_CORE_4 = $(ARDUINO_DIR)/hardware/arduino/sam/system/CMSIS/Device/ATMEL
IDIR_ARD_CORE_5 = $(ARDUINO_DIR)/hardware/arduino/sam/variants/arduino_due_x
IDIR_ARD_SPI = $(ARDUINO_DIR)/hardware/arduino/sam/libraries/SPI
IDIR_ARD_ETH = $(ARDUINO_DIR)/libraries/Ethernet/src
IDIR_ARD_ETH_UTIL = $(ARDUINO_DIR)/libraries/Ethernet/src/utility
INCD_ARD_WIFI = $(ARDUINO_DIR)/libraries/WiFi/src
INCD_ARD_WIFI_UTIL = $(ARDUINO_DIR)/libraries/WiFi/src/utility
INCD_ARD_TIME = $(ARDUINO_DIR)/libraries/Time/Time


INC_DIR_PLATFORM = -I$(IDIR_ARD_CORE_1) -I$(IDIR_ARD_CORE_2) -I$(IDIR_ARD_CORE_3) -I$(IDIR_ARD_CORE_4) -I$(IDIR_ARD_CORE_5) \
                    -I$(IDIR_ARD_SPI) -I$(INCD_ARD_TIME)

#Compiler/Linker flags
CFLAGS_PLATFORM = -ffunction-sections -fdata-sections -nostdlib --param max-inline-insns-single=500 -fno-rtti -fno-exceptions \
                     -Dprintf=iprintf -mcpu=cortex-m3 -DF_CPU=84000000L -DARDUINO=157 -DARDUINO_SAM_DUE -DARDUINO_ARCH_SAM \
                     -D__SAM3X8E__ -mthumb -DUSB_VID=0x2341 -DUSB_PID=0x003e -DUSBCON -DUSB_MANUFACTURER="Unknown" \
                     -DWITH_ARDUINO -DNDEBUG

#Compilers
CXX=$(ARDUINO_TOOLS_DIR)/arm-none-eabi-g++
CC=$(ARDUINO_TOOLS_DIR)/arm-none-eabi-gcc
AR=$(ARDUINO_TOOLS_DIR)/arm-none-eabi-ar
RANLIB=$(ARDUINO_TOOLS_DIR)/arm-none-eabi-ranlib
AVR_PROGRAMMER=$(ARDUINO_TOOLS_DIR)/bossac

#Needed object files
CORE_COBJ = hooks.o dtostrf.o iar_calls_sam3.o WInterrupts.o wiring.o wiring_digital.o wiring_analog.o wiring_shift.o\
                 wiring_pulse.o USARTClass.o USBCore.o RingBuffer.o cortex_handlers.o
CORE_CPPOBJ = itoa.o main.o Stream.o WMath.o WString.o Print.o IPAddress.o HID.o UARTClass.o CDC.o Reset.o cxxabi-compat.o
ETH_CPPOBJ = Dhcp.o Dns.o Ethernet.o EthernetUdp.o EthernetClient.o
ETH_UTIL_CPPOBJ = socket.o w5100.o
WIFI_COBJ = WiFi.o WiFiClient.o WiFiServer.o WiFiUdp.o server_drv.o spi_drv.o wifi_drv.o
VARIANT_OBJ = variant.o
SPI_OBJ = SPI.o
SYSCALLS_SAM3_OBJ = syscalls_sam3.o

PLATFORM_OBJS = $(SYSCALLS_SAM3_OBJ) $(SPI_OBJ) $(VARIANT_OBJ) $(CORE_COBJ) $(CORE_CPPOBJ)

#Include sources/objects corresponding to WiFi or Ethernet shield
ifeq ($(ARDUINOWIFI),1)
    INC_DIR_PLATFORM += -I$(INCD_ARD_WIFI) -I$(INCD_ARD_WIFI_UTIL)
    SDIR_ARD_PLATFORM += :$(SDIR_ARD_WIFI):$(SDIR_ARD_WIFI_UTIL)
    PLATFORM_OBJS += $(WIFI_COBJ)
else
    INC_DIR_PLATFORM += -I$(IDIR_ARD_ETH) -I$(IDIR_ARD_ETH_UTIL)
    SDIR_ARD_PLATFORM += :$(SDIR_ARD_ETH):$(SDIR_ARD_ETH_UTIL)
    PLATFORM_OBJS += $(ETH_CPPOBJ) $(ETH_UTIL_CPPOBJ)
endif


