*/*: Discontinue Gentoo SuperH port
[gentoo.git] / app-editors / emacs / emacs-27.0.90.ebuild
1 # Copyright 1999-2020 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
3
4 EAPI=7
5
6 inherit autotools elisp-common flag-o-matic readme.gentoo-r1
7
8 if [[ ${PV##*.} = 9999 ]]; then
9         inherit git-r3
10         EGIT_REPO_URI="https://git.savannah.gnu.org/git/emacs.git"
11         EGIT_BRANCH="emacs-27"
12         EGIT_CHECKOUT_DIR="${WORKDIR}/emacs"
13         S="${EGIT_CHECKOUT_DIR}"
14 else
15         SRC_URI="https://dev.gentoo.org/~ulm/distfiles/${P}.tar.xz
16                 mirror://gnu-alpha/emacs/pretest/${P}.tar.xz"
17         KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~ia64 ~mips ~ppc ~ppc64 ~riscv ~sparc ~x86 ~amd64-linux ~x86-linux ~ppc-macos ~x64-macos ~x86-macos"
18         # FULL_VERSION keeps the full version number, which is needed in
19         # order to determine some path information correctly for copy/move
20         # operations later on
21         FULL_VERSION="${PV%%_*}"
22         S="${WORKDIR}/emacs-${FULL_VERSION}"
23         [[ ${FULL_VERSION} != ${PV} ]] && S="${WORKDIR}/emacs"
24 fi
25
26 DESCRIPTION="The extensible, customizable, self-documenting real-time display editor"
27 HOMEPAGE="https://www.gnu.org/software/emacs/"
28
29 LICENSE="GPL-3+ FDL-1.3+ BSD HPND MIT W3C unicode PSF-2"
30 SLOT="27-vcs"
31 IUSE="acl alsa aqua athena cairo dbus dynamic-loading games gconf gfile gif +gmp gpm gsettings gtk gtk2 gzip-el harfbuzz imagemagick +inotify jpeg json kerberos lcms libxml2 livecd m17n-lib mailutils motif png selinux sound source ssl svg systemd +threads tiff toolkit-scroll-bars wide-int X Xaw3d xft +xpm xwidgets zlib"
32 REQUIRED_USE="?? ( aqua X )"
33 RESTRICT="test"
34
35 RDEPEND="sys-libs/ncurses:0=
36         >=app-eselect/eselect-emacs-1.16
37         >=app-emacs/emacs-common-gentoo-1.5[games?,X?]
38         acl? ( virtual/acl )
39         alsa? ( media-libs/alsa-lib )
40         dbus? ( sys-apps/dbus )
41         games? ( acct-group/gamestat )
42         gmp? ( dev-libs/gmp:0= )
43         gpm? ( sys-libs/gpm )
44         !inotify? ( gfile? ( >=dev-libs/glib-2.28.6 ) )
45         json? ( dev-libs/jansson )
46         kerberos? ( virtual/krb5 )
47         lcms? ( media-libs/lcms:2 )
48         libxml2? ( >=dev-libs/libxml2-2.2.0 )
49         mailutils? ( net-mail/mailutils[clients] )
50         !mailutils? ( net-libs/liblockfile )
51         selinux? ( sys-libs/libselinux )
52         ssl? ( net-libs/gnutls:0= )
53         systemd? ( sys-apps/systemd )
54         zlib? ( sys-libs/zlib )
55         X? (
56                 x11-libs/libICE
57                 x11-libs/libSM
58                 x11-libs/libX11
59                 x11-libs/libXext
60                 x11-libs/libXfixes
61                 x11-libs/libXinerama
62                 x11-libs/libXrandr
63                 x11-libs/libxcb
64                 x11-misc/xbitmaps
65                 gconf? ( >=gnome-base/gconf-2.26.2 )
66                 gsettings? ( >=dev-libs/glib-2.28.6 )
67                 gif? ( media-libs/giflib:0= )
68                 jpeg? ( virtual/jpeg:0= )
69                 png? ( >=media-libs/libpng-1.4:0= )
70                 svg? ( >=gnome-base/librsvg-2.0 )
71                 tiff? ( media-libs/tiff:0 )
72                 xpm? ( x11-libs/libXpm )
73                 imagemagick? ( >=media-gfx/imagemagick-6.6.2:0= )
74                 xft? (
75                         media-libs/fontconfig
76                         media-libs/freetype
77                         x11-libs/libXft
78                         x11-libs/libXrender
79                         cairo? ( >=x11-libs/cairo-1.12.18 )
80                         harfbuzz? ( media-libs/harfbuzz:0= )
81                         m17n-lib? (
82                                 >=dev-libs/libotf-0.9.4
83                                 >=dev-libs/m17n-lib-1.5.1
84                         )
85                 )
86                 gtk? (
87                         gtk2? ( x11-libs/gtk+:2 )
88                         !gtk2? (
89                                 x11-libs/gtk+:3
90                                 xwidgets? (
91                                         net-libs/webkit-gtk:4=
92                                         x11-libs/libXcomposite
93                                 )
94                         )
95                 )
96                 !gtk? (
97                         motif? (
98                                 >=x11-libs/motif-2.3:0
99                                 x11-libs/libXpm
100                                 x11-libs/libXmu
101                                 x11-libs/libXt
102                         )
103                         !motif? (
104                                 Xaw3d? (
105                                         x11-libs/libXaw3d
106                                         x11-libs/libXmu
107                                         x11-libs/libXt
108                                 )
109                                 !Xaw3d? ( athena? (
110                                         x11-libs/libXaw
111                                         x11-libs/libXmu
112                                         x11-libs/libXt
113                                 ) )
114                         )
115                 )
116         )"
117
118 DEPEND="${RDEPEND}
119         X? ( x11-base/xorg-proto )"
120
121 BDEPEND="sys-apps/texinfo
122         virtual/pkgconfig
123         gzip-el? ( app-arch/gzip )"
124
125 RDEPEND="${RDEPEND}
126         !app-editors/emacs-vcs:27"
127
128 EMACS_SUFFIX="emacs-${SLOT}"
129 SITEFILE="20${EMACS_SUFFIX}-gentoo.el"
130
131 src_prepare() {
132         if [[ ${PV##*.} = 9999 ]]; then
133                 FULL_VERSION=$(sed -n 's/^AC_INIT([^,]*,[ \t]*\([^ \t,)]*\).*/\1/p' \
134                         configure.ac)
135                 [[ ${FULL_VERSION} ]] || die "Cannot determine current Emacs version"
136                 einfo "Emacs branch: ${EGIT_BRANCH}"
137                 einfo "Commit: ${EGIT_VERSION}"
138                 einfo "Emacs version number: ${FULL_VERSION}"
139                 [[ ${FULL_VERSION} =~ ^${PV%.*}(\..*)?$ ]] \
140                         || die "Upstream version number changed to ${FULL_VERSION}"
141         fi
142
143         eapply_user
144
145         # Fix filename reference in redirected man page
146         sed -i -e "/^\\.so/s/etags/&-${EMACS_SUFFIX}/" doc/man/ctags.1 || die
147
148         AT_M4DIR=m4 eautoreconf
149 }
150
151 src_configure() {
152         strip-flags
153         filter-flags -pie                                       #526948
154
155         if use sh; then
156                 replace-flags "-O[1-9]" -O0             #262359
157         elif use ia64; then
158                 replace-flags "-O[2-9]" -O1             #325373
159         else
160                 replace-flags "-O[3-9]" -O2
161         fi
162
163         local myconf
164
165         if use alsa; then
166                 use sound || ewarn \
167                         "USE flag \"alsa\" overrides \"-sound\"; enabling sound support."
168                 myconf+=" --with-sound=alsa"
169         else
170                 myconf+=" --with-sound=$(usex sound oss)"
171         fi
172
173         if use X; then
174                 myconf+=" --with-x --without-ns"
175                 myconf+=" $(use_with gconf)"
176                 myconf+=" $(use_with gsettings)"
177                 myconf+=" $(use_with toolkit-scroll-bars)"
178                 myconf+=" $(use_with gif)"
179                 myconf+=" $(use_with jpeg)"
180                 myconf+=" $(use_with png)"
181                 myconf+=" $(use_with svg rsvg)"
182                 myconf+=" $(use_with tiff)"
183                 myconf+=" $(use_with xpm)"
184                 myconf+=" $(use_with imagemagick)"
185
186                 if use xft; then
187                         myconf+=" --with-xft"
188                         myconf+=" $(use_with cairo)"
189                         myconf+=" $(use_with harfbuzz)"
190                         myconf+=" $(use_with m17n-lib libotf)"
191                         myconf+=" $(use_with m17n-lib m17n-flt)"
192                 else
193                         myconf+=" --without-xft"
194                         myconf+=" --without-cairo"
195                         myconf+=" --without-libotf --without-m17n-flt"
196                         use cairo && ewarn \
197                                 "USE flag \"cairo\" has no effect if \"xft\" is not set."
198                         use m17n-lib && ewarn \
199                                 "USE flag \"m17n-lib\" has no effect if \"xft\" is not set."
200                 fi
201
202                 local f line
203                 if use gtk; then
204                         einfo "Configuring to build with GIMP Toolkit (GTK+)"
205                         while read line; do ewarn "${line}"; done <<-EOF
206                                 Your version of GTK+ will have problems with closing open
207                                 displays. This is no problem if you just use one display, but
208                                 if you use more than one and close one of them Emacs may crash.
209                                 See <https://bugzilla.gnome.org/show_bug.cgi?id=85715>.
210                                 If you intend to use more than one display, then it is strongly
211                                 recommended that you compile Emacs with the Athena/Lucid or the
212                                 Motif toolkit instead.
213                         EOF
214                         if use gtk2; then
215                                 myconf+=" --with-x-toolkit=gtk2 --without-xwidgets"
216                                 use xwidgets && ewarn \
217                                         "USE flag \"xwidgets\" has no effect if \"gtk2\" is set."
218                         else
219                                 myconf+=" --with-x-toolkit=gtk3 $(use_with xwidgets)"
220                         fi
221                         for f in motif Xaw3d athena; do
222                                 use ${f} && ewarn \
223                                         "USE flag \"${f}\" has no effect if \"gtk\" is set."
224                         done
225                 elif use motif; then
226                         einfo "Configuring to build with Motif toolkit"
227                         myconf+=" --with-x-toolkit=motif"
228                         for f in Xaw3d athena; do
229                                 use ${f} && ewarn \
230                                         "USE flag \"${f}\" has no effect if \"motif\" is set."
231                         done
232                 elif use athena || use Xaw3d; then
233                         einfo "Configuring to build with Athena/Lucid toolkit"
234                         myconf+=" --with-x-toolkit=lucid $(use_with Xaw3d xaw3d)"
235                 else
236                         einfo "Configuring to build with no toolkit"
237                         myconf+=" --with-x-toolkit=no"
238                 fi
239                 if ! use gtk; then
240                         use gtk2 && ewarn \
241                                 "USE flag \"gtk2\" has no effect if \"gtk\" is not set."
242                         use xwidgets && ewarn \
243                                 "USE flag \"xwidgets\" has no effect if \"gtk\" is not set."
244                 fi
245         elif use aqua; then
246                 einfo "Configuring to build with Nextstep (Cocoa) support"
247                 myconf+=" --with-ns --disable-ns-self-contained"
248                 myconf+=" --without-x"
249         else
250                 myconf+=" --without-x --without-ns"
251         fi
252
253         econf \
254                 --program-suffix="-${EMACS_SUFFIX}" \
255                 --includedir="${EPREFIX}"/usr/include/${EMACS_SUFFIX} \
256                 --infodir="${EPREFIX}"/usr/share/info/${EMACS_SUFFIX} \
257                 --localstatedir="${EPREFIX}"/var \
258                 --enable-locallisppath="${EPREFIX}/etc/emacs:${EPREFIX}${SITELISP}" \
259                 --without-compress-install \
260                 --without-hesiod \
261                 --without-pop \
262                 --with-dumping=pdumper \
263                 --with-file-notification=$(usev inotify || usev gfile || echo no) \
264                 $(use_enable acl) \
265                 $(use_with dbus) \
266                 $(use_with dynamic-loading modules) \
267                 $(use_with games gameuser ":gamestat") \
268                 $(use_with gmp libgmp) \
269                 $(use_with gpm) \
270                 $(use_with json) \
271                 $(use_with kerberos) $(use_with kerberos kerberos5) \
272                 $(use_with lcms lcms2) \
273                 $(use_with libxml2 xml2) \
274                 $(use_with mailutils) \
275                 $(use_with selinux) \
276                 $(use_with ssl gnutls) \
277                 $(use_with systemd libsystemd) \
278                 $(use_with threads) \
279                 $(use_with wide-int) \
280                 $(use_with zlib) \
281                 ${myconf}
282 }
283
284 #src_compile() {
285 #       # Disable sandbox when dumping. For the unbelievers, see bug #131505
286 #       emake RUN_TEMACS="SANDBOX_ON=0 LD_PRELOAD= env ./temacs"
287 #}
288
289 src_install() {
290         emake DESTDIR="${D}" NO_BIN_LINK=t install
291
292         mv "${ED}"/usr/bin/{emacs-${FULL_VERSION}-,}${EMACS_SUFFIX} || die
293         mv "${ED}"/usr/share/man/man1/{emacs-,}${EMACS_SUFFIX}.1 || die
294         mv "${ED}"/usr/share/metainfo/{emacs-,}${EMACS_SUFFIX}.appdata.xml || die
295
296         # move info dir to avoid collisions with the dir file generated by portage
297         mv "${ED}"/usr/share/info/${EMACS_SUFFIX}/dir{,.orig} || die
298         touch "${ED}"/usr/share/info/${EMACS_SUFFIX}/.keepinfodir
299         docompress -x /usr/share/info/${EMACS_SUFFIX}/dir.orig
300
301         # avoid collision between slots, see bug #169033 e.g.
302         rm "${ED}"/usr/share/emacs/site-lisp/subdirs.el
303         rm -rf "${ED}"/usr/share/{appdata,applications,icons}
304         rm -rf "${ED}/usr/$(get_libdir)"
305         rm -rf "${ED}"/var
306
307         # remove unused <version>/site-lisp dir
308         rm -rf "${ED}"/usr/share/emacs/${FULL_VERSION}/site-lisp
309
310         # remove COPYING file (except for etc/COPYING used by describe-copying)
311         rm "${ED}"/usr/share/emacs/${FULL_VERSION}/lisp/COPYING
312
313         if use systemd; then
314                 insinto /usr/lib/systemd/user
315                 sed -e "/^##/d" \
316                         -e "/^ExecStart/s,emacs,${EPREFIX}/usr/bin/${EMACS_SUFFIX}," \
317                         -e "/^ExecStop/s,emacsclient,${EPREFIX}/usr/bin/&-${EMACS_SUFFIX}," \
318                         etc/emacs.service | newins - ${EMACS_SUFFIX}.service
319                 assert
320         fi
321
322         if use gzip-el; then
323                 # compress .el files when a corresponding .elc exists
324                 find "${ED}"/usr/share/emacs/${FULL_VERSION}/lisp -type f \
325                         -name "*.elc" -print | sed 's/\.elc$/.el/' | xargs gzip -9n
326                 assert "gzip .el failed"
327         fi
328
329         local cdir
330         if use source; then
331                 cdir="/usr/share/emacs/${FULL_VERSION}/src"
332                 insinto "${cdir}"
333                 # This is not meant to install all the source -- just the
334                 # C source you might find via find-function
335                 doins src/*.{c,h,m}
336         elif has installsources ${FEATURES}; then
337                 cdir="/usr/src/debug/${CATEGORY}/${PF}/${S#"${WORKDIR}/"}/src"
338         fi
339
340         sed -e "${cdir:+#}/^Y/d" -e "s/^[XY]//" >"${T}/${SITEFILE}" <<-EOF || die
341         X
342         ;;; ${EMACS_SUFFIX} site-lisp configuration
343         X
344         (when (string-match "\\\\\`${FULL_VERSION//./\\\\.}\\\\>" emacs-version)
345         Y  (setq find-function-C-source-directory
346         Y       "${EPREFIX}${cdir}")
347         X  (let ((path (getenv "INFOPATH"))
348         X       (dir "${EPREFIX}/usr/share/info/${EMACS_SUFFIX}")
349         X       (re "\\\\\`${EPREFIX}/usr/share\\\\>"))
350         X    (and path
351         X        ;; move Emacs Info dir before anything else in /usr/share
352         X        (let* ((p (cons nil (split-string path ":" t))) (q p))
353         X          (while (and (cdr q) (not (string-match re (cadr q))))
354         X            (setq q (cdr q)))
355         X          (setcdr q (cons dir (delete dir (cdr q))))
356         X          (setq Info-directory-list (prune-directory-list (cdr p)))))))
357         EOF
358         elisp-site-file-install "${T}/${SITEFILE}" || die
359
360         dodoc README BUGS CONTRIBUTE
361
362         if use aqua; then
363                 dodir /Applications/Gentoo
364                 rm -rf "${ED}"/Applications/Gentoo/${EMACS_SUFFIX^}.app
365                 mv nextstep/Emacs.app \
366                         "${ED}"/Applications/Gentoo/${EMACS_SUFFIX^}.app || die
367         fi
368
369         local DOC_CONTENTS="You can set the version to be started by
370                 /usr/bin/emacs through the Emacs eselect module, which also
371                 redirects man and info pages. Therefore, several Emacs versions can
372                 be installed at the same time. \"man emacs.eselect\" for details.
373                 \\n\\nIf you upgrade from Emacs version 24.2 or earlier, then it is
374                 strongly recommended that you use app-admin/emacs-updater to rebuild
375                 all byte-compiled elisp files of the installed Emacs packages."
376         use X && DOC_CONTENTS+="\\n\\nYou need to install some fonts for Emacs.
377                 Installing media-fonts/font-adobe-{75,100}dpi on the X server's
378                 machine would satisfy basic Emacs requirements under X11.
379                 See also https://wiki.gentoo.org/wiki/Xft_support_for_GNU_Emacs
380                 for how to enable anti-aliased fonts."
381         use aqua && DOC_CONTENTS+="\\n\\n${EMACS_SUFFIX^}.app is in
382                 \"${EPREFIX}/Applications/Gentoo\". You may want to copy or symlink
383                 it into /Applications by yourself."
384         readme.gentoo_create_doc
385 }
386
387 pkg_preinst() {
388         # move Info dir file to correct name
389         if [[ -d ${ED}/usr/share/info ]]; then
390                 mv "${ED}"/usr/share/info/${EMACS_SUFFIX}/dir{.orig,} || die
391         fi
392 }
393
394 pkg_postinst() {
395         elisp-site-regen
396         readme.gentoo_print_elog
397
398         if use livecd; then
399                 # force an update of the emacs symlink for the livecd/dvd,
400                 # because some microemacs packages set it with USE=livecd
401                 eselect emacs update
402         elif [[ $(readlink "${EROOT}"/usr/bin/emacs) = ${EMACS_SUFFIX} ]]; then
403                 # refresh symlinks in case any installed files have changed
404                 eselect emacs set ${EMACS_SUFFIX}
405         else
406                 eselect emacs update ifunset
407         fi
408 }
409
410 pkg_postrm() {
411         elisp-site-regen
412         eselect emacs update ifunset
413 }