%global commit 490ec15087e37d8e1395e4dbfb99fc543c5bae5d
%global shortcommit %(c=%{commit}; echo ${c:0:7})
%global commitdate 20221121

Summary: sixel library
Name: libsixel
Version: 1.10.3
Release: 0.%{commitdate}git%{shortcommit}%{?dist}.2sunshine
License: MIT
Group: System Environment/Libraries
Url: https://github.com/libsixel/libsixel
Source0: %{url}/archive/%{commit}.tar.gz#/libsixel-%{commit}.tar.gz
Patch0: https://github.com/CorruptedVor/libsixel/commit/973f7fa3699d95672381eb88f1992a67dd9fa660.patch
Patch1: https://github.com/rokuyama/libsixel/commit/a04d7dec7b043a89db819259b30772e6bf8207f0.patch
Patch2: libsixel-c_conditionals.patch

BuildRequires: meson
BuildRequires: gcc
BuildRequires: pkgconfig(libpng)
BuildRequires: pkgconfig(libjpeg)
BuildRequires: pkgconfig(gdlib)
BuildRequires: pkgconfig(libcurl)

%description
This package provides encoder/decoder implementation for DEC SIXEL graphics,
and some converter programs.

%package        devel
Summary:        Development files for %{name}
Requires:       %{name}%{?_isa} = %{version}-%{release}

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

%package        tools
Summary:        Encoder/decoder tools for SIXEL
Requires:       %{name}%{?_isa} = %{version}-%{release}

%description    tools
Encoder/decoder tools for SIXEL image format using %{name}.

%prep
%autosetup -p1 -n libsixel-%{commit}

%build
%meson -Dgd=enabled -Dlibcurl=enabled -Dtests=enabled
%meson_build 

%install
%meson_install

%check
%meson_test

%files
%license LICENSE
%doc AUTHORS NEWS README.md
%{_libdir}/libsixel.so.*

%files devel
%doc examples/drawing examples/opengl
%{_libdir}/libsixel.so
%{_includedir}/sixel.h
%{_bindir}/libsixel-config
%{_libdir}/pkgconfig/libsixel.pc

%files tools
%{_bindir}/img2sixel
%{_bindir}/sixel2png
%{_mandir}/man1/img2sixel.1*
%{_mandir}/man1/sixel2png.1*
%{_datadir}/zsh/site-functions
%{_datadir}/bash-completion/completions

%changelog
* Mon Jul 10 2023 <moritz+rpm@barsnick.net> 1.10.3-0.20221121git490ec15.2sunshine
- add a patch for incorrect use of preprocessor macros, to fix builds with
  older gd
- move another file to devel package
- package tools separately

* Mon Jul 10 2023 <moritz+rpm@barsnick.net> 1.10.3-0.20221121git490ec15.1sunshine
- update to lastest git commit
- add two patches from other repositories
- drop useless Requires: and BR:s
- convert BRs to pkconfig()
- don't undefine _unpackaged_files_terminate_build
- package license and docs
- put proper files into devel package
- package examples in devel

* Wed Apr 05 2023 <lchh/libsixel> 1.10.3-1.20211215git8caeacc
- copr lchh/libsixel build