#   ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――
#   File: lexilla.spec
#   Copyright 🄯 2025 Van de Bugger.
#   SPDX-License-Identifier: FSFAP
#   ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――

Source1000:         vdb.lua
%global _vdb_debug_ 0
%include            %{S:1000}

%global maj         5
%global min         2
%global pat         7
%global rel         0.vdb.1

# 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 2

Name:               lexilla
Version:            %{maj}.%{min}.%{pat}
Release:            %{rel}%{?dist}
Summary:            A set of lexers and folders for Scintilla
License:            HPND
URL:                https://www.scintilla.org
Source0:            https://www.scintilla.org/%{name}%{maj}%{min}%{pat}.tgz

BuildRequires:      coreutils
BuildRequires:      make
BuildRequires:      gcc
BuildRequires:      gcc-c++ >= 4.7
    # TODO: -std=c++17 appeared in gcc ???.
BuildRequires:      python3
BuildRequires:      scintilla-gtk3-devel
BuildRequires:      %{__perl}

%package devel
Summary:            Development files for Lexilla

%description
%{text -- \
    Lexilla is a free library of language lexers that can be used with the Scintilla editing
    component. It comes with complete source code and a license that permits use in any free
    project or commercial product.
}

%description devel
%{text -- \
    Scintilla is free source code editing component.

    This package includes Lexilla development files.
}

%prep
%setup -q -n %{name}
%{__perl} -p -i~ \
    -e 's{^(\h*)\.\./\.\./scintilla/.*?(\\?\n)}{$1$2}' \
    src/deps.mak

%build
sci_cflags=$( pkg-config --cflags scintilla-gtk3 )
sci_libs=$( pkg-config --libs scintilla-gtk3 )
%{make_build} \
    -C src \
    CFLAGS="%{optflags}" \
    CXXFLAGS="$sci_cflags -std=c++17 -fPIC -fvisibility=hidden %{optflags}" \
    LDFLAGS="-shared -Wl,-soname=lib%{name}.so.%{maj} $sci_libs" \
    LEXILLA=../bin/lib%{name}.so.%{maj}.%{min}.%{pat} \
    ../bin/lib%{name}.so.%{maj}.%{min}.%{pat}
# Generate pc file:
{
    echo "libdir=%{_libdir}"
    echo "includedir=%{_includedir}"
    echo ""
    echo "Name: lexilla"
    echo "Description: %{summary}"
    echo "URL: %{url}"
    echo "Version: %{version}"
    echo "Cflags: -I\${includedir}/%{name}"
    echo "Libs: -L\${libdir} -llexilla"
    echo "Requires: scintilla-gtk3"
} > %{name}.pc.tmp
%{__mv} %{name}.pc.tmp %{name}.pc

%install
# Scintilla's makefile does not have install target.
%_install_D -p -m 644 -t "%{buildroot}%{_licensedir}/%{name}" License.txt
%_install_D -p -m 755 -t "%{buildroot}%{_libdir}"             bin/lib%{name}.so.%{maj}.%{min}.%{pat}
%_install_D -p -m 644 -t "%{buildroot}%{_includedir}/%{name}" include/*.h
%_install_D -p -m 644 -t "%{buildroot}%{_libdir}/pkgconfig"   %{name}.pc
%{__ln_s} lib%{name}.so.%{maj}.%{min}.%{pat} %{buildroot}%{_libdir}/lib%{name}.so.%{maj}
%{__ln_s} lib%{name}.so.%{maj}               %{buildroot}%{_libdir}/lib%{name}.so

%check

%files
%defattr( 644, root, root, 755 )
%attr( 755, -, - )  %{_libdir}/lib%{name}.so.%{maj}.%{min}.%{pat}
                    %{_libdir}/lib%{name}.so.%{maj}
%dir                %{_licensedir}/%{name}
                    %{_licensedir}/%{name}/License.txt

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

%post
%{__ldconfig}

%postun
%{__ldconfig}

%changelog

* Sun Mar  2 2025 Van de Bugger - 3.21.1-0.vdb.7
- GTK+ v2 excluded from default build.
- F41 rebuild.