File gdal.spec of Package gdal

# spec file for package gdal
# Copyright (c) 2018 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

# Soname should be bumped on API/ABI break
%define soversion 20
%define sourcename gdal
%bcond_with ecw_support
Name:           gdal
Version:        2.2.4
Release:        0
Summary:        GDAL/OGR - a translator library for raster and vector geospatial data formats
License:        MIT AND BSD-3-Clause AND SUSE-Public-Domain
Group:          Development/Libraries/C and C++
Patch0:         gdal-perl.patch
# Fix occasional parallel build failure
# Fix hard coded name of libproj library
# But is valid if libproj-devel is installed ?
Patch2:         gdal-libproj.patch
BuildRequires:  blas-devel
BuildRequires:  chrpath
BuildRequires:  curl-devel
BuildRequires:  dos2unix
BuildRequires:  doxygen >= 1.4.2
BuildRequires:  fdupes
BuildRequires:  gcc-c++
BuildRequires:  geos-devel >= 3
BuildRequires:  giflib-devel
BuildRequires:  lapack-devel
# No more please we have openjpeg2
# BuildRequires:  libjasper-devel
# Using jasper create build error on arm, powerpc, s390
BuildRequires:  libtool
BuildRequires:  mysql-devel
BuildRequires:  opencl-headers
BuildRequires:  perl-macros
BuildRequires:  pkgconfig
BuildRequires:  postgresql-devel
BuildRequires:  python-numpy-devel
BuildRequires:  python-setuptools
BuildRequires:  python3-numpy-devel
BuildRequires:  python3-setuptools
BuildRequires:  swig
BuildRequires:  unixODBC-devel
BuildRequires:  pkgconfig(expat) >= 1.95.0
BuildRequires:  pkgconfig(libgeotiff) >= 1.2.1
BuildRequires:  pkgconfig(libjpeg)
BuildRequires:  pkgconfig(liblzma)
BuildRequires:  pkgconfig(libopenjp2)
BuildRequires:  pkgconfig(libpng)
BuildRequires:  pkgconfig(libtiff-4) >= 3.6.0
BuildRequires:  pkgconfig(libxml-2.0)
BuildRequires:  pkgconfig(netcdf)
BuildRequires:  pkgconfig(poppler)
BuildRequires:  pkgconfig(proj)
BuildRequires:  pkgconfig(spatialite)
BuildRequires:  pkgconfig(sqlite3)
BuildRequires:  pkgconfig(xerces-c)
BuildRequires:  pkgconfig(zlib) >= 1.1.4
%if %{with ecw_support}
BuildRequires:  libecwj2-devel
%if 0%{?suse_version} >= 1310
BuildRequires:  autoconf
BuildRequires:  automake
BuildRequires:  hdf5-devel
BuildRequires:  pkgconfig(freexl)
BuildRequires:  pkgconfig(libwebp)
BuildRequires:  pkgconfig(libwebpdecoder)
BuildRequires:  pkgconfig(libwebpdemux)
BuildRequires:  pkgconfig(libwebpmux)
%if 0%{?suse_version} > 1320
BuildRequires:  opencl-headers
BuildRequires:  perl-ExtUtils-MakeMaker
BuildRequires:  pkgconfig(OpenCL)
BuildRequires:  pkgconfig(json)
BuildRequires:  pkgconfig(json-c)
BuildRequires:  pkgconfig(ocl-icd)
BuildRequires:  hdf-devel >= 4.0

GDAL is a translator library for raster geospatial data formats that
is released under an Open Source license. As a library, it presents a
single abstract data model to the calling application for all
supported formats. The related OGR library (which lives within the
GDAL source tree) provides a similar capability for simple features
vector data.

%package devel
Summary:        GDAL library header files
Group:          Development/Languages/C and C++
Requires:       lib%{name}%{soversion} = %{version}
Provides:       lib%{name}%{soversion}-devel
Provides:       lib%{name}-devel

