%bcond_with systemd
%bcond_with clang

## NOTE: Lots of files in various subdirectories have the same name (such as
## "LICENSE") so this short macro allows us to distinguish them by using their
## directory names (from the source tree) as prefixes for the files.
%global add_to_license_files() \
        mkdir -p _license_files ; \
        cp -p %1 _license_files/$(echo '%1' | sed -e 's!/!.!g')

Summary:        GTK+ Web content engine library
Name:           webkitgtk4
Version:        2.36.7
Release:        1%{?_dist_release}%{?with_systemd:.systemd}
Group:          system
Vendor:         Project Vine
Distribution:   Vine Linux

License:        LGPLv2
URL:            https://www.webkitgtk.org/
Source0:        https://webkitgtk.org/releases/webkitgtk-%{version}.tar.xz

%if %{with clang}
BuildRequires:  clang
BuildRequires:  lld
%endif
BuildRequires:  at-spi2-core-devel
BuildRequires:  bison
BuildRequires:  bubblewrap
BuildRequires:  cairo-devel
BuildRequires:  cmake
BuildRequires:  enchant2-devel
BuildRequires:  flex
BuildRequires:  fontconfig-devel
BuildRequires:  freetype-devel
BuildRequires:  geoclue2-devel
BuildRequires:  gettext
BuildRequires:  glib2-devel
BuildRequires:  gobject-introspection-devel
BuildRequires:  gperf
BuildRequires:  gstreamer1-devel
BuildRequires:  gstreamer1-plugins-base-devel
BuildRequires:  gtk2-devel
BuildRequires:  gtk3-devel
BuildRequires:  harfbuzz-icu-devel
BuildRequires:  lcms2-devel
BuildRequires:  libicu-devel
BuildRequires:  libjpeg-turbo-devel
BuildRequires:  libpng-devel
BuildRequires:  libseccomp-devel
BuildRequires:  libsecret-devel
BuildRequires:  libsoup-devel
BuildRequires:  libwebp-devel
BuildRequires:  libxslt-devel
BuildRequires:  libXt-devel
BuildRequires:  ninja
BuildRequires:  mesa-libGL-devel
BuildRequires:  pcre-devel
BuildRequires:  python3-devel
BuildRequires:  ruby
BuildRequires:  sqlite3-devel
BuildRequires:  libnotify-devel
BuildRequires:  hyphen-devel
BuildRequires:  woff2-devel
BuildRequires:  xdg-dbus-proxy
%if %{with systemd}
BuildRequires:  systemd-devel
%endif

Requires:       geoclue2

# for sandbox
Requires:       bubblewrap
Requires:       xdg-dbus-proxy

# Require the jsc subpackage
Requires:       %{name}-jsc = %{version}-%{release}

# Obsolete libwebkit2gtk from the webkitgtk3 package
Obsoletes:      libwebkit2gtk < 2.4.5-3
Provides:       libwebkit2gtk = %{version}-%{release}

# Filter out provides for private libraries
%global __provides_exclude_from ^%{_libdir}/webkit2gtk-4\\.0/.*\\.so$

%description
WebKitGTK+ is the port of the portable web rendering engine WebKit to the
GTK+ platform.

This package contains WebKitGTK+ for GTK+ 3.


%package        devel
Summary:        Development files for %{name}
Group:			programming
Requires:       %{name} = %{version}-%{release}
Requires:       %{name}-jsc-devel = %{version}-%{release}

%description    devel
The %{name}-devel package contains libraries, build data, and header
files for developing applications that use %{name}.


%package        jsc
Summary:        JavaScript engine from %{name}
Group:			system

%description    jsc
This package contains JavaScript engine from %{name}.


%package        jsc-devel
Summary:        Development files for JavaScript engine from %{name}
Group:			programming
Requires:       %{name}-jsc = %{version}-%{release}

%description    jsc-devel
The %{name}-jsc-devel package contains libraries, build data, and header
files for developing applications that use JavaScript engine from %{name}.


%debug_package


%prep
%setup -q -n webkitgtk-%{version}
%autopatch -p1

# Remove bundled libraries
rm -rf Source/ThirdParty/leveldb/
rm -rf Source/ThirdParty/gtest/
rm -rf Source/ThirdParty/qunit/


%build
%ifnarch x86_64
%define cflags_add --rtlib=compiler-rt
%endif

%if %{with clang}
export CC=clang
export CXX=clang++
export LD=ld.lld

%ifnarch x86_64
%define cflags_add --rtlib=compiler-rt
%endif

%global optflags  %(echo %{optflags} -DENABLE_YARR_JIT=0 | sed -e 's/-fno-schedule-insns2//') -fuse-ld=lld %{?cflags_add}
%global build_ldflags %{build_ldflags}
%else
%global optflags %(echo %{optflags} | sed 's/-g /-g1 /')
%endif

%cmake \
  -GNinja \
%if %{with clang}
  -DCOMPILER_IS_CLANG=ON \
  -DCMAKE_CXX_COMPILER=clang++ \
