x11-terms/mlterm: Fix typo in metadata.xml
[gentoo.git] / eclass / xemacs-elisp-common.eclass
1 # Copyright 1999-2012 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 #
4 # Copyright 2007-2011 Hans de Graaff <graaff@gentoo.org>
5 #
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>
12 #
13 # @ECLASS: xemacs-elisp-common.eclass
14 # @MAINTAINER:
15 # xemacs@gentoo.org
16 # @BLURB: XEmacs-related installation utilities
17 # @DESCRIPTION:
18 #
19 # Usually you want to use this eclass for (optional) XEmacs support of
20 # your package.  This is NOT for GNU Emacs!
21 #
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.
25 #
26 # When relying on the xemacs USE flag, you need to add
27 #
28 #       xemacs? ( app-editors/xemacs )
29 #
30 # to your DEPEND/RDEPEND line and use the functions provided here to bring
31 # the files to the correct locations.
32 #
33 # @ROFF .SS
34 # src_compile() usage:
35 #
36 # An elisp file is compiled by the xemacs-elisp-compile() function
37 # defined here and simply takes the source files as arguments.
38 #
39 #   xemacs-elisp-compile *.el
40 #
41 # In the case of interdependent elisp files, you can use the
42 # xemacs-elisp-comp() function which makes sure all files are
43 # loadable.
44 #
45 #   xemacs-elisp-comp *.el
46 #
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.
53 #
54 # @ROFF .SS
55 # src_install() usage:
56 #
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.
62 #
63 #   xemacs-elisp-install ${PN} *.el *.elc
64 #
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:
69 #
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)
73 #
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.
79 #
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.
87 #
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.
95 #
96 # Best practice is to define a SITEFILE variable in the global scope of
97 # your ebuild (e.g., right after S or RDEPEND):
98 #
99 #       SITEFILE="50${PN}-gentoo.el"
100 #
101 # Which is then installed by
102 #
103 #       xemacs-elisp-site-file-install "${FILESDIR}/${SITEFILE}" || die
104 #
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.
110
111 # @ECLASS-VARIABLE: XEMACS_SITELISP
112 # @DESCRIPTION:
113 # Directory where packages install indivivual XEmacs Lisp files.
114 XEMACS_SITELISP=/usr/share/xemacs/site-lisp
115
116 # @ECLASS-VARIABLE: XEMACS_SITEPACKAGE
117 # @DESCRIPTION:
118 # Directory where packages install XEmacs Lisp packages.
119 XEMACS_SITEPACKAGE=/usr/share/xemacs/site-packages
120
121 # @ECLASS-VARIABLE: XEMACS
122 # @DESCRIPTION:
123 # Path of XEmacs executable.
124 XEMACS=/usr/bin/xemacs
125
126 # @ECLASS-VARIABLE: XEMACS_BATCH_CLEAN
127 # @DESCRIPTION:
128 # Invocation of XEMACS in batch mode.
129 XEMACS_BATCH_CLEAN="${XEMACS} --batch --no-site-file --no-init-file"
130
131 # @FUNCTION: xemacs-elisp-compile
132 # @USAGE: <list of elisp files>
133 # @DESCRIPTION:
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 () {
137         {
138                 ${XEMACS_BATCH_CLEAN} -f batch-byte-compile "$@"
139                 xemacs-elisp-make-autoload-file "$@"
140         } || die "Compile lisp files failed"
141 }
142
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 "$@"
148 }
149
150 # @FUNCTION: xemacs-elisp-install
151 # @USAGE: <subdirectory> <list of files>
152 # @DESCRIPTION:
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.
157
158 xemacs-elisp-install () {
159         local subdir="$1"
160         shift
161         (  # use sub-shell to avoid possible environment polution
162                 dodir "${XEMACS_SITEPACKAGE}"/lisp/"${subdir}"
163                 insinto "${XEMACS_SITEPACKAGE}"/lisp/"${subdir}"
164                 doins "$@"
165         ) || die "Installing lisp files failed"
166 }
167
168 # @FUNCTION: xemacs-elisp-comp
169 # @USAGE: <list of elisp files>
170 # @DESCRIPTION:
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
174 # in Gentoo.
175
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.
183         #
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.
187
188         test $# -gt 0 || return 1
189
190         einfo "Compiling XEmacs Elisp files ..."
191
192         tempdir=elc.$$
193         mkdir ${tempdir}
194         cp "$@" ${tempdir}
195         pushd ${tempdir}
196
197         echo "(add-to-list 'load-path \"../\")" > script
198         ${XEMACS_BATCH_CLEAN} -l script -f batch-byte-compile *.el
199         local ret=$?
200         mv *.elc ..
201
202         popd
203         rm -fr ${tempdir}
204         return ${ret}
205 }
206
207 # @FUNCTION: xemacs-elisp-site-file-install
208 # @USAGE: <site-init file> [subdirectory]
209 # @DESCRIPTION:
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.
214
215 xemacs-elisp-site-file-install() {
216         local sf="${1##*/}" my_pn="${2:-${PN}}" ret
217         local header=";;; ${PN} site-lisp configuration"
218
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"
228                 doins "${sf}"
229         )
230         ret=$?
231         rm -f "${sf}"
232         eend ${ret} "xemacs-elisp-site-file-install: doins failed"
233 }
234
235 # @FUNCTION: xemacs-elisp-site-regen
236 # @DESCRIPTION:
237 # Regenerate the site-gentoo.el file, based on packages' site
238 # initialisation files in the /usr/share/xemacs/site-lisp/site-gentoo.d/
239 # directory.
240
241 xemacs-elisp-site-regen() {
242         local sitelisp=${ROOT}${EPREFIX}${XEMACS_SITELISP}
243         local sf i line null="" page=$'\f'
244         local -a sflist
245
246         if [ ! -d "${sitelisp}" ]; then
247                 eerror "xemacs-elisp-site-regen: Directory ${sitelisp} does not exist"
248                 return 1
249         fi
250
251         if [ ! -d "${T}" ]; then
252                 eerror "xemacs-elisp-site-regen: Temporary directory ${T} does not exist"
253                 return 1
254         fi
255
256         einfon "Regenerating site-gentoo.el for XEmacs (${EBUILD_PHASE}) ..."
257
258         for sf in "${sitelisp}"/site-gentoo.d/[0-9][0-9]*.el
259         do
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]}
265                 done
266                 sflist[i]=${sf}
267         done
268
269         cat <<-EOF >"${T}"/site-gentoo.el
270         ;;; site-gentoo.el --- site initialisation for Gentoo-installed packages
271
272         ;;; Commentary:
273         ;; Automatically generated by xemacs-elisp-common.eclass
274         ;; DO NOT EDIT THIS FILE
275
276         ;;; Code:
277         EOF
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
281
282         ${page}
283         (provide 'site-gentoo)
284
285         ;; Local ${null}Variables:
286         ;; no-byte-compile: t
287         ;; buffer-read-only: t
288         ;; End:
289
290         ;;; site-gentoo.el ends here
291         EOF
292
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
298                 echo " no changes."
299         else
300                 mv "${T}"/site-gentoo.el "${sitelisp}"/site-gentoo.el
301                 echo
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." ;;
306                 esac
307         fi
308
309         return 0
310 }