#-----------------------------------------------
# Make command:
# mingw32-make build=<build> target=<target> entry=main stack=0x400 heap=0x1000
# <build>: debug or release, release by default.
# <target>: sram or flash, flash by default.
#-----------------------------------------------

#-----------------------------------------------
# setup variables
# ----------------------------------------------

SDK_ROOT := $(abspath ../../../..)

#-----------------------------------------------
# set board infomation
# The CHIP must be set correctly, otherwise the
# platform_lib cannot be linked.
#-----------------------------------------------
BOARD := frdmk64f120m
CHIP := K64F12

APP_NAME = rtc_func
#-----------------------------------------------
# Debug or Release
# Release by default
#-----------------------------------------------
build ?= release

#-----------------------------------------------
# Sram target or flash target
# flash target by defult.
#-----------------------------------------------
target ?= flash

#-----------------------------------------------
# Choose the float point method.
# K64F12 can use: NO_FP, SOFT_FP and HARD_FP.
# Application's float point configuration must
# be the same with the libraries it linked.
#-----------------------------------------------
CHOOSE_FLOAT = NO_FP

include $(SDK_ROOT)/mk/common.mk

#-----------------------------------------------
# include library. Only the name of the lib is 
# needed here, the targets.mk will convert it
# to correct library file. e.g. if platform_lib
# is added here, targets.mk will convert it to
# $(OUTPUT_ROOT)/lib/<CHIP>/platform.a
#-----------------------------------------------
LINK_LIB_NAME := platform_lib

#-----------------------------------------------
# Include path. Add the include paths like this:
# INCLUDES += ./include/
#-----------------------------------------------
INCLUDES += $(SDK_LIB_ROOT)/drivers/rtc   \
            $(SDK_LIB_ROOT)/drivers/clock \
            $(SDK_LIB_ROOT)/drivers/gpio \
            $(SDK_LIB_ROOT)/drivers/interrupt \
            $(SDK_LIB_ROOT)/hal/rtc \
            $(SDK_LIB_ROOT)/hal/gpio \
            $(SDK_LIB_ROOT)/hal/port \
            $(SDK_LIB_ROOT)/hal/sim \
            $(SDK_LIB_ROOT)/hal/uart \
            $(APPS_ROOT)/utilities/shell \
            $(APPS_ROOT)/$(APP_NAME)/src \
            $(BOARD_ROOT)

#-----------------------------------------------
# Startup files
#-----------------------------------------------
STARTUP_ROOT := $(SDK_LIB_ROOT)/startup
STARTUP_SOURCES := $(STARTUP_ROOT)/startup.c \
                   $(STARTUP_ROOT)/M$(CHIP)/system_M$(CHIP).c \
                   $(STARTUP_ROOT)/M$(CHIP)/gcc/startup_M$(CHIP).S

#-----------------------------------------------
# Application files
#-----------------------------------------------
APP_SOURCES  := $(wildcard $(APPS_ROOT)/$(APP_NAME)/src/*.c) \
                $(APPS_ROOT)/utilities/shell/src/shell.c \
                $(APPS_ROOT)/utilities/shell/src/shell_cmdhelp.c

#-----------------------------------------------
# Board related files, e.g. platform_pins.c
#-----------------------------------------------
BOARD_SOURCES := $(wildcard $(BOARD_ROOT)/*.c)

#-----------------------------------------------
# Add all sources needed here
#-----------------------------------------------
SOURCES = $(STARTUP_SOURCES) $(APP_SOURCES) $(BOARD_SOURCES)

#-----------------------------------------------
# Link file
# Input only the name of the link file here,
# the targets.mk will convert it to
# platform/linker/gcc/<CHIP>/$(LD_FILE_NAME)
# e.g, if LD_FILE_NAME is set to K64FN1Mxxx12_flash.ld
# the link file platform/linker/gcc/K64F12/K64FN1Mxxx12_flash.ld
# will be used
#-----------------------------------------------
ifeq "$(target)" "sram"
LD_FILE_NAME := K64FN1Mxxx12_ram.ld
else
LD_FILE_NAME := K64FN1Mxxx12_flash.ld
endif

#-----------------------------------------------
# The start entry, if entry is not defined,
# _start of gcc library will be used by default.
#-----------------------------------------------
entry ?=
ifneq "$(entry)" ""
DEFINES += -D__START=$(entry)
endif

#-----------------------------------------------
# Define the stack size and heap size.
#-----------------------------------------------
stack ?= 0x400
heap  ?= 0x1000
DEFINES += -D__STACK_SIZE=$(stack) \
           -D__HEAP_SIZE=$(heap)

include $(SDK_ROOT)/mk/targets.mk 
