259fb7f0e46b033403acdc8a9ef625c268ec39e6
[gentoo.git] / app-editors / emacs / emacs-23.4-r18.ebuild
1 # Copyright 1999-2020 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
3
4 EAPI=7
5 WANT_AUTOMAKE="none"
6
7 inherit autotools elisp-common flag-o-matic readme.gentoo-r1 toolchain-funcs
8
9 DESCRIPTION="The extensible, customizable, self-documenting real-time display editor"
10 HOMEPAGE="https://www.gnu.org/software/emacs/"
11 SRC_URI="mirror://gnu/emacs/${P}.tar.bz2
12         https://dev.gentoo.org/~ulm/emacs/${P}-patches-23.tar.xz"
13
14 LICENSE="GPL-3+ FDL-1.3+ BSD HPND MIT W3C unicode PSF-2"
15 SLOT="23"
16 KEYWORDS="~alpha amd64 arm hppa ia64 ~mips ppc ppc64 ~sh ~sparc x86 ~amd64-linux ~x86-linux ~ppc-macos ~x86-macos"
17 IUSE="alsa aqua athena dbus games gconf gif gpm gtk gzip-el jpeg kerberos livecd m17n-lib motif png sound source svg tiff toolkit-scroll-bars X Xaw3d xft +xpm"
18 REQUIRED_USE="?? ( aqua X )"
19
20 RDEPEND="sys-libs/ncurses:0=
21         >=app-eselect/eselect-emacs-1.16
22         >=app-emacs/emacs-common-gentoo-1.5[games?,X?]
23         net-libs/liblockfile
24         kerberos? ( virtual/krb5 )
25         alsa? ( media-libs/alsa-lib )
26         games? ( acct-group/gamestat )
27         gpm? ( sys-libs/gpm )
28         dbus? ( sys-apps/dbus )
29         X? (
30                 x11-libs/libICE
31                 x11-libs/libSM
32                 x11-libs/libX11
33                 x11-misc/xbitmaps
34                 gconf? ( >=gnome-base/gconf-2.26.2 )
35                 gif? ( media-libs/giflib:0= )
36                 jpeg? ( virtual/jpeg:0= )
37                 png? ( >=media-libs/libpng-1.4:0= )
38                 svg? ( >=gnome-base/librsvg-2.0 )
39                 tiff? ( media-libs/tiff:0 )
40                 xpm? ( x11-libs/libXpm )
41                 xft? (
42                         media-libs/fontconfig
43                         media-libs/freetype
44                         x11-libs/libXft
45                         x11-libs/libXrender
46                         m17n-lib? (
47                                 >=dev-libs/libotf-0.9.4
48                                 >=dev-libs/m17n-lib-1.5.1
49                         )
50                 )
51                 gtk? ( x11-libs/gtk+:2 )
52                 !gtk? (
53                         motif? (
54                                 >=x11-libs/motif-2.3:0
55                                 x11-libs/libXpm
56                                 x11-libs/libXext
57                                 x11-libs/libXmu
58                                 x11-libs/libXt
59                         )
60                         !motif? (
61                                 Xaw3d? (
62                                         x11-libs/libXaw3d
63                                         x11-libs/libXext
64                                         x11-libs/libXmu
65                                         x11-libs/libXt
66                                 )
67                                 !Xaw3d? ( athena? (
68                                         x11-libs/libXaw
69                                         x11-libs/libXext
70                                         x11-libs/libXmu
71                                         x11-libs/libXt
72                                 ) )
73                         )
74                 )
75         )"
76
77 DEPEND="${RDEPEND}
78         X? ( x11-base/xorg-proto )"
79
80 BDEPEND="alsa? ( virtual/pkgconfig )
81         dbus? ( virtual/pkgconfig )
82         X? ( virtual/pkgconfig )
83         gzip-el? ( app-arch/gzip )"
84
85 EMACS_SUFFIX="emacs-${SLOT}"
86 SITEFILE="20${EMACS_SUFFIX}-gentoo.el"
87 # FULL_VERSION keeps the full version number, which is needed in
88 # order to determine some path information correctly for copy/move
89 # operations later on
90 FULL_VERSION="${PV%%_*}"
91 S="${WORKDIR}/emacs-${FULL_VERSION}"
92
93 src_prepare() {
94         eapply ../patch
95         eapply_user
96
97         sed -i -e "/^\\.so/s/etags/&-${EMACS_SUFFIX}/" doc/man/ctags.1 \
98                 || die "unable to sed ctags.1"
99
100         if ! use alsa; then
101                 # ALSA is detected even if not requested by its USE flag.
102                 # Suppress it by supplying pkg-config with a wrong library name.
103                 sed -i -e "/ALSA_MODULES=/s/alsa/DiSaBlEaLsA/" configure.in \
104                         || die "unable to sed configure.in"
105         fi
106         if ! use gzip-el; then
107                 # Emacs' build system automatically detects the gzip binary and
108                 # compresses el files. We don't want that so confuse it with a
109                 # wrong binary name
110                 sed -i -e "s/ gzip/ PrEvEnTcOmPrEsSiOn/" configure.in \
111                         || die "unable to sed configure.in"
112         fi
113
114         mv configure.in configure.ac || die
115         eautoreconf
116         touch src/stamp-h.in || die
117 }
118
119 src_configure() {
120         strip-flags
121         filter-flags -fstrict-aliasing -pie
122         append-flags $(test-flags -fno-strict-aliasing)
123         append-ldflags $(test-flags -no-pie)    #639568
124
125         if use sh; then
126                 replace-flags "-O[1-9]" -O0             #262359
127         elif use ia64; then
128                 replace-flags "-O[2-9]" -O1             #325373
129         else
130                 replace-flags "-O[3-9]" -O2
131         fi
132
133         # Don't trigger a floating point exception for NaNs on alpha
134         use alpha && append-flags -mieee
135
136         local myconf
137
138         if use alsa && ! use sound; then
139                 einfo "Although sound USE flag is disabled you chose to have alsa,"
140                 einfo "so sound is switched on anyway."
141                 myconf+=" --with-sound"
142         else
143                 myconf+=" $(use_with sound)"
144         fi
145
146         if use X; then
147                 myconf+=" --with-x --without-ns"
148                 myconf+=" $(use_with gconf)"
149                 myconf+=" $(use_with toolkit-scroll-bars)"
150                 myconf+=" $(use_with gif)"
151                 myconf+=" $(use_with jpeg)"
152                 myconf+=" $(use_with png)"
153                 myconf+=" $(use_with svg rsvg)"
154                 myconf+=" $(use_with tiff)"
155                 myconf+=" $(use_with xpm)"
156
157                 if use xft; then
158                         myconf+=" --with-xft"
159                         myconf+=" $(use_with m17n-lib libotf)"
160                         myconf+=" $(use_with m17n-lib m17n-flt)"
161                 else
162                         myconf+=" --without-xft"
163                         myconf+=" --without-libotf --without-m17n-flt"
164                         use m17n-lib && ewarn \
165                                 "USE flag \"m17n-lib\" has no effect if \"xft\" is not set."
166                 fi
167
168                 # GTK+ is the default toolkit if USE=gtk is chosen with other
169                 # possibilities. Emacs upstream thinks this should be standard
170                 # policy on all distributions
171                 local f
172                 if use gtk; then
173                         einfo "Configuring to build with GIMP Toolkit (GTK+)"
174                         myconf+=" --with-x-toolkit=gtk"
175                         for f in motif Xaw3d athena; do
176                                 use ${f} && ewarn \
177                                         "USE flag \"${f}\" has no effect if \"gtk\" is set."
178                         done
179                 elif use motif; then
180                         einfo "Configuring to build with Motif toolkit"
181                         myconf+=" --with-x-toolkit=motif"
182                         for f in Xaw3d athena; do
183                                 use ${f} && ewarn \
184                                         "USE flag \"${f}\" has no effect if \"motif\" is set."
185                         done
186                 elif use athena || use Xaw3d; then
187                         einfo "Configuring to build with Athena/Lucid toolkit"
188                         myconf+=" --with-x-toolkit=lucid $(use_with Xaw3d xaw3d)"
189                 else
190                         einfo "Configuring to build with no toolkit"
191                         myconf+=" --with-x-toolkit=no"
192                 fi
193         elif use aqua; then
194                 einfo "Configuring to build with Nextstep (Cocoa) support"
195                 myconf+=" --with-ns --disable-ns-self-contained"
196                 myconf+=" --without-x"
197         else
198                 myconf+=" --without-x --without-ns"
199         fi
200
201         # According to configure, this option is only used for GNU/Linux
202         # (x86_64 and s390). For Gentoo Prefix we have to explicitly spell
203         # out the location because $(get_libdir) does not necessarily return
204         # something that matches the host OS's libdir naming (e.g. RHEL).
205         local crtdir=$($(tc-getCC) -print-file-name=crt1.o)
206         crtdir=${crtdir%/*}
207
208         econf \
209                 --program-suffix="-${EMACS_SUFFIX}" \
210                 --infodir="${EPREFIX}"/usr/share/info/${EMACS_SUFFIX} \
211                 --localstatedir="${EPREFIX}"/var \
212                 --enable-locallisppath="${EPREFIX}/etc/emacs:${EPREFIX}${SITELISP}" \
213                 --with-crt-dir="${crtdir}" \
214                 --with-gameuser=":gamestat" \
215                 --without-hesiod \
216                 $(use_with kerberos) $(use_with kerberos kerberos5) \
217                 $(use_with gpm) \
218                 $(use_with dbus) \
219                 ${myconf}
220 }
221
222 src_compile() {
223         # Disable sandbox when dumping. For the unbelievers, see bug #131505
224         emake CC="$(tc-getCC)" \
225                 AR="$(tc-getAR) cq" \
226                 RANLIB="$(tc-getRANLIB)" \
227                 RUN_TEMACS="SANDBOX_ON=0 LD_PRELOAD= env ./temacs"
228 }
229
230 src_install() {
231         emake DESTDIR="${D}" install
232
233         rm "${ED}"/usr/bin/emacs-${FULL_VERSION}-${EMACS_SUFFIX} \
234                 || die "removing duplicate emacs executable failed"
235         mv "${ED}"/usr/bin/emacs-${EMACS_SUFFIX} "${ED}"/usr/bin/${EMACS_SUFFIX} \
236                 || die "moving emacs executable failed"
237
238         # move man pages to the correct place
239         local m
240         mv "${ED}"/usr/share/man/man1/{emacs,${EMACS_SUFFIX}}.1 \
241                 || die "moving emacs man page failed"
242         for m in b2m ctags ebrowse emacsclient etags grep-changelog rcs-checkin; do
243                 mv "${ED}"/usr/share/man/man1/${m}{,-${EMACS_SUFFIX}}.1 \
244                         || die "moving ${m} man page failed"
245         done
246
247         # move info dir to avoid collisions with the dir file generated by portage
248         mv "${ED}"/usr/share/info/${EMACS_SUFFIX}/dir{,.orig} \
249                 || die "moving info dir failed"
250         touch "${ED}"/usr/share/info/${EMACS_SUFFIX}/.keepinfodir
251         docompress -x /usr/share/info/${EMACS_SUFFIX}/dir.orig
252
253         # avoid collision between slots, see bug #169033 e.g.
254         rm "${ED}"/usr/share/emacs/site-lisp/subdirs.el
255         rm -rf "${ED}"/usr/share/{applications,icons}
256         rm -rf "${ED}"/var
257
258         # remove unused <version>/site-lisp dir
259         rm -rf "${ED}"/usr/share/emacs/${FULL_VERSION}/site-lisp
260
261         # remove COPYING file (except for etc/COPYING used by describe-copying)
262         rm "${ED}"/usr/share/emacs/${FULL_VERSION}/lisp/COPYING
263
264         local cdir
265         if use source; then
266                 cdir="/usr/share/emacs/${FULL_VERSION}/src"
267                 insinto "${cdir}"
268                 # This is not meant to install all the source -- just the
269                 # C source you might find via find-function
270                 doins src/*.{c,h,m}
271                 doins -r src/{m,s}
272                 rm "${ED}"/usr/share/emacs/${FULL_VERSION}/src/Makefile.c
273                 rm "${ED}"/usr/share/emacs/${FULL_VERSION}/src/{m,s}/README
274         elif has installsources ${FEATURES}; then
275                 cdir="/usr/src/debug/${CATEGORY}/${PF}/${S#"${WORKDIR}/"}/src"
276         fi
277
278         sed -e "${cdir:+#}/^Y/d" -e "s/^[XY]//" >"${T}/${SITEFILE}" <<-EOF || die
279         X
280         ;;; ${EMACS_SUFFIX} site-lisp configuration
281         X
282         (when (string-match "\\\\\`${FULL_VERSION//./\\\\.}\\\\>" emacs-version)
283         Y  (setq find-function-C-source-directory
284         Y       "${EPREFIX}${cdir}")
285         X  (let ((path (getenv "INFOPATH"))
286         X       (dir "${EPREFIX}/usr/share/info/${EMACS_SUFFIX}")
287         X       (re "\\\\\`${EPREFIX}/usr/share\\\\>"))
288         X    (and path
289         X        ;; move Emacs Info dir before anything else in /usr/share
290         X        (let* ((p (cons nil (split-string path ":" t))) (q p))
291         X          (while (and (cdr q) (not (string-match re (cadr q))))
292         X            (setq q (cdr q)))
293         X          (setcdr q (cons dir (delete dir (cdr q))))
294         X          (setq Info-directory-list (prune-directory-list (cdr p)))))))
295         EOF
296         elisp-site-file-install "${T}/${SITEFILE}" || die
297
298         dodoc README BUGS
299
300         if use aqua; then
301                 dodir /Applications/Gentoo
302                 rm -rf "${ED}"/Applications/Gentoo/${EMACS_SUFFIX^}.app
303                 mv nextstep/Emacs.app \
304                         "${ED}"/Applications/Gentoo/${EMACS_SUFFIX^}.app || die
305         fi
306
307         local DOC_CONTENTS="You can set the version to be started by
308                 /usr/bin/emacs through the Emacs eselect module, which also
309                 redirects man and info pages. Therefore, several Emacs versions can
310                 be installed at the same time. \"man emacs.eselect\" for details.
311                 \\n\\nIf you upgrade from a previous major version of Emacs, then
312                 it is strongly recommended that you use app-admin/emacs-updater
313                 to rebuild all byte-compiled elisp files of the installed Emacs
314                 packages."
315         use X && DOC_CONTENTS+="\\n\\nYou need to install some fonts for Emacs.
316                 Installing media-fonts/font-adobe-{75,100}dpi on the X server's
317                 machine would satisfy basic Emacs requirements under X11.
318                 See also https://wiki.gentoo.org/wiki/Xft_support_for_GNU_Emacs
319                 for how to enable anti-aliased fonts."
320         use aqua && DOC_CONTENTS+="\\n\\n${EMACS_SUFFIX^}.app is in
321                 \"${EPREFIX}/Applications/Gentoo\". You may want to copy or symlink
322                 it into /Applications by yourself."
323         readme.gentoo_create_doc
324 }
325
326 pkg_preinst() {
327         # move Info dir file to correct name
328         if [[ -d ${ED}/usr/share/info ]]; then
329                 mv "${ED}"/usr/share/info/${EMACS_SUFFIX}/dir{.orig,} || die
330         fi
331 }
332
333 pkg_postinst() {
334         elisp-site-regen
335         readme.gentoo_print_elog
336
337         if use livecd; then
338                 # force an update of the emacs symlink for the livecd/dvd,
339                 # because some microemacs packages set it with USE=livecd
340                 eselect emacs update
341         elif [[ $(readlink "${EROOT}"/usr/bin/emacs) = ${EMACS_SUFFIX} ]]; then
342                 # refresh symlinks in case any installed files have changed
343                 eselect emacs set ${EMACS_SUFFIX}
344         else
345                 eselect emacs update ifunset
346         fi
347 }
348
349 pkg_postrm() {
350         elisp-site-regen
351         eselect emacs update ifunset
352 }