# comment out if not nightly build
#define nightly	20180604
#define gitcommit cf92a76

%bcond_without translations

# rel to bump
%define rel	1

# build will override this anyway, so let's skip it
%define _fortify_cflags %nil

%define vendor_version 0.11.0

%if 0%{!?mkrel:1}
%define mkrel(c) %{1}%{?dist}
%endif

Name:		neovim
Version:	0.11.0
Release:	%mkrel 1.1
Summary:	Vim-fork focused on extensibility and usability
Group:		Editors
License:	ASL 2.0
URL:		https://neovim.io/
%if 0%{?nightly:1}
Source0:	https://github.com/neovim/neovim/archive/nightly/%{name}-%{version}-nightly%{nightly}.tar.gz
%else
Source0:	https://github.com/neovim/neovim/archive/v%{version}/%{name}-%{version}.tar.gz
%endif
Source1:        %{name}-%{vendor_version}-vendor.tar.gz

#Patch0:		neovim-0.5.0-bitop.patch

BuildRequires:	cmake
BuildRequires:	gcc
BuildRequires:	gperf
BuildRequires:	(ninja or ninja-build)
%if 0%{?epel} || 0%{?fedora} || 0%{?mageia} >= 9
BuildRequires:	pkgconfig(termkey)
BuildRequires:	pkgconfig(jemalloc)
BuildRequires:	pkgconfig(libbsd)
%endif
Requires:	%{name}-data >= %{version}-%{release}
Provides:	nvim = %{version}-%{release}
Recommends:	xclip
Recommends:     wl-clipboard
Recommends:     ripgrep
Recommends:	python3dist(pynvim)
Recommends:	npm(neovim)

%description
Neovim is a project that seeks to aggressively refactor Vim in order to:

- Simplify maintenance and encourage contributions
- Split the work between multiple developers
- Enable advanced UIs without modifications to the core
- Maximize extensibility

%package data
Summary:	Data files for %{name}
BuildArch:	noarch

%description data
Data files for %{name}.

%prep
%setup -q -b1
%autosetup -p1 -n %{name}-%{?nightly:nightly}%{?!nightly:%{version}}

sed -i "s|sys/end|bsd/sys/end|g" cmake.config/CMakeLists.txt

%build
# Make sure we have the dependencies
mkdir -p .deps/build/
mv -f ../%{name}-%{vendor_version}-vendor .deps/build/downloads
cmake -S cmake.deps -B .deps -G Ninja -D CMAKE_BUILD_TYPE=RelWithDebInfo -DUSE_BUNDLED=ON
cmake --build .deps

# Now the build itself
%cmake -GNinja \
%if %{with translations}
	-DENABLE_TRANSLATIONS=ON \
%endif
	-B build
%ninja_build -C build

%install
%ninja_install -C build

%if %{with translations}
%find_lang nvim
%endif

%files
%license LICENSE.txt
%doc CONTRIBUTING.md README.md
%{_bindir}/nvim
%{_mandir}/man1/nvim.1*
%{_iconsdir}/hicolor/*/apps/nvim.png
%{_datadir}/applications/nvim.desktop
%{_libdir}/nvim/parser

%files data -f nvim.lang
%{_datadir}/nvim/