1 # Copyright 1999-2012 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
5 # Copyright 2007-2011 Hans de Graaff <graaff@gentoo.org>
7 # Based on elisp-common.eclass:
8 # Copyright 2007 Christian Faulhammer <opfer@gentoo.org>
9 # Copyright 2002-2004 Matthew Kennedy <mkennedy@gentoo.org>
10 # Copyright 2004-2005 Mamoru Komachi <usata@gentoo.org>
11 # Copyright 2003 Jeremy Maitin-Shepard <jbms@attbi.com>
12 # Copyright 2007 Ulrich Müller <ulm@gentoo.org>
14 # @ECLASS: xemacs-elisp-common.eclass
17 # @BLURB: XEmacs-related installation utilities
20 # Usually you want to use this eclass for (optional) XEmacs support of
21 # your package. This is NOT for GNU Emacs!
23 # Many of the steps here are sometimes done by the build system of your
24 # package (especially compilation), so this is mainly for standalone elisp
25 # files you gathered from somewhere else.
27 # When relying on the xemacs USE flag, you need to add
29 # xemacs? ( app-editors/xemacs )
31 # to your DEPEND/RDEPEND line and use the functions provided here to bring
32 # the files to the correct locations.
35 # src_compile() usage:
37 # An elisp file is compiled by the xemacs-elisp-compile() function
38 # defined here and simply takes the source files as arguments.
40 # xemacs-elisp-compile *.el
42 # In the case of interdependent elisp files, you can use the
43 # xemacs-elisp-comp() function which makes sure all files are
46 # xemacs-elisp-comp *.el
48 # Function xemacs-elisp-make-autoload-file() can be used to generate a
49 # file with autoload definitions for the lisp functions. It takes a
50 # list of directories (default: working directory) as its argument.
51 # Use of this function requires that the elisp source files contain
52 # magic ";;;###autoload" comments. See the XEmacs Lisp Reference Manual
53 # (node "Autoload") for a detailed explanation.
56 # src_install() usage:
58 # The resulting compiled files (.elc) should be put in a subdirectory
59 # of /usr/lib/xemacs/site-lisp/ which is named after the first
60 # argument of xemacs-elisp-install(). The following parameters are
61 # the files to be put in that directory. Usually the subdirectory
62 # should be ${PN}, but you can choose something else.
64 # xemacs-elisp-install ${PN} *.el *.elc
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:
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)
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.
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.
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.
97 # Best practice is to define a SITEFILE variable in the global scope of
98 # your ebuild (e.g., right after S or RDEPEND):
100 # SITEFILE="50${PN}-gentoo.el"
102 # Which is then installed by
104 # xemacs-elisp-site-file-install "${FILESDIR}/${SITEFILE}" || die
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.
112 # @ECLASS-VARIABLE: XEMACS_SITELISP
114 # Directory where packages install indivivual XEmacs Lisp files.
115 XEMACS_SITELISP=/usr/share/xemacs/site-lisp
117 # @ECLASS-VARIABLE: XEMACS_SITEPACKAGE
119 # Directory where packages install XEmacs Lisp packages.
120 XEMACS_SITEPACKAGE=/usr/share/xemacs/site-packages
122 # @ECLASS-VARIABLE: XEMACS
124 # Path of XEmacs executable.
125 XEMACS=/usr/bin/xemacs
127 # @ECLASS-VARIABLE: XEMACS_BATCH_CLEAN
129 # Invocation of XEMACS in batch mode.
130 XEMACS_BATCH_CLEAN="${XEMACS} --batch --no-site-file --no-init-file"
132 # @FUNCTION: xemacs-elisp-compile
133 # @USAGE: <list of elisp files>
135 # Byte-compile elisp files with xemacs. This function will die when
136 # there is a problem compiling the lisp files.
137 xemacs-elisp-compile () {
139 ${XEMACS_BATCH_CLEAN} -f batch-byte-compile "$@"
140 xemacs-elisp-make-autoload-file "$@"
141 } || die "Compile lisp files failed"
144 xemacs-elisp-make-autoload-file () {
145 ${XEMACS_BATCH_CLEAN} \
146 -eval "(setq autoload-package-name \"${PN}\")" \
147 -eval "(setq generated-autoload-file \"${S}/auto-autoloads.el\")" \
148 -l autoload -f batch-update-autoloads "$@"
151 # @FUNCTION: xemacs-elisp-install
152 # @USAGE: <subdirectory> <list of files>
154 # Install elisp source and byte-compiled files. All files are installed
155 # in site-packages in their own directory, indicated by the first
156 # argument to the function. This function will die if there is a problem
157 # installing the list files.
159 xemacs-elisp-install () {
162 ( # use sub-shell to avoid possible environment polution
163 dodir "${XEMACS_SITEPACKAGE}"/lisp/"${subdir}"
164 insinto "${XEMACS_SITEPACKAGE}"/lisp/"${subdir}"
166 ) || die "Installing lisp files failed"
169 # @FUNCTION: xemacs-elisp-comp
170 # @USAGE: <list of elisp files>
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
177 xemacs-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.
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.
189 test $# -gt 0 || return 1
191 einfo "Compiling XEmacs Elisp files ..."
198 echo "(add-to-list 'load-path \"../\")" > script
199 ${XEMACS_BATCH_CLEAN} -l script -f batch-byte-compile *.el
208 # @FUNCTION: xemacs-elisp-site-file-install
209 # @USAGE: <site-init file> [subdirectory]
211 # Install XEmacs site-init file in XEMACS_SITELISP directory.
212 # Automatically inserts a standard comment header with the name of the
213 # package (unless it is already present). Token @SITELISP@ is replaced
214 # by the path to the package's subdirectory in XEMACS_SITELISP.
216 xemacs-elisp-site-file-install() {
217 local sf="${1##*/}" my_pn="${2:-${PN}}" ret
218 local header=";;; ${PN} site-lisp configuration"
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}${XEMACS_SITELISP}/${my_pn}:g" "${sf}"
227 ( # subshell to avoid pollution of calling environment
228 insinto "${XEMACS_SITELISP}/site-gentoo.d"
233 eend ${ret} "xemacs-elisp-site-file-install: doins failed"
236 # @FUNCTION: xemacs-elisp-site-regen
238 # Regenerate the site-gentoo.el file, based on packages' site
239 # initialisation files in the /usr/share/xemacs/site-lisp/site-gentoo.d/
242 xemacs-elisp-site-regen() {
243 local sitelisp=${ROOT}${EPREFIX}${XEMACS_SITELISP}
244 local sf i line null="" page=$'\f'
247 if [ ! -d "${sitelisp}" ]; then
248 eerror "xemacs-elisp-site-regen: Directory ${sitelisp} does not exist"
252 if [ ! -d "${T}" ]; then
253 eerror "xemacs-elisp-site-regen: Temporary directory ${T} does not exist"
257 einfon "Regenerating site-gentoo.el for XEmacs (${EBUILD_PHASE}) ..."
259 for sf in "${sitelisp}"/site-gentoo.d/[0-9][0-9]*.el
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]}
270 cat <<-EOF >"${T}"/site-gentoo.el
271 ;;; site-gentoo.el --- site initialisation for Gentoo-installed packages
274 ;; Automatically generated by xemacs-elisp-common.eclass
275 ;; DO NOT EDIT THIS FILE
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
284 (provide 'site-gentoo)
286 ;; Local ${null}Variables:
287 ;; no-byte-compile: t
288 ;; buffer-read-only: t
291 ;;; site-gentoo.el ends here
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
301 mv "${T}"/site-gentoo.el "${sitelisp}"/site-gentoo.el
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." ;;