# vim:ft=spec:

%if 0%{?el8}
# see https://fedoraproject.org/wiki/Changes/CMake_to_do_out-of-source_builds
# EPEL 8's %%cmake defaults to in-source build, which neovim does not support
%undefine __cmake_in_source_build
%endif

%bcond_with jemalloc
%ifarch %{arm} %{ix86} x86_64 %{mips} s390x
  %bcond_without luajit
%else
  %ifarch aarch64
    %if 0%{?el8}
      # luajit codepath buggy on el8 aarch64
      # https://bugzilla.redhat.com/show_bug.cgi?id=2065340
      %bcond_with luajit
    %else
      %bcond_without luajit
    %endif
  %else
    %bcond_with luajit
  %endif
%endif

%global luv_min_ver 1.43.0
%global tree_sitter_min_ver 0.22.5
%global vterm_min_ver 0.3.3

%global luv_include_dir %{_includedir}/luv
%if %{with luajit}
%global luajit_version 2.1
%global lua_prg %{_bindir}/luajit
%else
%global lua_version 5.1
%global lua_prg %{_bindir}/lua-5.1
%endif

Name:           neovim
Version:        0.11.0~dev.1296.g812d02970
Release:        1%{?dist}

License:        Apache-2.0 AND Vim
Summary:        Vim-fork focused on extensibility and agility
Url:            https://neovim.io

Source0:        neovim-9cf0c06c.tar.gz
Source1:        sysinit.vim
Source2:        spec-template

Patch1000:      neovim-lua-bit32.patch

BuildRequires:  gcc-c++
BuildRequires:  cmake
BuildRequires:  desktop-file-utils
BuildRequires:  fdupes
BuildRequires:  gettext
BuildRequires:  gperf
BuildRequires:  gcc
Requires:       utf8proc > 2.9.0
BuildRequires:  utf8proc-devel > 2.9.0
BuildRequires:  libluv-devel >= %{luv_min_ver}
%if %{with luajit}
# luajit implements version 5.1 of the lua language spec, so it needs the
# compat versions of libs.
BuildRequires:  luajit-devel
Requires:       luajit2.1-luv >= %{luv_min_ver}
%else
# lua5.1
BuildRequires:  compat-lua
BuildRequires:  compat-lua-devel
BuildRequires:  lua5.1-bit32
Requires:       lua5.1-luv >= %{luv_min_ver}
# /with luajit
%endif
Requires:       lua5.1-lpeg
BuildRequires:  lua5.1-lpeg
BuildRequires:  lua5.1-mpack >= 1.0.11
%if %{with jemalloc}
BuildRequires:  jemalloc-devel
%endif
BuildRequires:  msgpack-devel >= 3.1.0
BuildRequires:  pkgconfig(termkey)
BuildRequires:  pkgconfig(libuv) >= 1.42.0
BuildRequires:  pkgconfig(vterm) >= %{vterm_min_ver}
# need the build with the fix for the resize buffer issue
Requires:       libvterm >= %{vterm_min_ver}
BuildRequires:  pkgconfig(unibilium)
BuildRequires:  pkgconfig(tree-sitter) >= %{tree_sitter_min_ver}
# tree-sitter didn't do an soname bump. enforce the min version
# see https://github.com/nvim-treesitter/nvim-treesitter/pull/3055/files
Requires:       libtree-sitter >= %{tree_sitter_min_ver}
# Parser generator, only needed for :TSInstallFromGrammar
Recommends:     tree-sitter-cli
Suggests:       (python2-neovim if python2)
Suggests:       (python3-neovim if python3)
# XSel provides access to the system clipboard
Recommends:     xsel
Recommends:     wl-clipboard
Recommends:     ripgrep

%description
Neovim is a refactor - and sometimes redactor - in the tradition of
Vim, which itself derives from Stevie. It is not a rewrite, but a
continuation and extension of Vim. Many rewrites, clones, emulators
and imitators exist; some are very clever, but none are Vim. Neovim
strives to be a superset of Vim, notwithstanding some intentionally
removed misfeatures; excepting those few and carefully-considered
excisions, Neovim is Vim. It is built for users who want the good
parts of Vim, without compromise, and more.

%prep
%setup -T -b 0 -q -n neovim

