1 # Copyright 1999-2012 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
4 # Copyright 2007-2011 Hans de Graaff <graaff@gentoo.org>
6 # Based on elisp-common.eclass:
7 # Copyright 2007 Christian Faulhammer <opfer@gentoo.org>
8 # Copyright 2002-2004 Matthew Kennedy <mkennedy@gentoo.org>
9 # Copyright 2004-2005 Mamoru Komachi <usata@gentoo.org>
10 # Copyright 2003 Jeremy Maitin-Shepard <jbms@attbi.com>
11 # Copyright 2007 Ulrich Müller <ulm@gentoo.org>
13 # @ECLASS: xemacs-elisp-common.eclass
16 # @BLURB: XEmacs-related installation utilities
19 # Usually you want to use this eclass for (optional) XEmacs support of
20 # your package. This is NOT for GNU Emacs!
22 # Many of the steps here are sometimes done by the build system of your
23 # package (especially compilation), so this is mainly for standalone elisp
24 # files you gathered from somewhere else.
26 # When relying on the xemacs USE flag, you need to add
28 # xemacs? ( app-editors/xemacs )
30 # to your DEPEND/RDEPEND line and use the functions provided here to bring
31 # the files to the correct locations.
34 # src_compile() usage:
36 # An elisp file is compiled by the xemacs-elisp-compile() function
37 # defined here and simply takes the source files as arguments.
39 # xemacs-elisp-compile *.el
41 # In the case of interdependent elisp files, you can use the
42 # xemacs-elisp-comp() function which makes sure all files are
45 # xemacs-elisp-comp *.el
47 # Function xemacs-elisp-make-autoload-file() can be used to generate a
48 # file with autoload definitions for the lisp functions. It takes a
49 # list of directories (default: working directory) as its argument.
50 # Use of this function requires that the elisp source files contain
51 # magic ";;;###autoload" comments. See the XEmacs Lisp Reference Manual
52 # (node "Autoload") for a detailed explanation.
55 # src_install() usage:
57 # The resulting compiled files (.elc) should be put in a subdirectory
58 # of /usr/lib/xemacs/site-lisp/ which is named after the first
59 # argument of xemacs-elisp-install(). The following parameters are
60 # the files to be put in that directory. Usually the subdirectory
61 # should be ${PN}, but you can choose something else.
63 # xemacs-elisp-install ${PN} *.el *.elc
65 # To let the XEmacs support be activated by XEmacs on startup, you need
66 # to provide a site file (shipped in ${FILESDIR}) which contains the
67 # startup code (have a look in the documentation of your software).
68 # Normally this would look like this:
70 # (add-to-list 'load-path "@SITELISP@")
71 # (add-to-list 'auto-mode-alist '("\\.csv\\'" . csv-mode))
72 # (autoload 'csv-mode "csv-mode" "Major mode for csv files." t)
74 # If your XEmacs support files are installed in a subdirectory of
75 # /usr/share/xemacs/site-packages/ (which is strongly recommended), you need
76 # to extend XEmacs' load-path as shown in the first non-comment line.
77 # The xemacs-elisp-site-file-install() function of this eclass will replace
78 # "@SITELISP@" by the actual path.
80 # The next line tells XEmacs to load the mode opening a file ending
81 # with ".csv" and load functions depending on the context and needed
82 # features. Be careful though. Commands as "load-library" or "require"
83 # bloat the editor as they are loaded on every startup. When having
84 # many XEmacs support files, users may be annoyed by the start-up time.
85 # Also avoid keybindings as they might interfere with the user's
86 # settings. Give a hint in pkg_postinst(), which should be enough.
88 # The naming scheme for this site-init file matches the shell pattern
89 # "[1-8][0-9]*-gentoo*.el", where the two digits at the beginning define
90 # the loading order (numbers below 10 or above 89 are reserved for
91 # internal use). So if your initialisation depends on another XEmacs
92 # package, your site file's number must be higher! If there are no such
93 # interdependencies then the number should be 50. Otherwise, numbers
94 # divisible by 10 are preferred.
96 # Best practice is to define a SITEFILE variable in the global scope of
97 # your ebuild (e.g., right after S or RDEPEND):
99 # SITEFILE="50${PN}-gentoo.el"
101 # Which is then installed by
103 # xemacs-elisp-site-file-install "${FILESDIR}/${SITEFILE}" || die
105 # in src_install(). Any characters after the "-gentoo" part and before
106 # the extension will be stripped from the destination file's name.
107 # For example, a file "50${PN}-gentoo-${PV}.el" will be installed as
108 # "50${PN}-gentoo.el". If your subdirectory is not named ${PN}, give
109 # the differing name as second argument.
111 # @ECLASS-VARIABLE: XEMACS_SITELISP
113 # Directory where packages install indivivual XEmacs Lisp files.
114 XEMACS_SITELISP=/usr/share/xemacs/site-lisp
116 # @ECLASS-VARIABLE: XEMACS_SITEPACKAGE
118 # Directory where packages install XEmacs Lisp packages.
119 XEMACS_SITEPACKAGE=/usr/share/xemacs/site-packages
121 # @ECLASS-VARIABLE: XEMACS
123 # Path of XEmacs executable.
124 XEMACS=/usr/bin/xemacs
126 # @ECLASS-VARIABLE: XEMACS_BATCH_CLEAN
128 # Invocation of XEMACS in batch mode.
129 XEMACS_BATCH_CLEAN="${XEMACS} --batch --no-site-file --no-init-file"
131 # @FUNCTION: xemacs-elisp-compile
132 # @USAGE: <list of elisp files>
134 # Byte-compile elisp files with xemacs. This function will die when
135 # there is a problem compiling the lisp files.
136 xemacs-elisp-compile () {
138 ${XEMACS_BATCH_CLEAN} -f batch-byte-compile "$@"
139 xemacs-elisp-make-autoload-file "$@"
140 } || die "Compile lisp files failed"
143 xemacs-elisp-make-autoload-file () {
144 ${XEMACS_BATCH_CLEAN} \
145 -eval "(setq autoload-package-name \"${PN}\")" \
146 -eval "(setq generated-autoload-file \"${S}/auto-autoloads.el\")" \
147 -l autoload -f batch-update-autoloads "$@"
150 # @FUNCTION: xemacs-elisp-install
151 # @USAGE: <subdirectory> <list of files>
153 # Install elisp source and byte-compiled files. All files are installed
154 # in site-packages in their own directory, indicated by the first
155 # argument to the function. This function will die if there is a problem
156 # installing the list files.
158 xemacs-elisp-install () {
161 ( # use sub-shell to avoid possible environment polution
162 dodir "${XEMACS_SITEPACKAGE}"/lisp/"${subdir}"
163 insinto "${XEMACS_SITEPACKAGE}"/lisp/"${subdir}"
165 ) || die "Installing lisp files failed"
168 # @FUNCTION: xemacs-elisp-comp
169 # @USAGE: <list of elisp files>
171 # Byte-compile interdependent XEmacs lisp files.
172 # Originally taken from GNU autotools, but some configuration options
173 # removed as they don't make sense with the current status of XEmacs
176 xemacs-elisp-comp() {
177 # Copyright 1995 Free Software Foundation, Inc.
178 # François Pinard <pinard@iro.umontreal.ca>, 1995.
179 # This script byte-compiles all `.el' files which are part of its
180 # arguments, using XEmacs, and put the resulting `.elc' files into
181 # the current directory, so disregarding the original directories used
182 # in `.el' arguments.
184 # This script manages in such a way that all XEmacs LISP files to
185 # be compiled are made visible between themselves, in the event
186 # they require or load-library one another.
188 test $# -gt 0 || return 1
190 einfo "Compiling XEmacs Elisp files ..."
197 echo "(add-to-list 'load-path \"../\")" > script
198 ${XEMACS_BATCH_CLEAN} -l script -f batch-byte-compile *.el
207 # @FUNCTION: xemacs-elisp-site-file-install
208 # @USAGE: <site-init file> [subdirectory]
210 # Install XEmacs site-init file in XEMACS_SITELISP directory.
211 # Automatically inserts a standard comment header with the name of the
212 # package (unless it is already present). Token @SITELISP@ is replaced
213 # by the path to the package's subdirectory in XEMACS_SITELISP.
215 xemacs-elisp-site-file-install() {
216 local sf="${1##*/}" my_pn="${2:-${PN}}" ret
217 local header=";;; ${PN} site-lisp configuration"
219 [[ ${sf} == [0-9][0-9]*-gentoo*.el ]] \
220 || ewarn "xemacs-elisp-site-file-install: bad name of site-init file"
221 sf="${T}/${sf/%-gentoo*.el/-gentoo.el}"
222 ebegin "Installing site initialisation file for XEmacs"
223 [[ $1 = "${sf}" ]] || cp "$1" "${sf}"
224 sed -i -e "1{:x;/^\$/{n;bx;};/^;.*${PN}/I!s:^:${header}\n\n:;1s:^:\n:;}" \
225 -e "s:@SITELISP@:${EPREFIX}${XEMACS_SITELISP}/${my_pn}:g" "${sf}"
226 ( # subshell to avoid pollution of calling environment
227 insinto "${XEMACS_SITELISP}/site-gentoo.d"
232 eend ${ret} "xemacs-elisp-site-file-install: doins failed"
235 # @FUNCTION: xemacs-elisp-site-regen
237 # Regenerate the site-gentoo.el file, based on packages' site
238 # initialisation files in the /usr/share/xemacs/site-lisp/site-gentoo.d/
241 xemacs-elisp-site-regen() {
242 local sitelisp=${ROOT}${EPREFIX}${XEMACS_SITELISP}
243 local sf i line null="" page=$'\f'
246 if [ ! -d "${sitelisp}" ]; then
247 eerror "xemacs-elisp-site-regen: Directory ${sitelisp} does not exist"
251 if [ ! -d "${T}" ]; then
252 eerror "xemacs-elisp-site-regen: Temporary directory ${T} does not exist"
256 einfon "Regenerating site-gentoo.el for XEmacs (${EBUILD_PHASE}) ..."
258 for sf in "${sitelisp}"/site-gentoo.d/[0-9][0-9]*.el
260 [ -r "${sf}" ] || continue
261 # sort files by their basename. straight insertion sort.
262 for ((i=${#sflist[@]}; i>0; i--)); do
263 [[ ${sf##*/} < ${sflist[i-1]##*/} ]] || break
264 sflist[i]=${sflist[i-1]}
269 cat <<-EOF >"${T}"/site-gentoo.el
270 ;;; site-gentoo.el --- site initialisation for Gentoo-installed packages
273 ;; Automatically generated by xemacs-elisp-common.eclass
274 ;; DO NOT EDIT THIS FILE
278 # Use sed instead of cat here, since files may miss a trailing newline.
279 sed '$q' "${sflist[@]}" </dev/null >>"${T}"/site-gentoo.el
280 cat <<-EOF >>"${T}"/site-gentoo.el
283 (provide 'site-gentoo)
285 ;; Local ${null}Variables:
286 ;; no-byte-compile: t
287 ;; buffer-read-only: t
290 ;;; site-gentoo.el ends here
293 if cmp -s "${sitelisp}"/site-gentoo.el "${T}"/site-gentoo.el; then
294 # This prevents outputting unnecessary text when there
295 # was actually no change.
296 # A case is a remerge where we have doubled output.
297 rm -f "${T}"/site-gentoo.el
300 mv "${T}"/site-gentoo.el "${sitelisp}"/site-gentoo.el
302 case ${#sflist[@]} in
303 0) ewarn "... Huh? No site initialisation files found." ;;
304 1) einfo "... ${#sflist[@]} site initialisation file included." ;;
305 *) einfo "... ${#sflist[@]} site initialisation files included." ;;