xemacs-elisp-common.eclass 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  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. # @ECLASS-VARIABLE: XEMACS_SITELISP
  111. # @DESCRIPTION:
  112. # Directory where packages install indivivual XEmacs Lisp files.
  113. XEMACS_SITELISP=/usr/share/xemacs/site-lisp
  114. # @ECLASS-VARIABLE: XEMACS_SITEPACKAGE
  115. # @DESCRIPTION:
  116. # Directory where packages install XEmacs Lisp packages.
  117. XEMACS_SITEPACKAGE=/usr/share/xemacs/site-packages
  118. # @ECLASS-VARIABLE: XEMACS
  119. # @DESCRIPTION:
  120. # Path of XEmacs executable.
  121. XEMACS=/usr/bin/xemacs
  122. # @ECLASS-VARIABLE: XEMACS_BATCH_CLEAN
  123. # @DESCRIPTION:
  124. # Invocation of XEMACS in batch mode.
  125. XEMACS_BATCH_CLEAN="${XEMACS} --batch --no-site-file --no-init-file"
  126. # @FUNCTION: xemacs-elisp-compile
  127. # @USAGE: <list of elisp files>
  128. # @DESCRIPTION:
  129. # Byte-compile elisp files with xemacs. This function will die when
  130. # there is a problem compiling the lisp files.
  131. xemacs-elisp-compile () {
  132. {
  133. ${XEMACS_BATCH_CLEAN} -f batch-byte-compile "$@"
  134. xemacs-elisp-make-autoload-file "$@"
  135. } || die "Compile lisp files failed"
  136. }
  137. xemacs-elisp-make-autoload-file () {
  138. ${XEMACS_BATCH_CLEAN} \
  139. -eval "(setq autoload-package-name \"${PN}\")" \
  140. -eval "(setq generated-autoload-file \"${S}/auto-autoloads.el\")" \
  141. -l autoload -f batch-update-autoloads "$@"
  142. }
  143. # @FUNCTION: xemacs-elisp-install
  144. # @USAGE: <subdirectory> <list of files>
  145. # @DESCRIPTION:
  146. # Install elisp source and byte-compiled files. All files are installed
  147. # in site-packages in their own directory, indicated by the first
  148. # argument to the function. This function will die if there is a problem
  149. # installing the list files.
  150. xemacs-elisp-install () {
  151. local subdir="$1"
  152. shift
  153. ( # use sub-shell to avoid possible environment polution
  154. dodir "${XEMACS_SITEPACKAGE}"/lisp/"${subdir}"
  155. insinto "${XEMACS_SITEPACKAGE}"/lisp/"${subdir}"
  156. doins "$@"
  157. ) || die "Installing lisp files failed"
  158. }
  159. # @FUNCTION: xemacs-elisp-comp
  160. # @USAGE: <list of elisp files>
  161. # @DESCRIPTION:
  162. # Byte-compile interdependent XEmacs lisp files.
  163. # Originally taken from GNU autotools, but some configuration options
  164. # removed as they don't make sense with the current status of XEmacs
  165. # in Gentoo.
  166. xemacs-elisp-comp() {
  167. # Copyright 1995 Free Software Foundation, Inc.
  168. # François Pinard <pinard@iro.umontreal.ca>, 1995.
  169. # This script byte-compiles all `.el' files which are part of its
  170. # arguments, using XEmacs, and put the resulting `.elc' files into
  171. # the current directory, so disregarding the original directories used
  172. # in `.el' arguments.
  173. #
  174. # This script manages in such a way that all XEmacs LISP files to
  175. # be compiled are made visible between themselves, in the event
  176. # they require or load-library one another.
  177. test $# -gt 0 || return 1
  178. einfo "Compiling XEmacs Elisp files ..."
  179. tempdir=elc.$$
  180. mkdir ${tempdir}
  181. cp "$@" ${tempdir}
  182. pushd ${tempdir}
  183. echo "(add-to-list 'load-path \"../\")" > script
  184. ${XEMACS_BATCH_CLEAN} -l script -f batch-byte-compile *.el
  185. local ret=$?
  186. mv *.elc ..
  187. popd
  188. rm -fr ${tempdir}
  189. return ${ret}
  190. }
  191. # @FUNCTION: xemacs-elisp-site-file-install
  192. # @USAGE: <site-init file> [subdirectory]
  193. # @DESCRIPTION:
  194. # Install XEmacs site-init file in XEMACS_SITELISP directory.
  195. # Automatically inserts a standard comment header with the name of the
  196. # package (unless it is already present). Token @SITELISP@ is replaced
  197. # by the path to the package's subdirectory in XEMACS_SITELISP.
  198. xemacs-elisp-site-file-install() {
  199. local sf="${1##*/}" my_pn="${2:-${PN}}" ret
  200. local header=";;; ${PN} site-lisp configuration"
  201. [[ ${sf} == [0-9][0-9]*-gentoo*.el ]] \
  202. || ewarn "xemacs-elisp-site-file-install: bad name of site-init file"
  203. sf="${T}/${sf/%-gentoo*.el/-gentoo.el}"
  204. ebegin "Installing site initialisation file for XEmacs"
  205. [[ $1 = "${sf}" ]] || cp "$1" "${sf}"
  206. sed -i -e "1{:x;/^\$/{n;bx;};/^;.*${PN}/I!s:^:${header}\n\n:;1s:^:\n:;}" \
  207. -e "s:@SITELISP@:${EPREFIX}${XEMACS_SITELISP}/${my_pn}:g" "${sf}"
  208. ( # subshell to avoid pollution of calling environment
  209. insinto "${XEMACS_SITELISP}/site-gentoo.d"
  210. doins "${sf}"
  211. )
  212. ret=$?
  213. rm -f "${sf}"
  214. eend ${ret} "xemacs-elisp-site-file-install: doins failed"
  215. }
  216. # @FUNCTION: xemacs-elisp-site-regen
  217. # @DESCRIPTION:
  218. # Regenerate the site-gentoo.el file, based on packages' site
  219. # initialisation files in the /usr/share/xemacs/site-lisp/site-gentoo.d/
  220. # directory.
  221. xemacs-elisp-site-regen() {
  222. local sitelisp=${ROOT}${EPREFIX}${XEMACS_SITELISP}
  223. local sf i line null="" page=$'\f'
  224. local -a sflist
  225. if [ ! -d "${sitelisp}" ]; then
  226. eerror "xemacs-elisp-site-regen: Directory ${sitelisp} does not exist"
  227. return 1
  228. fi
  229. if [ ! -d "${T}" ]; then
  230. eerror "xemacs-elisp-site-regen: Temporary directory ${T} does not exist"
  231. return 1
  232. fi
  233. einfon "Regenerating site-gentoo.el for XEmacs (${EBUILD_PHASE}) ..."
  234. for sf in "${sitelisp}"/site-gentoo.d/[0-9][0-9]*.el
  235. do
  236. [ -r "${sf}" ] || continue
  237. # sort files by their basename. straight insertion sort.
  238. for ((i=${#sflist[@]}; i>0; i--)); do
  239. [[ ${sf##*/} < ${sflist[i-1]##*/} ]] || break
  240. sflist[i]=${sflist[i-1]}
  241. done
  242. sflist[i]=${sf}
  243. done
  244. cat <<-EOF >"${T}"/site-gentoo.el
  245. ;;; site-gentoo.el --- site initialisation for Gentoo-installed packages
  246. ;;; Commentary:
  247. ;; Automatically generated by xemacs-elisp-common.eclass
  248. ;; DO NOT EDIT THIS FILE
  249. ;;; Code:
  250. EOF
  251. # Use sed instead of cat here, since files may miss a trailing newline.
  252. sed '$q' "${sflist[@]}" </dev/null >>"${T}"/site-gentoo.el
  253. cat <<-EOF >>"${T}"/site-gentoo.el
  254. ${page}
  255. (provide 'site-gentoo)
  256. ;; Local ${null}Variables:
  257. ;; no-byte-compile: t
  258. ;; buffer-read-only: t
  259. ;; End:
  260. ;;; site-gentoo.el ends here
  261. EOF
  262. if cmp -s "${sitelisp}"/site-gentoo.el "${T}"/site-gentoo.el; then
  263. # This prevents outputting unnecessary text when there
  264. # was actually no change.
  265. # A case is a remerge where we have doubled output.
  266. rm -f "${T}"/site-gentoo.el
  267. echo " no changes."
  268. else
  269. mv "${T}"/site-gentoo.el "${sitelisp}"/site-gentoo.el
  270. echo
  271. case ${#sflist[@]} in
  272. 0) ewarn "... Huh? No site initialisation files found." ;;
  273. 1) einfo "... ${#sflist[@]} site initialisation file included." ;;
  274. *) einfo "... ${#sflist[@]} site initialisation files included." ;;
  275. esac
  276. fi
  277. return 0
  278. }