File postgis.spec of Package postgis

#
# spec file for package postgis
#
# 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 http://bugs.opensuse.org/
#


%define pgname @BUILD_FLAVOR@
%if "%{pgname}" == ""
%define         pgname postgresql
ExclusiveArch:  do_not_build
%endif
%if 0%{?suse_version} < 1500 && %{pgname} == "postgresql10"
ExclusiveArch:  do_not_build
%endif
%if 0%{?suse_version} == 1500 && %{pgname} == "postgresql93"
ExclusiveArch:  do_not_build
%endif
%if 0%{?suse_version} == 1500 && %{pgname} == "postgresql94"
ExclusiveArch:  do_not_build
%endif
%if 0%{?suse_version} == 1500 && %{pgname} == "postgresql95"
ExclusiveArch:  do_not_build
%endif
%define         sname postgis
%define         pg_bindir %(pg_config --bindir)
%define         pg_libdir %(pg_config --pkglibdir)
%define         pg_share %(pg_config --sharedir)
# double \ as they are escaped in %%() call
%define         pg_version %(pg_config --version | sed -e 's/.*[[:space:]]//' -e 's/\\.[0-9]*$//' -e 's/\\.//')
%define         main_version 2.4
%define         main_preversion 2.3
%define         previous_version 2.3.7
%define         liblwgeom_soversion 0.0.0
%define         liblwgeom_somajor 0
%define         libname liblwgeom-2_4-%{liblwgeom_somajor}
Name:           %{pgname}-%{sname}
Version:        2.4.4
Release:        0
Summary:        Geographic Information Systems Extensions to PostgreSQL
License:        GPL-2.0+
Group:          Productivity/Databases/Servers
URL:            http://www.postgis.org/
# Update once osgeo has fixed https usage on their servers
Source:         http://download.osgeo.org/postgis/source/%{sname}-%{version}.tar.gz
Source2:        http://download.osgeo.org/postgis/source/%{sname}-%{previous_version}.tar.gz
# Upstream Fix for json-c 0.13 from https://github.com/postgis/postgis/commit/ccb7b1.patch
# But modified to remove NEWS patching (only valid for 2.5.0)
# We keep it for patching 2.3
Patch0:         ccb7b1.patch
BuildRequires:  %{pgname}-devel
BuildRequires:  %{pgname}-server
#BuildRequires:  cgal-devel
BuildRequires:  fdupes
BuildRequires:  flex
BuildRequires:  gdal-devel >= 1.9.0
BuildRequires:  gtk2-devel
BuildRequires:  libgeos-devel >= 3.5.0
BuildRequires:  libproj-devel >= 4.6.0
BuildRequires:  libxml2-devel
#BuildRequires:  sfcgal-devel
BuildRequires:  update-alternatives
%requires_eq    %{pgname}-server
Requires(post): update-alternatives
Requires(postun): update-alternatives
Conflicts:      postgis2
Provides:       postgis
# json-c the name has changed with version 0.11
# need also a patch to include json-c/json.h
%if 0%{?suse_version} < 1320
BuildRequires:  libjson-devel
%else
BuildRequires:  libjson-c-devel
%endif

%description
PostGIS is a spatial database extender for PostgreSQL object-relational
database. It adds support for geographic objects allowing location queries
to be run in SQL.

%package devel
Summary:        Development files for %{name}
Group:          Development/Libraries/C and C++
Requires:       %{libname} = %{version}
Requires:       %{name} = %{version}
Requires:       %{pgname}-devel
Requires:       update-alternatives
Provides:       postgis-devel
%if 0%{?suse_version} < 1320
BuildRequires:  libjson-devel
%else
BuildRequires:  libjson-c-devel
%endif

%description devel
This package holds the development files for postgis

%package utils
Summary:        The utils for PostGIS
Group:          Productivity/Databases/Tools
Requires:       %{name} = %{version}
Requires:       perl-DBD-Pg
Provides:       postgis-utils

%description utils
The postgis-utils package provides utilities for PostGIS.

%package -n %{libname}
Summary:        LWGEOM geometry shared library
Group:          System/Libraries

%description -n %{libname}
PostGIS "Lightweight Geometry" library

%prep
%setup -q -n %{sname}-%{version}
echo "pg_version is %{pg_version}"
#Prepare older version
tar zxf %{SOURCE2}
pushd %{sname}-%{previous_version}
echo "$(pwd)"
%patch0 -p1
popd


%build
%configure \
   --with-raster \
   --with-topology \
   --with-gui \
   --with-json \

# UPSTREAM Recommandation
# Don't NEVER try to change that or get build failed
# You can still contribute upstream to get a cmake or working multithread
make V=1 -j1 shlib="%{sname}-%{main_version}.so" soname="%{sname}-%{main_version}.so"


%install
install -d -m 755 %{buildroot}%{pg_bindir}
%make_install