%endif
  -DPORT=GTK \
  -DCMAKE_BUILD_TYPE=Release \
  -DUSER_AGENT_BRANDING="Vine Linux" \
  -DENABLE_JIT=OFF \
  -DENABLE_LLINT_C_LOOP=ON \
  -DUSE_GSTREAMER_GL=OFF \
  -DUSE_OPENJPEG=OFF \
  -DENABLE_GTKDOC=OFF \
  -DUSE_WPE_RENDERER=OFF \
  -DENABLE_GAMEPAD=NO \
  -DUSE_SOUP2=ON \
%if %{with systemd}
  -DUSE_SYSTEMD=ON \
  -DENABLE_JOURNALD_LOG=ON \
%else
  -DUSE_SYSTEMD=OFF \
  -DENABLE_JOURNALD_LOG=OFF \
%endif

# Show the build time in the status
export NINJA_STATUS="[%f/%t][%e] "
%cmake_build


%install
%cmake_install

%find_lang WebKit2GTK-4.0

# Finally, copy over and rename various files for %%license inclusion
%add_to_license_files Source/JavaScriptCore/COPYING.LIB
%add_to_license_files Source/ThirdParty/ANGLE/LICENSE
%add_to_license_files Source/WebCore/LICENSE-APPLE
%add_to_license_files Source/WebCore/LICENSE-LGPL-2
%add_to_license_files Source/WebCore/LICENSE-LGPL-2.1
%add_to_license_files Source/WebInspectorUI/UserInterface/External/CodeMirror/LICENSE
%add_to_license_files Source/WebInspectorUI/UserInterface/External/Esprima/LICENSE
%add_to_license_files Source/WTF/icu/LICENSE
%add_to_license_files Source/WTF/wtf/dtoa/COPYING
%add_to_license_files Source/WTF/wtf/dtoa/LICENSE


