File netcdf-fortran.spec of Package netcdf-fortran

#
# spec file
#
# Copyright (c) 2023 SUSE LLC
#
# 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 https://bugs.opensuse.org/
#


%global flavor @BUILD_FLAVOR@%{nil}

%define _do_check 1

%global pname netcdf-fortran
%global ver 4.5.3
%global sover 7

%if 0%{?sle_version} >= 150200
%define DisOMPI1 ExclusiveArch:  do_not_build
%endif
%if !0%{?is_opensuse} && 0%{?sle_version:1}
 %if 0%{?sle_version} < 150200
  %define DisOMPI3 ExclusiveArch:  do_not_build
 %endif
 %if 0%{?sle_version} < 150300
  %define DisOMPI4 ExclusiveArch:  do_not_build
 %endif
%endif

ExcludeArch:    s390 s390x i586 %arm

%if "%flavor" == ""
ExclusiveArch:  do_not_build
%define package_name %pname
%define compiler_family gnu
%endif

ExcludeArch:    s390 s390x %ix86

%{bcond_with staticlibs}

%if "%flavor" == "standard"
%{bcond_with mpi}
%endif

%if "%flavor" == "openmpi4"
%{?DisOMPI4}
%global mpi_flavor openmpi
%global mpi_ver 4
%{bcond_without mpi}
%endif

%if "%flavor" == "openmpi5"
%{?DisOMPI5}
%global mpi_flavor openmpi
%global mpi_ver 5
%{bcond_without mpi}
%endif

%if "%flavor" == "mvapich2"
%global mpi_flavor mvapich2
%{bcond_without mpi}
%endif

%if "%flavor" == "mpich"
%global mpi_flavor mpich
%{bcond_without mpi}
%endif


%define limit_cores(c:) %{?_smp_mflags: %(a=1;
              b=$(sed -se "s/.*-j[[:space:]]*\\([[:digit:]]\\+\\).*/\\1/" <<< %_smp_mflags);
              [ $b -le $a ] || b=$a ;
              sed -se "s/\\(.*-j[[:space:]]*\\)[[:digit:]]\\+\\(.*\\)/\\1$b/" <<< %_smp_mflags )}

%define package_name netcdf-fortran%{?with_mpi:-%{mpi_flavor}%{?mpi_ver}}
%define libname libnetcdf-fortran%{?with_mpi:-%{mpi_flavor}%{?mpi_ver}}-%{sover}

Name:           %package_name
Summary:        Command-line programs for the NetCDF scientific data format
License:        NetCDF
Group:          Productivity/Scientific/Other
Version:        %ver
Release:        0
%define sonum   7
URL:            https://www.unidata.ucar.edu/software/netcdf/
Source:         https://github.com/Unidata/netcdf-fortran/archive/v%{version}.tar.gz#/%{pname}-%{version}.tar.gz
BuildRequires:  gawk
BuildRequires:  gcc-fortran
BuildRequires:  libcurl-devel >= 7.18.0
BuildRequires:  lua-lmod
BuildRequires:  m4
BuildRequires:  pkg-config
BuildRequires:  zlib-devel >= 1.2.5
BuildRequires:  fdupes
%if %{with mpi}
BuildRequires:  %{mpi_flavor}%{?mpi_ext}-devel
%endif
BuildRequires:  hdf5%{?with_mpi:-%{mpi_flavor}%{?mpi_ver}}-devel
BuildRequires:  netcdf%{?with_mpi:-%{mpi_flavor}%{?mpi_ver}}-devel >= 4.7.4
Requires:       %{libname} = %{version}

%description
NetCDF is a set of software libraries and self-describing,
machine-independent data formats that support the creation, access,
and sharing of array-oriented scientific data.

%if %{without mpi}
This package contains utility functions for working with NetCDF files.
%else
This package contains the %{mpi_flavor} version of utility functions for
working with NetCDF files.
%endif

%package -n     %{libname}
Summary:        Shared libraries for the NetCDF scientific data format
Group:          System/Libraries

%description -n %{libname}
NetCDF is a set of software libraries and self-describing,
machine-independent data formats that support the creation, access,
and sharing of array-oriented scientific data.

NetCDF (network Common Data Form) is an interface for array-oriented
data access and a collection of software libraries
for C, Fortran, C++, and Perl that provides an implementation of the
interface. The NetCDF library also defines a machine-independent
format for representing scientific data. Together, the interface,
library, and format support the creation, access, and sharing of
scientific data.

