#******************************************************************************
#
# Makefile - Rules for building the simplelink.
#
#  Copyright (C) 2015 Texas Instruments Incorporated - http:#www.ti.com/
#
#
#  Redistribution and use in source and binary forms, with or without
#  modification, are permitted provided that the following conditions
#  are met:
#
#    Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
#
#    Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the
#    distribution.
#
#    Neither the name of Texas Instruments Incorporated nor the names of
#    its contributors may be used to endorse or promote products derived
#    from this software without specific prior written permission.
#
#  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
#  OWNER 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.
#
#*****************************************************************************

#
# Include the common make definitions.
#
include Makefile.defs

.PHONY: help all clean ccs ccs_nonos ccs_os ewarm ewarm_nonos ewarm_os gcc \
gcc_nonos gcc_os clean_all clean_ccs clean_ccs_nonos clean_ccs_os \
clean_ewarm  clean_ewarm_nonos clean_ewarm_os clean_gcc clean_gcc_nonos \
clean_gcc_os

ifndef BUILD_TOOL
abort:
	make help
endif

#
# The rule to create the simplelink library
#
build: $(BUILDDIR) $(OBJ) .$(LIBRARY)

#
# The rule to display the available options
#
help:
	@echo Makefile to build simplelink component with CCS, IAR and GCC Tools
	@echo   goal              description
	@echo  -----------------------------------------------------------------------------
	@echo   "all			Builds simplelink using CCS, IAR and GCC"
	@echo   "ccs			Builds simplelink using CCS"
	@echo   "ewarm			Builds simplelink using IAR"
	@echo   "gcc			Builds simplelink using GCC"
	@echo   "ccs_nonos		Builds simplelink for nonos using CCS"
	@echo   "ccs_os			Builds simplelink for os using CCS"
	@echo   "ewarm_nonos		Builds simplelink for nonos using IAR"
	@echo   "ewarm_os		Builds simplelink for os using IAR"
	@echo   "gcc_nonos		Builds simplelink for nonos using GCC"
	@echo   "gcc_os			Builds simplelink for os using GCC"
	@echo   "clean_all		Cleans simplelink using CCS, IAR and GCC"
	@echo   "clean_ccs		Cleans simplelink using CCS"
	@echo   "clean_ewarm		Cleans simplelink using IAR"
	@echo   "clean_gcc		Cleans simplelink using GCC"
	@echo   "clean_ccs_nonos		Cleans simplelink for nonos using CCS"
	@echo   "clean_ccs_os		Cleans simplelink for os using CCS"
	@echo   "clean_ewarm_nonos	Cleans simplelink for nonos using IAR"
	@echo   "clean_ewarm_os		Cleans simplelink for os using IAR"
	@echo   "clean_gcc_nonos		Cleans simplelink for nonos using GCC"
	@echo   "clean_gcc_os		Cleans simplelink for os using GCC"
	@echo   "help			Displays this description"

#
# The rule to create the build directory
#
$(BUILDDIR):
	@mkdir -p $(BUILDDIR)

#
# The rule to clean the build and output directories
#
clean:
	@rm -rf $(BUILDDIR)/../exe
	@rm -rf $(BUILDDIR)/../Exe
	@rm -rf $(BUILDDIR)/../List
	@rm -rf $(BUILDDIR)

#
# The rule to build the libraries using CCS, IAR and GCC tools
#	
all: ccs ewarm gcc

#
# The rule to clean the libraries using CCS, IAR and GCC tool
#	
clean_all: clean_ccs clean_ewarm clean_gcc

#
# The rule to build the libraries using CCS tool
#
ccs: ccs_nonos ccs_os

#
# The rule to build the nonos library using CCS tool
#
ccs_nonos:
	make BUILD_TOOL=ccs CONFIG=nonos

#
# The rule to build the os library using CCS tool
#
ccs_os:
	make BUILD_TOOL=ccs CONFIG=os

#
# The rule to clean the libraries using CCS tool
#
clean_ccs: clean_ccs_nonos clean_ccs_os

#
# The rule to clean the nonos library using CCS tool
#
clean_ccs_nonos:
	make BUILD_TOOL=ccs CONFIG=nonos clean

#
# The rule to clean the os library using CCS tool
#
clean_ccs_os:
	make BUILD_TOOL=ccs CONFIG=os clean

#
# The rule to build the libraries using IAR tool
#
ewarm: ewarm_nonos ewarm_os

#
# The rule to build the nonos library using IAR tool
#
ewarm_nonos:
	make BUILD_TOOL=ewarm CONFIG=nonos

#
# The rule to build the os library using IAR tool
#
ewarm_os:
	make BUILD_TOOL=ewarm CONFIG=os

#
# The rule to clean the libraries using IAR tool
#
clean_ewarm: clean_ewarm_nonos clean_ewarm_os

#
# The rule to clean the nonos library using IAR tool
#
clean_ewarm_nonos:
	make BUILD_TOOL=ewarm CONFIG=nonos clean

#
# The rule to clean the os library using IAR tool
#
clean_ewarm_os:
	make BUILD_TOOL=ewarm CONFIG=os clean


#
# The rule to clean the libraries using GCC tool
#
gcc: gcc_nonos gcc_os

#
# The rule to build the nonos library using GCC tool
#
gcc_nonos:
	make BUILD_TOOL=gcc CONFIG=nonos

#
# The rule to build the os library using GCC tool
#
gcc_os:
	make BUILD_TOOL=gcc CONFIG=os


#
# The rule to clean the libraries using GCC tool
#
clean_gcc: clean_gcc_nonos clean_gcc_os

#
# The rule to clean the nonos library using GCC tool
#
clean_gcc_nonos:
	make BUILD_TOOL=gcc CONFIG=nonos clean

#
# The rule to clean the os library using GCC tool
#
clean_gcc_os:
	make BUILD_TOOL=gcc CONFIG=os clean