##******************************* 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 serialapi
##    This makefile defines the targets build
##
## Author:   Johann Sigfredsson
##
## Last Changed By:  $Author: efh $
## Revision:         $Revision: 22550 $
## Last Changed:     $Date: 2012-03-20 16:27:18 +0100 (Tue, 20 Mar 2012) $
##
##***************************************************************************/

# 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 UNDERSTAND_C

BDIRS=build


ZW0x0x: ZW020x ZW030x
ZW020x: ZW020x_EU ZW020x_US ZW020x_ANZ ZW020x_HK ZW020x_MY ZW020x_IN ZW020x_RU
ZW030x: ZW030x_EU ZW030x_US ZW030x_ANZ ZW030x_HK ZW030x_MY ZW030x_IN ZW030x_RU

all: ZW0x0x

default: all


# Common targets
##***************************************************************************/

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

dirs: $(BDIRS)

MAKEOPTS=--no-print-directory -C

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

ZW020x_US:MAKELINE=APP=prod_test_gen LIB=slave_prodtest_gen CHIP=ZW020x COUNTRY=US RF=US
ZW020x_US:
	$(MAKE) depend $(MAKEOPTS) . $(MAKELINE) -f Makefile.prod_test_gen_common
	$(MAKE) $(MAKEOPTS) . $(MAKELINE) -f Makefile.prod_test_gen_common

ZW020x_EU:MAKELINE=APP=prod_test_gen LIB=slave_prodtest_gen CHIP=ZW020x COUNTRY=EU RF=EU
ZW020x_EU:
	$(MAKE) depend $(MAKEOPTS) . $(MAKELINE) -f Makefile.prod_test_gen_common
	$(MAKE) $(MAKEOPTS) . $(MAKELINE) -f Makefile.prod_test_gen_common

ZW020x_ANZ:MAKELINE=APP=prod_test_gen LIB=slave_prodtest_gen CHIP=ZW020x COUNTRY=ANZ RF=ANZ
ZW020x_ANZ:
	$(MAKE) depend $(MAKEOPTS) . $(MAKELINE) -f Makefile.prod_test_gen_common
	$(MAKE) $(MAKEOPTS) . $(MAKELINE) -f Makefile.prod_test_gen_common

ZW020x_HK:MAKELINE=APP=prod_test_gen LIB=slave_prodtest_gen CHIP=ZW020x COUNTRY=HK RF=HK
ZW020x_HK:
	$(MAKE) depend $(MAKEOPTS) . $(MAKELINE) -f Makefile.prod_test_gen_common
	$(MAKE) $(MAKEOPTS) . $(MAKELINE) -f Makefile.prod_test_gen_common

ZW020x_MY:MAKELINE=APP=prod_test_gen LIB=slave_prodtest_gen CHIP=ZW020x COUNTRY=MY RF=MY
ZW020x_MY:
	$(MAKE) depend $(MAKEOPTS) . $(MAKELINE) -f Makefile.prod_test_gen_common
	$(MAKE) $(MAKEOPTS) . $(MAKELINE) -f Makefile.prod_test_gen_common

ZW020x_IN:MAKELINE=APP=prod_test_gen LIB=slave_prodtest_gen CHIP=ZW020x COUNTRY=IN RF=IN
ZW020x_IN:
	$(MAKE) depend $(MAKEOPTS) . $(MAKELINE) -f Makefile.prod_test_gen_common
	$(MAKE) $(MAKEOPTS) . $(MAKELINE) -f Makefile.prod_test_gen_common

ZW020x_RU:MAKELINE=APP=prod_test_gen LIB=slave_prodtest_gen CHIP=ZW020x COUNTRY=RU RF=RU
ZW020x_RU:
	$(MAKE) depend $(MAKEOPTS) . $(MAKELINE) -f Makefile.prod_test_gen_common
	$(MAKE) $(MAKEOPTS) . $(MAKELINE) -f Makefile.prod_test_gen_common

# Series 300 targets

ZW030x_US:MAKELINE=APP=prod_test_gen LIB=slave_prodtest_gen CHIP=ZW030x COUNTRY=US RF=US
ZW030x_US:
	$(MAKE) depend $(MAKEOPTS) . $(MAKELINE) -f Makefile.prod_test_gen_common
	$(MAKE) $(MAKEOPTS) . $(MAKELINE) -f Makefile.prod_test_gen_common

ZW030x_EU:MAKELINE=APP=prod_test_gen LIB=slave_prodtest_gen CHIP=ZW030x COUNTRY=EU RF=EU
ZW030x_EU:
	$(MAKE) depend $(MAKEOPTS) . $(MAKELINE) -f Makefile.prod_test_gen_common
	$(MAKE) $(MAKEOPTS) . $(MAKELINE) -f Makefile.prod_test_gen_common

ZW030x_ANZ:MAKELINE=APP=prod_test_gen LIB=slave_prodtest_gen CHIP=ZW030x COUNTRY=ANZ RF=ANZ
ZW030x_ANZ:
	$(MAKE) depend $(MAKEOPTS) . $(MAKELINE) -f Makefile.prod_test_gen_common
	$(MAKE) $(MAKEOPTS) . $(MAKELINE) -f Makefile.prod_test_gen_common

ZW030x_HK:MAKELINE=APP=prod_test_gen LIB=slave_prodtest_gen CHIP=ZW030x COUNTRY=HK RF=HK
ZW030x_HK:
	$(MAKE) depend $(MAKEOPTS) . $(MAKELINE) -f Makefile.prod_test_gen_common
	$(MAKE) $(MAKEOPTS) . $(MAKELINE) -f Makefile.prod_test_gen_common

ZW030x_MY:MAKELINE=APP=prod_test_gen LIB=slave_prodtest_gen CHIP=ZW030x COUNTRY=MY RF=MY
ZW030x_MY:
	$(MAKE) depend $(MAKEOPTS) . $(MAKELINE) -f Makefile.prod_test_gen_common
	$(MAKE) $(MAKEOPTS) . $(MAKELINE) -f Makefile.prod_test_gen_common

ZW030x_IN:MAKELINE=APP=prod_test_gen LIB=slave_prodtest_gen CHIP=ZW030x COUNTRY=IN RF=IN
ZW030x_IN:
	$(MAKE) depend $(MAKEOPTS) . $(MAKELINE) -f Makefile.prod_test_gen_common
	$(MAKE) $(MAKEOPTS) . $(MAKELINE) -f Makefile.prod_test_gen_common

ZW030x_RU:MAKELINE=APP=prod_test_gen LIB=slave_prodtest_gen CHIP=ZW030x COUNTRY=RU RF=RU
ZW030x_RU:
	$(MAKE) depend $(MAKEOPTS) . $(MAKELINE) -f Makefile.prod_test_gen_common
	$(MAKE) $(MAKEOPTS) . $(MAKELINE) -f Makefile.prod_test_gen_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   ZW0x0x     : ZW0x0x targets
	@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