/[gentoo-x86]/eclass/elisp-common.eclass
Gentoo

Diff of /eclass/elisp-common.eclass

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.70 Revision 1.84
1# Copyright 1999-2010 Gentoo Foundation 1# Copyright 1999-2013 Gentoo Foundation
2# Distributed under the terms of the GNU General Public License v2 2# Distributed under the terms of the GNU General Public License v2
3# $Header: /var/cvsroot/gentoo-x86/eclass/elisp-common.eclass,v 1.70 2010/11/29 17:07:22 ulm Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/elisp-common.eclass,v 1.84 2013/03/16 08:55:30 ulm Exp $
4#
5# Copyright 2002-2004 Matthew Kennedy <mkennedy@gentoo.org>
6# Copyright 2003 Jeremy Maitin-Shepard <jbms@attbi.com>
7# Copyright 2004-2005 Mamoru Komachi <usata@gentoo.org>
8# Copyright 2007-2008 Christian Faulhammer <fauli@gentoo.org>
9# Copyright 2007-2010 Ulrich Müller <ulm@gentoo.org>
10# 4#
11# @ECLASS: elisp-common.eclass 5# @ECLASS: elisp-common.eclass
12# @MAINTAINER: 6# @MAINTAINER:
13# Feel free to contact the Emacs team through <emacs@gentoo.org> if you 7# Gentoo Emacs team <emacs@gentoo.org>
14# have problems, suggestions or questions. 8# @AUTHOR:
9# Matthew Kennedy <mkennedy@gentoo.org>
10# Jeremy Maitin-Shepard <jbms@attbi.com>
11# Mamoru Komachi <usata@gentoo.org>
12# Christian Faulhammer <fauli@gentoo.org>
13# Ulrich Müller <ulm@gentoo.org>
15# @BLURB: Emacs-related installation utilities 14# @BLURB: Emacs-related installation utilities
16# @DESCRIPTION: 15# @DESCRIPTION:
17# 16#
18# Usually you want to use this eclass for (optional) GNU Emacs support 17# Usually you want to use this eclass for (optional) GNU Emacs support
19# of your package. This is NOT for XEmacs! 18# of your package. This is NOT for XEmacs!
40# 39#
41# Please note that such tests should be limited to packages that are 40# Please note that such tests should be limited to packages that are
42# known to fail with lower Emacs versions; the standard case is to 41# known to fail with lower Emacs versions; the standard case is to
43# depend on virtual/emacs without version. 42# depend on virtual/emacs without version.
44# 43#
45# .SS 44# @ROFF .SS
46# src_compile() usage: 45# src_compile() usage:
47# 46#
48# An elisp file is compiled by the elisp-compile() function defined 47# An elisp file is compiled by the elisp-compile() function defined
49# here and simply takes the source files as arguments. The case of 48# here and simply takes the source files as arguments. The case of
50# interdependent elisp files is also supported, since the current 49# interdependent elisp files is also supported, since the current
51# directory is added to the load-path which makes sure that all files 50# directory is added to the load-path which makes sure that all files
52# are loadable. 51# are loadable.
53# 52#
54# elisp-compile *.el || die 53# elisp-compile *.el
55# 54#
56# Function elisp-make-autoload-file() can be used to generate a file 55# Function elisp-make-autoload-file() can be used to generate a file
57# with autoload definitions for the lisp functions. It takes the output 56# with autoload definitions for the lisp functions. It takes the output
58# file name (default: "${PN}-autoloads.el") and a list of directories 57# file name (default: "${PN}-autoloads.el") and a list of directories
59# (default: working directory) as its arguments. Use of this function 58# (default: working directory) as its arguments. Use of this function
60# requires that the elisp source files contain magic ";;;###autoload" 59# requires that the elisp source files contain magic ";;;###autoload"
61# comments. See the Emacs Lisp Reference Manual (node "Autoload") for 60# comments. See the Emacs Lisp Reference Manual (node "Autoload") for
62# a detailed explanation. 61# a detailed explanation.
63# 62#
64# .SS 63# @ROFF .SS
65# src_install() usage: 64# src_install() usage:
66# 65#
67# The resulting compiled files (.elc) should be put in a subdirectory of 66# The resulting compiled files (.elc) should be put in a subdirectory of
68# /usr/share/emacs/site-lisp/ which is named after the first argument 67# /usr/share/emacs/site-lisp/ which is named after the first argument
69# of elisp-install(). The following parameters are the files to be put 68# of elisp-install(). The following parameters are the files to be put
70# in that directory. Usually the subdirectory should be ${PN}, you can 69# in that directory. Usually the subdirectory should be ${PN}, you can
71# choose something else, but remember to tell elisp-site-file-install() 70# choose something else, but remember to tell elisp-site-file-install()
72# (see below) the change, as it defaults to ${PN}. 71# (see below) the change, as it defaults to ${PN}.
73# 72#
74# elisp-install ${PN} *.el *.elc || die 73# elisp-install ${PN} *.el *.elc
75# 74#
76# To let the Emacs support be activated by Emacs on startup, you need 75# To let the Emacs support be activated by Emacs on startup, you need
77# to provide a site file (shipped in ${FILESDIR}) which contains the 76# to provide a site file (shipped in ${FILESDIR}) which contains the
78# startup code (have a look in the documentation of your software). 77# startup code (have a look in the documentation of your software).
79# Normally this would look like this: 78# Normally this would look like this:
93# features. Be careful though. Commands as "load-library" or "require" 92# features. Be careful though. Commands as "load-library" or "require"
94# bloat the editor as they are loaded on every startup. When having 93# bloat the editor as they are loaded on every startup. When having
95# many Emacs support files, users may be annoyed by the start-up time. 94# many Emacs support files, users may be annoyed by the start-up time.
96# Also avoid keybindings as they might interfere with the user's 95# Also avoid keybindings as they might interfere with the user's
97# settings. Give a hint in pkg_postinst(), which should be enough. 96# settings. Give a hint in pkg_postinst(), which should be enough.
97# The guiding principle is that emerging your package should not by
98# itself cause a change of standard Emacs behaviour.
98# 99#
99# The naming scheme for this site-init file matches the shell pattern 100# The naming scheme for this site-init file matches the shell pattern
100# "[1-8][0-9]*-gentoo*.el", where the two digits at the beginning define 101# "[1-8][0-9]*-gentoo*.el", where the two digits at the beginning define
101# the loading order (numbers below 10 or above 89 are reserved for 102# the loading order (numbers below 10 or above 89 are reserved for
102# internal use). So if your initialisation depends on another Emacs 103# internal use). So if your initialisation depends on another Emacs
109# 110#
110# SITEFILE="50${PN}-gentoo.el" 111# SITEFILE="50${PN}-gentoo.el"
111# 112#
112# Which is then installed by 113# Which is then installed by
113# 114#
114# elisp-site-file-install "${FILESDIR}/${SITEFILE}" || die 115# elisp-site-file-install "${FILESDIR}/${SITEFILE}"
115# 116#
116# in src_install(). Any characters after the "-gentoo" part and before 117# in src_install(). Any characters after the "-gentoo" part and before
117# the extension will be stripped from the destination file's name. 118# the extension will be stripped from the destination file's name.
118# For example, a file "50${PN}-gentoo-${PV}.el" will be installed as 119# For example, a file "50${PN}-gentoo-${PV}.el" will be installed as
119# "50${PN}-gentoo.el". If your subdirectory is not named ${PN}, give 120# "50${PN}-gentoo.el". If your subdirectory is not named ${PN}, give
120# the differing name as second argument. 121# the differing name as second argument.
121# 122#
122# .SS 123# @ROFF .SS
123# pkg_postinst() / pkg_postrm() usage: 124# pkg_postinst() / pkg_postrm() usage:
124# 125#
125# After that you need to recreate the start-up file of Emacs after 126# After that you need to recreate the start-up file of Emacs after
126# emerging and unmerging by using 127# emerging and unmerging by using
127# 128#
156EMACS=${EPREFIX}/usr/bin/emacs 157EMACS=${EPREFIX}/usr/bin/emacs
157 158
158# @ECLASS-VARIABLE: EMACSFLAGS 159# @ECLASS-VARIABLE: EMACSFLAGS
159# @DESCRIPTION: 160# @DESCRIPTION:
160# Flags for executing Emacs in batch mode. 161# Flags for executing Emacs in batch mode.
161# These work for Emacs versions 18-23, so don't change them. 162# These work for Emacs versions 18-24, so don't change them.
162EMACSFLAGS="-batch -q --no-site-file" 163EMACSFLAGS="-batch -q --no-site-file"
163 164
164# @ECLASS-VARIABLE: BYTECOMPFLAGS 165# @ECLASS-VARIABLE: BYTECOMPFLAGS
165# @DESCRIPTION: 166# @DESCRIPTION:
166# Emacs flags used for byte-compilation in elisp-compile(). 167# Emacs flags used for byte-compilation in elisp-compile().
167BYTECOMPFLAGS="-L ." 168BYTECOMPFLAGS="-L ."
168 169
169# @FUNCTION: elisp-emacs-version 170# @FUNCTION: elisp-emacs-version
171# @RETURN: exit status of Emacs
170# @DESCRIPTION: 172# @DESCRIPTION:
171# Output version of currently active Emacs. 173# Output version of currently active Emacs.
172 174
173elisp-emacs-version() { 175elisp-emacs-version() {
176 local ret
174 # The following will work for at least versions 18-23. 177 # The following will work for at least versions 18-24.
175 echo "(princ emacs-version)" >"${T}"/emacs-version.el 178 echo "(princ emacs-version)" >"${T}"/emacs-version.el
176 ${EMACS} ${EMACSFLAGS} -l "${T}"/emacs-version.el 179 ${EMACS} ${EMACSFLAGS} -l "${T}"/emacs-version.el
180 ret=$?
177 rm -f "${T}"/emacs-version.el 181 rm -f "${T}"/emacs-version.el
182 if [[ ${ret} -ne 0 ]]; then
183 eerror "elisp-emacs-version: Failed to run ${EMACS}"
184 fi
185 return ${ret}
178} 186}
179 187
180# @FUNCTION: elisp-need-emacs 188# @FUNCTION: elisp-need-emacs
181# @USAGE: <version> 189# @USAGE: <version>
182# @RETURN: 0 if true, 1 otherwise 190# @RETURN: 0 if true, 1 if false, 2 if trouble
183# @DESCRIPTION: 191# @DESCRIPTION:
184# Test if the eselected Emacs version is at least the major version 192# Test if the eselected Emacs version is at least the major version
185# specified as argument. 193# of GNU Emacs specified as argument.
186 194
187elisp-need-emacs() { 195elisp-need-emacs() {
188 local need_emacs=$1 196 local need_emacs=$1 have_emacs
189 local have_emacs=$(elisp-emacs-version) 197 have_emacs=$(elisp-emacs-version) || return 2
190 einfo "Emacs version: ${have_emacs}" 198 einfo "Emacs version: ${have_emacs}"
199 if [[ ${have_emacs} =~ XEmacs|Lucid ]]; then
200 eerror "This package needs GNU Emacs."
201 return 1
202 fi
191 if ! [[ ${have_emacs%%.*} -ge ${need_emacs%%.*} ]]; then 203 if ! [[ ${have_emacs%%.*} -ge ${need_emacs%%.*} ]]; then
192 eerror "This package needs at least Emacs ${need_emacs%%.*}." 204 eerror "This package needs at least Emacs ${need_emacs%%.*}."
193 eerror "Use \"eselect emacs\" to select the active version." 205 eerror "Use \"eselect emacs\" to select the active version."
194 return 1 206 return 1
195 fi 207 fi
210# in case they require or load one another. 222# in case they require or load one another.
211 223
212elisp-compile() { 224elisp-compile() {
213 ebegin "Compiling GNU Emacs Elisp files" 225 ebegin "Compiling GNU Emacs Elisp files"
214 ${EMACS} ${EMACSFLAGS} ${BYTECOMPFLAGS} -f batch-byte-compile "$@" 226 ${EMACS} ${EMACSFLAGS} ${BYTECOMPFLAGS} -f batch-byte-compile "$@"
215 eend $? "elisp-compile: batch-byte-compile failed" 227 eend $? "elisp-compile: batch-byte-compile failed" || die
216} 228}
217 229
218# @FUNCTION: elisp-make-autoload-file 230# @FUNCTION: elisp-make-autoload-file
219# @USAGE: [output file] [list of directories] 231# @USAGE: [output file] [list of directories]
220# @DESCRIPTION: 232# @DESCRIPTION:
246 ${EMACS} ${EMACSFLAGS} \ 258 ${EMACS} ${EMACSFLAGS} \
247 --eval "(setq make-backup-files nil)" \ 259 --eval "(setq make-backup-files nil)" \
248 --eval "(setq generated-autoload-file (expand-file-name \"${f}\"))" \ 260 --eval "(setq generated-autoload-file (expand-file-name \"${f}\"))" \
249 -f batch-update-autoloads "${@-.}" 261 -f batch-update-autoloads "${@-.}"
250 262
251 eend $? "elisp-make-autoload-file: batch-update-autoloads failed" 263 eend $? "elisp-make-autoload-file: batch-update-autoloads failed" || die
252} 264}
253 265
254# @FUNCTION: elisp-install 266# @FUNCTION: elisp-install
255# @USAGE: <subdirectory> <list of files> 267# @USAGE: <subdirectory> <list of files>
256# @DESCRIPTION: 268# @DESCRIPTION:
262 ebegin "Installing Elisp files for GNU Emacs support" 274 ebegin "Installing Elisp files for GNU Emacs support"
263 ( # subshell to avoid pollution of calling environment 275 ( # subshell to avoid pollution of calling environment
264 insinto "${SITELISP}/${subdir}" 276 insinto "${SITELISP}/${subdir}"
265 doins "$@" 277 doins "$@"
266 ) 278 )
267 eend $? "elisp-install: doins failed" 279 eend $? "elisp-install: doins failed" || die
268} 280}
269 281
270# @FUNCTION: elisp-site-file-install 282# @FUNCTION: elisp-site-file-install
271# @USAGE: <site-init file> [subdirectory] 283# @USAGE: <site-init file> [subdirectory]
272# @DESCRIPTION: 284# @DESCRIPTION:
282 294
283 [[ ${sf} == [0-9][0-9]*-gentoo*.el ]] \ 295 [[ ${sf} == [0-9][0-9]*-gentoo*.el ]] \
284 || ewarn "elisp-site-file-install: bad name of site-init file" 296 || ewarn "elisp-site-file-install: bad name of site-init file"
285 sf="${T}/${sf/%-gentoo*.el/-gentoo.el}" 297 sf="${T}/${sf/%-gentoo*.el/-gentoo.el}"
286 ebegin "Installing site initialisation file for GNU Emacs" 298 ebegin "Installing site initialisation file for GNU Emacs"
287 [[ $1 = ${sf} ]] || cp "$1" "${sf}" 299 [[ $1 = "${sf}" ]] || cp "$1" "${sf}"
288 sed -i -e "1{:x;/^\$/{n;bx;};/^;.*${PN}/I!s:^:${header}\n\n:;1s:^:\n:;}" \ 300 sed -i -e "1{:x;/^\$/{n;bx;};/^;.*${PN}/I!s:^:${header}\n\n:;1s:^:\n:;}" \
289 -e "s:@SITELISP@:${EPREFIX}${SITELISP}/${my_pn}:g" \ 301 -e "s:@SITELISP@:${EPREFIX}${SITELISP}/${my_pn}:g" \
290 -e "s:@SITEETC@:${EPREFIX}${SITEETC}/${my_pn}:g;\$q" "${sf}" 302 -e "s:@SITEETC@:${EPREFIX}${SITEETC}/${my_pn}:g;\$q" "${sf}"
291 ( # subshell to avoid pollution of calling environment 303 ( # subshell to avoid pollution of calling environment
292 insinto "${SITELISP}/site-gentoo.d" 304 insinto "${SITELISP}/site-gentoo.d"
293 doins "${sf}" 305 doins "${sf}"
294 ) 306 )
295 ret=$? 307 ret=$?
296 rm -f "${sf}" 308 rm -f "${sf}"
297 eend ${ret} "elisp-site-file-install: doins failed" 309 eend ${ret} "elisp-site-file-install: doins failed" || die
298} 310}
299 311
300# @FUNCTION: elisp-site-regen 312# @FUNCTION: elisp-site-regen
301# @DESCRIPTION: 313# @DESCRIPTION:
302# Regenerate the site-gentoo.el file, based on packages' site 314# Regenerate the site-gentoo.el file, based on packages' site
307# in /usr/share/emacs/site-lisp/. For backwards compatibility, this 319# in /usr/share/emacs/site-lisp/. For backwards compatibility, this
308# location is still supported when generating site-gentoo.el. 320# location is still supported when generating site-gentoo.el.
309 321
310elisp-site-regen() { 322elisp-site-regen() {
311 local sitelisp=${ROOT}${EPREFIX}${SITELISP} 323 local sitelisp=${ROOT}${EPREFIX}${SITELISP}
312 local sf i line null="" page=$'\f' 324 local sf i null="" page=$'\f'
313 local -a sflist 325 local -a sflist
314 326
315 if [ ! -d "${sitelisp}" ]; then 327 if [[ ! -d ${sitelisp} ]]; then
316 eerror "elisp-site-regen: Directory ${sitelisp} does not exist" 328 eerror "elisp-site-regen: Directory ${sitelisp} does not exist"
317 return 1 329 return 1
318 fi 330 fi
319 331
320 if [ ! -d "${T}" ]; then 332 if [[ ! -d ${T} ]]; then
321 eerror "elisp-site-regen: Temporary directory ${T} does not exist" 333 eerror "elisp-site-regen: Temporary directory ${T} does not exist"
322 return 1 334 return 1
323 fi 335 fi
324 336
325 einfon "Regenerating site-gentoo.el for GNU Emacs (${EBUILD_PHASE}) ..." 337 ebegin "Regenerating site-gentoo.el for GNU Emacs (${EBUILD_PHASE})"
326
327 # Until January 2009, elisp-common.eclass sometimes created an
328 # auxiliary file for backwards compatibility. Remove any such file.
329 rm -f "${sitelisp}"/00site-gentoo.el
330 338
331 for sf in "${sitelisp}"/[0-9][0-9]*-gentoo.el \ 339 for sf in "${sitelisp}"/[0-9][0-9]*-gentoo.el \
332 "${sitelisp}"/site-gentoo.d/[0-9][0-9]*.el 340 "${sitelisp}"/site-gentoo.d/[0-9][0-9]*.el
333 do 341 do
334 [ -r "${sf}" ] || continue 342 [[ -r ${sf} ]] || continue
335 # sort files by their basename. straight insertion sort. 343 # sort files by their basename. straight insertion sort.
336 for ((i=${#sflist[@]}; i>0; i--)); do 344 for ((i=${#sflist[@]}; i>0; i--)); do
337 [[ ${sf##*/} < ${sflist[i-1]##*/} ]] || break 345 [[ ${sf##*/} < ${sflist[i-1]##*/} ]] || break
338 sflist[i]=${sflist[i-1]} 346 sflist[i]=${sflist[i-1]}
339 done 347 done
367 if cmp -s "${sitelisp}"/site-gentoo.el "${T}"/site-gentoo.el; then 375 if cmp -s "${sitelisp}"/site-gentoo.el "${T}"/site-gentoo.el; then
368 # This prevents outputting unnecessary text when there 376 # This prevents outputting unnecessary text when there
369 # was actually no change. 377 # was actually no change.
370 # A case is a remerge where we have doubled output. 378 # A case is a remerge where we have doubled output.
371 rm -f "${T}"/site-gentoo.el 379 rm -f "${T}"/site-gentoo.el
380 eend
372 echo " no changes." 381 einfo "... no changes."
373 else 382 else
374 mv "${T}"/site-gentoo.el "${sitelisp}"/site-gentoo.el 383 mv "${T}"/site-gentoo.el "${sitelisp}"/site-gentoo.el
375 echo 384 eend
376 case ${#sflist[@]} in 385 case ${#sflist[@]} in
386 0) [[ ${PN} = emacs-common-gentoo ]] \
377 0) ewarn "... Huh? No site initialisation files found." ;; 387 || ewarn "... Huh? No site initialisation files found." ;;
378 1) einfo "... ${#sflist[@]} site initialisation file included." ;; 388 1) einfo "... ${#sflist[@]} site initialisation file included." ;;
379 *) einfo "... ${#sflist[@]} site initialisation files included." ;; 389 *) einfo "... ${#sflist[@]} site initialisation files included." ;;
380 esac 390 esac
381 fi 391 fi
382 392

Legend:
Removed from v.1.70  
changed lines
  Added in v.1.84

  ViewVC Help
Powered by ViewVC 1.1.20