#
# @package      hubzero-submit-distributor
# @file         Makefile
# @author       Nicholas J. Kisseberth <nkissebe@purdue.edu>
# @copyright    Copyright (c) 2010-2011 Purdue University. All rights reserved.
# @license      http://www.gnu.org/licenses/lgpl-3.0.html LGPLv3
#
# Copyright (c) 2010-2011 Purdue University
# All rights reserved.
#
# This file is part of: The HUBzero(R) Platform for Scientific Collaboration
#
# The HUBzero(R) Platform for Scientific Collaboration (HUBzero) is free
# software: you can redistribute it and/or modify it under the terms of
# the GNU Lesser General Public License as published by the Free Software
# Foundation, either version 3 of the License, or (at your option) any
# later version.
#
# HUBzero is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
# HUBzero is a registered trademark of Purdue University.
#
PYFILES = \
    distributor.py               MonitorsInfo.py            RemoteInstantSCRIPT.py  \
    EnvironmentWhitelistInfo.py  monitorTunnelA.py          RemoteJobMonitor.py     \
    GroupMembership.py           monitorTunnelD.py          RemoteTunnelMonitor.py  \
    JobDistributor.py            monitorTunnelI.py          SitesInfo.py            \
    JobMonitor.py                monitorTunnel.py           TarCommand.py           \
    JobStatistic.py              monitorTunnelR.py          TimeConversion.py       \
    LocalBatchCONDOR.py          monitorTunnelT.py          ToolsInfo.py            \
    LogMessage.py                RemoteBatchAppScript.py    TunnelMonitor.py        \
    ManagersInfo.py              RemoteBatchCONDOR.py       TunnelsInfo.py          \
    MessageCore.py               RemoteBatchLL.py           VenueMechanismCore.py   \
    monitorJob.py                RemoteBatchLSF.py          VenueMechanismGsiSsh.py \
    monitorJobQ.py               RemoteBatchPBS8.py         VenueMechanismLocal.py  \
    monitorJobR.py               RemoteBatchPBS.py          VenueMechanismSsh.py    \
    monitorJobS.py               RemoteBatchSLURM.py \
    monitorJobT.py               RemoteInstantAppScript.py

BATCHMONITORS = \
    BatchMonitors/monitorCondor.py  BatchMonitors/monitorLL.py     \
    BatchMonitors/monitorLSF.py     BatchMonitors/monitorSLURM.py  \
    BatchMonitors/monitorPBS.py

SCRIPTS = \
    Scripts/solarisscript/transmitresults.sh Scripts/solarisscript/epochtime.py      \
    Scripts/solarisscript/cleanupjob.sh      Scripts/solarisscript/submitbatchjob.sh \
    Scripts/solarisscript/receiveinput.sh                                            \
    Scripts/pbs/killbatchjob.sh              Scripts/pbs/transmitresults.sh          \
    Scripts/pbs/cleanupjob.sh                Scripts/pbs/submitbatchjob.sh           \
    Scripts/pbs/receiveinput.sh                                                      \
    Scripts/slurm/killbatchjob.sh            Scripts/slurm/transmitresults.sh        \
    Scripts/slurm/cleanupjob.sh              Scripts/slurm/submitbatchjob.sh         \
    Scripts/slurm/receiveinput.sh                                                    \
    Scripts/lsf/killbatchjob.sh              Scripts/lsf/transmitresults.sh          \
    Scripts/lsf/cleanupjob.sh                Scripts/lsf/submitbatchjob.sh           \
    Scripts/lsf/receiveinput.sh                                                      \
    Scripts/condor/killbatchjob.sh           Scripts/condor/transmitresults.sh       \
    Scripts/condor/cleanupjob.sh             Scripts/condor/submitbatchjob.sh        \
    Scripts/condor/receiveinput.sh                                                   \
    Scripts/ll/killbatchjob.sh               Scripts/ll/transmitresults.sh           \
    Scripts/ll/cleanupjob.sh                 Scripts/ll/submitbatchjob.sh            \
    Scripts/ll/receiveinput.sh

