# @package      hubzero-submit-pegasus
# @file         Makefile
# @copyright    Copyright (c) 2010-2020 The Regents of the University of California.
# @license      http://www.apache.org/licenses/LICENSE-2.0 Apache2
#
# Copyright (c) 2010-2020 The Regents of the University of California.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# HUBzero is a registered trademark of The Regents of the University of California.
#

ETC=$(DESTDIR)/etc
USRLOCAL=$(DESTDIR)/usr/local

DISTRIBUTION := $(shell lsb_release -i -s)
MAJORVERSION := $(shell lsb_release -rs | cut -d . -f 1)

PEGASUSVERSION = 4.8.0

ifeq ($(DISTRIBUTION),Debian)
ifeq ($(MAJORVERSION),9)
   PEGASUSTARBALL = pegasus-binary-$(PEGASUSVERSION)-x86_64_deb_$(MAJORVERSION).tar.gz
else
   PEGASUSTARBALL = pegasus-nodocs-$(PEGASUSVERSION)-x86_64_deb_$(MAJORVERSION).tar.gz
endif
else
PEGASUSTARBALL = pegasus-nodocs-$(PEGASUSVERSION)-x86_64_rhel_$(MAJORVERSION).tar.gz
endif

PEGASUS_ROOT=${USRLOCAL}/pegasus
PEGASUS_INSTALL=${PEGASUS_ROOT}/pegasus-${PEGASUSVERSION}
PEGASUS_USE_INSTALL=/usr/local/pegasus/pegasus-${PEGASUSVERSION}

all:
	@true

install:
	install --mode 0755 --directory ${PEGASUS_ROOT}
	install --mode 0755 --directory ${ETC}/environ.d
	tar -C ${PEGASUS_ROOT} -zxvpf ${PEGASUSTARBALL}
	sed -e "s#@PEGASUS_INSTALL@#$(PEGASUS_USE_INSTALL)#g" pegasus.in  > ${ETC}/environ.d/pegasus-${PEGASUSVERSION}

uninstall:
	rm -fr ${PEGASUS_INSTALL}
	rm -fr ${ETC}/environ.d/pegasus-${PEGASUSVERSION}

postinst:
	@true

clean:
	@true

.PHONY: all install uninstall postinst clean
