# file: scintilla.spec #

Source1000:     vdb.lua
%include        %{S:1000}

%bcond_without gtk2
%bcond_without gtk3

%{lua:
    if expand( "%{with gtk2}%{with gtk3}" ) == "00" then
        die( "Neither gtk2 nor gtk3 is enabled." )
    end
}

%global major   3
%global minor   21
%global patch   1
%global rel     0.vdb.5

# In Fedora, installed ldconfig is located in /usr/sbin/ directory. However, in glibc rpm package
# it resides in /sbin/ directory. dnf fails to install a package which requires /usr/sbin/ldconfig.
%global __ldconfig /sbin/ldconfig

#global _default_patch_fuzz 0

Name:           scintilla
Version:        %{major}.%{minor}.%{patch}
Release:        %{rel}%{?dist}
Summary:        Free source code editing component
License:        MIT
    # Scintilla license is HPND, but <https://fedoraproject.org/wiki/Licensing:Main> prescribes
    # using "MIT" license identifier.
URL:            http://www.scintilla.org
Source0:        https://sourceforge.net/projects/scintilla/files/%{name}/%{major}.%{minor}.%{patch}/%{name}%{major}%{minor}%{patch}.tgz
Source1001:     scintilla-3.21.1-LexJulia.cxx
# Stick to current column when moving the caret up and down:
Patch1001:      scintilla-3.21.0-wobble-free.vdb.patch
# Use system Lua instead of bundled one:
Patch1002:      scintilla-3.21.0-use-system-lua.vdb.patch
Patch1003:      scintilla-3.21.1-gcc11.patch
Patch1004:      scintilla-3.21.1-julia.vdb.patch

%if %{with gtk2}
Requires:       %{name}-gtk2%{?_isa} = %{version}-%{release}
%endif
%if %{with gtk3}
Requires:       %{name}-gtk3%{?_isa} = %{version}-%{release}
%endif

BuildRequires:  coreutils
BuildRequires:  make
BuildRequires:  gcc
BuildRequires:  gcc-c++ >= 4.7
    # -std=c++11 appeared in gcc 4.7.
BuildRequires:  pkgconfig(lua)
%if %{with gtk2}
BuildRequires:  pkgconfig(gtk+-2.0)
%endif
%if %{with gtk3}
BuildRequires:  pkgconfig(gtk+-3.0)
%endif
BuildRequires:  python3

%package doc
Summary:        Scintilla documentation

%if %{with gtk2}

%package gtk2
Summary:        Scintilla built with GTK+ v2
Requires:       %{__ldconfig}

%package gtk2-devel
Summary:        Development files for Scintilla built with GTK+ v2
Requires:       %{name}-gtk2%{?_isa} = %{version}-%{release}
Requires:       pkgconfig

%endif

%if %{with gtk3}

%package gtk3
Summary:        Scintilla built with GTK+ v3
Requires:       %{__ldconfig}

%package gtk3-devel
Summary:        Development files for Scintilla built with GTK+ v3
Requires:       %{name}-gtk3%{?_isa} = %{version}-%{release}
Requires:       pkgconfig

%endif

%description
Scintilla includes features especially useful when editing and debugging source
code. These include support for syntax styling, error indicators, code
completion and call tips. The selection margin can contain markers like those
used in debuggers to indicate breakpoints and the current line. Styling choices
are more open than with many editors, allowing the use of proportional fonts,
bold and italics, multiple foreground and background colors and multiple fonts.

This is a meta-package, which contains no files but brings Scintilla shared
libraries built with GTK2 and GTK3.

%description doc
Scintilla is free source code editing component.

This package includes Scintilla documentation. Note that target audience is
developers who use Scintilla in their programs, this is *not* helpful for
end users.

%if %{with gtk2}

%description gtk2
Scintilla is free source code editing component.

This package includes Scintilla shared library, built with GTK+ v2.

%description gtk2-devel
Scintilla is free source code editing component.

This package includes Scintilla development files.

%endif

%if %{with gtk3}

%description gtk3
Scintilla is free source code editing component.

This package includes Scintilla shared library, built with GTK+ v3.

%description gtk3-devel
Scintilla is free source code editing component.

This package includes Scintilla development files.

%endif

%prep
%setup -q -n %{name}%{major}%{minor}%{patch}
%{__rm} -rf lua     # Remove bundled Lua.
%patch1001
%patch1002
%patch1003
%patch1004
cp %{S:1001} lexers/LexJulia.cxx
( cd scripts && %{__python3} ./HFacer.py )
( cd gtk     && %{__python3} ./DepGen.py )

