# @package      hubzero-rappture-deb7
# @file         Makefile
# @copyright    Copyright (c) 2010-2020 The Regents of the University of California.
# @license      http://www.gnu.org/licenses/lgpl-3.0.html LGPLv3
#
# Copyright (c) 2010-2020 The Regents of the University of California.
#
# 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 The Regents of the University of California.
#

VERSION:=tag-1.7.1-6544-2041
APPSSHAREDIR:=$(DESTDIR)/apps/share
PWD:=$(shell pwd)

all:
	@true

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

install:
	install -d $(APPSSHAREDIR)/rappture/$(VERSION)
	tar -C $(APPSSHAREDIR)/rappture -zxvpf rappture-$(VERSION).tar.gz
	(cd $(APPSSHAREDIR)/rappture; ln -fs $(VERSION) current)
	(cd $(APPSSHAREDIR)/rappture; ln -fs current/bin bin)
	(cd $(APPSSHAREDIR)/rappture; ln -fs current/examples examples)
	(cd $(APPSSHAREDIR)/rappture; ln -fs current/include include)
	(cd $(APPSSHAREDIR)/rappture; ln -fs current/lib lib)
	(cd $(APPSSHAREDIR)/rappture; ln -fs current/share share)
	install --mode 0644 -D $(APPSSHAREDIR)/rappture/$(VERSION)/bin/rappture.use $(APPSSHAREDIR)/environ.d/rappture
	find $(APPSSHAREDIR)/rappture/$(VERSION) -type f -exec chmod u+rw,g+r,o+r  {} \;
	find $(APPSSHAREDIR)/rappture/$(VERSION) -type d -exec chmod 0755 {} \;
	find $(APPSSHAREDIR)/rappture/$(VERSION) -type f -name "*.h" -exec chmod a-x {} \;
	find $(APPSSHAREDIR)/rappture/$(VERSION) -type f -name "*.a" -exec chmod a-x {} \;
	find $(APPSSHAREDIR)/rappture/$(VERSION) -type f -name "*.so" -exec chmod a-x {} \;
	find $(APPSSHAREDIR)/rappture/$(VERSION) -type f -executable -exec file -i '{}' \; | grep -P '(x-executable|x-sharedlib); charset=binary' | cut -d':' -f1 | xargs -L 1 strip -p
	rm $(APPSSHAREDIR)/rappture/$(VERSION)/bin/ccmake 
	rm $(APPSSHAREDIR)/rappture/$(VERSION)/bin/cmake 
	rm $(APPSSHAREDIR)/rappture/$(VERSION)/bin/ctest
	rm $(APPSSHAREDIR)/rappture/$(VERSION)/bin/cpack
	rm -r $(APPSSHAREDIR)/rappture/$(VERSION)/doc/cmake-2.8
	rm -r $(APPSSHAREDIR)/rappture/$(VERSION)/share/cmake-2.8
	rm -r $(APPSSHAREDIR)/rappture/$(VERSION)/lib/cmake
	rm -r $(APPSSHAREDIR)/rappture/$(VERSION)/lib/R
	rm $(APPSSHAREDIR)/rappture/$(VERSION)/man/man1/cmake.1
	rm $(APPSSHAREDIR)/rappture/$(VERSION)/man/man1/cmakecommands.1
	rm $(APPSSHAREDIR)/rappture/$(VERSION)/man/man1/cmakeprops.1
	rm $(APPSSHAREDIR)/rappture/$(VERSION)/man/man1/cmakepolicies.1
	rm $(APPSSHAREDIR)/rappture/$(VERSION)/man/man1/cmakemodules.1
	rm $(APPSSHAREDIR)/rappture/$(VERSION)/man/man1/ccmake.1
	rm $(APPSSHAREDIR)/rappture/$(VERSION)/man/man1/cmakecompat.1
	rm $(APPSSHAREDIR)/rappture/$(VERSION)/man/man1/cmakevars.1
	rm $(APPSSHAREDIR)/rappture/$(VERSION)/man/man1/cpack.1
	rm $(APPSSHAREDIR)/rappture/$(VERSION)/man/man1/ctest.1
	rm $(APPSSHAREDIR)/rappture/$(VERSION)/share/aclocal/cmake.m4
	find $(APPSSHAREDIR)/rappture/$(VERSION) -depth -type d -name ".svn" -exec rm -r {} \;
	find $(APPSSHAREDIR)/rappture/$(VERSION) -type f -name "*.pyc" -exec rm -r {} \;
	find $(APPSSHAREDIR)/rappture/$(VERSION)/examples -name Makefile -exec sed -i 's/\/share64\/debian7/\/share/g' {} \;
	find $(APPSSHAREDIR)/rappture/$(VERSION) -name "*Config.sh" -exec sed -i 's/\/share64\/debian7/\/share/g' {} \;
	sed -i 's/\/share64\/debian7/\/share/g' $(APPSSHAREDIR)/rappture/$(VERSION)/lib/perl/perllocal.pod
	sed -i 's/\/share64\/debian7/\/share/g' $(APPSSHAREDIR)/rappture/$(VERSION)/lib/blt2.4/pkgIndex.tcl
	sed -i 's/\/share64\/debian7/\/share/g' $(APPSSHAREDIR)/rappture/$(VERSION)/bin/puq.sh
	sed -i 's/\/share64\/debian7/\/share/g' $(APPSSHAREDIR)/rappture/$(VERSION)/bin/rappture.use
	sed -i 's/\/share64\/debian7/\/share/g' $(APPSSHAREDIR)/rappture/$(VERSION)/bin/rappture-csh.env
	sed -i 's/\/share64\/debian7/\/share/g' $(APPSSHAREDIR)/rappture/$(VERSION)/bin/rappture.env
	sed -i 's/\/share64\/debian7/\/share/g' $(APPSSHAREDIR)/environ.d/rappture
	find $(APPSSHAREDIR)/rappture/$(VERSION) -name "*Config.sh" -exec sed -i  's/\/home\/nanohub\/apps\//\/apps\/share\/rappture\//g' {} \;
	find $(APPSSHAREDIR)/rappture/$(VERSION)/man/mann -name "*.n" -exec sed -i  's/\/home\/nanohub\/apps\//\/apps\/share\/rappture\//g' {} \;
	find $(APPSSHAREDIR)/rappture/$(VERSION)/include/vtk-6.0 -name "*.h" -exec sed -i  's/\/home\/nanohub\/apps\//\/apps\/share\/rappture\//g' {} \;

uninstall:
	@true

postinst:
	@true

clean:
	@true

.PHONY: all install uninstall postinst clean
