Merge branch 'gammu'
[gentoo.git] / app-editors / vim / vim-9999.ebuild
1 # Copyright 1999-2016 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Id$
4
5 EAPI=5
6 VIM_VERSION="7.4"
7 PYTHON_COMPAT=( python{2_7,3_3,3_4,3_5} )
8 PYTHON_REQ_USE=threads
9 inherit eutils vim-doc flag-o-matic fdo-mime versionator bash-completion-r1 python-r1
10
11 if [[ ${PV} == 9999* ]] ; then
12         inherit git-r3
13         EGIT_REPO_URI="https://github.com/vim/vim.git"
14 else
15         SRC_URI="https://github.com/vim/vim/archive/v${PV}.tar.gz -> ${P}.tar.gz
16                 https://dev.gentoo.org/~radhermit/vim/vim-7.4.827-gentoo-patches.tar.bz2"
17         KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~ia64 ~m68k ~mips ~ppc ~ppc64 ~s390 ~sh ~sparc ~x86 ~ppc-aix ~amd64-fbsd ~sparc-fbsd ~x86-fbsd ~x64-freebsd ~x86-freebsd ~hppa-hpux ~ia64-hpux ~x86-interix ~amd64-linux ~x86-linux ~ppc-macos ~x64-macos ~x86-macos ~m68k-mint ~sparc-solaris ~sparc64-solaris ~x64-solaris ~x86-solaris"
18 fi
19
20 DESCRIPTION="Vim, an improved vi-style text editor"
21 HOMEPAGE="http://www.vim.org/ https://github.com/vim/vim"
22
23 SLOT="0"
24 LICENSE="vim"
25 IUSE="X acl cscope debug gpm lua luajit minimal nls perl python racket ruby selinux tcl vim-pager"
26 REQUIRED_USE="
27         luajit? ( lua )
28         python? (
29                 || ( $(python_gen_useflags '*') )
30                 ?? ( $(python_gen_useflags 'python2*') )
31                 ?? ( $(python_gen_useflags 'python3*') )
32         )
33 "
34
35 RDEPEND="
36         >=app-eselect/eselect-vi-1.1
37         >=sys-libs/ncurses-5.2-r2:=
38         nls? ( virtual/libintl )
39         acl? ( kernel_linux? ( sys-apps/acl ) )
40         cscope? ( dev-util/cscope )
41         gpm? ( >=sys-libs/gpm-1.19.3 )
42         lua? (
43                 luajit? ( dev-lang/luajit:2= )
44                 !luajit? ( dev-lang/lua:0[deprecated] )
45         )
46         !minimal? (
47                 ~app-editors/vim-core-${PV}
48                 dev-util/ctags
49         )
50         perl? ( dev-lang/perl:= )
51         python? ( ${PYTHON_DEPS} )
52         racket? ( dev-scheme/racket )
53         ruby? ( || ( dev-lang/ruby:2.3 dev-lang/ruby:2.2 dev-lang/ruby:2.1 dev-lang/ruby:2.0 ) )
54         selinux? ( sys-libs/libselinux )
55         tcl? ( dev-lang/tcl:0= )
56         X? ( x11-libs/libXt )
57 "
58 DEPEND="${RDEPEND}
59         sys-devel/autoconf
60         nls? ( sys-devel/gettext )
61 "
62
63 pkg_setup() {
64         # people with broken alphabets run into trouble. bug 82186.
65         unset LANG LC_ALL
66         export LC_COLLATE="C"
67
68         # Gnome sandbox silliness. bug #114475.
69         mkdir -p "${T}"/home
70         export HOME="${T}"/home
71 }
72
73 src_prepare() {
74         if [[ ${PV} != 9999* ]] ; then
75                 if [[ -d "${WORKDIR}"/patches/ ]]; then
76                         # Gentoo patches to fix runtime issues, cross-compile errors, etc
77                         EPATCH_SUFFIX="patch" EPATCH_FORCE="yes" \
78                                 epatch "${WORKDIR}"/patches/
79                 fi
80         fi
81
82         # Fixup a script to use awk instead of nawk
83         sed -i '1s|.*|#!'"${EPREFIX}"'/usr/bin/awk -f|' "${S}"/runtime/tools/mve.awk \
84                 || die "mve.awk sed failed"
85
86         # Read vimrc and gvimrc from /etc/vim
87         echo '#define SYS_VIMRC_FILE "'${EPREFIX}'/etc/vim/vimrc"' >> "${S}"/src/feature.h
88         echo '#define SYS_GVIMRC_FILE "'${EPREFIX}'/etc/vim/gvimrc"' >> "${S}"/src/feature.h
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 's/\<ctags\("\| [-*.]\)/exuberant-&/g' \
94                 "${S}"/runtime/doc/syntax.txt \
95                 "${S}"/runtime/doc/tagsrch.txt \
96                 "${S}"/runtime/doc/usr_29.txt \
97                 "${S}"/runtime/menu.vim \
98                 "${S}"/src/configure.in || die 'sed failed'
99
100         # Don't be fooled by /usr/include/libc.h.  When found, vim thinks
101         # this is NeXT, but it's actually just a file in dev-libs/9libs
102         # This fixes bug 43885 (20 Mar 2004 agriffis)
103         sed -i 's/ libc\.h / /' "${S}"/src/configure.in || die 'sed failed'
104
105         # gcc on sparc32 has this, uhm, interesting problem with detecting EOF
106         # correctly. To avoid some really entertaining error messages about stuff
107         # which isn't even in the source file being invalid, we'll do some trickery
108         # to make the error never occur. bug 66162 (02 October 2004 ciaranm)
109         find "${S}" -name '*.c' | while read c ; do echo >> "$c" ; done
110
111         # conditionally make the manpager.sh script
112         if use vim-pager ; then
113                 cat <<-END > "${S}"/runtime/macros/manpager.sh
114                         #!/bin/sh
115                         sed -e 's/\x1B\[[[:digit:]]\+m//g' | col -b | \\
116                                         vim \\
117                                                 -c 'let no_plugin_maps = 1' \\
118                                                 -c 'set nolist nomod ft=man ts=8' \\
119                                                 -c 'let g:showmarks_enable=0' \\
120                                                 -c 'runtime! macros/less.vim' -
121                         END
122         fi
123
124         # Try to avoid sandbox problems. Bug #114475.
125         if [[ -d "${S}"/src/po ]] ; then
126                 sed -i '/-S check.vim/s,..VIM.,ln -s $(VIM) testvim \; ./testvim -X,' \
127                         "${S}"/src/po/Makefile
128         fi
129
130         if version_is_at_least 7.3.122 ; then
131                 cp "${S}"/src/config.mk.dist "${S}"/src/auto/config.mk
132         fi
133
134         # Bug #378107 - Build properly with >=perl-core/ExtUtils-ParseXS-3.20.0
135         if version_is_at_least 7.3 ; then
136                 sed -i "s:\\\$(PERLLIB)/ExtUtils/xsubpp:${EPREFIX}/usr/bin/xsubpp:"     \
137                         "${S}"/src/Makefile || die 'sed for ExtUtils-ParseXS failed'
138         fi
139
140         epatch_user
141 }
142
143 src_configure() {
144         local myconf=()
145
146         # Fix bug 37354: Disallow -funroll-all-loops on amd64
147         # Bug 57859 suggests that we want to do this for all archs
148         filter-flags -funroll-all-loops
149
150         # Fix bug 76331: -O3 causes problems, use -O2 instead. We'll do this for
151         # everyone since previous flag filtering bugs have turned out to affect
152         # multiple archs...
153         replace-flags -O3 -O2
154
155         # Fix bug 18245: Prevent "make" from the following chain:
156         # (1) Notice configure.in is newer than auto/configure
157         # (2) Rebuild auto/configure
158         # (3) Notice auto/configure is newer than auto/config.mk
159         # (4) Run ./configure (with wrong args) to remake auto/config.mk
160         sed -i 's# auto/config\.mk:#:#' src/Makefile || die "Makefile sed failed"
161         rm -f src/auto/configure
162         emake -j1 -C src autoconf
163
164         # This should fix a sandbox violation (see bug 24447). The hvc
165         # things are for ppc64, see bug 86433.
166         for file in /dev/pty/s* /dev/console /dev/hvc/* /dev/hvc* ; do
167                 [[ -e ${file} ]] && addwrite $file
168         done
169
170         if use minimal ; then
171                 myconf=(
172                         --with-features=tiny
173                         --disable-nls
174                         --disable-multibyte
175                         --disable-acl
176                         --enable-gui=no
177                         --without-x
178                         --disable-darwin
179                         --disable-luainterp
180                         --disable-perlinterp
181                         --disable-pythoninterp
182                         --disable-mzschemeinterp
183                         --disable-rubyinterp
184                         --disable-selinux
185                         --disable-tclinterp
186                         --disable-gpm
187                 )
188         else
189                 use debug && append-flags "-DDEBUG"
190
191                 myconf=(
192                         --with-features=huge
193                         --enable-multibyte
194                         $(use_enable acl)
195                         $(use_enable cscope)
196                         $(use_enable gpm)
197                         $(use_enable lua luainterp)
198                         $(usex lua "--with-lua-prefix=${EPREFIX}/usr" "")
199                         $(use_with luajit)
200                         $(use_enable nls)
201                         $(use_enable perl perlinterp)
202                         $(use_enable racket mzschemeinterp)
203                         $(use_enable ruby rubyinterp)
204                         $(use_enable selinux)
205                         $(use_enable tcl tclinterp)
206                 )
207
208                 if use python ; then
209                         py_add_interp() {
210                                 local v
211
212                                 [[ ${EPYTHON} == python3* ]] && v=3
213                                 myconf+=(
214                                         --enable-python${v}interp
215                                         vi_cv_path_python${v}="${PYTHON}"
216                                 )
217                         }
218
219                         python_foreach_impl py_add_interp
220                 else
221                         myconf+=(
222                                 --disable-pythoninterp
223                                 --disable-python3interp
224                         )
225                 fi
226
227                 # --with-features=huge forces on cscope even if we --disable it. We need
228                 # to sed this out to avoid screwiness. (1 Sep 2004 ciaranm)
229                 if ! use cscope ; then
230                         sed -i '/# define FEAT_CSCOPE/d' src/feature.h || \
231                                 die "couldn't disable cscope"
232                 fi
233
234                 # don't test USE=X here ... see bug #19115
235                 # but need to provide a way to link against X ... see bug #20093
236                 myconf+=(
237                         --enable-gui=no
238                         --disable-darwin
239                         $(use_with X x)
240                 )
241         fi
242
243         # Let Portage do the stripping. Some people like that.
244         export ac_cv_prog_STRIP="$(type -P true ) faking strip"
245
246         # Keep Gentoo Prefix env contained within the EPREFIX
247         use prefix && myconf+=( --without-local-dir )
248
249         econf \
250                 --with-modified-by=Gentoo-${PVR} \
251                 "${myconf[@]}"
252 }
253
254 src_compile() {
255         # The following allows emake to be used
256         emake -j1 -C src auto/osdef.h objects
257
258         emake
259 }
260
261 src_test() {
262         echo
263         einfo "Starting vim tests. Several error messages will be shown"
264         einfo "while the tests run. This is normal behaviour and does not"
265         einfo "indicate a fault."
266         echo
267         ewarn "If the tests fail, your terminal may be left in a strange"
268         ewarn "state. Usually, running 'reset' will fix this."
269         echo
270
271         # Don't let vim talk to X
272         unset DISPLAY
273
274         # We've got to call make test from within testdir, since the Makefiles
275         # don't pass through our VIMPROG argument
276         cd "${S}"/src/testdir
277
278         # Test 49 won't work inside a portage environment
279         einfo "Test 49 isn't sandbox-friendly, so it will be skipped."
280         sed -i 's~test49.out~~g' Makefile
281
282         # We don't want to rebuild vim before running the tests
283         sed -i 's,: \$(VIMPROG),: ,' Makefile
284
285         # Don't try to do the additional GUI test
286         emake -j1 VIMPROG=../vim nongui
287 }
288
289 # Make convenience symlinks, hopefully without stepping on toes.  Some
290 # of these links are "owned" by the vim ebuild when it is installed,
291 # but they might be good for gvim as well (see bug 45828)
292 update_vim_symlinks() {
293         local f syms
294         syms="vimdiff rvim rview"
295         einfo "Calling eselect vi update..."
296         # Call this with --if-unset to respect user's choice (bug 187449)
297         eselect vi update --if-unset
298
299         # Make or remove convenience symlink, vim -> gvim
300         if [[ -f "${EROOT}"/usr/bin/gvim ]]; then
301                 ln -s gvim "${EROOT}"/usr/bin/vim 2>/dev/null
302         elif [[ -L "${EROOT}"/usr/bin/vim && ! -f "${EROOT}"/usr/bin/vim ]]; then
303                 rm "${EROOT}"/usr/bin/vim
304         fi
305
306         # Make or remove convenience symlinks to vim
307         if [[ -f "${EROOT}"/usr/bin/vim ]]; then
308                 for f in ${syms}; do
309                         ln -s vim "${EROOT}"/usr/bin/${f} 2>/dev/null
310                 done
311         else
312                 for f in ${syms}; do
313                         if [[ -L "${EROOT}"/usr/bin/${f} && ! -f "${EROOT}"/usr/bin/${f} ]]; then
314                                 rm -f "${EROOT}"/usr/bin/${f}
315                         fi
316                 done
317         fi
318
319         # This will still break if you merge then remove the vi package,
320         # but there's only so much you can do, eh?  Unfortunately we don't
321         # have triggers like are done in rpm-land.
322 }
323
324 src_install() {
325         local vimfiles=/usr/share/vim/vim${VIM_VERSION/.}
326
327         # Note: Do not install symlinks for 'vi', 'ex', or 'view', as these are
328         #       managed by eselect-vi
329         dobin src/vim
330         dosym vim /usr/bin/vimdiff
331         dosym vim /usr/bin/rvim
332         dosym vim /usr/bin/rview
333         if use vim-pager ; then
334                 dosym ${vimfiles}/macros/less.sh /usr/bin/vimpager
335                 dosym ${vimfiles}/macros/manpager.sh /usr/bin/vimmanpager
336                 insinto ${vimfiles}/macros
337                 doins runtime/macros/manpager.sh
338                 fperms a+x ${vimfiles}/macros/manpager.sh
339         fi
340
341         newbashcomp "${FILESDIR}"/${PN}-completion ${PN}
342         # keep in sync with 'complete ... -F' list
343         bashcomp_alias vim ex vi view rvim rview vimdiff
344
345         # We shouldn't be installing the ex or view man page symlinks, as they
346         # are managed by eselect-vi
347         rm -f "${ED}"/usr/share/man/man1/{ex,view}.1
348 }
349
350 pkg_postinst() {
351         # Update documentation tags (from vim-doc.eclass)
352         update_vim_helptags
353
354         # Make convenience symlinks
355         update_vim_symlinks
356 }
357
358 pkg_postrm() {
359         # Update documentation tags (from vim-doc.eclass)
360         update_vim_helptags
361
362         # Make convenience symlinks
363         update_vim_symlinks
364 }