%define pkg_name    netcdf
%define pkg_version 4.3.2
%define pkg_release 2%{?_dist_release}

Summary: Libraries for the Unidata network Common Data Form
Name:    %{pkg_name}
Version: %{pkg_version}
Release: %{pkg_release}

License: NetCDF
Group:   System Environment/Libraries
URL:     http://www.unidata.ucar.edu/downloads/netcdf/index.jsp

Source0: ftp://ftp.unidata.ucar.edu/pub/netcdf/%{name}-%{version}.tar.gz

# Use pkgconfig in nc-config to avoid multi-lib issues
Patch0: netcdf-pkgconfig.patch
# Upstream patch to support hdf5 1.8.13 mpio change
Patch1: netcdf-mpio.patch

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

BuildRequires: chrpath
BuildRequires: curl-devel
BuildRequires: doxygen
BuildRequires: gawk
BuildRequires: hdf-devel
BuildRequires: hdf5-devel
BuildRequires: m4
BuildRequires: libjpeg-turbo-devel
BuildRequires: zlib-devel

Requires: hdf5


%description
NetCDF (network Common Data Form) is an interface for array-oriented
data access and a freely-distributed 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. The NetCDF software was developed at the Unidata
Program Center in Boulder, Colorado.

NetCDF data is:

   o Self-Describing: A NetCDF file includes information about the
     data it contains.

   o 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.

   o Direct-access:  A small subset of a large dataset may be accessed
     efficiently, without first reading through all the preceding
     data.

   o 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.

   o Sharable:  One writer and multiple readers may simultaneously
     access the same NetCDF file.


%package devel
Summary:  Development files for netcdf
Group:    Development/Libraries
Requires: %{name} = %{version}-%{release}

%description devel
This package contains the netCDF header files, libs, and man pages.


%package static
Summary:  Static libs for netcdf
Group:    Development/Libraries
Requires: %{name} = %{version}-%{release}

%description static
This package contains the netCDF C static libs.


%prep
%setup -q -n %{name}-%{version}
%patch0 -p1 -b .pkgconfig
%patch1 -p1 -b .mpio

%build
export LDFLAGS="-L%{_libdir}/hdf"
export CPPFLAGS=-I%{_includedir}/hdf
export LIBS="-ldf -ljpeg"
%configure \
    --enable-shared \
    --enable-netcdf-4 \
    --enable-dap \
    --enable-extra-example-tests \
    --enable-hdf4 \
    --disable-dap-remote-tests

%{__make} %{?_smp_mflags}


%install
%{__rm} -rf ${RPM_BUILD_ROOT}
%{__make} install DESTDIR=${RPM_BUILD_ROOT}

chrpath --delete ${RPM_BUILD_ROOT}%{_bindir}/nc{copy,dump,gen,gen3}
%{__rm} -f ${RPM_BUILD_ROOT}%{_libdir}/*.la
%{__rm} -f ${RPM_BUILD_ROOT}%{_infodir}/dir

%check
%{__make} check

%clean
%{__rm} -rf ${RPM_BUILD_ROOT}

%post -p %{_syssbindir}/ldconfig

%postun -p %{_syssbindir}/ldconfig


%files
%defattr(-,root,root,-)
%doc COPYRIGHT README.md RELEASE_NOTES.md
%{_bindir}/*
%{_libdir}/*.so.*
%{_mandir}/man1/*

%files devel
%defattr(-,root,root,-)
%{_includedir}/*
%{_libdir}/*.so
%{_libdir}/pkgconfig/*
%{_mandir}/man3/*

%files static
%{_libdir}/*.a


%changelog
* Sun Jul 01 2018 Toshiaki Ara <ara_t@384.jp> 4.3.2-2
- rebuild under hdf5-1.8.20

* Sun Jan 25 2015 Ryoichi INAGAKI <ryo1@toki.waseda.jp> 4.3.2-1
- updated to 4.3.2
- built with hdf and hdf5

* Sun May 12 2013 Yoji TOYODA <bsyamato@sea.plala.or.jp> 4.2.1.1-2
- add configure options (--enable-netcdf-4, --enable-dap)
- add BuildRequires: curl-devel

* Sun Oct 28 2012 Yoji TOYODA <bsyamato@sea.plala.or.jp> 4.2.1.1-1
- update to 4.2.1.1
- add BuildRequires: zlib-devel, hdf5-devel

* Mon Jan 11 2010 Yoji TOYODA <bsyamato@sea.plala.or.jp> 4.0.1-1
- new upstream release

* Sun Oct  5 2008 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 3.6.0.p1-1
- new versioning policy

* Sat Aug 25 2007 Shu KONNO <owa@bg.wakwak.com> 3.6.0.p1-0vl2
- changed BuildRequires gcc-g77 to gcc-gfortran

* Fri Oct 21 2005 Daisuke SUZUKI <daisuke@linux.or.jp> 3.6.0.p1-0vl1
- initial build for Vine Linux
