##******************************* Makefile *********************************
##           #######
##           ##  ##
##           #  ##    ####   #####    #####  ##  ##   #####
##             ##    ##  ##  ##  ##  ##      ##  ##  ##
##            ##  #  ######  ##  ##   ####   ##  ##   ####
##           ##  ##  ##      ##  ##      ##   #####      ##
##          #######   ####   ##  ##  #####       ##  #####
##                                           #####
##          Z-Wave, the wireless language.
##
##              Copyright (c) 2001
##              Zensys A/S
##              Denmark
##
##              All Rights Reserved
##
##    This source file is subject to the terms and conditions of the
##    Zensys Software License Agreement which restricts the manner
##    in which it may be used.
##
##---------------------------------------------------------------------------
##
## Description:
##    Makefile for the ZW0x0x development kit LED_Dimmer
##    This makefile defines the targets built
##
## Author:   Erik Friis Harck
##
## Last Changed By:  $Author: psh $
## Revision:         $Revision: 22671 $
## Last Changed:     $Date: 2012-05-02 17:57:21 +0200 (Wed, 02 May 2012) $
##
##***************************************************************************/

#---------------------------------------------------------------------------------------------------------
# HOW-TO: Specifying which subset of "everything", you wan't to build:
#
# You can specify a single frequency to build for in 3 different ways:
# 1. By specifying the frequency in your command line, like:
#    > make FREQUENCY=EU ....
# 2. By uncommenting and correcting the following line:
#FREQUENCY:=EU
# 3. Alternativly you can do the same by setting your environment with:
#    > SET FREQUENCY=EU
#    Remember to UNSET this when you jump to work on other things.
#
# You can specify a single code memory mode to build for in 3 different ways:
# 1. By specifying the code memory mode in your command line, like:
#    > make CODE_MEMORY_MODE=devmode_patch ....
# 2. By uncommenting and correcting the following line:
#CODE_MEMORY_MODE:=normal
# 3. Alternativly you can do the same by setting your environment with:
#    > SET CODE_MEMORY_MODE=normal
#    Remember to UNSET this when you jump to work on other things.
#
# You can specify a single library to build for in 3 different ways:
# 1. By specifying the library in your command line, like:
#    > make LIBRARY=controller_portable ....
# 2. By uncommenting and correcting the following line:
LIBRARY:=slave_routing
# 3. Alternativly you can do the same by setting your environment with:
#    > SET LIBRARY=controller_portable
#    Remember to UNSET this when you jump to work on other things.
#
# You can specify a single host interface to build for in 3 different ways:
# 1. By specifying the host interface in your command line, like:
#    > make HOST_INTERFACE=UART ....
# 2. By uncommenting and correcting the following line:
HOST_INTERFACE:=UART
# 3. Alternativly you can do the same by setting your environment with:
#    > SET HOST_INTERFACE=UART
#    Remember to UNSET this when you jump to work on other things.
#
# You can specify a single sensor type to build for in 3 different ways:
# 1. By specifying the sensor type in your command line, like:
#    > make SENSOR_TYPE=NON_BATT ....
# 2. By uncommenting and correcting the following line:
SENSOR_TYPE:=NON_BATT
# 3. Alternativly you can do the same by setting your environment with:
#    > SET SENSOR_TYPE=NON_BATT
#    Remember to UNSET this when you jump to work on other things.
#
# You can specify a single board type to build for in 3 different ways:
# 1. By specifying the board type in your command line, like:
#    > make BOARD=ZDP03A ....
# 2. By uncommenting and correcting the following line:
#BOARD:=ZDP03A
# 3. Alternativly you can do the same by setting your environment with:
#    > SET BOARD=ZDP03A
#    Remember to UNSET this when you jump to work on other things.
#
# And yes... You can combine these methods in any way.
#
# If you do nothing of the above, you will be building target code for all combinations of frequencies and
# code memory modes in the lists below.
#
# And yes... You can of course manipulate the lists below, if you have special needs for ranges of targets.
#---------------------------------------------------------------------------------------------------------

# Full list of all supported frequencies can be found in $(ZWLIBROOT)\Common\Makefile.common
# Downgraded list of supported frequencies for LED_Dimmer.
LIST_OF_FREQUENCIES:=US EU ANZ HK MY IN JP

# Downgraded list of supported supported boards for LED_Dimmer.
LIST_OF_BOARDS:=ZDP03A ZM4102

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

# If not supplied by application here, the name of the application will be set equal to it's directory name.
APP_NAME:=leddimmer

# Target name (Name of your target files)
ifneq ($(SCHEME),)
SEC=_$(SCHEME)
endif

# If building for the ZM4102 module, make special selections for LED1, SPI memory and UART
ifeq ($(BOARD),ZM4102)
## Set the driver for external serial non-volatile memory for use of P0.4 as chip select.
NVM_TYPE:=at25128a_p0_4
CHIPPACK:=ZM4102
else
# Else we are building for the normal general ZW040x chip.
CHIPPACK:=$(CHIP)
endif

# Target name (Name of your target directory and base name of your target files)
TARGET:=$(APP)$(UART_CONTROL)$(ENH)_$(CHIPPACK)$(META)_$(COUNTRY)$(TEST)$(SEC)

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

ifeq ($(CODE_MEMORY_MODE),banking)
# List ZW_library modules, which you want forced into COMMON bank
COMMON_ZWLIB_MODULES:=

