#********************************  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: Make file for the ZW0102 slave application
#
#  Author:   Peter Shorty
#
#  Last Changed By:  $Author: efh $
#  Revision:         $Revision: 21413 $
#  Last Changed:     $Date: 2011-09-27 16:43:35 +0200 (Tue, 27 Sep 2011) $
#
#****************************************************************************

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

# The command to make dependencies from the headerfiles
# included by a file.
INCDEP=python $(subst \,\\,$(TOOLSDIR)\IncDep\incdep.py)

# 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 INCDEP ZWLIBROOT

BDIRS=build

all: default

default: ZW0x0x

ZW0x0x: ZW020x ZW030x

release: release_ZW0x0x

release_ZW0x0x: ZW0x0x

ZW020x: ZW020x_US ZW020x_EU ZW020x_ANZ ZW020x_HK ZW020x_MY ZW020x_IN

ZW030x: ZW030x_US ZW030x_EU ZW030x_ANZ ZW030x_HK ZW030x_MY ZW030x_IN

myproduct_ZW0x0x: release

##***************************************************************************/

# Include test targets (if any)
-include Makefile.TestTargets
-include Makefile.Testdefines

dirs: $(BDIRS)

MAKEOPTS=--no-print-directory -C

##***************************************************************************/

# ZW020x targets
ZW020x_US:MAKELINE=APP=MyProduct LIB=slave_routing CHIP=ZW020x COUNTRY=US RF=US
ZW020x_US:
	$(MAKE) depend $(MAKEOPTS) . $(MAKELINE) -f Makefile.myproduct_common
	$(MAKE) $(MAKEOPTS) . $(MAKELINE) -f Makefile.myproduct_common

ZW020x_EU:MAKELINE=APP=MyProduct LIB=slave_routing CHIP=ZW020x COUNTRY=EU RF=EU
ZW020x_EU:
	$(MAKE) depend $(MAKEOPTS) . $(MAKELINE) -f Makefile.myproduct_common
	$(MAKE) $(MAKEOPTS) . $(MAKELINE) -f Makefile.myproduct_common

ZW020x_ANZ:MAKELINE=APP=MyProduct LIB=slave_routing CHIP=ZW020x COUNTRY=ANZ RF=ANZ
ZW020x_ANZ:
	$(MAKE) depend $(MAKEOPTS) . $(MAKELINE) -f Makefile.myproduct_common
	$(MAKE) $(MAKEOPTS) . $(MAKELINE) -f Makefile.myproduct_common

ZW020x_HK:MAKELINE=APP=MyProduct LIB=slave_routing CHIP=ZW020x COUNTRY=HK RF=HK
ZW020x_HK:
	$(MAKE) depend $(MAKEOPTS) . $(MAKELINE) -f Makefile.myproduct_common
	$(MAKE) $(MAKEOPTS) . $(MAKELINE) -f Makefile.myproduct_common

ZW020x_MY:MAKELINE=APP=MyProduct LIB=slave_routing CHIP=ZW020x COUNTRY=MY RF=MY
ZW020x_MY:
	$(MAKE) depend $(MAKEOPTS) . $(MAKELINE) -f Makefile.myproduct_common
	$(MAKE) $(MAKEOPTS) . $(MAKELINE) -f Makefile.myproduct_common

ZW020x_IN:MAKELINE=APP=MyProduct LIB=slave_routing CHIP=ZW020x COUNTRY=IN RF=IN
ZW020x_IN:
	$(MAKE) depend $(MAKEOPTS) . $(MAKELINE) -f Makefile.myproduct_common
	$(MAKE) $(MAKEOPTS) . $(MAKELINE) -f Makefile.myproduct_common


# ZW030x targets
ZW030x_US:MAKELINE=APP=MyProduct LIB=slave_routing CHIP=ZW030x COUNTRY=US RF=US
ZW030x_US:
	$(MAKE) depend $(MAKEOPTS) . $(MAKELINE) -f Makefile.myproduct_common
	$(MAKE) $(MAKEOPTS) . $(MAKELINE) -f Makefile.myproduct_common

ZW030x_EU:MAKELINE=APP=MyProduct LIB=slave_routing CHIP=ZW030x COUNTRY=EU RF=EU
ZW030x_EU:
	$(MAKE) depend $(MAKEOPTS) . $(MAKELINE) -f Makefile.myproduct_common
	$(MAKE) $(MAKEOPTS) . $(MAKELINE) -f Makefile.myproduct_common

ZW030x_ANZ:MAKELINE=APP=MyProduct LIB=slave_routing CHIP=ZW030x COUNTRY=ANZ RF=ANZ
ZW030x_ANZ:
	$(MAKE) depend $(MAKEOPTS) . $(MAKELINE) -f Makefile.myproduct_common
	$(MAKE) $(MAKEOPTS) . $(MAKELINE) -f Makefile.myproduct_common

ZW030x_HK:MAKELINE=APP=MyProduct LIB=slave_routing CHIP=ZW030x COUNTRY=HK RF=HK
ZW030x_HK:
	$(MAKE) depend $(MAKEOPTS) . $(MAKELINE) -f Makefile.myproduct_common
	$(MAKE) $(MAKEOPTS) . $(MAKELINE) -f Makefile.myproduct_common

ZW030x_MY:MAKELINE=APP=MyProduct LIB=slave_routing CHIP=ZW030x COUNTRY=MY RF=MY
ZW030x_MY:
	$(MAKE) depend $(MAKEOPTS) . $(MAKELINE) -f Makefile.myproduct_common
	$(MAKE) $(MAKEOPTS) . $(MAKELINE) -f Makefile.myproduct_common

ZW030x_IN:MAKELINE=APP=MyProduct LIB=slave_routing CHIP=ZW030x COUNTRY=IN RF=IN
ZW030x_IN:
	$(MAKE) depend $(MAKEOPTS) . $(MAKELINE) -f Makefile.myproduct_common
	$(MAKE) $(MAKEOPTS) . $(MAKELINE) -f Makefile.myproduct_common


##***************************************************************************/

# Deletes all generated files (relocatables, downloadables,
# dependency files and the generated C and headerfiles from ZUIB)
clean:
ifeq ($(OS), Windows_NT)
	@cmd /c "if exist build\NUL rd build /s /q"
else
	@deltree /Y $(subst \,\\,build)
endif

##***************************************************************************/

# Catch all targets which we do not handle and tell world that
%:
	@echo Could not find rule for target '$@'
	@echo Some of the known targets are :
	@echo   ZW020x     : ZW020x targets
	@echo   ZW030x     : ZW030x targets

# All targets that shouldn't result in a file/directory
# with the same name as the target should be listed here.
# Otherwise the above rule will make a directory with
# the targetname


.PHONY: dirs clean depend all default Makefile.TestTargets Makefile.Testdefines ZW0x0x ZW020x ZW030x
