
#Source directories
SDIR_ARD_CORE = $(ARDUINO_DIR)/hardware/arduino/avr/cores/arduino
SDIR_ARD_SPI = $(ARDUINO_DIR)/hardware/arduino/avr/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):$(SDIR_ARD_SPI):$(SDIR_ARD_TIME)

#include directories
INCD_ARD_CORE = -I$(ARDUINO_DIR)/hardware/arduino/avr/cores/arduino
INCD_ARD_VARIANT = -I$(ARDUINO_DIR)/hardware/arduino/avr/variants/mega
INCD_ARD_SPI = -I$(ARDUINO_DIR)/hardware/arduino/avr/libraries/SPI
INCD_ARD_ETH = -I$(ARDUINO_DIR)/libraries/Ethernet/src
INCD_ARD_ETH_UTIL = -I$(ARDUINO_DIR)/libraries/Ethernet/src/utility
INCD_ARD_WIFI = -I$(ARDUINO_DIR)/libraries/WiFi/src
INCD_ARD_WIFI_UTIL = -I$(ARDUINO_DIR)/libraries/WiFi/src/utility
INCD_ARD_TIME = -I$(ARDUINO_DIR)/libraries/Time/Time

INC_DIR_PLATFORM = $(INCD_ARD_CORE) $(INCD_ARD_VARIANT) $(INCD_ARD_SPI) $(INCD_ARD_TIME)

#Compiler/Linker flags
CFLAGS_PLATFORM =  -mmcu=atmega2560 -DF_CPU=16000000L -DARDUINO=156 -DARDUINO_AVR_MEGA2560 -DARDUINO_ARCH_AVR -DWITH_ARDUINO \
                   -MMD -std=c++0x -Wno-write-strings -ffunction-sections -fdata-sections -fno-exceptions -felide-constructors -DATMEGA2560 -DNDEBUG

#Compilers
CXX=$(ARDUINO_TOOLS_DIR)/avr-g++
CC=$(ARDUINO_TOOLS_DIR)/avr-gcc
AR=$(ARDUINO_TOOLS_DIR)/avr-ar
RANLIB=$(ARDUINO_TOOLS_DIR)/avr-ranlib
AVR_OBJCOPY=$(ARDUINO_TOOLS_DIR)/avr-objcopy
AVR_PROGRAMMER=$(ARDUINO_TOOLS_DIR)/avrdude

#Needed object files
CORE_COBJ = hooks.o WInterrupts.o wiring.o wiring_digital.o wiring_analog.o wiring_shift.o wiring_pulse.o
CORE_CPPOBJ = CDC.o HardwareSerial.o HardwareSerial0.o HardwareSerial1.o HardwareSerial2.o HardwareSerial3.o IPAddress.o HID.o \
              main.o new.o Print.o Stream.o Tone.o USBCore.o WMath.o WString.o SPI.o
ETH_CPPOBJ = Dhcp.o Dns.o Ethernet.o EthernetUdp.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
OCDEPENDENT_CPPOBJ = wiring_analog.o

PLATFORM_OBJS = $(CORE_COBJ) $(CORE_CPPOBJ) $(OCDEPENDENT_CPPOBJ)

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

