File postgis.spec of Package postgis

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

%define pgname @BUILD_FLAVOR@
%define         sname postgis
%define         pg_bindir %(pg_config --bindir)
%define         pg_libdir %(pg_config --pkglibdir)
%define         pg_share %(pg_config --sharedir)
%if 0%{?is_opensuse} && 0%{?suse_version} >= 1500 && ("%{pgname}" == "postgresql11" || "%{pgname}" == "postgresql12" || "%{pgname}" == "postgresql13")
%bcond_without  llvm
%else
%bcond_with     llvm
%endif
# 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 3.1
%if "%{pgname}" == ""
Name:           %{sname}
ExclusiveArch:  do_not_build
%else
Name:           %{pgname}-%{sname}
%endif
# Build for Leap 15.2 but not for missing postgresql13
%if (0%{?is_opensuse} && 0%{?sle_version} == 150200) && ("%{pgname}" == "postgresql13")
ExclusiveArch:  do_not_build
%endif
Version:        3.1.4
Release:        0
Summary:        Geographic Information Systems Extensions to PostgreSQL
License:        GPL-2.0-or-later
Group:          Productivity/Databases/Servers
URL:            https://postgis.net/
Source:         https://download.osgeo.org/postgis/source/%{sname}-%{version}.tar.gz
Patch0:         patch-tests-results.patch
BuildRequires:  %{pgname}-devel >= 10
%if "%{pgname}" == "postgresql11" || "%{pgname}" == "postgresql12" || "%{pgname}" == "postgresql13"
BuildRequires:  %{pgname}-server-devel >= 11
%endif
BuildRequires:  %{pgname}-server >= 10
%if %{with llvm}
BuildRequires:  clang-devel
BuildRequires:  llvm-devel
BuildRequires:  %{pgname}-llvmjit
%endif
BuildRequires:  cgal-devel
BuildRequires:  cunit-devel
BuildRequires:  fdupes
BuildRequires:  flex
BuildRequires:  gcc-c++
%if 0%{?sle_version} >= 150000 && 0%{?sle_version} <= 150100 && 0%{?is_opensuse}
BuildRequires:  gdal-devel
%else
BuildRequires:  gdal-devel >= 3.0
%endif
BuildRequires:  gtk2-devel
BuildRequires:  libprotobuf-c-devel
BuildRequires:  libgeos-devel >= 3.7.0
BuildRequires:  libjson-c-devel
BuildRequires:  libproj-devel >= 6.0.0
# proj.db is required for ST_ functions and tests boo#1188129
BuildRequires:  proj
BuildRequires:  libxml2-devel
BuildRequires:  docbook-xsl-stylesheets
BuildRequires:  libxml2-tools
# building doc but would add 350 texlive packages
# BuildRequires:  dblatex
# BuildRequires:  ImageMagick
BuildRequires:  protobuf-c >= 1.1.0
BuildRequires:  sfcgal-devel > 1.3.1
BuildRequires:  update-alternatives
%requires_eq    %{pgname}-server
# proj.db is required for ST_ functions and tests boo#1188129
Requires:       proj
Requires(post): update-alternatives
Requires(postun): update-alternatives
Conflicts:      postgis2
Provides:       postgis

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

%if %{with llvm}
%package llvmjit
Summary:        Just-in-time compilation support for PostgreSQL %{sname} extension
Group:          Productivity/Databases/Servers
Requires:       %{pgname}-%{sname} = %{version}-%{release}
Requires:       %{pgname}-llvmjit
Supplements:    packageand(%{pgname}-llvmjit:%{name})

%description llvmjit
This package contains support for just-in-time compiling parts of
PostgreSQL queries. Using LLVM it compiles e.g. expressions and tuple
deforming into native code, with the goal of accelerating analytics
queries.
%endif

%prep
%setup -q -n %{sname}-%{version}
echo "pg_version is %{pg_version}"
%patch0 -p1

%build
%configure \
    --with-protobuf \
    --with-raster \
    --with-topology \
    --with-gui \
    --with-json \
    --with-sfcgal=%{_bindir}/sfcgal-config \
    --disable-rpath \
    --with-wagyu \
    --disable-gtktest \
    --with-interrupt-tests \
    --with-raster-dblwarning

%make_build 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}
# fix shebang and install utils
sed -i 's,^#!/usr/bin/env perl,#!/usr/bin/perl,g' utils/*.pl regress/*.pl
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
# 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}

# To avoid shm trouble we just skip tests for 9.6
%if "%{pgname}" != "postgresql96"
%check
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8
export PGDATA=/home/abuild/postgis_tests/data
export PGHOST=/tmp
export PGPORT=5454
mkdir -p "${PGDATA}"
initdb --pgdata=${PGDATA} --auth=peer --auth-host=scram-sha-256 --auth-local=peer --encoding=UTF-8 --locale=en_US.UTF-8 --lc-message=en_US.UTF-8
pg_ctl -D "${PGDATA}" -l logfile -o "-p ${PGPORT} -k ${PGHOST} -B 1024" start
psql -d postgres -c "\dx"
# Don't fail test yet, we have a different result for mvt between Leap and TW
make check || :
pg_ctl -D "${PGDATA}" --mode="fast" stop
%endif

%postun
%{_datadir}/postgresql/install-alternatives %pg_version

%post
%{_datadir}/postgresql/install-alternatives %pg_version

%postun utils
%{_datadir}/postgresql/install-alternatives %pg_version

%post utils
%{_datadir}/postgresql/install-alternatives %pg_version

%files
%defattr(-,root,root)
%license COPYING
%doc ChangeLog README.postgis MIGRATION NEWS extensions/address_standardizer/README.address_standardizer
%{pg_libdir}
%exclude %{pg_libdir}/bitcode/*
%{_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*

%if %{with llvm}
%files llvmjit
%{pg_libdir}/bitcode/*
%endif

%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}/repo_revision.pl
%{pg_bindir}/create_extension_unpackage.pl
%{pg_bindir}/create_unpackaged.pl
%{pg_bindir}/create_spatial_ref_sys_config_dump.pl
%{pg_bindir}/postgis_proc_upgrade.pl
%{pg_bindir}/test_estimation.pl
%{pg_bindir}/test_joinestimation.pl
%{pg_bindir}/test_geography_estimation.pl
%{pg_bindir}/test_geography_joinestimation.pl

%changelog
openSUSE Build Service is sponsored by