%define _python3ver__ %(fullver=%{__python3} --version | awk '{print $2}';echo ${fullver:0:3})
%define _python3path__ %{_includedir}/%{_python3ver__}m

%{!?_with_selinux__:%global _with_selinux__ 1}
%{!?_with_ruby__:%define _with_ruby__ 1}
%{!?_with_lua__:%define _with_lua__ 1}
%{!?_with_netbeans__:%define _with_netbeans__ 1}

%define vimdir vim82
%define python_ver 3.8

Name:           vim
Epoch:          2
Version:        8.2
Release:        7
Summary:        Vim is a highly configurable text editor for efficiently creating and changing any kind of text.
License:        Vim and MIT
URL:            http://www.vim.org
Source0:        ftp://ftp.vim.org/pub/vim/unix/vim-8.2.tar.bz2
Source1:	    virc
Source2:	    vimrc

Patch0000:      vim-7.0-fixkeys.patch
Patch0001:      vim-7.4-specsyntax.patch
Patch0002:      vim-7.4-syntax.patch
Patch0003:      vim-7.4-nowarnings.patch
Patch0004:      vim-7.0-rclocation.patch
Patch0005:      vim-7.4-checkhl.patch
Patch0006:      vim-7.4-fstabsyntax.patch
Patch0007:      vim-7.4-syncolor.patch
Patch0009:      vim-7.4-globalsyntax.patch
Patch0010:      vim-7.4-releasestring-1318991.patch
Patch0011:      vim-8.0-copy-paste.patch
Patch0012:      vim-python3-tests.patch
Patch0013:	Fix-vim-lua5.4.0-defines+luaL_typeerror-twice.patch
Patch0014:	backport-Fix-build-failuers-with-perl-5.32.patch

Patch9000:      bugfix-rm-modify-info-version.patch

BuildRequires:  autoconf python3-devel ncurses-devel gettext perl-devel perl-generators gcc
BuildRequires:  perl(ExtUtils::Embed) perl(ExtUtils::ParseXS) libacl-devel gpm-devel file
BuildRequires:  desktop-file-utils >= 0.2.93
%if %{_with_selinux__}
BuildRequires:  libselinux-devel
%endif
%if %{_with_ruby__}
BuildRequires:  ruby-devel ruby
%endif
%if %{_with_lua__}
BuildRequires:  lua-devel
%endif
Requires:       desktop-file-utils
Conflicts:      filesystem < 3

%description
Vim is an advanced text editor that seeks to provide the power of the
de-facto Unix editor 'Vi', with a more complete feature set. Vim is a
highly configurable text editor built to enable efficient text editing.
It is an improved version of the vi editor distributed with most UNIX
systems.

%package common
Summary:        This contains some common files to use vim editor.
Requires:       %{name}-filesystem
Conflicts:      man-pages-fr < 0.9.7-14 man-pages-it < 0.3.0-17 man-pages-pl < 0.24-2 %{name}-minimal < 8.0.1428-4

%description common
This common package contains files that will be needed when you run vim editor. This is also needed by vim-enhaned and vim-X11 packages.

%package minimal
Summary:        This package provides the basic and minimal functionalities of vim editor.
Provides:       vi = %{version}-%{release} %{_bindir}/vi
Conflicts:      %{name}-common < 8.0.1428-4

%description minimal
The minimal package provides a minimal version of vim editor. It will be installed as /usr/bin/vi.

%package enhanced
Summary:        This is a package containing enhanced vim editor.
Requires:       vim-common = %{epoch}:%{version}-%{release} which gpm-libs
Provides:       vim = %{version}-%{release} %{_bindir}/mergetool %{_bindir}/vim
Suggests:       python3 python3-libs
Suggests:       perl(:MODULE_COMPAT_%(eval "`%{__perl} -V:version`"; echo $version))
Suggests:       perl-libs perl-devel
%if %{_with_ruby__}
Suggests:       ruby-libs ruby
%endif
%if %{_with_lua__}
Suggests:       lua-libs
%endif

%description enhanced
This packages includes some enhancements for the vim editor.

