%global sname pglogical
%global tag 2_4_3

%global pgmajorversion 13
%global llvm 0

%if 0%{?rhel} > 7
%if 0%{?postgresql_server_llvmjit}
  %global llvm 1
%endif
%endif
%if 0%{?postgresql_major}
%global pgmajorversion %postgresql_major
%endif

Summary:	Logical Replication extension for PostgreSQL
Name:		postgresql-%{sname}
Version:	2.4.3
Release:	1%{dist}
License:	PostgreSQL
URL:		https://github.com/2ndQuadrant/%{sname}
Source0:	https://github.com/2ndQuadrant/%{sname}/archive/REL%{tag}.tar.gz
Patch0:	    pglogical_dump.patch
Patch1:     alternative_regression_outputs.patch

BuildRequires:	postgresql-server-devel >= %{pgmajorversion}, postgresql-static >= %{pgmajorversion}
BuildRequires:  libxml2-devel zlib-devel libxslt-devel

%if %{pgmajorversion} > 13
%postgresql_module_requires
%else
Requires: postgresql-server
%endif


%description
pglogical is a logical replication system implemented entirely as a PostgreSQL
extension. Fully integrated, it requires no triggers or external programs.
This alternative to physical replication is a highly efficient method of
replicating data using a publish/subscribe model for selective replication.

he pglogical 2 extension provides logical streaming replication for
PostgreSQL, using a publish/subscribe model.

%if %llvm
%package llvmjit
Summary:	Just-in-time compilation support for pglogical
Requires:	%{name}%{?_isa} = %{version}-%{release}
# Packages come from Appstream:
BuildRequires:	llvm-devel >= 8.0.1 clang-devel >= 8.0.1


%description llvmjit
This packages provides JIT support for pglogical
%endif

%prep
%autosetup -p1 -n %{sname}-REL%{tag}


%build
%make_build

%install
%make_install


%clean
%{__rm} -rf %{buildroot}

%files
%defattr(-,root,root,-)

%license COPYRIGHT
%doc docs/README.md
%{_libdir}/pgsql/%{sname}.so
%{_datadir}/pgsql/extension/%{sname}-*.sql
%{_datadir}/pgsql/extension/%{sname}.control
%{_bindir}/%{sname}_create_subscriber
%{_libdir}/pgsql/%{sname}_output.so
%{_datadir}/pgsql/extension/%{sname}_origin--1.0.0.sql
%{_datadir}/pgsql/extension/%{sname}_origin.control

%if %llvm
%files llvmjit
   %{_libdir}/pgsql/bitcode/%{sname}_output/*.bc
   %{_libdir}/pgsql/bitcode/%{sname}*.bc
   %{_libdir}/pgsql/bitcode/%{sname}/compat%{pgmajorversion}/*.bc
   %{_libdir}/pgsql/bitcode/%{sname}/*.bc*
%endif

%changelog
* Tue May 30 2023 Raven <raven@sysadmins.ws> - 2.4.3-1
- initial build