File openfoam.spec of Package openfoam

#
# Spec file for meta-package openfoam
#
# Copyright (c) 2018-2020 OpenCFD Ltd. (www.openfoam.com)
#
# 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.
# The license of the pristine package is GPL-3.0-or-later.

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

%define foam_version 2006
%define foam_patch %{nil}

# Require min patch-level?
%if 0%{?foam_patch}
%define full_version  %{foam_version}.%{foam_patch}
%define redirect_version >= %{foam_patch}
%else
%define full_version  %{foam_version}
%define redirect_version %{nil}
%endif

%define redirect openfoam%{foam_version}

# Enable openfoam-selector for openSUSE (part of the science repo)
%if 0%{?suse_version}
 %bcond_without foam_selector
%else
 %bcond_with    foam_selector
%endif

# ------------------

Name:           openfoam
Version:        %{full_version}
Release:        0
Url:            http://www.openfoam.com
Summary:        Free, Open Source, Computational Fluid Dynamics Package
Group:          Productivity/Scientific/Physics
License:        GPL-3.0-or-later
Prefix:         /usr/lib/openfoam
Requires:       %{redirect} %{redirect_version}
%if %{with foam_selector}
Requires(post):  openfoam-selector
Requires(preun): openfoam-selector
%endif

%package devel
Summary:        OpenFOAM source code headers and wmake build chain
Group:          Development/Tools/Other
BuildArch:      noarch
Requires:       %{name}
Requires:       %{redirect}-devel %{redirect_version}

%package default
Summary:        OpenFOAM default installation bundle
Group:          Productivity/Scientific/Physics
Requires:       %{name}-devel = %{version}
Requires:       %{name}-tutorials = %{version}
Requires:       %{redirect}-default %{redirect_version}


# Descriptions

%global _description1 %{expand:
OpenFOAM is a free, open source computational fluid dynamics (CFD)
software package produced by OpenCFD Ltd with twice yearly releases.}

%global _description2 %{expand:
* Release notes:  https://www.openfoam.com/releases/openfoam-v%{foam_version}
* Documentation:  https://www.openfoam.com/documentation/
* Issue Tracker:  https://develop.openfoam.com/Development/openfoam/issues/}


%description            %_description1
%_description2

Meta-package for %{redirect}


%description devel      %_description1
%_description2

Meta-package for %{redirect}-devel


%description default  %_description1
%_description2

Meta-package for %{redirect}-default


%prep
# Not needed

%build
echo "Meta-package for dependency on the corresponding %{redirect} package" > README

%install
%{__rm} -rf %{buildroot}%{prefix}
%{__mkdir_p} %{buildroot}%{prefix}

(cd %{buildroot}%{prefix} && %{__ln_s} openfoam%{version} openfoam)


%post
projectDir="${RPM_INSTALL_PREFIX}/openfoam%{version}"

# Create/update /usr/bin/openfoam -> openfoamVERSION link
(
    cd %{_bindir} || exit

    if [ -f "openfoam%{version}" ]
    then
        %{__ln_s} -f "openfoam%{version}" openfoam
        echo "Create %{_bindir}/openfoam link for openfoam%{version}"
    else
        echo "No plausible means to create %{_bindir}/openfoam link"
        %{__rm} -f %{_bindir}/openfoam
    fi
)


# Register with openfoam-selector if possible
selector="%{_bindir}/openfoam-selector"
if [ -x "$selector" ]
then
    if "$selector" \
        --register %{name} \
        --source-dir "${projectDir}" \
        --yes
    then
        echo "Registered %{name} with openfoam-selector"
    else
        echo "Failed to register %{name} with openfoam-selector"
    fi
fi

%preun
session="%{_bindir}/openfoam"

# Only unregister when uninstalling
if [ "$1" = "0" ]
then
    if linked=$(readlink "$session")
    then
        echo "Remove $session link for $linked"
    fi
    %{__rm} -f "$session"

    # Deregister default if we are uninstalling it
    selector="%{_bindir}/openfoam-selector"
    if [ -x "$selector" ]
    then
        if [ "$($selector --system --query)" = "%{name}" ]
        then
            "$selector" --system --unset --yes
        fi
        if "$selector" --unregister %{name} --yes
        then
            echo "Unregistered %{name} from openfoam-selector"
        else
            echo "No %{name} found to unregister from openfoam-selector"
        fi
    fi
fi


%files
# Include ownership of /usr/lib/openfoam prefix
%dir %{prefix}
%{prefix}/%{name}*
%doc README

%files devel
%doc README

%files default
%doc README

%changelog