| 1 |
# Copyright 1999-2012 Gentoo Foundation
|
| 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.6 2012/05/19 16:26:10 ulm Exp $
|
| 4 |
#
|
| 5 |
# Copyright 2007-2011 Hans de Graaff <graaff@gentoo.org>
|
| 6 |
#
|
| 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>
|
| 13 |
#
|
| 14 |
# @ECLASS: xemacs-elisp-common.eclass
|
| 15 |
# @MAINTAINER:
|
| 16 |
# xemacs@gentoo.org
|
| 17 |
# @BLURB: XEmacs-related installation utilities
|
| 18 |
# @DESCRIPTION:
|
| 19 |
#
|
| 20 |
# Usually you want to use this eclass for (optional) XEmacs support of
|
| 21 |
# your package. This is NOT for GNU Emacs!
|
| 22 |
#
|
| 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.
|
| 26 |
#
|
| 27 |
# When relying on the xemacs USE flag, you need to add
|
| 28 |
#
|
| 29 |
# xemacs? ( app-editors/xemacs )
|
| 30 |
#
|
| 31 |
# to your DEPEND/RDEPEND line and use the functions provided here to bring
|
| 32 |
# the files to the correct locations.
|
| 33 |
#
|
| 34 |
# @ROFF .SS
|
| 35 |
# src_compile() usage:
|
| 36 |
#
|
| 37 |
# An elisp file is compiled by the xemacs-elisp-compile() function
|
| 38 |
# defined here and simply takes the source files as arguments.
|
| 39 |
#
|
| 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
|
| 47 |
#
|
| 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.
|
| 54 |
#
|
| 55 |
# @ROFF .SS
|
| 56 |
# src_install() usage:
|
| 57 |
#
|
| 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.
|
| 63 |
#
|
| 64 |
# xemacs-elisp-install ${PN} *.el *.elc
|
| 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.
|
| 111 |
|
| 112 |
# @ECLASS-VARIABLE: XEMACS_SITELISP
|
| 113 |
# @DESCRIPTION:
|
| 114 |
# Directory where packages install indivivual XEmacs Lisp files.
|
| 115 |
XEMACS_SITELISP=/usr/share/xemacs/site-lisp
|
| 116 |
|
| 117 |
# @ECLASS-VARIABLE: XEMACS_SITEPACKAGE
|
| 118 |
# @DESCRIPTION:
|
| 119 |
# Directory where packages install XEmacs Lisp packages.
|
| 120 |
XEMACS_SITEPACKAGE=/usr/share/xemacs/site-packages
|
| 121 |
|
| 122 |
# @ECLASS-VARIABLE: XEMACS
|
| 123 |
# @DESCRIPTION:
|
| 124 |
# Path of XEmacs executable.
|
| 125 |
XEMACS=/usr/bin/xemacs
|
| 126 |
|
| 127 |
# @ECLASS-VARIABLE: XEMACS_BATCH_CLEAN
|
| 128 |
# @DESCRIPTION:
|
| 129 |
# Invocation of XEMACS in batch mode.
|
| 130 |
XEMACS_BATCH_CLEAN="${XEMACS} --batch --no-site-file --no-init-file"
|
| 131 |
|
| 132 |
# @FUNCTION: xemacs-elisp-compile
|
| 133 |
# @USAGE: <list of elisp files>
|
| 134 |
# @DESCRIPTION:
|
| 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 () {
|
| 138 |
{
|
| 139 |
${XEMACS_BATCH_CLEAN} -f batch-byte-compile "$@"
|
| 140 |
xemacs-elisp-make-autoload-file "$@"
|
| 141 |
} || die "Compile lisp files failed"
|
| 142 |
}
|
| 143 |
|
| 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 "$@"
|
| 149 |
}
|
| 150 |
|
| 151 |
# @FUNCTION: xemacs-elisp-install
|
| 152 |
# @USAGE: <subdirectory> <list of files>
|
| 153 |
# @DESCRIPTION:
|
| 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.
|
| 158 |
|
| 159 |
xemacs-elisp-install () {
|
| 160 |
local subdir="$1"
|
| 161 |
shift
|
| 162 |
( # use sub-shell to avoid possible environment polution
|
| 163 |
dodir "${XEMACS_SITEPACKAGE}"/lisp/"${subdir}"
|
| 164 |
insinto "${XEMACS_SITEPACKAGE}"/lisp/"${subdir}"
|
| 165 |
doins "$@"
|
| 166 |
) || die "Installing lisp files failed"
|
| 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 |
|
| 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.
|
| 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 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.
|
| 215 |
|
| 216 |
xemacs-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}${XEMACS_SITELISP}/${my_pn}:g" "${sf}"
|
| 227 |
( # subshell to avoid pollution of calling environment
|
| 228 |
insinto "${XEMACS_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 |
|
| 242 |
xemacs-elisp-site-regen() {
|
| 243 |
local sitelisp=${ROOT}${EPREFIX}${XEMACS_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 |
}
|