1 ;;; ede-proj-elisp.el --- EDE Generic Project Emacs Lisp support
3 ;;; Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007 Eric M. Ludlam
5 ;; Author: Eric M. Ludlam <zappo@gnu.org>
6 ;; Keywords: project, make
7 ;; RCS: $Id: ede-proj-elisp.el,v 1.1 2007-11-26 15:22:08 michaels Exp $
9 ;; This software is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; This software is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
21 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 ;; Boston, MA 02110-1301, USA.
26 ;; Handle Emacs Lisp in and EDE Project file.
33 (defclass ede-proj-target-elisp (ede-proj-target-makefile)
35 (keybindings :initform nil)
37 (sourcetype :initform (ede-source-emacs))
38 (availablecompilers :initform (ede-emacs-compiler ede-xemacs-compiler))
39 (aux-packages :initarg :aux-packages
42 :custom (repeat string)
43 :documentation "Additional packages needed.
44 There should only be one toplevel package per auxiliary tool needed.
45 These packages location is found, and added to the compile time
48 "This target consists of a group of lisp files.
49 A lisp target may be one general program with many separate lisp files in it.")
51 (defvar ede-source-emacs
52 (ede-sourcecode "ede-emacs-source"
54 :sourcepattern "\\.el$"
55 :garbagepattern '("*.elc"))
56 "Emacs Lisp source code definition.")
58 (defvar ede-emacs-compiler
62 :variables '(("EMACS" . "emacs"))
64 '("@echo \"(add-to-list 'load-path nil)\" > $@-compile-script"
65 "for loadpath in . ${LOADPATH}; do \\"
66 " echo \"(add-to-list 'load-path \\\"$$loadpath\\\")\" >> $@-compile-script; \\"
68 "@echo \"(setq debug-on-error t)\" >> $@-compile-script"
69 "\"$(EMACS)\" -batch --no-site-file -l $@-compile-script -f batch-byte-compile $^"
71 :autoconf '("AM_PATH_LISPDIR")
72 :sourcetype '(ede-source-emacs)
73 ; :objectextention ".elc"
75 "Compile Emacs Lisp programs.")
77 (defvar ede-xemacs-compiler
78 (clone ede-emacs-compiler "ede-xemacs-compiler"
80 :variables '(("EMACS" . "xemacs")))
81 "Compile Emacs Lisp programs with XEmacs.")
84 (defmethod ede-buffer-mine ((this ede-proj-target-elisp) buffer)
85 "Return t if object THIS lays claim to the file in BUFFER.
86 Lays claim to all .elc files that match .el files in this target."
87 (if (string-match "\\.elc$" (buffer-file-name buffer))
90 (file-name-sans-extension (buffer-file-name buffer))
93 ;; Is this in our list.
94 (member fname (oref this auxsource))
96 (call-next-method) ; The usual thing.
99 ;;; Emacs Lisp Compiler
100 ;;; Emacs Lisp Target
101 (defun ede-proj-elisp-packages-to-loadpath (packages)
102 "Convert a list of PACKAGES, to a list of load path."
106 (or (setq ldir (locate-library (car packages)))
107 (error "Cannot find package %s" (car packages)))
108 (setq paths (cons (file-relative-name (file-name-directory ldir))
110 packages (cdr packages)))
113 (defmethod project-compile-target ((obj ede-proj-target-elisp))
114 "Compile all sources in a Lisp target OBJ."
115 (let ((cb (current-buffer)))
116 (mapcar (lambda (src)
117 (let ((elc (concat (file-name-sans-extension src) ".elc")))
119 (if (or (not (file-exists-p elc))
120 (file-newer-than-file-p src elc))
121 (byte-compile-file src))))
123 (message "All Emacs Lisp sources are up to date in %s" (object-name obj)))
125 (defmethod ede-update-version-in-source ((this ede-proj-target-elisp) version)
126 "In a Lisp file, updated a version string for THIS to VERSION.
127 There are standards in Elisp files specifying how the version string
128 is found, such as a `-version' variable, or the standard header."
129 (if (and (slot-boundp this 'versionsource)
130 (oref this versionsource))
131 (let ((vs (oref this versionsource))
135 (set-buffer (find-file-noselect
136 (ede-expand-filename this (car vs))))
137 (goto-char (point-min))
138 (let ((case-fold-search t))
139 (if (re-search-forward "-version\\s-+\"\\([^\"]+\\)\"" nil t)
142 (delete-region (match-beginning 1)
144 (goto-char (match-beginning 1))
147 (if (not match) (call-next-method)))))
150 ;;; Makefile generation functions
152 (defmethod ede-proj-makefile-sourcevar ((this ede-proj-target-elisp))
153 "Return the variable name for THIS's sources."
154 (cond ((ede-proj-automake-p) '("lisp_LISP" . share))
155 (t (concat (ede-pmake-varname this) "_LISP"))))
157 (defun ede-proj-makefile-insert-loadpath-items (items)
158 "Insert a sequence of ITEMS into the Makefile LOADPATH variable."
160 (ede-pmake-insert-variable-shared "LOADPATH"
161 (let ((begin (save-excursion (re-search-backward "\\s-*="))))
163 (when (not (save-excursion
165 (concat "\\s-" (regexp-quote (car items)) "[ \n\t\\]")
167 (insert " " (car items)))
168 (setq items (cdr items)))))
171 (defmethod ede-proj-makefile-insert-variables :AFTER ((this ede-proj-target-elisp))
172 "Insert variables needed by target THIS."
173 (let ((newitems (if (oref this aux-packages)
174 (ede-proj-elisp-packages-to-loadpath
175 (oref this aux-packages))))
177 (ede-proj-makefile-insert-loadpath-items newitems)))
179 (defun ede-proj-elisp-add-path (path)
180 "Add path PATH into the file if it isn't already there."
181 (goto-char (point-min))
182 (if (re-search-forward (concat "(cons \\\""
185 nil;; We have it already
186 (if (re-search-forward "(cons nil" nil t)
191 " echo \"(setq load-path (cons \\\""
193 "\\\" load-path))\" >> script")
195 (error "Don't know how to update load path"))))
197 (defmethod ede-proj-tweak-autoconf ((this ede-proj-target-elisp))
198 "Tweak the configure file (current buffer) to accomodate THIS."
200 ;; Ok, now we have to tweak the autoconf provided `elisp-comp' program.
201 (let ((ec (ede-expand-filename this "elisp-comp")))
202 (if (not (file-exists-p ec))
203 (message "There may be compile errors. Rerun a second time.")
205 (if (file-symlink-p ec)
208 (rename-file ec (concat ec ".tmp"))
209 (copy-file (concat ec ".tmp") ec)
210 (delete-file (concat ec ".tmp"))))
211 (set-buffer (find-file-noselect ec t))
212 (ede-proj-elisp-add-path "..")
213 (let ((paths (ede-proj-elisp-packages-to-loadpath
214 (oref this aux-packages))))
215 ;; Add in the current list of paths
217 (ede-proj-elisp-add-path (car paths))
218 (setq paths (cdr paths))))
221 (defmethod ede-proj-flush-autoconf ((this ede-proj-target-elisp))
222 "Flush the configure file (current buffer) to accomodate THIS."
223 ;; Remove crufty old paths from elisp-compile
224 (let ((ec (ede-expand-filename this "elisp-comp"))
225 (paths (ede-proj-elisp-packages-to-loadpath
226 (oref this aux-packages))))
227 (if (file-exists-p ec)
229 (set-buffer (find-file-noselect ec t))
230 (goto-char (point-min))
231 (while (re-search-forward "(cons \\([^ ]+\\) load-path)"
233 (let ((path (match-string 1)))
234 (if (string= path "nil")
236 (delete-region (save-excursion (beginning-of-line) (point))
237 (save-excursion (end-of-line)
242 ;; Autoload generators
244 (defclass ede-proj-target-elisp-autoloads (ede-proj-target-elisp)
245 ((availablecompilers :initform (ede-emacs-cedet-autogen-compiler))
246 (aux-packages :initform ("cedet-autogen"))
248 (autoload-file :initarg :autoload-file
249 :initform "loaddefs.el"
252 :documentation "The file that autoload definitions are placed in.
253 There should be one load defs file for a given package. The load defs are created
254 for all Emacs Lisp sources that exist in the directory of the created target.")
255 (autoload-dirs :initarg :autoload-dirs
258 :custom (repeat string)
259 :documentation "The directories to scan for autoload definitions.
260 If nil defaults to the current directory.")
262 "Target that builds an autoload file.
263 Files do not need to be added to this target.")
265 (defvar ede-emacs-cedet-autogen-compiler
267 "ede-emacs-autogen-compiler"
269 :variables '(("EMACS" . "emacs"))
271 '("@echo \"(add-to-list 'load-path nil)\" > $@-compile-script"
272 "for loadpath in . ${LOADPATH}; do \\"
273 " echo \"(add-to-list 'load-path \\\"$$loadpath\\\")\" >> $@-compile-script; \\"
275 "@echo \"(require 'cedet-autogen)\" >> $@-compile-script"
276 "\"$(EMACS)\" -batch --no-site-file -l $@-compile-script -f cedet-batch-update-autoloads $(LOADDEFS) $(LOADDIRS)"
278 :sourcetype '(ede-source-emacs)
280 "Build an autoloads file.")
282 (defmethod ede-proj-compilers ((obj ede-proj-target-elisp-autoloads))
283 "List of compilers being used by OBJ.
284 If the `compiler' slot is empty, get the car of the compilers list."
285 (let ((comp (oref obj compiler)))
288 (setq comp (mapcar 'symbol-value comp))
289 (setq comp (list (symbol-value comp))))
290 ;; Get the first element from our list of compilers.
291 (let ((avail (mapcar 'symbol-value (oref obj availablecompilers))))
292 (setq comp (list (car avail)))))
295 (defmethod ede-proj-makefile-insert-source-variables ((this ede-proj-target-elisp-autoloads)
298 "Insert the source variables needed by THIS.
299 Optional argument MORESOURCE is a list of additional sources to add to the
303 (defmethod ede-proj-makefile-sourcevar ((this ede-proj-target-elisp-autoloads))
304 "Return the variable name for THIS's sources."
307 (defmethod ede-proj-makefile-dependencies ((this ede-proj-target-elisp-autoloads))
308 "Return a string representing the dependencies for THIS.
309 Always return an empty string for an autoloads generator."
312 (defmethod ede-proj-makefile-insert-variables :AFTER ((this ede-proj-target-elisp-autoloads))
313 "Insert variables needed by target THIS."
314 (ede-pmake-insert-variable-shared "LOADDEFS"
315 (insert (oref this autoload-file)))
316 (ede-pmake-insert-variable-shared "LOADDIRS"
317 (insert (mapconcat 'identity
318 (or (oref this autoload-dirs) '("."))
322 (defmethod project-compile-target ((obj ede-proj-target-elisp-autoloads))
323 "Create or update the autoload target."
324 (require 'cedet-autogen)
325 (call-interactively 'cedet-update-autoloads))
327 (defmethod ede-update-version-in-source ((this ede-proj-target-elisp-autoloads) version)
328 "In a Lisp file, updated a version string for THIS to VERSION.
329 There are standards in Elisp files specifying how the version string
330 is found, such as a `-version' variable, or the standard header."
333 (defmethod ede-proj-makefile-insert-dist-dependencies ((this ede-proj-target-elisp-autoloads))
334 "Insert any symbols that the DIST rule should depend on.
335 Emacs Lisp autoload files ship the generated .el files.
336 Argument THIS is the target which needs to insert an info file."
337 ;; In some cases, this is ONLY the index file. That should generally
339 (insert " " (ede-proj-makefile-target-name this))
342 (defmethod ede-proj-makefile-insert-dist-filepatterns ((this ede-proj-target-elisp-autoloads))
343 "Insert any symbols that the DIST rule should distribute.
344 Emacs Lisp autoload files ship the generated .el files.
345 Argument THIS is the target which needs to insert an info file."
346 (insert " " (oref this autoload-file))
349 (defmethod ede-proj-tweak-autoconf ((this ede-proj-target-elisp-autoloads))
350 "Tweak the configure file (current buffer) to accomodate THIS."
351 (error "Autoloads not supported in autoconf yet."))
353 (defmethod ede-proj-flush-autoconf ((this ede-proj-target-elisp-autoloads))
354 "Flush the configure file (current buffer) to accomodate THIS."
357 (provide 'ede-proj-elisp)
359 ;;; ede-proj-elisp.el ends here