DATA = monitors managers sites tools tunnels environmentwhitelist

BIN = bin/genuserid bin/update-known-hosts

EXEC = distributor.py monitorJob.py monitorJobQ.py monitorJobR.py monitorJobS.py \
monitorJobT.py monitorTunnelA.py monitorTunnelD.py monitorTunnelI.py monitorTunnel.py \
monitorTunnelR.py monitorTunnelT.py

OWNER=root
GROUP=root
PYDIR=$(DESTDIR)/opt/submit
DATDIR=$(DESTDIR)/opt/submit
ETCDIR=$(DESTDIR)/etc
USRSHAREDIR=$(DESTDIR)/usr/share
VARLOGDIR=$(DESTDIR)/var/log

clean:
	rm -f build-stamp configure-stamp *.pyc

install:
	install --owner root --group root --mode 0775 -d $(PYDIR)
	install --owner root --group root --mode 0775 -d $(PYDIR)/bin
	install --owner root --group root --mode 0775 -d $(PYDIR)/etc
	install --owner root --group root --mode 0775 -d $(PYDIR)/Scripts
	install --owner root --group root --mode 0775 -d $(PYDIR)/Scripts/solarisscript
	install --owner root --group root --mode 0775 -d $(PYDIR)/Scripts/pbs
	install --owner root --group root --mode 0775 -d $(PYDIR)/Scripts/slurm
	install --owner root --group root --mode 0775 -d $(PYDIR)/Scripts/lsf
	install --owner root --group root --mode 0775 -d $(PYDIR)/Scripts/condor
	install --owner root --group root --mode 0775 -d $(PYDIR)/Scripts/ll
	install --owner root --group root --mode 0775 -d $(PYDIR)/BatchMonitors
	install --owner root --group root --mode 0775 -d $(USRSHAREDIR)/hubzero-submit-distributor
	install --owner $(OWNER) --group $(GROUP) --mode 0771 -d $(VARLOGDIR)/submit
	install --owner $(OWNER) --group $(GROUP) --mode 0771 -d $(VARLOGDIR)/submit/distributor
	install --owner $(OWNER) --group $(GROUP) --mode 0771 -d $(VARLOGDIR)/submit/monitors

	for f in $(PYFILES); do install $$f $(PYDIR)/$$f --owner $(OWNER) --group $(GROUP) --mode 0644 ; done
	for f in $(SCRIPTS);  do install $$f $(PYDIR)/$$f --owner $(OWNER) --group $(GROUP) --mode 0644 ; done
	for f in $(BATCHMONITORS);  do install $$f $(PYDIR)/$$f --owner $(OWNER) --group $(GROUP) --mode 0755 ; done
	for f in $(BIN); do install $$f $(PYDIR)/$$f --owner $(OWNER) --group $(GROUP) --mode 0755 ; done
	for f in $(DATA); do install $$f.dft $(USRSHAREDIR)/hubzero-submit-distributor --owner $(OWNER) --group $(GROUP) --mode 0644 ; done
	for f in $(EXEC); do chmod a+x $(PYDIR)/$$f ; done
	install distributor.sh $(PYDIR)/distributor.sh --owner $(OWNER) --group $(GROUP) --mode 0744
	install --owner root --group root --mode 0700 -D submon.rc $(ETCDIR)/init.d/submon
	install --owner root --group root --mode 0700 -D subtun.rc $(ETCDIR)/init.d/subtun
	ln -f -s -T distributor.py $(PYDIR)/distributor
	for f in $(DATA); do if [ ! -e $(PYDIR)/$$f.dat ] ; then install $$f.dft $(PYDIR)/$$f.dat --owner $(OWNER) --group $(GROUP) --mode 0644 ; fi ; done


