*/*: Clean PYTHON_COMPAT of obsolete impls
[gentoo.git] / app-editors / vim / vim-9999.ebuild
1 # Copyright 1999-2020 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
3
4 EAPI=6
5 VIM_VERSION="8.1"
6 PYTHON_COMPAT=( python{2_7,3_6,3_7} )
7 PYTHON_REQ_USE="threads(+)"
8 USE_RUBY="ruby24 ruby25 ruby26"
9
10 inherit vim-doc flag-o-matic bash-completion-r1 python-single-r1 ruby-single desktop xdg-utils
11
12 if [[ ${PV} == 9999* ]] ; then
13         inherit git-r3
14         EGIT_REPO_URI="https://github.com/vim/vim.git"
15 else
16         SRC_URI="https://github.com/vim/vim/archive/v${PV}.tar.gz -> ${P}.tar.gz
17                 https://dev.gentoo.org/~radhermit/vim/vim-8.0.0938-gentoo-patches.tar.bz2"
18         KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~ia64 ~m68k ~mips ~ppc ~ppc64 ~riscv ~s390 ~sh ~sparc ~x86 ~ppc-aix ~x64-cygwin ~amd64-linux ~x86-linux ~ppc-macos ~x64-macos ~x86-macos ~m68k-mint ~sparc-solaris ~sparc64-solaris ~x64-solaris ~x86-solaris"
19 fi
20
21 DESCRIPTION="Vim, an improved vi-style text editor"
22 HOMEPAGE="https://vim.sourceforge.io/ https://github.com/vim/vim"
23
24 SLOT="0"
25 LICENSE="vim"
26 IUSE="X acl cscope debug gpm lua luajit minimal nls perl python racket ruby selinux sound tcl terminal vim-pager"
27 REQUIRED_USE="
28         python? ( ${PYTHON_REQUIRED_USE} )
29         vim-pager? ( !minimal )
30 "
31
32 RDEPEND="
33         >=app-eselect/eselect-vi-1.1
34         >=sys-libs/ncurses-5.2-r2:0=
35         nls? ( virtual/libintl )
36         acl? ( kernel_linux? ( sys-apps/acl ) )
37         cscope? ( dev-util/cscope )
38         gpm? ( >=sys-libs/gpm-1.19.3 )
39         lua? (
40                 luajit? ( dev-lang/luajit:2= )
41                 !luajit? ( dev-lang/lua:0[deprecated] )
42         )
43         !minimal? ( ~app-editors/vim-core-${PV} )
44         vim-pager? ( app-editors/vim-core[-minimal] )
45         perl? ( dev-lang/perl:= )
46         python? ( ${PYTHON_DEPS} )
47         racket? ( dev-scheme/racket )
48         ruby? ( ${RUBY_DEPS} )
49         selinux? ( sys-libs/libselinux )
50         sound? ( media-libs/libcanberra )
51         tcl? ( dev-lang/tcl:0= )
52         X? ( x11-libs/libXt )
53 "
54
55 DEPEND="
56         ${RDEPEND}
57         sys-devel/autoconf
58         nls? ( sys-devel/gettext )
59 "
60
61 pkg_setup() {
62         # people with broken alphabets run into trouble. bug 82186.
63         unset LANG LC_ALL
64         export LC_COLLATE="C"
65
66         # Gnome sandbox silliness. bug #114475.
67         mkdir -p "${T}"/home || die "mkdir failed"
68         export HOME="${T}"/home
69
70         use python && python-single-r1_pkg_setup
71 }
72
73 src_prepare() {
74         if [[ ${PV} != 9999* ]] ; then
75                 # Gentoo patches to fix runtime issues, cross-compile errors, etc
76                 eapply "${WORKDIR}"/patches/
77         fi
78
79         # Fixup a script to use awk instead of nawk
80         sed -i -e \
81                 '1s|.*|#!'"${EPREFIX}"'/usr/bin/awk -f|' \
82                 "${S}"/runtime/tools/mve.awk || die "mve.awk sed failed"
83
84         # Read vimrc and gvimrc from /etc/vim
85         echo '#define SYS_VIMRC_FILE "'${EPREFIX}'/etc/vim/vimrc"' \
86                 >> "${S}"/src/feature.h || die "echo failed"
87         echo '#define SYS_GVIMRC_FILE "'${EPREFIX}'/etc/vim/gvimrc"' \
88                 >> "${S}"/src/feature.h || die "echo failed"
89
90         # Use exuberant ctags which installs as /usr/bin/exuberant-ctags.
91         # Hopefully this pattern won't break for a while at least.
92         # This fixes bug 29398 (27 Sep 2003 agriffis)
93         sed -i -e \
94                 's/\<ctags\("\| [-*.]\)/exuberant-&/g' \
95                 "${S}"/runtime/doc/syntax.txt \
96                 "${S}"/runtime/doc/tagsrch.txt \
97                 "${S}"/runtime/doc/usr_29.txt \
98                 "${S}"/runtime/menu.vim \
99                 "${S}"/src/configure.ac || die 'sed failed'
100
101         # Don't be fooled by /usr/include/libc.h.  When found, vim thinks
102         # this is NeXT, but it's actually just a file in dev-libs/9libs
103         # This fixes bug 43885 (20 Mar 2004 agriffis)
104         sed -i -e \
105                 's/ libc\.h / /' \
106                 "${S}"/src/configure.ac || die 'sed failed'
107
108         # gcc on sparc32 has this, uhm, interesting problem with detecting EOF
109         # correctly. To avoid some really entertaining error messages about stuff
110         # which isn't even in the source file being invalid, we'll do some trickery
111         # to make the error never occur. bug 66162 (02 October 2004 ciaranm)
112         find "${S}" -name '*.c' | while read c; do
113             echo >> "$c" || die "echo failed"
114         done
115
116         # conditionally make the manpager.sh script
117         if use vim-pager; then
118                 cat > "${S}"/runtime/macros/manpager.sh <<-_EOF_ || die "cat EOF failed"
119                         #!/bin/sh
120                         sed -e 's/\x1B\[[[:digit:]]\+m//g' | col -b | \\
121                                         vim \\
122                                                 -c 'let no_plugin_maps = 1' \\
123                                                 -c 'set nolist nomod ft=man ts=8' \\
124                                                 -c 'let g:showmarks_enable=0' \\
125                                                 -c 'runtime! macros/less.vim' -
126                         _EOF_
127         fi
128
129         # Try to avoid sandbox problems. Bug #114475.
130         if [[ -d "${S}"/src/po ]]; then
131                 sed -i -e \
132                         '/-S check.vim/s,..VIM.,ln -s $(VIM) testvim \; ./testvim -X,' \
133                         "${S}"/src/po/Makefile || die "sed failed"
134         fi
135
136         cp -v "${S}"/src/config.mk.dist "${S}"/src/auto/config.mk || die "cp failed"
137
138         sed -i -e \
139                 "s:\\\$(PERLLIB)/ExtUtils/xsubpp:${EPREFIX}/usr/bin/xsubpp:" \
140                 "${S}"/src/Makefile || die 'sed for ExtUtils-ParseXS failed'
141
142         eapply_user
143 }
144
145 src_configure() {
146         local myconf=()
147
148         # Fix bug 37354: Disallow -funroll-all-loops on amd64
149         # Bug 57859 suggests that we want to do this for all archs
150         filter-flags -funroll-all-loops
151
152         # Fix bug 76331: -O3 causes problems, use -O2 instead. We'll do this for
153         # everyone since previous flag filtering bugs have turned out to affect
154         # multiple archs...
155         replace-flags -O3 -O2
156
157         # Fix bug 18245: Prevent "make" from the following chain:
158         # (1) Notice configure.ac is newer than auto/configure
159         # (2) Rebuild auto/configure
160         # (3) Notice auto/configure is newer than auto/config.mk
161         # (4) Run ./configure (with wrong args) to remake auto/config.mk
162         sed -i 's# auto/config\.mk:#:#' src/Makefile || die "Makefile sed failed"
163         rm src/auto/configure || die "rm failed"
164         emake -j1 -C src autoconf
165
166         # This should fix a sandbox violation (see bug 24447). The hvc
167         # things are for ppc64, see bug 86433.
168         for file in /dev/pty/s* /dev/console /dev/hvc/* /dev/hvc*; do
169                 if [[ -e "${file}" ]]; then
170                         addwrite $file
171                 fi
172         done
173
174         if use minimal; then
175                 myconf=(
176                         --with-features=tiny
177                         --disable-nls
178                         --disable-canberra
179                         --disable-acl
180                         --enable-gui=no
181                         --without-x
182                         --disable-darwin
183                         --disable-luainterp
184                         --disable-perlinterp
185                         --disable-pythoninterp
186                         --disable-mzschemeinterp
187                         --disable-rubyinterp
188                         --disable-selinux
189                         --disable-tclinterp
190                         --disable-gpm
191                 )
192         else
193                 use debug && append-flags "-DDEBUG"
194
195                 myconf=(
196                         --with-features=huge
197                         $(use_enable sound canberra)
198                         $(use_enable acl)
199                         $(use_enable cscope)
200                         $(use_enable gpm)
201                         $(use_enable lua luainterp)
202                         $(usex lua "--with-lua-prefix=${EPREFIX}/usr" "")
203                         $(use_with luajit)
204                         $(use_enable nls)
205                         $(use_enable perl perlinterp)
206                         $(use_enable python pythoninterp)
207                         $(use_enable python python3interp)
208                         $(use_with python python-command $(type -P $(eselect python show --python2)))
209                         $(use_with python python3-command $(type -P $(eselect python show --python3)))
210                         $(use_enable racket mzschemeinterp)
211                         $(use_enable ruby rubyinterp)
212                         $(use_enable selinux)
213                         $(use_enable tcl tclinterp)
214                         $(use_enable terminal)
215                 )
216
217                 # --with-features=huge forces on cscope even if we --disable it. We need
218                 # to sed this out to avoid screwiness. (1 Sep 2004 ciaranm)
219                 if ! use cscope; then
220                         sed -i -e \
221                                 '/# define FEAT_CSCOPE/d' src/feature.h || die "sed failed"
222                 fi
223
224                 # don't test USE=X here ... see bug #19115
225                 # but need to provide a way to link against X ... see bug #20093
226                 myconf+=(
227                         --enable-gui=no
228                         --disable-darwin
229                         $(use_with X x)
230                 )
231         fi
232
233         # let package manager strip binaries
234         export ac_cv_prog_STRIP="$(type -P true ) faking strip"
235
236         # keep prefix env contained within the EPREFIX
237         use prefix && myconf+=( --without-local-dir )
238
239         econf \
240                 --with-modified-by=Gentoo-${PVR} \
241                 "${myconf[@]}"
242 }
243
244 src_compile() {
245         # The following allows emake to be used
246         emake -j1 -C src auto/osdef.h objects
247
248         emake
249 }
250
251 src_test() {
252         einfo
253         einfo "Starting vim tests. Several error messages will be shown"
254         einfo "while the tests run. This is normal behaviour and does not"
255         einfo "indicate a fault."
256         einfo
257         ewarn "If the tests fail, your terminal may be left in a strange"
258         ewarn "state. Usually, running 'reset' will fix this."
259         einfo
260
261         # Don't let vim talk to X
262         unset DISPLAY
263
264         emake -j1 -C src/testdir nongui
265 }
266
267 # Call eselect vi update with --if-unset
268 # to respect user's choice (bug 187449)
269 eselect_vi_update() {
270         einfo "Calling eselect vi update..."
271         eselect vi update --if-unset
272         eend $?
273 }
274
275 src_install() {
276         local vimfiles=/usr/share/vim/vim${VIM_VERSION/.}
277
278         # Note: Do not install symlinks for 'vi', 'ex', or 'view', as these are
279         #       managed by eselect-vi
280         dobin src/vim
281         dosym vim /usr/bin/vimdiff
282         dosym vim /usr/bin/rvim
283         dosym vim /usr/bin/rview
284         if use vim-pager ; then
285                 dosym ${vimfiles}/macros/less.sh /usr/bin/vimpager
286                 dosym ${vimfiles}/macros/manpager.sh /usr/bin/vimmanpager
287                 insinto ${vimfiles}/macros
288                 doins runtime/macros/manpager.sh
289                 fperms a+x ${vimfiles}/macros/manpager.sh
290         fi
291
292         domenu runtime/vim.desktop
293
294         newbashcomp "${FILESDIR}"/${PN}-completion ${PN}
295
296         # keep in sync with 'complete ... -F' list
297         bashcomp_alias vim ex vi view rvim rview vimdiff
298 }
299
300 pkg_postinst() {
301         # Update documentation tags (from vim-doc.eclass)
302         update_vim_helptags
303
304         # Call eselect vi update
305         eselect_vi_update
306
307         # update desktop file mime cache
308         xdg_desktop_database_update
309 }
310
311 pkg_postrm() {
312         # Update documentation tags (from vim-doc.eclass)
313         update_vim_helptags
314
315         # Call eselect vi update
316         eselect_vi_update
317
318         # update desktop file mime cache
319         xdg_desktop_database_update
320 }