# List ZW_library modules, which you want forced into BANK1
ifeq ($(MAKESCHEME),)
BANK1_ZWLIB_MODULES:=\
 ZW_DEBUG,\
 ZW_INTERNAL_NVM,\
 ZW_MEM,\
 ZW_MEM_SUPPORT,\
 ZW_MEM_API,\
 ZW_PHY_MTP_040X,\
 ZW_UART0_SUPPORT,\
 ZW_UART1_SUPPORT,\
 ZW_TRANSPORT,\
 ZW_TRANSPORT_SUPPORT
else
BANK1_ZWLIB_MODULES:=\
 ZW_DEBUG,\
 ZW_MEM,\
 ZW_MEM_SUPPORT,\
 ZW_MEM_API,\
 ZW_UART0_SUPPORT,\
 ZW_UART1_SUPPORT,\
 ZW_TRANSPORT,\
 ZW_TRANSPORT_SUPPORT
endif
# List ZW_library modules, which you want forced into BANK2
BANK2_ZWLIB_MODULES:=

# List ZW_library modules, which you want forced into BANK3
BANK3_ZWLIB_MODULES:=
endif

# List of object modules constituting the program for the different code memory modes.

ifeq ($(CODE_MEMORY_MODE),banking)
# build the project the original way for OTP. "serialapi"
COMMON_RELFILES:=\
 ZW_L51_BANK.obj\
 App_RFSetup.obj

BANK1_RELFILES:=

BANK2_RELFILES:=\
 LEDdim.obj\
 one_button.obj\
 led_control.obj\
 association.obj\
 slave_learn.obj
ifneq ($(SCHEME),)
BANK2_RELFILES+=\
 ZW_Security_AES_module.obj \
 ZW_TransportSecurity.obj
endif

BANK3_RELFILES:=

RELFILES:=$(COMMON_RELFILES) $(BANK1_RELFILES) $(BANK2_RELFILES) $(BANK3_RELFILES)

endif

ifeq ($(CODE_MEMORY_MODE),normal)
# build the project the original way for OTP. "leddimmer"
RELFILES=\
 LEDdim.obj\
 one_button.obj\
 led_control.obj\
 association.obj\
 slave_learn.obj\
 App_RFSetup.obj
ifneq ($(SCHEME),)
RELFILES+=\
 ZW_Security_AES_module.obj \
 ZW_TransportSecurity.obj
endif
endif

ifeq ($(CODE_MEMORY_MODE),devmode)
# build the project for development mode for OTP. "leddimmer_devmode"
RELFILES=\
 LEDdim.obj\
 one_button.obj\
 led_control.obj\
 association.obj\
 slave_learn.obj\
 App_RFSetup.obj
ifneq ($(SCHEME),)
RELFILES+=\
 ZW_Security_AES_module.obj \
 ZW_TransportSecurity.obj
endif
endif

ifeq ($(CODE_MEMORY_MODE),devmode_patch)
# build patch code for development mode RAM. "leddimmer_devmode_patch" (all patched modules)
RELFILES=\
 LEDdim_patch.obj
 endif

ifeq ($(CODE_MEMORY_MODE),starter_devmode)
# build the project for development mode for OTP. "starter_devmode" (empty program with library)
RELFILES:=\
 starter.obj\
 App_RFSetup.obj
ifneq ($(SCHEME),)
RELFILES+=\
 ZW_Security_AES_module.obj \
 ZW_TransportSecurity.obj
endif
endif

ifeq ($(CODE_MEMORY_MODE),starter_devmode_patch)
# build patch code for development mode RAM. "starter_devmode_leddimmer_patch" (all application except library)
RELFILES=\
 LEDdim_patch.obj\
 starter_patch.obj\
 one_button.obj\
 led_control.obj\
 association.obj\
 slave_learn.obj
endif

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

# Find the current directory
# used as a base for all other paths.
BASEDIR=$(shell cd)

# Find the product name from the subdirectoryname
BASEDIRWORDLIST=$(subst \, ,$(BASEDIR))
BASEDIRLASTWORDINDEX=$(words $(BASEDIRWORDLIST))
PRODUCTDIR=$(word $(BASEDIRLASTWORDINDEX),$(BASEDIRWORDLIST))

# Find the Z-Wave library location (if not forced by setting the environment variable ZWLIBROOT)
ifndef ZWLIBROOT
ZWLIBROOT:=$(subst \$(PRODUCTDIR),,$(subst \Product,\Z-Wave,$(BASEDIR)))
endif

# Library location when making release of application
ifdef SVNLIBRELEASEDIRBIN
ZWLIBROOT:=$(SVNLIBRELEASEDIRBIN)
endif

# Export the variables declared above to the other makefiles.
export BASEDIR ZWLIBROOT UNDERSTAND_C

include $(ZWLIBROOT)\Common\Makefile.common

CDEFINES+=,\
 APPL_PROD_TEST

ifeq ($(BOARD),ZM4102)
CDEFINES+=,\
 ZM4102
ADEFINES+=,\
 ZM4102
endif

#Test if we should build with security
ifneq ($(SCHEME),)
CDEFINES+=,\
 SECURITY=$(SCHEME),\
 $(SCHEME),\
 AES_ON_CHIP
ADEFINES+=,\
 SECURITY=$(SCHEME),\
 $(SCHEME)
endif

#Test if we should define META
ifneq ($(META),)
CDEFINES+=,\
 METADATA_DUT
endif

ifneq ($(UART_CONTROL),)
CDEFINES+=,\
 ZW_BUTTON_UART_CONTROL
endif