# install manpages format them as our pg packages
install -d -m 755 %{buildroot}%{_mandir}/man1
install -m 644 doc/man/pgsql2shp.1 %{buildroot}%{_mandir}/man1/pgsql2shp.1pg%{pg_version}
install -m 644 doc/man/shp2pgsql.1 %{buildroot}%{_mandir}/man1/shp2pgsql.1pg%{pg_version}
install -m 755 utils/*.pl %{buildroot}%{pg_bindir}
#
# Wrong location (this is new on 2.2.x) automatically installed we already place it to pgbindir
rm %{buildroot}%{pg_share}/contrib/%{sname}-%{main_version}/postgis_restore.pl
# Wrong right (missing x)
chmod +x %{buildroot}%{pg_bindir}/postgis_restore.pl
sed -i 's/\r$//g' %{buildroot}%{pg_bindir}/postgis_proc_set_search_path.pl

# remove .a and .la files
rm -f %{buildroot}/%{_libdir}/*.la
rm -f %{buildroot}/%{_libdir}/*.a

# Temporary fix we re-add the readme with doc macro
rm -fr %{buildroot}%{_docdir}/%{pgname}

%fdupes %{buildroot}/%{pg_share}

echo " --- Building Previous Version --- "
# Credits hack to http://git.pgrpms.org/browser/rpm/redhat/9.3/postgis2/F-20/postgis2.spec
# This is the way upstream and all yum packages are builded.
# PostGIS 2x breaks compatibility with previous version, and we need to ship the preversion
# so files along with new one in packages, so that we can upgrade:
# with "ALTER EXTENSION postgis UPDATE TO '%{version}';"
# It also benefit to all admins that can't immediately upgrade their extensions to
# backup and restore old dumps.
# Notice we don't ship anymore the older (previous-1) version.

pushd %{sname}-%{previous_version}
%configure --with-raster --without-topology --without-gui
make V=1 -j1 shlib="%{sname}-%{main_preversion}.so" soname="%{sname}-%{main_preversion}.so"

install -m 644 ./postgis/%{sname}-%{main_preversion}.so %{buildroot}%{pg_libdir}/%{sname}-%{main_preversion}.so
install -m 644 ./raster/rt_pg/%{sname}-%{main_preversion}.so %{buildroot}%{pg_libdir}/rt%{sname}-%{main_preversion}.so
popd
echo " --- End Building Previous Version --- "

# One word about alternatives
# the actual way postgresql is doing its magics under openSUSE is that it pick also our binaries
# in its group. so we can't make it more proper than it is.
# We are missing man, desktop, icons.
# install-alternatives is only available in TW or post 42.3
%if 0%{?suse_version} >= 1500
%postun
%{_datadir}/postgresql/install-alternatives %pg_version
%endif

%if 0%{?suse_version} >= 1500
%post
%{_datadir}/postgresql/install-alternatives %pg_version
%endif

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

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

%files
%defattr(-,root,root)
%doc ChangeLog README.postgis COPYING MIGRATION NEWS extensions/address_standardizer/README.address_standardizer
%{pg_libdir}
%{_mandir}/man1/pgsql2shp.1pg%{pg_version}.gz
%{_mandir}/man1/shp2pgsql.1pg%{pg_version}.gz
%{pg_bindir}/pgsql2shp
%{pg_bindir}/raster2pgsql
%{pg_bindir}/shp2pgsql
%{pg_bindir}/shp2pgsql-gui
%dir %{pg_share}/applications
%{pg_share}/applications/shp2pgsql-gui.desktop
%dir %{pg_share}/icons
%{pg_share}/icons/*
%dir %{pg_share}/contrib
%{pg_share}/contrib/postgis*
%{pg_share}/extension/postgis*
%{pg_share}/extension/address_standardizer*

%files devel
%defattr(-,root,root)
%attr(0644,root,root) %{_includedir}/liblwgeom.h
%attr(0644,root,root) %{_includedir}/liblwgeom_topo.h
%{_libdir}/liblwgeom.so

%files utils
%defattr(755,root,root)
%{pg_bindir}/create_undef.pl
%{pg_bindir}/postgis_proc_upgrade.pl
%{pg_bindir}/postgis_restore.pl
%{pg_bindir}/profile_intersects.pl
%{pg_bindir}/read_scripts_version.pl
%{pg_bindir}/create_unpackaged.pl
%{pg_bindir}/create_spatial_ref_sys_config_dump.pl
%{pg_bindir}/postgis_proc_set_search_path.pl
%{pg_bindir}/svn_repo_revision.pl
%{pg_bindir}/test_estimation.pl
%{pg_bindir}/test_joinestimation.pl
%{pg_bindir}/test_geography_estimation.pl
%{pg_bindir}/test_geography_joinestimation.pl

%files -n %{libname}
%defattr(755,root,root)
%{_libdir}/liblwgeom-%{main_version}.so.%{liblwgeom_somajor}
%{_libdir}/liblwgeom-%{main_version}.so.%{liblwgeom_soversion}

%changelog
openSUSE Build Service is sponsored by