%package filesystem
Summary:        The vim filesystem.
BuildArch:      noarch

%description filesystem
This package contains the vim filesystem.

%package X11
Summary:        Vim for the X Window System i.e.gvim
BuildRequires:  gtk3-devel libX11-devel libSM-devel libXt-devel libXpm-devel libICE-devel libappstream-glib
Requires:       vim-common = %{epoch}:%{version}-%{release} libattr >= 2.4 gtk3 hicolor-icon-theme
Requires:       libICE libSM libX11 libXt cairo gdk-pixbuf2 pango
Provides:       gvim = %{version}-%{release} %{_bindir}/mergetool %{_bindir}/gvim
Suggests:       python3 python3-libs
Suggests:       perl(:MODULE_COMPAT_%(eval "`%{__perl} -V:version`"; echo $version))
Suggests:       perl-libs perl-devel
%if %{_with_ruby__}
Suggests:       ruby-libs ruby
%endif
%if %{_with_lua__}
Suggests:       lua-libs
%endif

%description X11
This X11 package serves you the ability to use vim with graphics and mouse.

%prep
%autosetup -b 0 -n %{vimdir} -p1

%build
%define _make_cmd__() %{make_build} VIMRCLOC=/etc VIMRUNTIMEDIR=/usr/share/vim/%{vimdir}; cp vim %{?1}; %{!?2:make clean}

export CFLAGS="%{optflags} -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_FORTIFY_SOURCE=2 -I%{_python3path__} -D__linux__ -D_REENTRANT"
export CXXFLAGS="%{optflags} -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_FORTIFY_SOURCE=2 -I%{_python3path__} -D__linux__ -D_REENTRANT"

sed -i 's/nawk/awk/g' runtime/tools/mve.awk
cd src; autoconf

cp -f os_unix.h os_unix.h.bak

sed -i 's/vimrc/virc/' os_unix.h
%configure --with-features=small --with-x=no --enable-multibyte --disable-netbeans \
 --disable-pythoninterp --disable-perlinterp --disable-tclinterp --with-tlib=ncurses \
 --enable-gui=no --disable-gpm --exec-prefix=/ \
 --enable-fail-if-missing --with-python3-config-dir=/usr/lib64/python%{python_ver}/config-%{python_ver}-%{_arch}-linux-gnu \
%if %{_with_selinux__}
 --enable-selinux \
%else
 --disable-selinux \
%endif

%{_make_cmd__ vim-minimal}

mv os_unix.h.bak os_unix.h

%configure --with-features=huge --enable-python3interp=dynamic \
 --enable-perlinterp=dynamic --disable-tclinterp --with-x=yes --enable-xim --enable-multibyte \
 --with-tlib=ncurses --enable-gtk3-check --enable-gui=gtk3 \
 --enable-cscope --enable-fail-if-missing --with-python3-config-dir=/usr/lib64/python%{python_ver}/config-%{python_ver}-%{_arch}-linux-gnu \
%if %{_with_netbeans__}
 --enable-netbeans \
%else
 --disable-netbeans \
%endif
%if %{_with_selinux__}
 --enable-selinux \
%else
 --disable-selinux \
%endif
%if %{_with_ruby__}
 --enable-rubyinterp=dynamic \
%else
 --disable-rubyinterp \
%endif
%if %{_with_lua__}
 --enable-luainterp=dynamic \
%else
 --disable-luainterp \
%endif

%{_make_cmd__ vim-X11}

%configure --with-features=huge --enable-python3interp=dynamic \
 --enable-perlinterp=dynamic --disable-tclinterp --with-x=no --enable-gui=no --enable-multibyte \
 --enable-cscope --with-tlib=ncurses --with-python3-config-dir=/usr/lib64/python%{python_ver}/config-%{python_ver}-%{_arch}-linux-gnu \
 --enable-fail-if-missing \
%if %{_with_netbeans__}
 --enable-netbeans \
%else
 --disable-netbeans \
%endif
%if %{_with_selinux__}
 --enable-selinux \
%else
 --disable-selinux \
