File postgis.spec of Package postgis

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

%define pgname @BUILD_FLAVOR@
%if "%{pgname}" == ""
%define         pgname postgresql
ExclusiveArch:  do_not_build
%if 0%{?suse_version} < 1550 && %{pgname} == "postgresql11"
ExclusiveArch:  do_not_build
%if 0%{?suse_version} < 1315 && %{pgname} == "postgresql10"
ExclusiveArch:  do_not_build
%if 0%{?suse_version} == 1500 && %{pgname} == "postgresql94"
ExclusiveArch:  do_not_build
%if 0%{?suse_version} == 1500 && %{pgname} == "postgresql95"
ExclusiveArch:  do_not_build
%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.5
%define         main_preversion 2.4
%define         previous_version 2.4.7
%define         liblwgeom_soversion 0.0.0
%define         liblwgeom_somajor 0
%define         libname liblwgeom-2_5-%{liblwgeom_somajor}
Name:           %{pgname}-%{sname}
Version:        2.5.2
Release:        0
Summary:        Geographic Information Systems Extensions to PostgreSQL
License:        GPL-2.0+
Group:          Productivity/Databases/Servers
BuildRequires:  %{pgname}-devel >= 9.4
BuildRequires:  %{pgname}-server >= 9.4
%if 0%{suse_version} >= 1550
BuildRequires:  %{pgname}-server-devel >= 9.4
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
BuildRequires:  libjson-c-devel

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
BuildRequires:  libjson-c-devel

%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

%setup -q -n %{sname}-%{version}
echo "pg_version is %{pg_version}"
#Prepare older version
tar zxf %{SOURCE2}

%configure \
   --with-raster \
   --with-topology \
   --with-gui \
   --with-sfcgal=%{_bindir}/sfcgal-config \
   --disable-rpath \
   --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 -d -m 755 %{buildroot}%{pg_bindir}

# 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}/
# Wrong right (missing x)
chmod +x %{buildroot}%{pg_bindir}/
sed -i 's/\r$//g' %{buildroot}%{pg_bindir}/

# 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
# 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 --disable-rpath
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
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
%{_datadir}/postgresql/install-alternatives %pg_version

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

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

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

%doc ChangeLog README.postgis COPYING MIGRATION NEWS extensions/address_standardizer/README.address_standardizer
%dir %{pg_share}/applications
%dir %{pg_share}/icons
%dir %{pg_share}/contrib

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

%files utils

%files -n %{libname}