rm -rf .deps
cp -as $PWD/vendor .deps

%if %{without luajit}
%patch -P 1000 -p1
%endif

%build
# set vars to make build reproducible; see config/CMakeLists.txt
HOSTNAME=koji
USERNAME=koji

 # Build the tree-sitter parsers first
%define _vpath_srcdir cmake.deps
%define __cmake_builddir .deps
%cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo \
       -DUSE_BUNDLED=OFF \
       -DUSE_BUNDLED_TS_PARSERS=ON
%cmake_build

# Build neovim
%define _vpath_srcdir .
%define __cmake_builddir redhat-linux-build
%cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo \
       -DPREFER_LUA=%{?with_luajit:OFF}%{!?with_luajit:ON} \
       -DLUA_PRG=%{lua_prg} \
       -DENABLE_JEMALLOC=%{?with_jemalloc:ON}%{!?with_jemalloc:OFF} \
       -DLIBLUV_INCLUDE_DIR:PATH=%{luv_include_dir} \
       -DNVIM_VERSION_MEDIUM="v0.11.0-dev+1296-g812d02970"

%cmake_build

%install
%cmake_install

install -p -m 644 %{SOURCE1} %{buildroot}%{_datadir}/nvim/sysinit.vim
install -p -m 644 %{SOURCE2} %{buildroot}%{_datadir}/nvim/template.spec

desktop-file-install --dir=%{buildroot}%{_datadir}/applications \
    runtime/nvim.desktop
install -d -m0755 %{buildroot}%{_datadir}/pixmaps
install -m0644 runtime/nvim.png %{buildroot}%{_datadir}/pixmaps/nvim.png

%fdupes %{buildroot}%{_datadir}/
# Fix exec bits
find %{buildroot}%{_datadir} \( -name "*.bat" -o -name "*.awk" \) \
    -print -exec chmod -x '{}' \;
%find_lang nvim

# Refresh documentation helptags.
%transfiletriggerin -- %{_datadir}/nvim/runtime/doc
%{_bindir}/nvim -u NONE -es -c ":helptags %{_datadir}/nvim/runtime/doc" -c ":q" &> /dev/null || :

%transfiletriggerpostun -- %{_datadir}/nvim/runtime/doc
> %{_datadir}/nvim/runtime/doc/tags || :
%{_bindir}/nvim -u NONE -es -c ":helptags %{_datadir}/nvim/runtime/doc" -c ":q" &> /dev/null || :

%files -f nvim.lang
%license LICENSE.txt
%doc CONTRIBUTING.md MAINTAIN.md README.md
%{_bindir}/nvim