%build
lua_cflags="$( pkg-config --cflags lua )"
lua_libs="$( pkg-config --libs lua )"
for gtk in %{?with_gtk2: gtk2} %{?with_gtk3: gtk3}; do
    %{__cp} -r gtk $gtk
    %{make_build} \
        -C $gtk \
        ${gtk^^*}=1 \
        LPEG_LEXER=1 \
        LUA_OBJS= \
        CFLAGS="%{optflags} $lua_cflags" \
        CXXFLAGS="-std=c++11 %{optflags} $lua_cflags" \
        COMPLIB=../bin/lib%{name}-$gtk.so.%{major}.%{minor}.%{patch} \
        AR="\$(CXX)" \
        ARFLAGS="-shared -Wl,-soname=lib%{name}-$gtk.so.%{major} $lua_libs -o " \
        RANLIB=@:
    # Generate pc file:
    {
        echo "libdir=%{_libdir}"
        echo "includedir=%{_includedir}"
        echo ""
        echo "Name: scintilla-$gtk"
        echo "Description: Scintilla editing component built with GTK+ v${gtk#gtk}"
        echo "URL: %{url}"
        echo "Version: %{version}"
        echo "Cflags: -I\${includedir}/%{name}"
        echo "Libs: -L\${libdir} -lscintilla-$gtk"
        echo "Requires: gtk+-${gtk#gtk}.0 lua"
    } > %{name}-$gtk.pc.tmp
    %{__mv} %{name}-$gtk.pc.tmp %{name}-$gtk.pc
done

%check

