###############################################################################
## Stage Controller MakefileSupport.mk
##
## Author:  William Layne
##
## Description:  This is a top-level file which contains all of the support
##				 definitions for makefiles
###############################################################################
###############################################################################
# DEFINITION OF SHELL EXECUTABLES
###############################################################################
MKDIR  	   = mkdir -p 
CP         = rsync -rRl --prune-empty-dirs --exclude='[uU]nit_[tT]ests' --exclude='[uU]nit_[tT]est' --exclude='*/.gitkeep'
CP_TO_DIR  = rsync -rl --prune-empty-dirs --exclude='[uU]nit_[tT]ests' --exclude='[uU]nit_[tT]est' --exclude='*/.gitkeep'
CP_FILES = rsync -r --exclude='[uU]nit_[tT]ests' --exclude='[uU]nit_[tT]est' --exclude='*/.gitkeep'
RM         = rm -rf
CHMOD_DIR  = chmod 755
CHMOD_READ = chmod 444
CHMOD_EXE  = chmod 755
CAT        = cat
###############################################################################
#  Define target variables
###############################################################################
BUILD_PREFIX=build_
INSTALL_PREFIX=install_
CLEAN_PREFIX=clean_
UNINSTALL_PREFIX=uninstall_
###############################################################################
# Define make and if checks
###############################################################################
# Name: EPICS_TARGET_MAKE
# Description:
#	Echos what the build is currently doing using the target and directory name passed in.
#	Then if the directory passed in exists, it calls whatever was passed in argument 2 as args.
#	Else it echos that the directory does not exist.
# Arguments:
# 	Arg 1 - Directory name
# 	Arg 2 - Make args
define IF_DIR_EXISTS
@echo "--------------- $@ $(1) ---------------"
@if [ -d "$(1)" ]; then \
$(2); \
else \
echo "$(1) not a directory."; \
fi
endef
# Name: EPICS_BUILD
# Description:
#	Definition to call IF_DIR_EXISTS passing in directory name and call normal make.
#	Used to not pass in the target.
# Arguments:
# 	Arg 1 - Directory name
# 	Arg 2 - Make args
define EPICS_BUILD
$(call IF_DIR_EXISTS,$(1),$(MAKE) -C $(1) $(2))
endef
# Name: EPICS_TARGET_MAKE
# Description:
#	Definition to call IF_DIR_EXISTS passing in directory name, and additional
#	Make arguments with ADDITION of the target that calls this definition.
# Arguments:
# 	Arg 1 - Directory name
# 	Arg 2 - Make args
define EPICS_TARGET_MAKE
$(call EPICS_BUILD,$(1), $(2) $@)
endef

define TARG_DEPEND
$(addprefix $(3),$(2)) : $(addprefix $(3), $(1))
endef

define SET_TARG_ARG
$(addprefix $(2),$(1)) : TARG_ARGS+=$(3)
endef