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

Diff of /eclass/xemacs-elisp-common.eclass

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

Revision 1.1 Revision 1.5
1# Copyright 1999-2007 Gentoo Foundation 1# Copyright 1999-2011 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/xemacs-elisp-common.eclass,v 1.1 2007/09/15 07:19:22 graaff Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/xemacs-elisp-common.eclass,v 1.5 2011/12/27 17:55:13 fauli Exp $
4# 4#
5# Copyright 2007 Hans de Graaff <graaff@gentoo.org> 5# Copyright 2007-2011 Hans de Graaff <graaff@gentoo.org>
6# 6#
7# Based on elisp-common.eclass: 7# Based on elisp-common.eclass:
8# Copyright 2007 Christian Faulhammer <opfer@gentoo.org> 8# Copyright 2007 Christian Faulhammer <opfer@gentoo.org>
9# Copyright 2002-2004 Matthew Kennedy <mkennedy@gentoo.org> 9# Copyright 2002-2004 Matthew Kennedy <mkennedy@gentoo.org>
10# Copyright 2004-2005 Mamoru Komachi <usata@gentoo.org> 10# Copyright 2004-2005 Mamoru Komachi <usata@gentoo.org>
24# package (especially compilation), so this is mainly for standalone elisp 24# package (especially compilation), so this is mainly for standalone elisp
25# files you gathered from somewhere else. 25# files you gathered from somewhere else.
26# 26#
27# When relying on the xemacs USE flag, you need to add 27# When relying on the xemacs USE flag, you need to add
28# 28#
29# xemacs? ( virtual/xemacs ) 29# xemacs? ( app-editors/xemacs )
30# 30#
31# to your DEPEND/RDEPEND line and use the functions provided here to bring 31# to your DEPEND/RDEPEND line and use the functions provided here to bring
32# the files to the correct locations. 32# the files to the correct locations.
33# 33#
34# .SS 34# .SS
35# src_compile() usage: 35# src_compile() usage:
36# 36#
37# An elisp file is compiled by the xemacs-elisp-compile() function 37# An elisp file is compiled by the xemacs-elisp-compile() function
38# defined here and simply takes the source files as arguments. 38# defined here and simply takes the source files as arguments.
39# 39#
40# xemacs-elisp-compile *.el || die "xemacs-elisp-compile failed" 40# xemacs-elisp-compile *.el
41#
42# In the case of interdependent elisp files, you can use the
43# xemacs-elisp-comp() function which makes sure all files are
44# loadable.
45#
46# xemacs-elisp-comp *.el
41# 47#
42# Function xemacs-elisp-make-autoload-file() can be used to generate a 48# Function xemacs-elisp-make-autoload-file() can be used to generate a
43# file with autoload definitions for the lisp functions. It takes a 49# file with autoload definitions for the lisp functions. It takes a
44# list of directories (default: working directory) as its argument. 50# list of directories (default: working directory) as its argument.
45# Use of this function requires that the elisp source files contain 51# Use of this function requires that the elisp source files contain
47# (node "Autoload") for a detailed explanation. 53# (node "Autoload") for a detailed explanation.
48# 54#
49# .SS 55# .SS
50# src_install() usage: 56# src_install() usage:
51# 57#
52# The resulting compiled files (.elc) should be put in a subdirectory of 58# The resulting compiled files (.elc) should be put in a subdirectory
53# /usr/lib/xemacs/site-lisp/ which is named after the first argument 59# of /usr/lib/xemacs/site-lisp/ which is named after the first
54# of elisp-install(). The following parameters are the files to be put in 60# argument of xemacs-elisp-install(). The following parameters are
55# that directory. Usually the subdirectory should be ${PN}, you can choose 61# the files to be put in that directory. Usually the subdirectory
56# something else, but remember to tell elisp-site-file-install() (see below) 62# should be ${PN}, but you can choose something else.
57# the change, as it defaults to ${PN}.
58# 63#
59# elisp-install ${PN} *.el *.elc || die "elisp-install failed" 64# xemacs-elisp-install ${PN} *.el *.elc
60# 65#
66# To let the XEmacs support be activated by XEmacs on startup, you need
67# to provide a site file (shipped in ${FILESDIR}) which contains the
68# startup code (have a look in the documentation of your software).
69# Normally this would look like this:
70#
71# (add-to-list 'load-path "@SITELISP@")
72# (add-to-list 'auto-mode-alist '("\\.csv\\'" . csv-mode))
73# (autoload 'csv-mode "csv-mode" "Major mode for csv files." t)
74#
75# If your XEmacs support files are installed in a subdirectory of
76# /usr/share/xemacs/site-packages/ (which is strongly recommended), you need
77# to extend XEmacs' load-path as shown in the first non-comment line.
78# The xemacs-elisp-site-file-install() function of this eclass will replace
79# "@SITELISP@" by the actual path.
80#
81# The next line tells XEmacs to load the mode opening a file ending
82# with ".csv" and load functions depending on the context and needed
83# features. Be careful though. Commands as "load-library" or "require"
84# bloat the editor as they are loaded on every startup. When having
85# many XEmacs support files, users may be annoyed by the start-up time.
86# Also avoid keybindings as they might interfere with the user's
87# settings. Give a hint in pkg_postinst(), which should be enough.
88#
89# The naming scheme for this site-init file matches the shell pattern
90# "[1-8][0-9]*-gentoo*.el", where the two digits at the beginning define
91# the loading order (numbers below 10 or above 89 are reserved for
92# internal use). So if your initialisation depends on another XEmacs
93# package, your site file's number must be higher! If there are no such
94# interdependencies then the number should be 50. Otherwise, numbers
95# divisible by 10 are preferred.
96#
97# Best practice is to define a SITEFILE variable in the global scope of
98# your ebuild (e.g., right after S or RDEPEND):
99#
100# SITEFILE="50${PN}-gentoo.el"
101#
102# Which is then installed by
103#
104# xemacs-elisp-site-file-install "${FILESDIR}/${SITEFILE}" || die
105#
106# in src_install(). Any characters after the "-gentoo" part and before
107# the extension will be stripped from the destination file's name.
108# For example, a file "50${PN}-gentoo-${PV}.el" will be installed as
109# "50${PN}-gentoo.el". If your subdirectory is not named ${PN}, give
110# the differing name as second argument.
61 111
112# @ECLASS-VARIABLE: SITELISP
113# @DESCRIPTION:
114# Directory where packages install indivivual XEmacs Lisp files.
115SITELISP=/usr/share/xemacs/site-lisp
62 116
117# @ECLASS-VARIABLE: SITEPACKAGE
118# @DESCRIPTION:
119# Directory where packages install XEmacs Lisp packages.
63SITEPACKAGE=/usr/lib/xemacs/site-packages 120SITEPACKAGE=/usr/share/xemacs/site-packages
121
122# @ECLASS-VARIABLE: XEMACS
123# @DESCRIPTION:
124# Path of XEmacs executable.
64XEMACS=/usr/bin/xemacs 125XEMACS=/usr/bin/xemacs
126
127# @ECLASS-VARIABLE: XEMACS_BATCH_CLEAN
128# @DESCRIPTION:
129# Invocation of XEMACS in batch mode.
65XEMACS_BATCH_CLEAN="${XEMACS} --batch --no-site-file --no-init-file" 130XEMACS_BATCH_CLEAN="${XEMACS} --batch --no-site-file --no-init-file"
66 131
67# @FUNCTION: xemacs-elisp-compile 132# @FUNCTION: xemacs-elisp-compile
68# @USAGE: <list of elisp files> 133# @USAGE: <list of elisp files>
69# @DESCRIPTION: 134# @DESCRIPTION:
70# Byte-compile elisp files with xemacs 135# Byte-compile elisp files with xemacs. This function will die when
136# there is a problem compiling the lisp files.
71xemacs-elisp-compile () { 137xemacs-elisp-compile () {
138 {
72 ${XEMACS_BATCH_CLEAN} -f batch-byte-compile "$@" 139 ${XEMACS_BATCH_CLEAN} -f batch-byte-compile "$@"
73 xemacs-elisp-make-autoload-file "$@" 140 xemacs-elisp-make-autoload-file "$@"
141 } || die "Compile lisp files failed"
74} 142}
75 143
76xemacs-elisp-make-autoload-file () { 144xemacs-elisp-make-autoload-file () {
77 ${XEMACS_BATCH_CLEAN} \ 145 ${XEMACS_BATCH_CLEAN} \
78 -eval "(setq autoload-package-name \"${PN}\")" \ 146 -eval "(setq autoload-package-name \"${PN}\")" \
83# @FUNCTION: xemacs-elisp-install 151# @FUNCTION: xemacs-elisp-install
84# @USAGE: <subdirectory> <list of files> 152# @USAGE: <subdirectory> <list of files>
85# @DESCRIPTION: 153# @DESCRIPTION:
86# Install elisp source and byte-compiled files. All files are installed 154# Install elisp source and byte-compiled files. All files are installed
87# in site-packages in their own directory, indicated by the first 155# in site-packages in their own directory, indicated by the first
88# argument to the function. 156# argument to the function. This function will die if there is a problem
157# installing the list files.
89 158
90xemacs-elisp-install () { 159xemacs-elisp-install () {
91 local subdir="$1" 160 local subdir="$1"
92 shift 161 shift
93 ( # use sub-shell to avoid possible environment polution 162 ( # use sub-shell to avoid possible environment polution
94 dodir "${SITEPACKAGE}"/lisp/"${subdir}" 163 dodir "${SITEPACKAGE}"/lisp/"${subdir}"
95 insinto "${SITEPACKAGE}"/lisp/"${subdir}" 164 insinto "${SITEPACKAGE}"/lisp/"${subdir}"
96 doins "$@" 165 doins "$@"
97 ) || die "Installing lisp files failed" 166 ) || die "Installing lisp files failed"
98} 167}
168
169# @FUNCTION: xemacs-elisp-comp
170# @USAGE: <list of elisp files>
171# @DESCRIPTION:
172# Byte-compile interdependent XEmacs lisp files.
173# Originally taken from GNU autotools, but some configuration options
174# removed as they don't make sense with the current status of XEmacs
175# in Gentoo.
176
177xemacs-elisp-comp() {
178 # Copyright 1995 Free Software Foundation, Inc.
179 # Fran├žois Pinard <pinard@iro.umontreal.ca>, 1995.
180 # This script byte-compiles all `.el' files which are part of its
181 # arguments, using XEmacs, and put the resulting `.elc' files into
182 # the current directory, so disregarding the original directories used
183 # in `.el' arguments.
184 #
185 # This script manages in such a way that all XEmacs LISP files to
186 # be compiled are made visible between themselves, in the event
187 # they require or load-library one another.
188
189 test $# -gt 0 || return 1
190
191 einfo "Compiling XEmacs Elisp files ..."
192
193 tempdir=elc.$$
194 mkdir ${tempdir}
195 cp "$@" ${tempdir}
196 pushd ${tempdir}
197
198 echo "(add-to-list 'load-path \"../\")" > script
199 ${XEMACS_BATCH_CLEAN} -l script -f batch-byte-compile *.el
200 local ret=$?
201 mv *.elc ..
202
203 popd
204 rm -fr ${tempdir}
205 return ${ret}
206}
207
208# @FUNCTION: xemacs-elisp-site-file-install
209# @USAGE: <site-init file> [subdirectory]
210# @DESCRIPTION:
211# Install XEmacs site-init file in SITELISP directory. Automatically
212# inserts a standard comment header with the name of the package (unless
213# it is already present). Tokens @SITELISP@ is replaced by the path to
214# the package's subdirectory in SITELISP.
215
216xemacs-elisp-site-file-install() {
217 local sf="${1##*/}" my_pn="${2:-${PN}}" ret
218 local header=";;; ${PN} site-lisp configuration"
219
220 [[ ${sf} == [0-9][0-9]*-gentoo*.el ]] \
221 || ewarn "xemacs-elisp-site-file-install: bad name of site-init file"
222 sf="${T}/${sf/%-gentoo*.el/-gentoo.el}"
223 ebegin "Installing site initialisation file for XEmacs"
224 [[ $1 = "${sf}" ]] || cp "$1" "${sf}"
225 sed -i -e "1{:x;/^\$/{n;bx;};/^;.*${PN}/I!s:^:${header}\n\n:;1s:^:\n:;}" \
226 -e "s:@SITELISP@:${EPREFIX}${SITELISP}/${my_pn}:g" "${sf}"
227 ( # subshell to avoid pollution of calling environment
228 insinto "${SITELISP}/site-gentoo.d"
229 doins "${sf}"
230 )
231 ret=$?
232 rm -f "${sf}"
233 eend ${ret} "xemacs-elisp-site-file-install: doins failed"
234}
235
236# @FUNCTION: xemacs-elisp-site-regen
237# @DESCRIPTION:
238# Regenerate the site-gentoo.el file, based on packages' site
239# initialisation files in the /usr/share/xemacs/site-lisp/site-gentoo.d/
240# directory.
241
242xemacs-elisp-site-regen() {
243 local sitelisp=${ROOT}${EPREFIX}${SITELISP}
244 local sf i line null="" page=$'\f'
245 local -a sflist
246
247 if [ ! -d "${sitelisp}" ]; then
248 eerror "xemacs-elisp-site-regen: Directory ${sitelisp} does not exist"
249 return 1
250 fi
251
252 if [ ! -d "${T}" ]; then
253 eerror "xemacs-elisp-site-regen: Temporary directory ${T} does not exist"
254 return 1
255 fi
256
257 einfon "Regenerating site-gentoo.el for XEmacs (${EBUILD_PHASE}) ..."
258
259 for sf in "${sitelisp}"/site-gentoo.d/[0-9][0-9]*.el
260 do
261 [ -r "${sf}" ] || continue
262 # sort files by their basename. straight insertion sort.
263 for ((i=${#sflist[@]}; i>0; i--)); do
264 [[ ${sf##*/} < ${sflist[i-1]##*/} ]] || break
265 sflist[i]=${sflist[i-1]}
266 done
267 sflist[i]=${sf}
268 done
269
270 cat <<-EOF >"${T}"/site-gentoo.el
271 ;;; site-gentoo.el --- site initialisation for Gentoo-installed packages
272
273 ;;; Commentary:
274 ;; Automatically generated by xemacs-elisp-common.eclass
275 ;; DO NOT EDIT THIS FILE
276
277 ;;; Code:
278 EOF
279 # Use sed instead of cat here, since files may miss a trailing newline.
280 sed '$q' "${sflist[@]}" </dev/null >>"${T}"/site-gentoo.el
281 cat <<-EOF >>"${T}"/site-gentoo.el
282
283 ${page}
284 (provide 'site-gentoo)
285
286 ;; Local ${null}Variables:
287 ;; no-byte-compile: t
288 ;; buffer-read-only: t
289 ;; End:
290
291 ;;; site-gentoo.el ends here
292 EOF
293
294 if cmp -s "${sitelisp}"/site-gentoo.el "${T}"/site-gentoo.el; then
295 # This prevents outputting unnecessary text when there
296 # was actually no change.
297 # A case is a remerge where we have doubled output.
298 rm -f "${T}"/site-gentoo.el
299 echo " no changes."
300 else
301 mv "${T}"/site-gentoo.el "${sitelisp}"/site-gentoo.el
302 echo
303 case ${#sflist[@]} in
304 0) ewarn "... Huh? No site initialisation files found." ;;
305 1) einfo "... ${#sflist[@]} site initialisation file included." ;;
306 *) einfo "... ${#sflist[@]} site initialisation files included." ;;
307 esac
308 fi
309
310 return 0
311}

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.5

  ViewVC Help
Powered by ViewVC 1.1.20