%description devel
Development Libraries for the GDAL file format library

%package -n lib%{name}%{soversion}
Summary:        GDAL static libraries
Group:          System/Libraries

%description -n lib%{name}%{soversion}
GDAL and OGR are translator libraries for raster and vector geospatial data
formats. As a library, it presents a single abstract data model to the calling
application for all supported formats.

%package -n perl-%{name}
Summary:        Perl bindings for GDAL
Group:          Development/Languages/Perl
Requires:       %{name} = %{version}-%{release}
%if 0%{?suse_version} < 1140
Requires:       perl = %{perl_version}

%description -n perl-%{name}
Perl bindings for GDAL - Geo::GDAL, Geo::OGR and Geo::OSR modules.

%package -n python-%{name}
Summary:        GDAL Python module
Group:          Development/Languages/Python
Requires:       %{name} = %{version}-%{release}
Provides:       python2-%{name} = %{version}

%description -n python-%{name}
The GDAL python modules provide support to handle multiple GIS file formats.

%package -n python3-%{name}
Summary:        GDAL Python3 module
Group:          Development/Languages/Python
Requires:       %{name} = %{version}-%{release}

%description -n python3-%{name}
The GDAL python modules provide support to handle multiple GIS file formats.

%setup -q -n %{sourcename}-%{version}
%patch0 -p1
%patch1 -p1
%patch2 -p1

# Fix mandir
sed -i "s|^mandir=.*|mandir='\${prefix}/share/man'|" configure

# Fix wrong encoding EOL
for F in frmt_twms_srtm.xml frmt_wms_bluemarble_s3_tms.xml frmt_wms_virtualearth.xml frmt_twms_Clementine.xml;do
  find . -name "${F}" -exec dos2unix {} \;

#Fix wrong /usr/bin/env phyton
#Create the move to python3
find . -iname "*.py" -exec sed -i 's,^#!%{_bindir}/env python$,#!%{_bindir}/python3,' {} \;

# need to regenerate (old one does not accept CFLAGS)
autoreconf -fi

%configure \
        --prefix=%{_prefix}     \
        --includedir=%{_includedir}/gdal \
        --datadir=%{_datadir}/gdal \
        --with-threads          \
        --disable-static        \
        --with-geotiff          \
        --with-libtiff          \
        --with-rename-internal-libtiff-symbols=yes \
        --with-rename-internal-libgeotiff-symbols=yes \
        --with-libz             \
        --with-liblzma          \
        --with-cfitsio=no       \
        --with-netcdf           \
        --with-openjpeg         \
        --with-curl             \
        --with-pg               \
        --with-ogdi             \
        --without-pcraster      \
        --with-jpeg12=no        \
        --without-libgrass      \
        --without-grass         \
        --enable-shared         \
        --with-geos             \
        --with-expat            \
        --without-jasper        \
        --with-png              \
        --with-gif              \
        --with-jpeg             \
        --with-spatialite       \
        --with-poppler          \
        --with-python           \
        --with-perl             \
        --with-mysql            \
        --with-freexl           \
        --with-xerces=yes       \
        --with-xerces-lib="-lxerces-c" \
        --with-xerces-inc=%{_includedir}/xercesc \
%if %{with ecw_support}
        --with-ecw              \
        CFLAGS="$CFLAGS -pthread" \
%if 0%{?suse_version} > 1320
        --with-opencl           \
%if 0%{?suse_version} > 1310
        --without-hdf4          \
        --with-hdf5             \
        --with-webp             \
        --with-hdf4             \

# regenerate where needed
for M in perl python;
  make %{?_smp_mflags} -C swig/${M} veryclean
  make %{?_smp_mflags} -C swig/${M} generate

make %{?_smp_mflags} VERBOSE=1 all docs man

# Make Python 3 module
pushd swig/python
  python3 build


# Install Python 3 module
# Must be done first so executables are env python
pushd swig/python
  python3 install --prefix=%{_prefix} --root=%{buildroot}

