#*************************************************************************
# Copyright (c) 2013 UChicago Argonne LLC, as Operator of Argonne
#     National Laboratory.
# Copyright (c) 2002 The Regents of the University of California, as
#     Operator of Los Alamos National Laboratory.
# EPICS BASE is distributed subject to a Software License Agreement found
# in file LICENSE that is included with this distribution.
#*************************************************************************
# RULES.cpu
# This file contains targets needed in CPU directories

include $(CONFIG)/RULES_DIRS

CONVERTRELEASE = perl $(TOP)/cpuBoot/convertRelease.pl

build$(DIVIDER)$(ARCH) build: buildInstall
install$(DIVIDER)$(ARCH) install: buildInstall
$(ARCH): buildInstall

ifeq ($(filter $(ARCH),$(BUILD_ARCHS)),$(strip $(ARCH)))
    buildInstall$(DIVIDER)$(ARCH) buildInstall: $(TARGETS)

    clean$(DIVIDER)$(ARCH) clean: cpu_clean
else
    buildInstall$(DIVIDER)$(ARCH) buildInstall:
    clean$(DIVIDER)$(ARCH) clean:
endif

# Notes re IOCS_APPL_TOP vs IOC_APPL_TOP
# IOCS_APPL_TOP is the traditional macro for EPICS that
# is set to the absolute pathname of INSTALL_LOCATION.
# The ioc can use this to locate it's executables, db files, etc
#
# IOC_APPL_TOP was introduced by SLAC for templated ioc's
# IOC_APPL_TOP gets set in the build files for templated
# ioc's to the TOP for it's parent IOC build.
# The build system and the ioc application use this to locate
# the executables, db files, etc
#
# While nearly the same, convertRelease needs to use the
# -T option for IOCS_APPL_TOP and the
# -t option for IOC_APPL_TOP
# to find the RELEASE* files
cdCommands dllPath.bat relPaths.sh: \
    $(wildcard $(TOP)/configure/RELEASE*) \
    $(wildcard $(TOP)/configure/CONFIG*) $(INSTALL_BIN)\
    $(wildcard $(TOP)/RELEASE_SITE) \
    $(wildcard $(TOP)/RELEASE.local)
ifeq ($(IOC_APPL_TOP),)
	 -a $(ARCH) -T $(IOCS_APPL_TOP) $@
else
	 -a $(ARCH) -t $(IOC_APPL_TOP) $@
endif

envPaths cpuEnv.sh: $(wildcard $(TOP)/configure/RELEASE*) \
    $(wildcard $(TOP)/RELEASE_SITE) \
    $(wildcard $(TOP)/configure/CONFIG_SITE*) $(INSTALL_BIN)
	@echo Building $@ ...
ifeq ($(IOC_APPL_TOP),)
	$(CONVERTRELEASE) -a $(ARCH) -T $(IOCS_APPL_TOP) $@
else
	$(CONVERTRELEASE) -a $(ARCH) -t $(IOC_APPL_TOP) $@
endif

realclean: cpu_clean

cpu_clean:
	$(RM) cpuEnv.sh cdCommands envPaths dllPath.bat relPaths.sh

