##############################################################################
# Build global options
# NOTE: Can be overridden externally.
#
# This is stripped down from a working file; unlikely to work as-is
# -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
# 	Configure Some Options

	USE_PROCESS_STACKSIZE = 0x1000


# ------------------------------------------
#	Other Options
	USE_LTO = no
	DO_MEM_CACHE=no
# ------------------------------------------

    # Compiler options here.
    ifeq ($(USE_OPT),)
    ##  USE_OPT = -O2 -ggdb -fomit-frame-pointer -falign-functions=16
      USE_OPT = -O0 -ggdb -fomit-frame-pointer -falign-functions=16
    endif
#  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --
    # C specific options here (added to USE_OPT).
    ifeq ($(USE_COPT),)
      USE_COPT = 
    endif
#  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --
    # C++ specific options here (added to USE_OPT).
    # New settings from http://www.chibios.com/forum/viewtopic.php?f=3&t=3287
    ifeq ($(USE_CPPOPT),)
      USE_CPPOPT = -fno-rtti -fno-non-call-exceptions -fno-exceptions -fno-threadsafe-statics -fno-use-cxa-atexit
    ##  USE_CPPOPT = -fno-rtti
    endif
#  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --
    # Enable this if you want the linker to remove unused code and data
    ifeq ($(USE_LINK_GC),)
      USE_LINK_GC = yes
    endif
#  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --
    # Linker extra options here.
    ifeq ($(USE_LDOPT),)
      USE_LDOPT = 
    endif
#  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --
    # Enable this if you want link time optimizations (LTO)
    ifeq ($(USE_LTO),)
      USE_LTO = yes
    endif
    
#  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --
    # Enable this if you want to see the full log while compiling.
    ifeq ($(USE_VERBOSE_COMPILE),)
      USE_VERBOSE_COMPILE = no
    endif
#  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --
    # If enabled, this option makes the build process faster by not compiling
    # modules not used in the current configuration.
    ifeq ($(USE_SMART_BUILD),)
      USE_SMART_BUILD = yes
    endif

#==============================================================================
# Architecture or project specific options
#==============================================================================

# Stack size to be allocated to the Cortex-M process stack. This stack is
# the stack used by the main() thread.
ifeq ($(USE_PROCESS_STACKSIZE),)
  USE_PROCESS_STACKSIZE = 0x400
endif
#  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --
# Stack size to the allocated to the Cortex-M main/exceptions stack. This
# stack is used for processing interrupts and exceptions.
ifeq ($(USE_EXCEPTIONS_STACKSIZE),)
  USE_EXCEPTIONS_STACKSIZE = 0x400
endif
#  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --
# Enables the use of FPU (no, softfp, hard).
ifeq ($(USE_FPU),)
  USE_FPU = hard
endif
#  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --
# FPU-related options.
ifeq ($(USE_FPU_OPT),)
  USE_FPU_OPT = -mfloat-abi=$(USE_FPU) -mfpu=fpv5-d16
endif


# Initialise certain variables
UDEFS =

#==============================================================================
# Project, sources and paths
#==============================================================================

# Define project name here
PROJECT = ddf1017
#  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --
MCU  = cortex-m7

# 	Select a version of ChibiOs
CHIBIOS 	= ../../chibios_19.1.3
#  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  -- 
CONFDIR  := ./cfg
BUILDDIR := ./build
DEPDIR   := ./.dep
GFXLIB	  	= ../../ugfx_2.8
# -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
# Licensing files.
include $(CHIBIOS)/os/license/license.mk
#  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --
# 	Startup files - must match processor
include $(CHIBIOS)/os/common/startup/ARMCMx/compilers/GCC/mk/startup_stm32f7xx.mk
#  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --
# 	HAL-OSAL files
include $(CHIBIOS)/os/hal/hal.mk
#  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --
	#Add the platform for the given processor