%endif
%if %{_with_ruby__}
 --enable-rubyinterp=dynamic \
%else
 --disable-rubyinterp \
%endif
%if %{_with_lua__}
 --enable-luainterp=dynamic \
%else
 --disable-luainterp \
%endif

%{_make_cmd__ vim-enhanced noclean}

%install
pushd src
%make_install BINDIR=%{_bindir} VIMRCLOC=%{_sysconfdir} VIMRUNTIMEDIR=%{_datadir}/%{name}/%{vimdir}
make installgtutorbin  DESTDIR=%{buildroot} BINDIR=%{_bindir} VIMRCLOC=%{_sysconfdir} VIMRUNTIMEDIR=%{_datadir}/%{name}/%{vimdir}

install -m755 vim-minimal %{buildroot}%{_bindir}/vi
install -m755 vim-enhanced %{buildroot}%{_bindir}/vim
install -m755 vim-X11 %{buildroot}%{_bindir}/gvim
popd

rm -f README*.info

for dir in {autoload,colors,compiler,doc,ftdetect,ftplugin,indent,keymap,lang,plugin,print,spell,syntax,tutor}
do
    install -d %{buildroot}%{_datadir}/%{name}/vimfiles/${dir}
    install -d %{buildroot}%{_datadir}/%{name}/vimfiles/after/${dir}
done

install -m644 %{_builddir}/%{vimdir}/runtime/doc/uganda.txt %{_builddir}/%{vimdir}/LICENSE

install -d %{buildroot}%{_datadir}/icons/hicolor/{16x16,32x32,48x48,64x64}/apps

install -d %{buildroot}%{_metainfodir}
cat > %{buildroot}%{_metainfodir}/gvim.appdata.xml <<EOF
<?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright 2014 Richard Hughes <richard@hughsie.com> -->
<!--
EmailAddress: Bram@moolenaar.net>
SentUpstream: 2014-05-22
-->
<application>
  <id type="desktop">gvim.desktop</id>
  <metadata_license>CC0-1.0</metadata_license>
  <project_license>Vim</project_license>
  <description>
    <p>
     Vim is an advanced text editor that seeks to provide the power of the
     de-facto Unix editor 'Vi', with a more complete feature set.
     It's useful whether you're already using vi or using a different editor.
    </p>
    <p>
     Vim is a highly configurable text editor built to enable efficient text
     editing.
     Vim is often called a "programmer's editor," and so useful for programming
     that many consider it an entire IDE. It is not just for programmers, though.
     Vim is perfect for all kinds of text editing, from composing email to
     editing configuration files.
    </p>
  </description>
  <screenshots>
    <screenshot type="default">
      <image>https://raw.githubusercontent.com/zdohnal/vim/zdohnal-screenshot/gvim16_9.png</image>
    </screenshot>
  </screenshots>
  <url type="homepage">http://www.vim.org/</url>
</application>
EOF

%define _linkvi__ %{buildroot}%{_bindir}/{rvi,rview,view,ex}
%define _linkvim__ %{buildroot}%{_bindir}/{rvim,vimdiff}
%define _linkgvim__ %{buildroot}%{_bindir}/{gview,gex,evim,gvimdiff,vimx}
%define _linkcmds__() for file in %{expand:%{_link%{1}__}};do ln -sf %{1} ${file};done;

%{_linkcmds__ vi}
%{_linkcmds__ vim}
%{_linkcmds__ gvim}

pushd %{buildroot}%{_mandir}/man1
sed -i 's,%{buildroot},,' {vim.1,vimtutor.1}
rm -f rvim.1
install -p vim.1 vi.1
ln -sf vi.1.gz rvi.1.gz
ln -sf vim.1.gz vimdiff.1.gz
popd

desktop-file-install --dir %{buildroot}%{_datadir}/applications %{_builddir}/%{vimdir}/runtime/gvim.desktop