%files -f WebKit2GTK-4.0.lang
%license _license_files/*
%{_libdir}/libwebkit2gtk-4.0.so.*
%{_libdir}/girepository-1.0/WebKit2-4.0.typelib
%{_libdir}/girepository-1.0/WebKit2WebExtension-4.0.typelib
%{_libdir}/webkit2gtk-4.0/
%{_libexecdir}/webkit2gtk-4.0/*
%exclude %{_libexecdir}/webkit2gtk-4.0/jsc
%{_bindir}/WebKitWebDriver

%files jsc
%license _license_files/*JavaScriptCore*
%dir %{_libexecdir}/webkit2gtk-4.0/
%{_libexecdir}/webkit2gtk-4.0/jsc
%{_libdir}/libjavascriptcoregtk-4.0.so.*
%{_libdir}/girepository-1.0/JavaScriptCore-4.0.typelib

%files devel
%{_includedir}/webkitgtk-4.0/*
%exclude %{_includedir}/webkitgtk-4.0/JavaScriptCore/
%{_libdir}/libwebkit2gtk-4.0.so
%{_libdir}/pkgconfig/webkit2gtk-4.0.pc
%{_libdir}/pkgconfig/webkit2gtk-web-extension-4.0.pc
%{_datadir}/gir-1.0/WebKit2-4.0.gir
%{_datadir}/gir-1.0/WebKit2WebExtension-4.0.gir

%files jsc-devel
%dir %{_includedir}/webkitgtk-4.0
%{_includedir}/webkitgtk-4.0/JavaScriptCore/
%{_libdir}/libjavascriptcoregtk-4.0.so
%{_libdir}/pkgconfig/javascriptcoregtk-4.0.pc
%{_datadir}/gir-1.0/JavaScriptCore-4.0.gir


%changelog
* Tue Aug 30 2022 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> - 2.36.7-1
- new upstream release.

* Thu Aug 11 2022 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> - 2.36.6-1
- new upstream release.

* Fri Dec 24 2021 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> - 2.34.3-1
- new upstream release.

* Fri Oct 29 2021 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> - 2.24.1-1
- new upstream release.
- built with icu-70.1.

* Sun Jul 11 2021 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> - 2.32.2-1
- new upstream release.
- dropped Patch1.

* Fri Apr 09 2021 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> - 2.32.0-2
- rebuilt with icu69.
- added Patch1 to build with icu69.

* Thu Apr 01 2021 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> - 2.32.0-1
- new upstream release.
- dropped ldconfig scriptlets.

* Tue Mar 02 2021 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> - 2.30.5-1
- new upstream release.

* Tue Dec 08 2020 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> - 2.30.3-1
- new upstream release.
- added systemd support (disabled as default).

* Tue Sep 08 2020 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> - 2.28.4-1
- new upstream release.

* Sun Jul 26 2020 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> - 2.28.3-1
- new upstream release.

* Thu Jul 02 2020 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> - 2.28.2-1
- new upstream release.

* Fri Apr 24 2020 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> - 2.28.1-1
- new upstream release.
- rebuilt with libicu67.

* Fri Mar 20 2020 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> - 2.28.0-2
- rebuilt with libicu66.

* Sun Mar 15 2020 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> - 2.28.0-1
- new upstream release.
- dropped Patch1: fixed in upstream.

* Sun Oct 13 2019 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> - 2.26.1-1
- new upstream release.
- built with icu-65.

* Fri Sep 20 2019 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> - 2.26.0-1
- new upstream release.
- switched build-system to ninja.

* Tue Aug 27 2019 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> - 2.24.3-1
- new upstream release.

* Thu Jan 03 2019 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> - 2.22.5-1
- new upstream release.

* Thu Jan 11 2018 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> - 2.18.5-1
- new upstream release.
- added subpackages webkitgtk4-jsc{,-devel}.

* Mon Jan 08 2018 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> - 2.18.4-1
- new upstream release.

* Wed Jun 29 2016 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> - 2.12.3-2
- rebuilt with new toolchain.

* Sun Jun 12 2016 Yoji TOYODA <bsyamato@sea.plala.or.jp> 2.12.3-1
- new upstream release
  (including security fix for CVE-2016-1856,1857)

* Sun May 08 2016 Yoji TOYODA <bsyamato@sea.plala.or.jp> 2.12.2-1
- new upstream release
- remove Patch0
- add BuildRequires: libnotify-devel, hyphen-devel

* Wed Dec 30 2015 Yoji TOYODA <bsyamato@sea.plala.or.jp> 2.8.5-3
- rebuild with gnutls-3.4.7

* Sat Oct 31 2015 Yoji TOYODA <bsyamato@sea.plala.or.jp> 2.8.5-2
- rebuild with icu-56.1

* Mon Aug 17 2015 Yoji TOYODA <bsyamato@sea.plala.or.jp> 2.8.5-1
- new upstream release

* Sun Jul 19 2015 Yoji TOYODA <bsyamato@sea.plala.or.jp> 2.8.4-1
- new upstream release

* Fri May 22 2015 Yoji TOYODA <bsyamato@sea.plala.or.jp> 2.8.3-1
- new upstream release

* Fri May 15 2015 Yoji TOYODA <bsyamato@sea.plala.or.jp> 2.8.2-1
- new upstream release

* Wed Apr 15 2015 Yoji TOYODA <bsyamato@sea.plala.or.jp> 2.8.1-1
- new upstream release

* Sun Mar 29 2015 Yoji TOYODA <bsyamato@sea.plala.or.jp> 2.8.0-1
- new upstream release
- update Patch0

* Sun Mar 01 2015 Yoji TOYODA <bsyamato@sea.plala.or.jp> 2.6.5-1
- new upstream release

* Sat Nov 29 2014 Yoji TOYODA <bsyamato@sea.plala.or.jp> 2.6.4-2
- add Group tag

* Mon Nov 24 2014 Yoji TOYODA <bsyamato@sea.plala.or.jp> 2.6.4-1
- new upstream release

* Tue Nov 18 2014 Yoji TOYODA <bsyamato@sea.plala.or.jp> 2.6.3-1
- new upstream release

* Sun Oct 26 2014 Yoji TOYODA <bsyamato@sea.plala.or.jp> 2.6.2-1
- initial build for Vine Linux


* Thu Sep 25 2014 Tomas Popela <tpopela@redhat.com> - 2.6.0-1
- Add the wrongly removed CLoop patch and remove the one that was upstreamed

* Wed Sep 24 2014 Kalev Lember <kalevlember@gmail.com> - 2.6.0-1
- Update to 2.6.0

* Mon Sep 22 2014 Tomas Popela <tpopela@redhat.com> - 2.5.90-1
- Update to 2.5.90

* Tue Aug 26 2014 Kalev Lember <kalevlember@gmail.com> - 2.5.3-7
- Obsolete libwebkit2gtk from the webkitgtk3 package

* Tue Aug 26 2014 David Tardon <dtardon@redhat.com> - 2.5.3-6
- rebuild for ICU 53.1

* Mon Aug 25 2014 Tomas Popela <tpopela@redhat.com> - 2.5.3-5
- Add support for secondary arches

* Fri Aug 22 2014 Michael Catanzaro <mcatanzaro@gnome.org> - 2.5.3-4
- Add webkitgtk-2.5.3-toggle-buttons.patch

* Thu Aug 21 2014 Kalev Lember <kalevlember@gmail.com> - 2.5.3-3
- More package review fixes (#1131284)
- Correct the license tag to read LGPLv2
- Filter out provides for private libraries

* Tue Aug 19 2014 Kalev Lember <kalevlember@gmail.com> - 2.5.3-2
- Remove bundled leveldb, gtest, qunit in %%prep (#1131284)

* Fri Aug 15 2014 Kalev Lember <kalevlember@gmail.com> - 2.5.3-1
- Update to 2.5.3

* Fri Aug 01 2014 Kalev Lember <kalevlember@gmail.com> - 2.5.1-1
- Initial Fedora packaging, based on the webkitgtk3 package