make %{?_smp_mflags} install install-man \
  DESTDIR=%{buildroot} INST_MAN=%{_mandir}

# Not on buildroot : broke everything with python3
# If done got python3 needing python2 package heretic ..
# Futhermore duplicates are only existing in src html dir
%fdupes -s html
# Empty file
rm -f html/do-not-remove

# chrpath must be removed here
chmod 644 %{buildroot}%{perl_vendorarch}/auto/Geo/GDAL/Const/
chmod 644 %{buildroot}%{perl_vendorarch}/auto/Geo/GDAL/
chmod 644 %{buildroot}%{perl_vendorarch}/auto/Geo/GNM/
chmod 644 %{buildroot}%{perl_vendorarch}/auto/Geo/OGR/
chmod 644 %{buildroot}%{perl_vendorarch}/auto/Geo/OSR/

chrpath --delete %{buildroot}%{perl_vendorarch}/auto/Geo/GDAL/Const/
chrpath --delete %{buildroot}%{perl_vendorarch}/auto/Geo/GDAL/
chrpath --delete %{buildroot}%{perl_vendorarch}/auto/Geo/GNM/
chrpath --delete %{buildroot}%{perl_vendorarch}/auto/Geo/OGR/
chrpath --delete %{buildroot}%{perl_vendorarch}/auto/Geo/OSR/

%if 0%{?suse_version} <= 1315
# perl bs 0 length files cleanup
find %{buildroot}%{perl_vendorarch} -iname "*.bs" -exec rm -fv {} \;
# Those are deleted.

# do not ship these
rm -rf %{buildroot}%{_mandir}/man1/_*
rm -rf %{buildroot}%{_libdir}/
rm -rf %{buildroot}%{perl_archlib}/perllocal.pod
rm -rf %{buildroot}%{perl_vendorarch}/auto/Geo/*/.packlist
rm -rf %{buildroot}%{perl_vendorarch}/auto/Geo/GDAL/Const/.packlist
rm -rf %{buildroot}%{_bindir}/*.dox
# License doesn't go there
rm -f %{buildroot}%{_datadir}/gdal/LICENSE.TXT

# avoid PACKAGE redefines
sed -i 's,\(#define PACKAGE_.*\),/* \1 */,' %{buildroot}%{_includedir}/gdal/cpl_config.h

%post -n lib%{name}%{soversion} -p /sbin/ldconfig
%postun	-n lib%{name}%{soversion} -p /sbin/ldconfig

%files -n lib%{name}%{soversion}
%license LICENSE.TXT

%license LICENSE.TXT

%files devel
%license LICENSE.TXT
%doc html
%attr(755,root,root) %{_bindir}/gdal-config
%dir %{_includedir}/gdal

%files -n perl-%{name}
%license LICENSE.TXT
%dir %{perl_vendorarch}/Geo/GDAL
%dir %{perl_vendorarch}/Geo
%dir %{perl_vendorarch}/auto/Geo
%dir %{perl_vendorarch}/auto/Geo/GDAL
%attr(755,root,root) %{perl_vendorarch}/auto/Geo/GDAL/
%dir %{perl_vendorarch}/auto/Geo/GDAL/Const
%attr(755,root,root) %{perl_vendorarch}/auto/Geo/GDAL/Const/
%dir %{perl_vendorarch}/auto/Geo/GNM
%attr(755,root,root) %{perl_vendorarch}/auto/Geo/GNM/
%dir %{perl_vendorarch}/auto/Geo/OGR
%attr(755,root,root) %{perl_vendorarch}/auto/Geo/OGR/
%dir %{perl_vendorarch}/auto/Geo/OSR
%attr(755,root,root) %{perl_vendorarch}/auto/Geo/OSR/

%files -n python-%{name}
%license LICENSE.TXT

%files -n python3-%{name}
%license LICENSE.TXT