appstream-util validate-relax --nonet %{buildroot}%{_datadir}/metainfo/*.appdata.xml

pushd %{buildroot}%{_datadir}/%{name}/%{vimdir}/tutor
ln -sf menu_ja_jp.ujis.vim %{buildroot}%{_datadir}/%{name}/%{vimdir}/lang/menu_ja_jp.eucjp.vim
for files in {tutor.ca,tutor.it,tutor.fr,tutor.es,tutor.de,tutor.sv,tutor.no}
do
    iconv -f CP1252 -t UTF8 ${files} -o ${files}.bak;mv ${files}.bak ${files}
done
iconv -f ISO-8859-2 -t UTF8 tutor.pl -o tutor.pl.bak;mv tutor.pl.bak tutor.pl
iconv -f ISO-8859-2 -t UTF8 tutor.sk -o tutor.sk.bak;mv tutor.sk.bak tutor.sk
iconv -f KOI8R -t UTF8 tutor.ru -o tutor.ru.bak;mv tutor.ru.bak tutor.ru
popd

install -Dpm644 %{SOURCE1} %{buildroot}%{_sysconfdir}/virc
install -pm644 %{SOURCE2} %{buildroot}%{_sysconfdir}/vimrc

pushd %{buildroot}%{_mandir}
for files in `find ??/ -type f`
do
    if [[ "`file ${files}`" == *UTF-8\ Unicode\ text* ]]
    then
        continue
    fi
    iconv -f latin1 -t UTF8 ${files} -o ${files}.bak; mv ${files}.bak ${files}
done
popd

mv %{buildroot}%{_mandir}/ru.UTF-8 %{buildroot}%{_mandir}/ru

install -d %{buildroot}%{_mandir}/man5
for files in %{buildroot}%{_mandir}/{man1/{rvim.1,gvim.1,gex.1,gview.1,vimx.1},man5/vimrc.5}
do
    echo ".so man1/vim.1" > ${files}
done
echo ".so man1/vimdiff.1" > %{buildroot}%{_mandir}/man1/gvimdiff.1
echo ".so man1/vimtutor.1" > %{buildroot}%{_mandir}/man1/gvimtutor.1
echo ".so man1/vi.1" > %{buildroot}%{_mandir}/man5/virc.5
touch %{buildroot}%{_datadir}/%{name}/vimfiles/doc/tags

pushd runtime
rm -rf doc
ln -sf ../../%{name}/%{vimdir}/doc docs
popd

%transfiletriggerin common -- %{_datadir}/%{name}/vimfiles/doc
%{_bindir}/vim -c ":helptags %{_datadir}/%{name}/vimfiles/doc" -c :q &> /dev/null || :

%transfiletriggerpostun common -- %{_datadir}/%{name}/vimfiles/doc
> %{_datadir}/%{name}/vimfiles/doc/tags || :
%{_bindir}/vim -c ":helptags %{_datadir}/%{name}/vimfiles/doc" -c :q &> /dev/null || :

%files common
%exclude %{_datadir}/vim/%{vimdir}/macros/maze/maze*.c
%exclude %{_datadir}/vim/%{vimdir}/tools
%exclude %{_datadir}/vim/%{vimdir}/doc/vim2html.pl
%exclude %{_mandir}/{pl.ISO8859-2,it.ISO8859-1,ru.KOI8-R,fr.ISO8859-1,da.ISO8859-1}
%exclude %{_mandir}/{de.ISO8859-1,fr.UTF-8,it.UTF-8,pl.UTF-8,da.UTF-8,de.UTF-8}
%{!?_licensedir:%global license %%doc}
%license LICENSE
%doc README*
%doc runtime/docs
%config(noreplace) %{_sysconfdir}/vimrc
%{_datadir}/%{name}/%{vimdir}/{rgb.txt,autoload,colors,compiler,pack,doc}
%{_datadir}/%{name}/%{vimdir}/{*.vim,ftplugin,indent,keymap,macros,plugin}
%{_datadir}/%{name}/%{vimdir}/{print,syntax,tutor,spell}
%{_datadir}/%{name}/%{vimdir}/lang/{*.vim,*.txt}
%{_bindir}/xxd
%lang(af) %{_datadir}/%{name}/%{vimdir}/lang/af
%lang(ca) %{_datadir}/%{name}/%{vimdir}/lang/ca
%lang(cs) %{_datadir}/%{name}/%{vimdir}/lang/cs
%lang(cs.cp1250) %{_datadir}/%{name}/%{vimdir}/lang/cs.cp1250
%lang(da) %{_datadir}/%{name}/%{vimdir}/lang/da
%lang(de) %{_datadir}/%{name}/%{vimdir}/lang/de
%lang(en_GB) %{_datadir}/%{name}/%{vimdir}/lang/en_GB
%lang(eo) %{_datadir}/%{name}/%{vimdir}/lang/eo
%lang(es) %{_datadir}/%{name}/%{vimdir}/lang/es
%lang(fi) %{_datadir}/%{name}/%{vimdir}/lang/fi
%lang(fr) %{_datadir}/%{name}/%{vimdir}/lang/fr
%lang(ga) %{_datadir}/%{name}/%{vimdir}/lang/ga
%lang(it) %{_datadir}/%{name}/%{vimdir}/lang/it
%lang(ja) %{_datadir}/%{name}/%{vimdir}/lang/ja
%lang(ja.euc-jp) %{_datadir}/%{name}/%{vimdir}/lang/ja.euc-jp
%lang(ja.sjis) %{_datadir}/%{name}/%{vimdir}/lang/ja.sjis
%lang(ko) %{_datadir}/%{name}/%{vimdir}/lang/ko
%lang(ko) %{_datadir}/%{name}/%{vimdir}/lang/ko.UTF-8
%lang(lv) %{_datadir}/%{name}/%{vimdir}/lang/lv
%lang(nb) %{_datadir}/%{name}/%{vimdir}/lang/nb
%lang(nl) %{_datadir}/%{name}/%{vimdir}/lang/nl
%lang(no) %{_datadir}/%{name}/%{vimdir}/lang/no
%lang(pl) %{_datadir}/%{name}/%{vimdir}/lang/pl
%lang(pl.UTF-8) %{_datadir}/%{name}/%{vimdir}/lang/pl.UTF-8
%lang(pl.cp1250) %{_datadir}/%{name}/%{vimdir}/lang/pl.cp1250
%lang(pt_BR) %{_datadir}/%{name}/%{vimdir}/lang/pt_BR
%lang(ru) %{_datadir}/%{name}/%{vimdir}/lang/ru
%lang(ru.cp1251) %{_datadir}/%{name}/%{vimdir}/lang/ru.cp1251
%lang(sk) %{_datadir}/%{name}/%{vimdir}/lang/sk
%lang(sk.cp1250) %{_datadir}/%{name}/%{vimdir}/lang/sk.cp1250
%lang(sr) %{_datadir}/%{name}/%{vimdir}/lang/sr
%lang(sv) %{_datadir}/%{name}/%{vimdir}/lang/sv
%lang(tr) %{_datadir}/%{name}/%{vimdir}/lang/tr
%lang(uk) %{_datadir}/%{name}/%{vimdir}/lang/uk
%lang(uk.cp1251) %{_datadir}/%{name}/%{vimdir}/lang/uk.cp1251
%lang(vi) %{_datadir}/%{name}/%{vimdir}/lang/vi
%lang(zh_CN) %{_datadir}/%{name}/%{vimdir}/lang/zh_CN
%lang(zh_CN.cp936) %{_datadir}/%{name}/%{vimdir}/lang/zh_CN.cp936
%lang(zh_TW) %{_datadir}/%{name}/%{vimdir}/lang/zh_TW
%lang(zh_CN.UTF-8) %{_datadir}/%{name}/%{vimdir}/lang/zh_CN.UTF-8
%lang(zh_TW.UTF-8) %{_datadir}/%{name}/%{vimdir}/lang/zh_TW.UTF-8
%lang(fr) %{_mandir}/fr/man1/*
%lang(da) %{_mandir}/da/man1/*
%lang(de) %{_mandir}/de/man1/*
%lang(it) %{_mandir}/it/man1/*
%lang(ja) %{_mandir}/ja/man1/*
%lang(pl) %{_mandir}/pl/man1/*
%lang(ru) %{_mandir}/ru/man1/*
%{_mandir}/man1/{gex.*,gview.*,gvim*,rvim.*,vim.*,vimdiff.*}
%{_mandir}/man1/{vimtutor.*,vimx.*,xxd.*}
%{_mandir}/man5/vimrc.*

%files minimal
%config(noreplace) %{_sysconfdir}/virc
%{_bindir}/{ex,vi,view,rvi,rview}
%{_mandir}/man1/{vi.*,ex.*,rvi.*,rview.*,view.*}
%{_mandir}/man5/virc.*

%files enhanced
%{_bindir}/{vim,rvim,vimdiff,vimtutor}

%files filesystem
%dir %{_datadir}/%{name}/vimfiles/after/*
%dir %{_datadir}/%{name}/vimfiles/{autoload,colors,compiler,doc,ftdetect,ftplugin}
%dir %{_datadir}/%{name}/vimfiles/{indent,keymap,lang,plugin,print,spell,syntax,tutor}
%ghost %{_datadir}/%{name}/vimfiles/doc/tags

%files X11
%exclude /%{_datadir}/applications/vim.desktop
%{_datadir}/metainfo/*.appdata.xml
%{_datadir}/applications/*
%{_datadir}/icons/{hicolor,locolor}/*/apps/*
%{_bindir}/{gvimtutor,gvim,gvimdiff,gview,gex}
%{_bindir}/{vimtutor,vimx,evim}
%{_mandir}/man1/evim.*

%changelog
* Sat Jun 12 2021 shixuantong<shixuantong@huawei> - 2:8.2-7
- Type:bugfix
- ID:NA
- SUG:NA
- DESC:add gcc to BuildRequires

* Mon Nov 2 2020 wangjie<wangjie294@huawei.com> -2:8.2-6
- Type:NA
- ID:NA
- SUG:NA
- DESC:remove python2

* Wed Oct 14 2020 Jie Yang<yangjieyj.yang@huawei.com> - 2:8.2-5
- Type:bugfix
- ID:NA
- SUG:NA
- DESC:Fix wrong path passed to --with-python3-config-dir.

* Sat Aug 15 2020 shixuantong<shixuantong@huawei.com> - 2:8.2-4
- Type:bugfix
- ID:NA
- SUG:NA
- DESC:Fix build failuers with perl 5.32

* Fri Aug 7 2020 wenzhanli<wenzhanli2@huawei.com> - 2:8.2-3
- Type:bugfix
- ID:NA
- SUG:NA
- DESC:Fix make test because lua update version 5.4.0

* Mon Jun 15 2020 chengquan<chengquan3@huawei.com> -2:8.2-2
- Type:bugfix
- ID:NA
- SUG:NA
- DESC:Fix compilation errors caused by python upgrade

* Thu Apr 16 2020 chengquan<chengquan3@huawei.com> -2:8.2-1
- Type:enhancement
- ID:NA
- SUG:NA
- DESC:upgrade software to v8.2

* Sat Feb 29 2020 openEuler Buildteam <buildteam@openeuler.org> - 2:8.1.450-8
- update virc/vimrc to make escape work in insert mode

* Thu Jan 21 2020 openEuler Buildteam <buildteam@openeuler.org> - 2:8.1.450-7
- make vi/vim  easy to uses

* Sun Jan 19 2020 openEuler Buildteam <buildteam@openeuler.org> - 2:8.1.450-6
- fix bug in install files

* Sat Jan 18 2020 openEuler Buildteam <buildteam@openeuler.org> - 2:8.1.450-5
- make vi easy to use

* Thu Jan 9 2020 openEuler Buildteam <buildteam@openeuler.org> - 2:8.1.450-4
- update spec and patch

* Sun Dec 22 2019 openEuler Buildteam <buildteam@openeuler.org> - 2:8.1.450-3
- update vimrc/virc info

* Mon Sep 23 2019 huzhiyu<huzhiyu1@huawei.com> - 2:8.1.450-2
- Package init