%dir %{_libdir}/nvim
%dir %{_libdir}/nvim/parser
%{_libdir}/nvim/parser/*.so

%{_mandir}/man1/nvim.1*
%{_datadir}/applications/nvim.desktop
%{_datadir}/pixmaps/nvim.png
%{_datadir}/icons/hicolor/128x128/apps/nvim.png

%{_datadir}/nvim


%changelog
* Fri Dec 06 2024 Aron Griffis <aron@scampersand.com> - 0.11.0~dev.1296.g812d02970-1
- Nightly build from git master

* Tue Jul 02 2024 Andreas Schneider <asn@cryptomilk.org> - 0.10.0-6
- resolves: rhbz#2283574 - Bundle required tree-sitter parsers

* Fri May 24 2024 Andreas Schneider <asn@cryptomilk.org> - 0.10.0-5
- Fix updating helptags

* Wed May 22 2024 Danie de Jager <danie.dejager@doxim.com> - 0.10.0-4
- Add missing lua5.1-lpeg runtime requirement

* Tue May 21 2024 Andreas Schneider <asn@cryptomilk.org> - 0.10.0-3
- Add RPM file triggers support to regenerate helptags

* Thu May 16 2024 Andreas Schneider <asn@cryptomilk.org> - 0.10.0-2
- Update neovim-lua-bit32.patch

* Thu May 16 2024 Andreas Schneider <asn@cryptomilk.org> - 0.10.0-1
- Update to version 0.10.0 - check `:help news` for important changes

* Mon Mar 04 2024 Andreas Schneider <asn@redhat.com> - 0.9.5-4
- resolves: #2222911 - Build with luajit on s390x

* Thu Jan 25 2024 Fedora Release Engineering <releng@fedoraproject.org> - 0.9.5-3
- Rebuilt for https://fedoraproject.org/wiki/Fedora_40_Mass_Rebuild

* Sun Jan 21 2024 Fedora Release Engineering <releng@fedoraproject.org> - 0.9.5-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_40_Mass_Rebuild

* Tue Jan 02 2024 Andreas Schneider <asn@redhat.com> - 0.9.5-1
- Update to version 0.9.5
  * https://github.com/neovim/neovim/releases/tag/v0.9.5
  * For bigger version bump changelog see `:help news`
  * resolves: rhbz#2256278

* Fri Oct 20 2023 Andreas Schneider <asn@redhat.com> - 0.9.4-1
- Update to version 0.9.4
  * https://github.com/neovim/neovim/releases/tag/v0.9.4
  * For bigger version bump changelog see `:help news`
  * resolves: rhbz#2243010

* Thu Sep 07 2023 Andreas Schneider <asn@redhat.com> - 0.9.2-1
- Update to version 0.9.2
  * For changelog see `:help news`

* Mon Aug 28 2023 LuK1337 <priv.luk@gmail.com> - 0.9.1-4
- Improve spec template

* Thu Jul 20 2023 Fedora Release Engineering <releng@fedoraproject.org> - 0.9.1-3
- Rebuilt for https://fedoraproject.org/wiki/Fedora_39_Mass_Rebuild

* Tue Jun 06 2023 Andreas Schneider <asn@redhat.com> - 0.9.1-2
- Build with new libluv-devel

* Wed May 31 2023 Andreas Schneider <asn@redhat.com> - 0.9.1-1
- Update to version 0.9.1
  * For changelog see `:help news`

* Tue May 02 2023 Andreas Schneider <asn@redhat.com> - 0.9.0-3
- Improve semantic token performance
- related: rhbz#2188229 - Fix applying patches

* Fri Apr 21 2023 Andreas Schneider <asn@redhat.com> - 0.9.0-2
- resolves: rhbz#2188229 - Fix buffer overflow for user command

* Fri Apr 07 2023 Andreas Schneider <asn@redhat.com> - 0.9.0-1
- Update to version 0.9.0
  * For changelog see `:help news`

* Mon Mar 27 2023 Andreas Schneider <asn@redhat.com> - 0.8.3-4
- resolves: rhbz#2181836 - Fix snprintf buffer overflow with tags

* Sat Mar 25 2023 Andreas Schneider <asn@redhat.com> - 0.8.3-3
- resolves: rhbz#2165805 - Fix snprintf buffer overflow

* Sun Mar 05 2023 Andreas Schneider <asn@redhat.com> - 0.8.3-2
- Update License to SPDX expression
- Update spec template for auto(release|changelog)

* Thu Feb 02 2023 Andreas Schneider <asn@redhat.com> - 0.8.3-1
- Update to version 0.8.3
  * https://github.com/neovim/neovim/releases/tag/v0.8.3

* Thu Jan 19 2023 Fedora Release Engineering <releng@fedoraproject.org> - 0.8.2-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_38_Mass_Rebuild

* Fri Dec 30 2022 Andreas Schneider <asn@redhat.com> - 0.8.2-1
- Update to version 0.8.2
  * https://github.com/neovim/neovim/releases/tag/v0.8.2

* Mon Nov 14 2022 Andreas Schneider <asn@redhat.com> - 0.8.1-1
- Update to version 0.8.1
  * https://github.com/neovim/neovim/releases/tag/v0.8.1

* Fri Sep 30 2022 Andreas Schneider <asn@redhat.com> - 0.8.0-1
- Update to version 0.8.0
  * https://github.com/neovim/neovim/releases/tag/v0.8.0

* Wed Sep 21 2022 Andreas Schneider <asn@redhat.com> - 0.7.2-4
- Build with libvterm 0.3

* Thu Aug 25 2022 Michel Alexandre Salim <salimma@fedoraproject.org> - 0.7.2-3
- Enforce the minimum tree-sitter version at runtime (Fixes: rhbz#2100577)

* Fri Jul 22 2022 Fedora Release Engineering <releng@fedoraproject.org> - 0.7.2-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_37_Mass_Rebuild