NetCDF data is:
   - Self-Describing: A NetCDF file includes information about the
     data it contains.
   - Network-transparent:  A NetCDF file is represented in a form that
     can be accessed by computers with different ways of storing
     integers, characters, and floating-point numbers.
   - Direct-access:  A small subset of a large dataset may be accessed
     efficiently, without first reading through all the preceding
     data.
   - Appendable:  Data can be appended to a NetCDF dataset along one
     dimension without copying the dataset or redefining its
     structure. The structure of a NetCDF dataset can be changed,
     though this sometimes causes the dataset to be copied.
   - Sharable:  One writer and multiple readers may simultaneously
     access the same NetCDF file.

This package contains all files needed to create projects that use
%{?mpi_flavor:the %mpi_flavor version of} NetCDF.

%package devel
Summary:        Development files for %{name}
Group:          Development/Libraries/Parallel
Requires:       %{libname} = %{version}
Requires:       libcurl-devel >= 7.18.0
Requires:       pkgconfig
Requires:       zlib-devel >= 1.2.5
Requires:       netcdf%{?with_mpi:-%{mpi_flavor}%{?mpi_ver}}-devel
Obsoletes:      %{name} < %{version}-%{release}
Provides:       %{name} = %{version}-%{release}

%description devel
NetCDF is a set of software libraries and self-describing,
machine-independent data formats that support the creation, access,
and sharing of array-oriented scientific data.

This package contains all files needed to create projects that use
%{?mpi_flavor:the %mpi_flavor version of} NetCDF.

%package devel-static
Summary:        Static development files for %{name}
Group:          Development/Libraries/Parallel
Requires:       %{name}-devel = %{version}
#Requires:       hdf-devel
Requires:       hdf5%{?with_mpi:-%{mpi_flavor}%{?mpi_ver}}-devel
Requires:       libcurl-devel >= 7.18.0
Requires:       zlib-devel >= 1.2.5

%description devel-static
NetCDF is a set of software libraries and self-describing,
machine-independent data formats that support the creation, access,
and sharing of array-oriented scientific data.

This package contains the static libraries for
%{?mpi_flavor:the %mpi_flavor version of} NetCDF.

%if %{with mpi}
%global _prefix %_libdir/mpi/gcc/%{mpi_flavor}%{?mpi_ver}
%endif

%prep
%setup -q -n %{pname}-%{version}

# Fix spurious-executable-perm RPMLINT warning
chmod a-x RELEASE_NOTES.md

%build

%{?_lto_cflags: %global _lto_cflags %{?_lto_cflags} -ffat-lto-objects}
%{?with_staticlibs:%{?_smp_mflags:%global _smp_mflags %{limit_cores -c 8}}}
export CFLAGS="%{optflags} -L%_libdir -lnetcdf -lhdf5"
export FCFLAGS="%{optflags} -std=legacy"
export FFLAGS=$FCFLAGS
export CPPFLAGS=$CFLAGS
export LDFLAGS="-L%_libdir -lnetcdf -lhdf5"

%if %{with mpi}
. %{_bindir}/mpivars.sh
export CC="mpicc"
export FC="mpif90"
export F77="mpif77"
%endif
%configure \
    --prefix=%_prefix \
    --enable-shared \
    --with-pic \
    --disable-doxygen \
%if %{with staticlibs}
    --enable-static
%else
    --disable-static
%endif

make %{?_smp_mflags}

%install
export CFLAGS="%{optflags} -L%_libdir -lnetcdf -lhdf5"
export FCFLAGS="%{optflags}"
export CPPFLAGS=$CFLAGS
export LDFLAGS="-L%_libdir -lnetcdf -lhdf5"
%if %{with mpi}
. %{_bindir}/mpivars.sh
export CC="mpicc"
export FC="mpif90"
export F77="mpif77"
%endif

make install DESTDIR="%{buildroot}"

rm -f %{buildroot}%{_libdir}/*.la
%fdupes -s %{buildroot}%{_datadir}

%if %_do_check
%check
export CFLAGS="-L%_libdir -lnetcdf -lhdf5"
export CPPFLAGS=$CFLAGS
export LDFLAGS="-L%_libdir -lnetcdf -lhdf5"
%if 0%{with mpi}
. %{_bindir}/mpivars.sh
export CC="mpicc"
export FC="mpif90"
export F77="mpif77"
%endif
    make check
%endif

%post -n %{libname} -p /sbin/ldconfig

%postun -n %{libname} -p /sbin/ldconfig

%files -n %{libname}
%doc COPYRIGHT README.md RELEASE_NOTES.md
%{_libdir}/libnetcdff.so.*

%files devel
%{_libdir}/pkgconfig/netcdf-fortran.pc
%{_libdir}/*.so
%{_bindir}/*
%{_includedir}/*
%{_mandir}/man3/*
%{_libdir}/libnetcdff.settings

%if %{with staticlibs}
%files devel-static
%{_libdir}/libnetcdff.a
%endif

%changelog
openSUSE Build Service is sponsored by