include $(CHIBIOS)/os/hal/ports/STM32/STM32F7xx/platform.mk
include $(CHIBIOS)/os/hal/osal/rt/osal.mk
# --- --- --- --- --- --- --- --- --- ---
# Board Files
include $(GFXLIB)/boards/base/custom_board/board.mk
# --- --- --- --- --- --- --- --- --- ---
# RTOS files (optional).
include $(CHIBIOS)/os/rt/rt.mk
include $(CHIBIOS)/os/common/ports/ARMCMx/compilers/GCC/mk/port_v7m.mk
#  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --
# 	Define linker script file - partitions flash to have space for loader, flash file system
##	LDSCRIPT= $(STARTUPLD)/STM32F76xxI.ld
	LDSCRIPT= $(STARTUPLD)/STM32F76xxI_fs.ld

#==============================================================================
#	LIBRARIES
#==============================================================================

#  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --
#	ChibiOs Streams
include $(CHIBIOS)/os/hal/lib/streams/streams.mk

#  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --
#LWIP LIBRARY
	include $(CHIBIOS)/os/various/lwip_bindings/lwip.mk

#  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --

#Graphics LIBRARY
include $(GFXLIB)/gfx.mk


#==============================================================================
#	C & C++ Sources
#==============================================================================

# C sources that can be compiled in ARM or THUMB mode depending on the global
# setting.

CSRC = 	$(ALLCSRC)
CSRC += $(CHIBIOS)/os/various/evtimer.c
CSRC += main.c


# ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
# C++ sources that can be compiled in ARM or THUMB mode depending on the global
# setting.

CPPSRC  = $(ALLCPPSRC)
CPPSRC += housekeeping.cpp

# ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
# 	Subdirectories C & C++
#
#	Files are grouped together and sorted into sub-categories
#	Using the += system we can add to CSRC & CPPSRC without it
#	all being in one line.
#
#	Organising it like this means we can compare the list to the
#	folders to see if the right things are actually being compiled!
#


#==============================================================================
#	Special Mode Sources
#==============================================================================

# C sources to be compiled in ARM mode regardless of the global setting.
# NOTE: Mixing ARM and THUMB mode enables the -mthumb-interwork compiler
#       option that results in lower performance and larger code size.
ACSRC =

# C++ sources to be compiled in ARM mode regardless of the global setting.
# NOTE: Mixing ARM and THUMB mode enables the -mthumb-interwork compiler
#       option that results in lower performance and larger code size.
ACPPSRC =

# C sources to be compiled in THUMB mode regardless of the global setting.
# NOTE: Mixing ARM and THUMB mode enables the -mthumb-interwork compiler
#       option that results in lower performance and larger code size.
TCSRC =

# C++ sources to be compiled in THUMB mode regardless of the global setting.
# NOTE: Mixing ARM and THUMB mode enables the -mthumb-interwork compiler
#       option that results in lower performance and larger code size.
TCPPSRC =

# List ASM source files here
ASMSRC  = $(ALLASMSRC)
ASMXSRC = $(ALLXASMSRC)

#==============================================================================
#Include Paths
#==============================================================================

    INCDIR  = $(CONFDIR) $(ALLINC)
INCDIR += $(CHIBIOS)/os/various 			# For event timer no seperate make

#==============================================================================
# Compiler settings
#==============================================================================


# Define C warning options here
CWARN = -Wall -Wextra -Wundef -Wstrict-prototypes

# Define C++ warning options here
CPPWARN = -Wall -Wextra -Wundef

#
# Compiler settings
##############################################################################

##############################################################################
# Start of user section
#

# -----------------------------------------------
#
#	List all user C define here, like -D_DEBUG=1


#	List all user C define here, like -D_DEBUG=1  (N.B. may be some earlier in file)
	UDEFS += -DCHPRINTF_USE_FLOAT=TRUE    
	UDEFS += -D_GNU_SOURCE=1
	UDEFS += -DCRT0_CALL_DESTRUCTORS=FALSE
#	UDEFS +=
#	UDEFS +=
#	UDEFS +=

# ------------------------------------------


# Define ASM defines here
UADEFS =

# List all user directories here
UINCDIR =

# List the user directory to look for the libraries here
ULIBDIR =

# List all user libraries here
ULIBS =

#

#==============================================================================
#	Make Rules
#==============================================================================

RULESPATH = $(CHIBIOS)/os/common/startup/ARMCMx/compilers/GCC/mk
include $(RULESPATH)/arm-none-eabi.mk
include $(RULESPATH)/rules.mk
	
#==============================================================================