%install
# Scintilla's makefile does not have install target.
%_install_D -p -m 644 -t "%{buildroot}%{_licensedir}/%{name}" License.txt
%_install_D -p -m 644 -t "%{buildroot}%{_pkgdocdir}"          doc/*.{html,png}
%_install_D -p -m 755 -t "%{buildroot}%{_libdir}"             bin/lib%{name}-gtk[23].so.%{major}.%{minor}.%{patch}
%_install_D -p -m 644 -t "%{buildroot}%{_includedir}/%{name}" include/*.h
%_install_D -p -m 644 -t "%{buildroot}%{_libdir}/pkgconfig"   %{name}-gtk[23].pc
for gtk in %{?with_gtk2: gtk2} %{?with_gtk3: gtk3}; do
    %{__ln_s} lib%{name}-$gtk.so.%{major}.%{minor}.%{patch} %{buildroot}%{_libdir}/lib%{name}-$gtk.so.%{major}
    %{__ln_s} lib%{name}-$gtk.so.%{major}                   %{buildroot}%{_libdir}/lib%{name}-$gtk.so
done

%clean

%files
%defattr( 644, root, root, 755 )

%files doc
%defattr( 644, root, root, 755 )
%doc %dir           %{_pkgdocdir}
%doc                %{_pkgdocdir}/*

%if %{with gtk2}

%files gtk2
%defattr( 644, root, root, 755 )
%attr( 755, -, - )  %{_libdir}/lib%{name}-gtk2.so.%{major}.%{minor}.%{patch}
                    %{_libdir}/lib%{name}-gtk2.so.%{major}
%dir                %{_licensedir}/%{name}
                    %{_licensedir}/%{name}/License.txt

%files gtk2-devel
%defattr( 644, root, root, 755 )
                    %{_libdir}/lib%{name}-gtk2.so
%dir                %{_includedir}/%{name}
                    %{_includedir}/%{name}/*
                    %{_libdir}/pkgconfig/%{name}-gtk2.pc

%post gtk2
%{__ldconfig}

%postun gtk2
%{__ldconfig}

%endif

%if %{with gtk3}

%files gtk3
%defattr( 644, root, root, 755 )
%attr( 755, -, - )  %{_libdir}/lib%{name}-gtk3.so.%{major}.%{minor}.%{patch}
                    %{_libdir}/lib%{name}-gtk3.so.%{major}
%dir                %{_licensedir}/%{name}
                    %{_licensedir}/%{name}/License.txt

%files gtk3-devel
%defattr( 644, root, root, 755 )
                    %{_libdir}/lib%{name}-gtk3.so
%dir                %{_includedir}/%{name}
                    %{_includedir}/%{name}/*
                    %{_libdir}/pkgconfig/%{name}-gtk3.pc

%post gtk3
%{__ldconfig}

%postun gtk3
%{__ldconfig}

%endif

%changelog
* Sat Apr 29 2023 Van de Bugger - 3.21.1-0.vdb.5
- Spec does guess gtk2 and gtk3 presence but relies on the `--witout gtk2` and `--without gtk3`
  options.
- F38 rebuild.

* Thu Nov 24 2022 Van de Bugger - 3.21.1-0.vdb.4
- F37 rebuild.

* Wed Jun 15 2022 Van de Bugger - 3.21.1-0.vdb.3
- Julia lexer ported from Geany.
- F36 rebuild.

* Mon Aug 09 2021 Van de Bugger - 3.21.1-0.vdb.2
- Patch for GCC 11.0.
- F34 enabled.

* Wed Dec 02 2020 Van de Bugger - 3.21.1-0.vdb.1
- Scintilla 3.21.1.

* Wed Dec 02 2020 Van de Bugger - 3.21.0-0.vdb.1
- Scintilla 3.21.0.

* Mon Nov 30 2020 Van de Bugger - 3.20.0-0.vdb.1
- Scintilla 3.20.0.
- Patches updated to apply smoothly.
- Not sure Lpeg lexer works because Geany doesn't use it.

* Tue Oct 27 2020 Van de Bugger - 3.11.2-0.vdb.2
- Only one variant of gtk2 and gtk3 is built by default.

* Mon Oct 19 2020 Van de Bugger - 3.11.2-0.vdb.1
- Scintilla 3.11.2.

* Mon Oct 19 2020 Van de Bugger - 3.11.1-0.vdb.1
- Scintilla 3.11.1.

* Mon Oct 19 2020 Van de Bugger - 3.11.0-0.vdb.1
- Scintilla 3.11.0.

* Sun Oct 18 2020 Van de Bugger - 3.10.6-0.vdb.3
- Rebuild for F33.

* Thu Jun 04 2020 Van de Bugger - 3.10.6-0.vdb.2
- Rebuild for F32.

* Fri Nov 15 2019 Van de Bugger - 3.10.6-0.vdb.1
- Scintilla 3.10.6.
- wobble-free-patch updated to meet 3.10.6.
- gcc=c++ >= 4.7 required (because of -std=c++11).
- .pc file slightly fixed to use `Requires:` only once.

* Mon Apr 08 2019 Van de Bugger - 3.10.0-0.1.vdb
- Lua lexers enabled; not sure they work, though.
- Lua debundled.
- Release number changed in incompatible way, sorry.
- vdb.lua updated.
- _pkgdocdir defined in vdb.lua if it is not defined yet, it helps to build
  scintilla on OpenSuse.
- _install_D macro used. It does not help much because EPEL has problem with
  license macro anyway.

* Thu Jan 17 2019 Van de Bugger - 3.10.0-2.vdb
- New vdb.lua used.

* Fri Jan 11 2019 Van de Bugger - 3.10.0-1.vdb
- Scintilla v3.10.0.

* Fri Jan 11 2019 Van de Bugger - 3.8.0-1.vdb
- Scintilla v3.8.0.

* Mon Dec  3 2018 Van de Bugger - 3.7.6-4.vdb
- Typo in comment fixed.
- vdb.lua updated.
- Built for F29.

* Sat May  5 2018 Van de Bugger - 3.7.6-3.vdb
- pc file: Bad -I option dropped; added dependency on gtk.
- F28 rebuilt.

* Wed Feb 21 2018 Van de Bugger - 3.7.6-2.vdb
- scintilla-3.7.6-wobble-free.vdb.patch applied. If virtual space is enabled,
  vertical caret movement keeps the caret in the same column, if possible.

* Sun Jan 28 2018 Van de Bugger - 3.7.6-1.vdb
- Version v3.7.6.
- Group tag dropped.
- doc package added.

* Fri Jan 26 2018 Van de Bugger - 3.7.5-1.vdb
- Version v3.7.5.

* Wed Sep 28 2016 Van de Bugger - 3.6.7-2.vdb
- scintilla-common package dropped.
- License.txt is a part of both scintilla-gtk2 and scintilla-gtk3.
- ldconfig added to requirements.
- More rpm macros used (e. g. make_build, __cp, etc).
- Dependency on gtk-devel dropped in favour of dependency on
  pkgconfig(gtk+-x.0).

* Wed Sep 14 2016 Van de Bugger - 3.6.7-1.vdb
- All the patches dropped -- they were accepted upstream.
- Added rpmbuild options --without gtk2 and --without gtk3.
- Lua module used to perform some magic behind the scene.
- Shared libraries stripped.

* Thu Sep 08 2016 Van de Bugger - 3.6.6-1.vdb
- Initial revision.