#########################################################################
#
# MODULE:   JN-AN-1212-PER-Test 
#
# DESCRIPTION: AN-1212_PER_Slave MakeFile
#
############################################################################
#
# This software is owned by NXP B.V. and/or its supplier and is protected
# under applicable copyright laws. All rights are reserved. We grant You,
# and any third parties, a license to use this software solely and
# exclusively on NXP products [NXP Microcontrollers such as JN5168, JN5179].
# You, and any third parties must reproduce the copyright and warranty notice
# and any other legend of ownership on each copy or partial copy of the
# software.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# Copyright NXP B.V. 2015. All rights reserved
#
############################################################################

# Application target name

TARGET = AN1212_PER_Slave

##############################################################################
#User definable make parameters that may be overwritten from the command line

# Default target device is the JN5179

JENNIC_CHIP ?= JN5179

##############################################################################
# Default SDK is the IEEE802.15.4 SDK

JENNIC_SDK ?= JN-SW-4263

##############################################################################
# Default DK2 development kit target hardware

JENNIC_PCB ?= DEVKIT5

##############################################################################
# Select the network stack (e.g. MAC, ZBPRO)

JENNIC_STACK ?= MAC
JENNIC_MAC   ?= MAC

##############################################################################
# Default Channel

CFLAGS += -DDEFAULT_CHANNEL=11

##############################################################################
# Debug options

# Define DEBUG_MODE to one of SWD, SWD_TRACE or JTAG to enable debug
# DEBUG_MODE ?= SWD

# Define DEBUG_OPT to SIZE to maintain size optimisations during debug
# DEBUG_OPT ?= SIZE

##############################################################################
# Define TRACE to use with DBG module
#TRACE ?=1

##############################################################################
# Path definitions

SDK_HOME           ?= ../lpcxpresso/sdk/
SDK_BASE_DIR       ?= $(SDK_HOME)/$(JENNIC_SDK)/
APP_BASE            = ../..
APP_BLD_DIR         = .
APP_SRC_DIR         = ../Source
APP_COMMON_SRC_DIR  = $(APP_BASE)/Common/Source

##############################################################################
# Application Source files

# Note: Path to source file is found using vpath below, so only .c filename is required
APPSRC += ${TARGET}.c
APPSRC += AppQueueApi.c

APPSRC += Printf.c
APPSRC += UartBuffered.c
APPSRC += PerTest.c

##############################################################################
# Additional Application Source directories
# Define any additional application directories outside the application directory
# e.g. for AppQueueApi

ADDITIONAL_SRC_DIR += $(COMPONENTS_BASE_DIR)/AppQueueApi/Source

##############################################################################
# Standard Application header search paths

INCFLAGS += -I$(APP_SRC_DIR)
INCFLAGS += -I$(APP_COMMON_SRC_DIR)

# Application specific include files
INCFLAGS += -I$(COMPONENTS_BASE_DIR)/Utilities/Include
INCFLAGS += -I$(COMPONENTS_BASE_DIR)/AppQueueApi/Include 
INCFLAGS += -I$(COMPONENTS_BASE_DIR)/ProductionTestApi/Include
INCFLAGS += -I$(COMPONENTS_BASE_DIR)/Xcv/Include

CFLAGS += -DJENNIC_PCB_$(JENNIC_PCB)
CFLAGS += -DJENNIC_MAC=$(JENNIC_MAC)

##############################################################################
# Application libraries
# Specify additional Component libraries

#APPLIBS += 

##############################################################################

# You should not need to edit below this line

##############################################################################
##############################################################################
# Configure for the selected chip or chip family

include $(SDK_BASE_DIR)/Chip/Common/Build/config.mk
include $(SDK_BASE_DIR)/Platform/Common/Build/config.mk
include $(SDK_BASE_DIR)/Stack/Common/Build/config.mk

##############################################################################

APPOBJS = $(APPSRC:.c=.o)

##############################################################################
# Application dynamic dependencies

APPDEPS = $(APPOBJS:.o=.d)

#########################################################################
# Linker

# Add application libraries before chip specific libraries to linker so
# symbols are resolved correctly (i.e. ordering is significant for GCC)

LDLIBS := $(addsuffix _$(JENNIC_CHIP_FAMILY),$(APPLIBS)) $(LDLIBS)

#########################################################################
# Dependency rules

.PHONY: all clean
# Path to directories containing application source 
vpath % $(APP_SRC_DIR):$(APP_COMMON_SRC_DIR):$(ADDITIONAL_SRC_DIR)

.PRECIOUS: %.elf

all: $(TARGET)_$(JENNIC_CHIP)_$(JENNIC_MAC)$(BIN_SUFFIX).bin

-include $(APPDEPS)

%.o: %.S
	$(info Assembling $< ...)
	$(CC) -c -o $@ $(CFLAGS) $(INCFLAGS) $< -MMD -MF $*.d -MP
	@echo

%.o: %.c
	$(info Compiling $< ...)
	$(CC) -c -o $@ $(CFLAGS) $(INCFLAGS) $< -MMD -MF $*.d -MP
	@echo

%.elf: $(APPOBJS) $(addsuffix _$(JENNIC_CHIP_FAMILY).a,$(addprefix $(COMPONENTS_BASE_DIR)/Library/lib,$(APPLIBS))) 
	$(info Linking $@ ...)
	$(CC) -Wl,--gc-sections -Wl,-u_AppColdStart -Wl,-u_AppWarmStart $(LDFLAGS) -T$(LINKCMD) -o $@ $(APPOBJS) -Wl,--start-group  $(addprefix -l,$(LDLIBS)) -Wl,--end-group -Wl,-Map,$*.map 
	${SIZE} $@
	@echo

%.bin: %.elf 
	$(info Generating binary ...)
	$(OBJCOPY) -S -O binary $< $@
	
#########################################################################

clean:
	rm -f $(APPOBJS) $(APPDEPS) $(TARGET)_$(JENNIC_CHIP)*.bin $(TARGET)_$(JENNIC_CHIP)*.elf $(TARGET)_$(JENNIC_CHIP)*.map

#########################################################################
