File lua-lmod.spec of Package lua-lmod

#
# spec file for package lua-lmod
#
# Copyright (c) 2017 SUSE LINUX GmbH, Nuernberg, Germany.
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via http://bugs.opensuse.org/
#


#
%define ohpc 0

%define lua_lmod_modulesdir %{_datarootdir}/lmod/modulefiles
%define lua_lmod_admin_modulesdir %{_datarootdir}/lmod/admin/modulefiles
%define lua_lmod_moduledeps %{_datarootdir}/lmod/moduledeps
%define lua_path ?.lua;?/?.lua;%{lua_noarchdir}/?.lua;%{lua_noarchdir}/?/init.lua
%define lua_cpath ?.so;?/?.so;%{lua_archdir}/?.so

Name:           lua-lmod
Summary:        Lua based Environment Modules
License:        MIT
Group:          Development/Libraries/Other
Version:        6.5.11
Release:        0
Url:            https://github.com/TACC/Lmod
BuildArch:      noarch
%if 0%{?ohpc}
BuildRequires:  ohpc
%endif

Source0:        https://github.com/TACC/Lmod/archive/%{version}.tar.gz#$/%{name}-%{version}.tar.gz
Patch1:         lmod.consulting.patch
Patch2:         lmod.site.patch

BuildRoot:      %{_tmppath}/%{name}-%{version}-build

BuildRequires:  lua >= %{lua_version}
BuildRequires:  lua-devel >= %{lua_version}
BuildRequires:  lua-luafilesystem
BuildRequires:  lua-luaposix
BuildRequires:  lua-luaterm
BuildRequires:  procps
BuildRequires:  python-Sphinx
BuildRequires:  rsync
BuildRequires:  tcl
BuildRequires:  texlive
BuildRequires:  texlive-babel
BuildRequires:  texlive-babel-english
BuildRequires:  texlive-capt-of
BuildRequires:  texlive-caption
BuildRequires:  texlive-cmap
BuildRequires:  texlive-courier
BuildRequires:  texlive-dvips
BuildRequires:  texlive-eqparbox
BuildRequires:  texlive-fancybox
BuildRequires:  texlive-fancyhdr
BuildRequires:  texlive-fancyvrb
BuildRequires:  texlive-framed
BuildRequires:  texlive-helvetic
BuildRequires:  texlive-mdwtools
BuildRequires:  texlive-multirow
BuildRequires:  texlive-needspace
BuildRequires:  texlive-parskip
BuildRequires:  texlive-psnfss
BuildRequires:  texlive-threeparttable
BuildRequires:  texlive-times
BuildRequires:  texlive-titlesec
BuildRequires:  texlive-upquote
BuildRequires:  texlive-wrapfig
Requires:       lua >= %{lua_version}
Requires:       lua-luafilesystem
Requires:       lua-luaposix
Requires:       lua-luaterm
Requires:       tcl
%if 0%{?is_opensuse} || 0%{?sle_version} >= 150000
BuildRequires:  python-Sphinx-latex
%endif

%description
Lmod is an Environment Module System based on Lua, Reads TCL Modules,
Supports a Software Hierarchy.

%package doc
Summary:        Documentation for Lmod
Group:          Documentation/Libraries/Other

%description doc
Documentation (pdf) for the Lmod Environment Modules System

%prep
%setup -q -n Lmod-%{version}
%patch1 -p1
%patch2 -p1

%build
export LUA_CPATH="%{lua_cpath}"
export LUA_PATH="%{lua_path}"
%configure --prefix=%{_datadir} \
    --with-module-root-path=%{lua_lmod_modulesdir} \
    --libdir=%{lua_archdir} \
    --datadir=%{lua_noarchdir} \
    --with-redirect=yes \
    --with-autoSwap=no
make
find my_docs/ -name .gitignore | xargs rm
cd docs; make latexpdf man; cd ..

%install
export LUA_CPATH="%{lua_cpath}"
export LUA_PATH="%{lua_path}"
make DESTDIR=%{buildroot} install

mkdir -p %{buildroot}%{_sysconfdir}/rpm
cat <<EOF > %{buildroot}%{_sysconfdir}/rpm/macros.lmod
%%lua_lmod_modulesdir %{lua_lmod_modulesdir}
%%lua_lmod_admin_modulesdir %{lua_lmod_admin_modulesdir}
%%lua_lmod_moduledeps %{lua_lmod_moduledeps}
EOF
mkdir -p %{buildroot}%{lua_lmod_modulesdir}
mkdir -p %{buildroot}%{lua_lmod_admin_modulesdir}
mkdir -p %{buildroot}%{lua_lmod_moduledeps}
mkdir -p %{buildroot}/%{_mandir}/man1                                                       
install -p -m644 docs/build/man/lmod.1 %{buildroot}/%{_mandir}/man1/

