##******************************* 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 doorbell test application
##
## Author:   Peter Shorty
##
## Last Changed By:  $Author: efh $
## Revision:         $Revision: 21401 $
## Last Changed:     $Date: 2011-09-27 16:37:40 +0200 (Tue, 27 Sep 2011) $
##
##***************************************************************************/

# 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

BDIRS=build

all: ZW0x0x

default: ZW0x0x

ZW0x0x: ZW0201 ZW0301

# Common targets
ZW0201: ZW0201_Slave
ZW0301: ZW0301_Slave

ZW0201_Slave: ZW0201_Slave_EU ZW0201_Slave_US ZW0201_Slave_HK ZW0201_Slave_ANZ ZW0201_Slave_MY ZW0201_Slave_IN
ZW0301_Slave: ZW0301_Slave_EU ZW0301_Slave_US ZW0301_Slave_HK ZW0301_Slave_ANZ ZW0301_Slave_MY ZW0301_Slave_IN

bell: ZW0201_Slave

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

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

dirs: $(BDIRS)

MAKEOPTS=--no-print-directory -C

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

## 200 series targets

ZW0201_Slave_US:MAKELINE=APP=doorbell_bell LIB=slave_routing CHIP=ZW020x COUNTRY=US RF=US
ZW0201_Slave_US:
	$(MAKE) depend $(MAKEOPTS) . $(MAKELINE) -f Makefile.doorbell_common
	$(MAKE) $(MAKEOPTS) . $(MAKELINE) -f Makefile.doorbell_common

ZW0201_Slave_EU:MAKELINE=APP=doorbell_bell LIB=slave_routing CHIP=ZW020x COUNTRY=EU RF=EU
ZW0201_Slave_EU:
	$(MAKE) depend $(MAKEOPTS) . $(MAKELINE) -f Makefile.doorbell_common
	$(MAKE) $(MAKEOPTS) . $(MAKELINE) -f Makefile.doorbell_common

ZW0201_Slave_HK:MAKELINE=APP=doorbell_bell LIB=slave_routing CHIP=ZW020x COUNTRY=HK RF=HK
ZW0201_Slave_HK:
	$(MAKE) depend $(MAKEOPTS) . $(MAKELINE) -f Makefile.doorbell_common
	$(MAKE) $(MAKEOPTS) . $(MAKELINE) -f Makefile.doorbell_common

ZW0201_Slave_ANZ:MAKELINE=APP=doorbell_bell LIB=slave_routing CHIP=ZW020x COUNTRY=ANZ RF=ANZ
ZW0201_Slave_ANZ:
	$(MAKE) depend $(MAKEOPTS) . $(MAKELINE) -f Makefile.doorbell_common
	$(MAKE) $(MAKEOPTS) . $(MAKELINE) -f Makefile.doorbell_common

ZW0201_Slave_MY:MAKELINE=APP=doorbell_bell LIB=slave_routing CHIP=ZW020x COUNTRY=MY RF=MY
ZW0201_Slave_MY:
	$(MAKE) depend $(MAKEOPTS) . $(MAKELINE) -f Makefile.doorbell_common
	$(MAKE) $(MAKEOPTS) . $(MAKELINE) -f Makefile.doorbell_common

ZW0201_Slave_IN:MAKELINE=APP=doorbell_bell LIB=slave_routing CHIP=ZW020x COUNTRY=IN RF=IN
ZW0201_Slave_IN:
	$(MAKE) depend $(MAKEOPTS) . $(MAKELINE) -f Makefile.doorbell_common
	$(MAKE) $(MAKEOPTS) . $(MAKELINE) -f Makefile.doorbell_common

## 300 series targets

ZW0301_Slave_US:MAKELINE=APP=doorbell_bell LIB=slave_routing CHIP=ZW030x COUNTRY=US RF=US
ZW0301_Slave_US:
	$(MAKE) depend $(MAKEOPTS) . $(MAKELINE) -f Makefile.doorbell_common
	$(MAKE) $(MAKEOPTS) . $(MAKELINE) -f Makefile.doorbell_common

ZW0301_Slave_EU:MAKELINE=APP=doorbell_bell LIB=slave_routing CHIP=ZW030x COUNTRY=EU RF=EU
ZW0301_Slave_EU:
	$(MAKE) depend $(MAKEOPTS) . $(MAKELINE) -f Makefile.doorbell_common
	$(MAKE) $(MAKEOPTS) . $(MAKELINE) -f Makefile.doorbell_common

ZW0301_Slave_HK:MAKELINE=APP=doorbell_bell LIB=slave_routing CHIP=ZW030x COUNTRY=HK RF=HK
ZW0301_Slave_HK:
	$(MAKE) depend $(MAKEOPTS) . $(MAKELINE) -f Makefile.doorbell_common
	$(MAKE) $(MAKEOPTS) . $(MAKELINE) -f Makefile.doorbell_common

ZW0301_Slave_ANZ:MAKELINE=APP=doorbell_bell LIB=slave_routing CHIP=ZW030x COUNTRY=ANZ RF=ANZ
ZW0301_Slave_ANZ:
	$(MAKE) depend $(MAKEOPTS) . $(MAKELINE) -f Makefile.doorbell_common
	$(MAKE) $(MAKEOPTS) . $(MAKELINE) -f Makefile.doorbell_common

ZW0301_Slave_MY:MAKELINE=APP=doorbell_bell LIB=slave_routing CHIP=ZW030x COUNTRY=MY RF=MY
ZW0301_Slave_MY:
	$(MAKE) depend $(MAKEOPTS) . $(MAKELINE) -f Makefile.doorbell_common
	$(MAKE) $(MAKEOPTS) . $(MAKELINE) -f Makefile.doorbell_common

ZW0301_Slave_IN:MAKELINE=APP=doorbell_bell LIB=slave_routing CHIP=ZW030x COUNTRY=IN RF=IN
ZW0301_Slave_IN:
	$(MAKE) depend $(MAKEOPTS) . $(MAKELINE) -f Makefile.doorbell_common
	$(MAKE) $(MAKEOPTS) . $(MAKELINE) -f Makefile.doorbell_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 '$@'

# 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 ZW0201_Slave_EU ZW0201_Slave_US ZW0201 ZW0201_Ctrl ZW0201_Slave bell pushbutton ZW0x0x ZW0301 ZW0301_Slave