# Fix exec warning
chmod u+x %{buildroot}%{_datadir}/lmod/%{version}/libexec/ignore_dirs_converter
# Fix file duplicates
rm -f %{buildroot}/%{_datadir}/lmod/%{version}/init/ksh
ln -s %{_datadir}/lmod/%{version}/init/sh  %{buildroot}/%{_datadir}/lmod/%{version}/init/ksh
rm -f %{buildroot}/%{_datadir}/lmod/%{version}/init/zsh
ln -s %{_datadir}/lmod/%{version}/init/bash  %{buildroot}/%{_datadir}/lmod/%{version}/init/zsh
rm -f %{buildroot}/%{_datadir}/lmod/%{version}/init/tcsh
ln -s %{_datadir}/lmod/%{version}/init/csh %{buildroot}/%{_datadir}/lmod/%{version}/init/tcsh
rm -f %{buildroot}/%{_datadir}/lmod/%{version}/settarg/Version.lua 
ln -s %{_datadir}/lmod/%{version}/libexec/Version.lua %{buildroot}/%{_datadir}/lmod/%{version}/settarg/Version.lua

mkdir -p %{buildroot}/%{_sysconfdir}/profile.d
%{__cat} <<EOF > %{buildroot}/%{_sysconfdir}/profile.d/lmod.sh
# -*- shell-script -*-
########################################################################
#  This is the system wide source file for setting up
#  modules:
#
########################################################################

# NOOP if running under known resource manager
if [ ! -z "\$SLURM_NODELIST" ];then
     return
fi

export LMOD_SETTARG_CMD=":"
export LMOD_FULL_SETTARG_SUPPORT=no
export LMOD_COLORIZE=no
export LMOD_PREPEND_BLOCK=normal

if [ \$EUID -eq 0 ]; then
    export MODULEPATH=%{?OHPC_MODULES:%{OHPC_ADMIN}/modulefiles:%{OHPC_MODULES}:}%{lua_lmod_admin_modulesdir}:%{lua_lmod_modulesdir}
else
    export MODULEPATH=%{?OHPC_MODULES:%{OHPC_MODULES}:}%{lua_lmod_modulesdir}
fi

export BASH_ENV=%{_datadir}/lmod/%{version}/init/bash

# Initialize modules system
. \${BASH_ENV} >/dev/null

# Load baseline OpenHPC environment
module try-add ohpc

EOF

%{__cat} <<EOF > %{buildroot}/%{_sysconfdir}/profile.d/lmod.csh
# -*- shell-script -*-
########################################################################
#  This is the system wide source file for setting up
#  modules:
#
########################################################################

if ( \$?SLURM_NODELIST ) then
    exit 0
endif

setenv LMOD_SETTARG_CMD ":"
setenv LMOD_FULL_SETTARG_SUPPORT "no"
setenv LMOD_COLORIZE "no"
setenv LMOD_PREPEND_BLOCK "normal"

if ( \`id -u\` == "0" ) then
   setenv MODULEPATH "%{?OHPC_MODULES:%{OHPC_ADMIN}/modulefiles:%{OHPC_MODULES}:}%{lua_lmod_admin_modulesdir}:%{lua_lmod_modulesdir}"
else   
   setenv MODULEPATH "%{?OHPC_MODULES:%{OHPC_MODULES}:}%{lua_lmod_modulesdir}"
endif

# Initialize modules system
source %{_datadir}/lmod/%{version}/init/csh >/dev/null

# Load baseline OpenHPC environment
module try-add ohpc 

EOF

%files
%defattr(-,root,root,-)
%config %{_sysconfdir}/profile.d/lmod.sh
%config %{_sysconfdir}/profile.d/lmod.csh
%config %{_sysconfdir}/rpm/macros.lmod
%dir %{_datadir}/lmod
%dir %{lua_lmod_modulesdir}
%dir %{lua_lmod_admin_modulesdir}
%dir %{lua_lmod_moduledeps}
%{_datadir}/lmod/*
%{_mandir}/man1/lmod.1.*
%doc License
%doc README

%files doc
%defattr(-,root,root,-)
%doc my_docs/*.txt my_docs/*.pdf my_docs/*.md
%doc docs/build/latex/Lmod.pdf

%changelog