]> code.delx.au - gnu-emacs/blobdiff - lisp/cedet/ede/proj-elisp.el
Merge from origin/emacs-24
[gnu-emacs] / lisp / cedet / ede / proj-elisp.el
index f442b1a071f4ea10c7ed4e0dd639d30ace7c484a..778d485c44cdf0862d553121bccc51feeb23f04c 100644 (file)
@@ -1,7 +1,6 @@
 ;;; ede-proj-elisp.el --- EDE Generic Project Emacs Lisp support
 
-;; Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007,
-;;   2008, 2009, 2010, 2011  Free Software Foundation, Inc.
+;; Copyright (C) 1998-2005, 2007-2015 Free Software Foundation, Inc.
 
 ;; Author: Eric M. Ludlam <zappo@gnu.org>
 ;; Keywords: project, make
 There should only be one toplevel package per auxiliary tool needed.
 These packages location is found, and added to the compile time
 load path."
-   ))
+   )
+   (pre-load-packages :initarg :pre-load-packages
+                     :initform nil
+                     :type list
+                     :custom (repeat string)
+                     :documentation "Additional packages to pre-load.
+Each package name will be loaded with `require'.
+Each package's directory should also appear in :aux-packages via a package name.")
+   )
   "This target consists of a group of lisp files.
 A lisp target may be one general program with many separate lisp files in it.")
 
+(cl-defmethod ede-proj-makefile-insert-rules :after ((this ede-proj-target-elisp))
+    "Insert rules needed by THIS target.
+This inserts the PRELOADS target-local variable."
+    (let ((preloads (oref this pre-load-packages)))
+      (when preloads
+       (insert (format "%s: PRELOADS=%s\n"
+                       (oref this name)
+                       (mapconcat 'identity preloads " ")))))
+    (insert "\n"))
+
+(cl-defmethod ede-proj-makefile-dependencies ((this ede-proj-target-elisp))
+  "Return a string representing the dependencies for THIS.
+Some compilers only use the first element in the dependencies, others
+have a list of intermediates (object files), and others don't care.
+This allows customization of how these elements appear.
+For Emacs Lisp, return addsuffix command on source files."
+  (format "$(addsuffix c, $(%s))"
+         (ede-proj-makefile-sourcevar this)))
+
 (defvar ede-source-emacs
   (ede-sourcecode "ede-emacs-source"
                  :name "Emacs Lisp"
@@ -62,18 +88,17 @@ A lisp target may be one general program with many separate lisp files in it.")
    "ede-emacs-compiler"
    :name "emacs"
    :variables '(("EMACS" . "emacs")
-               ("EMACSFLAGS" . "-batch --no-site-file"))
-   :commands
-   '("@echo \"(add-to-list 'load-path nil)\" > $@-compile-script"
-     "for loadpath in . ${LOADPATH}; do \\"
-     "   echo \"(add-to-list 'load-path \\\"$$loadpath\\\")\" >> $@-compile-script; \\"
-     "done;"
-     "@echo \"(setq debug-on-error t)\" >> $@-compile-script"
-     "\"$(EMACS)\" $(EMACSFLAGS) -l $@-compile-script -f batch-byte-compile $^"
-     )
+               ("EMACSFLAGS" . "-batch --no-site-file --eval '(setq debug-on-error t)'")
+               ("require" . "$(foreach r,$(1),(require (quote $(r))))"))
+   :rules (list (ede-makefile-rule
+                "elisp-inference-rule"
+                :target "%.elc"
+                :dependencies "%.el"
+                :rules '("$(EMACS) $(EMACSFLAGS) $(addprefix -L ,$(LOADPATH)) \
+--eval '(progn $(call require, $(PRELOADS)))' -f batch-byte-compile $^")))
    :autoconf '("AM_PATH_LISPDIR")
    :sourcetype '(ede-source-emacs)
-;   :objectextention ".elc"
+   :objectextention ".elc"
    )
   "Compile Emacs Lisp programs.")
 
@@ -84,7 +109,7 @@ A lisp target may be one general program with many separate lisp files in it.")
   "Compile Emacs Lisp programs with XEmacs.")
 
 ;;; Claiming files
-(defmethod ede-buffer-mine ((this ede-proj-target-elisp) buffer)
+(cl-defmethod ede-buffer-mine ((this ede-proj-target-elisp) buffer)
   "Return t if object THIS lays claim to the file in BUFFER.
 Lays claim to all .elc files that match .el files in this target."
   (if (string-match "\\.elc$" (buffer-file-name buffer))
@@ -96,7 +121,7 @@ Lays claim to all .elc files that match .el files in this target."
        ;; Is this in our list.
        (member fname (oref this auxsource))
        )
-    (call-next-method) ; The usual thing.
+    (cl-call-next-method) ; The usual thing.
     ))
 
 ;;; Emacs Lisp Compiler
@@ -113,14 +138,14 @@ Lays claim to all .elc files that match .el files in this target."
             (full nil)
             )
        ;; Make sure the relative name isn't to far off
-       (when (string-match "^\\.\\./\\.\\./\\.\\./\\.\\." rel)
+       (when (string-match "^\\.\\./\\.\\./\\.\\./\\.\\./\\.\\." rel)
          (setq full fnd))
        ;; Do the setup.
        (setq paths (cons (or full rel) paths)
              packages (cdr packages))))
     paths))
 
-(defmethod project-compile-target ((obj ede-proj-target-elisp))
+(cl-defmethod project-compile-target ((obj ede-proj-target-elisp))
   "Compile all sources in a Lisp target OBJ.
 Bonus: Return a cons cell: (COMPILED . UPTODATE)."
   (let* ((proj (ede-target-parent obj))
@@ -130,14 +155,25 @@ Bonus: Return a cons cell: (COMPILED . UPTODATE)."
     (mapc (lambda (src)
            (let* ((fsrc (expand-file-name src dir))
                   (elc (concat (file-name-sans-extension fsrc) ".elc")))
-             (if (eq (byte-recompile-file fsrc nil 0) t)
-                  (setq comp (1+ comp))
-               (setq utd (1+ utd)))))
+             (with-no-warnings
+               (if (< emacs-major-version 24)
+                   ;; Does not have `byte-recompile-file'
+                   (if (or (not (file-exists-p elc))
+                           (file-newer-than-file-p fsrc elc))
+                       (progn
+                         (setq comp (1+ comp))
+                         (byte-compile-file fsrc))
+                     (setq utd (1+ utd)))
+
+                 (if (eq (byte-recompile-file fsrc nil 0) t)
+                     (setq comp (1+ comp))
+                   (setq utd (1+ utd)))))))
+
            (oref obj source))
-    (message "All Emacs Lisp sources are up to date in %s" (object-name obj))
+    (message "All Emacs Lisp sources are up to date in %s" (eieio-object-name obj))
     (cons comp utd)))
 
-(defmethod ede-update-version-in-source ((this ede-proj-target-elisp) version)
+(cl-defmethod ede-update-version-in-source ((this ede-proj-target-elisp) version)
   "In a Lisp file, updated a version string for THIS to VERSION.
 There are standards in Elisp files specifying how the version string
 is found, such as a `-version' variable, or the standard header."
@@ -158,12 +194,13 @@ is found, such as a `-version' variable, or the standard header."
                    (goto-char (match-beginning 1))
                    (insert version)))))
          (setq vs (cdr vs)))
-       (if (not match) (call-next-method)))))
+       ;; The next method will include comments such as "Version:"
+       (cl-call-next-method))))
 
 
 ;;; Makefile generation functions
 ;;
-(defmethod ede-proj-makefile-sourcevar ((this ede-proj-target-elisp))
+(cl-defmethod ede-proj-makefile-sourcevar ((this ede-proj-target-elisp))
   "Return the variable name for THIS's sources."
   (cond ((ede-proj-automake-p) '("lisp_LISP" . share))
        (t (concat (ede-pmake-varname this) "_LISP"))))
@@ -182,12 +219,11 @@ is found, such as a `-version' variable, or the standard header."
            (setq items (cdr items)))))
       ))
 
-(defmethod ede-proj-makefile-insert-variables :AFTER ((this ede-proj-target-elisp))
+(cl-defmethod ede-proj-makefile-insert-variables :after ((this ede-proj-target-elisp))
   "Insert variables needed by target THIS."
   (let ((newitems (if (oref this aux-packages)
                      (ede-proj-elisp-packages-to-loadpath
-                      (oref this aux-packages))))
-       )
+                      (oref this aux-packages)))))
     (ede-proj-makefile-insert-loadpath-items newitems)))
 
 (defun ede-proj-elisp-add-path (path)
@@ -208,17 +244,18 @@ is found, such as a `-version' variable, or the standard header."
          )
       (error "Don't know how to update load path"))))
 
-(defmethod ede-proj-tweak-autoconf ((this ede-proj-target-elisp))
-  "Tweak the configure file (current buffer) to accomodate THIS."
-  (call-next-method)
+(cl-defmethod ede-proj-tweak-autoconf ((this ede-proj-target-elisp))
+  "Tweak the configure file (current buffer) to accommodate THIS."
+  (cl-call-next-method)
   ;; Ok, now we have to tweak the autoconf provided `elisp-comp' program.
-  (let ((ec (ede-expand-filename this "elisp-comp" 'newfile)))
+  (let ((ec (ede-expand-filename this "elisp-comp" 'newfile))
+       (enable-local-variables nil))
     (if (or (not ec) (not (file-exists-p ec)))
        (message "No elisp-comp file.  There may be compile errors?  Rerun a second time.")
       (save-excursion
        (if (file-symlink-p ec)
            (progn
-             ;; Desymlinkafy
+             ;; Change symlinks to copies.
              (rename-file ec (concat ec ".tmp"))
              (copy-file (concat ec ".tmp") ec)
              (delete-file (concat ec ".tmp"))))
@@ -230,13 +267,14 @@ is found, such as a `-version' variable, or the standard header."
          (while paths
            (ede-proj-elisp-add-path (car paths))
            (setq paths (cdr paths))))
-       (save-buffer)) )))
+       (save-buffer)
+       (kill-buffer)))))
 
-(defmethod ede-proj-flush-autoconf ((this ede-proj-target-elisp))
-  "Flush the configure file (current buffer) to accomodate THIS."
+(cl-defmethod ede-proj-flush-autoconf ((this ede-proj-target-elisp))
+  "Flush the configure file (current buffer) to accommodate THIS."
   ;; Remove crufty old paths from elisp-compile
   (let ((ec (ede-expand-filename this "elisp-comp" 'newfile))
-       )
+       (enable-local-variables nil))
     (if (and ec (file-exists-p ec))
        (with-current-buffer (find-file-noselect ec t)
          (goto-char (point-min))
@@ -252,8 +290,8 @@ is found, such as a `-version' variable, or the standard header."
 ;;
 (defclass ede-proj-target-elisp-autoloads (ede-proj-target-elisp)
   ((availablecompilers :initform '(ede-emacs-cedet-autogen-compiler))
-   (aux-packages :initform ("cedet-autogen"))
    (phony :initform t)
+   (rules :initform nil)
    (autoload-file :initarg :autoload-file
                  :initform "loaddefs.el"
                  :type string
@@ -273,14 +311,14 @@ Files do not need to be added to this target.")
 
 
 ;;; Claiming files
-(defmethod ede-buffer-mine ((this ede-proj-target-elisp-autoloads) buffer)
+(cl-defmethod ede-buffer-mine ((this ede-proj-target-elisp-autoloads) buffer)
   "Return t if object THIS lays claim to the file in BUFFER.
 Lays claim to all .elc files that match .el files in this target."
   (if (string-match
        (concat (regexp-quote (oref this autoload-file)) "$")
        (buffer-file-name buffer))
       t
-    (call-next-method) ; The usual thing.
+    (cl-call-next-method) ; The usual thing.
     ))
 
 ;; Compilers
@@ -288,20 +326,19 @@ Lays claim to all .elc files that match .el files in this target."
   (ede-compiler
    "ede-emacs-autogen-compiler"
    :name "emacs"
-   :variables '(("EMACS" . "emacs"))
+   :variables '(("EMACS" . "emacs")
+               ("EMACSFLAGS" . "-batch --no-site-file --eval '(setq debug-on-error t)'")
+               ("require" . "$(foreach r,$(1),(require (quote $(r))))"))
    :commands
-   '("@echo \"(add-to-list 'load-path nil)\" > $@-compile-script"
-     "for loadpath in . ${LOADPATH}; do \\"
-     "   echo \"(add-to-list 'load-path \\\"$$loadpath\\\")\" >> $@-compile-script; \\"
-     "done;"
-     "@echo \"(require 'cedet-autogen)\" >> $@-compile-script"
-     "\"$(EMACS)\" -batch --no-site-file -l $@-compile-script -f cedet-batch-update-autoloads $(LOADDEFS) $(LOADDIRS)"
-     )
+   '("$(EMACS) $(EMACSFLAGS) $(addprefix -L ,$(LOADPATH)) \
+--eval '(setq generated-autoload-file \"$(abspath $(LOADDEFS))\")' \
+-f batch-update-autoloads $(abspath $(LOADDIRS))")
+   :rules (list (ede-makefile-rule "clean-autoloads" :target "clean-autoloads" :phony t :rules '("rm -f $(LOADDEFS)")))
    :sourcetype '(ede-source-emacs)
    )
   "Build an autoloads file.")
 
-(defmethod ede-proj-compilers ((obj ede-proj-target-elisp-autoloads))
+(cl-defmethod ede-proj-compilers ((obj ede-proj-target-elisp-autoloads))
   "List of compilers being used by OBJ.
 If the `compiler' slot is empty, get the car of the compilers list."
   (let ((comp (oref obj compiler)))
@@ -314,7 +351,7 @@ If the `compiler' slot is empty, get the car of the compilers list."
        (setq comp (list (car avail)))))
     comp))
 
-(defmethod ede-proj-makefile-insert-source-variables ((this ede-proj-target-elisp-autoloads)
+(cl-defmethod ede-proj-makefile-insert-source-variables ((this ede-proj-target-elisp-autoloads)
                                                      &optional
                                                      moresource)
   "Insert the source variables needed by THIS.
@@ -322,16 +359,16 @@ Optional argument MORESOURCE is a list of additional sources to add to the
 sources variable."
   nil)
 
-(defmethod ede-proj-makefile-sourcevar ((this ede-proj-target-elisp-autoloads))
+(cl-defmethod ede-proj-makefile-sourcevar ((this ede-proj-target-elisp-autoloads))
   "Return the variable name for THIS's sources."
   nil) ; "LOADDEFS")
 
-(defmethod ede-proj-makefile-dependencies ((this ede-proj-target-elisp-autoloads))
+(cl-defmethod ede-proj-makefile-dependencies ((this ede-proj-target-elisp-autoloads))
   "Return a string representing the dependencies for THIS.
 Always return an empty string for an autoloads generator."
   "")
 
-(defmethod ede-proj-makefile-insert-variables :AFTER ((this ede-proj-target-elisp-autoloads))
+(cl-defmethod ede-proj-makefile-insert-variables :after ((this ede-proj-target-elisp-autoloads))
   "Insert variables needed by target THIS."
   (ede-pmake-insert-variable-shared "LOADDEFS"
     (insert (oref this autoload-file)))
@@ -341,7 +378,7 @@ Always return an empty string for an autoloads generator."
                        " ")))
   )
 
-(defmethod project-compile-target ((obj ede-proj-target-elisp-autoloads))
+(cl-defmethod project-compile-target ((obj ede-proj-target-elisp-autoloads))
   "Create or update the autoload target."
   (require 'cedet-autogen)
   (let ((default-directory (ede-expand-filename obj ".")))
@@ -350,13 +387,13 @@ Always return an empty string for an autoloads generator."
           (oref obj autoload-dirs))
     ))
 
-(defmethod ede-update-version-in-source ((this ede-proj-target-elisp-autoloads) version)
+(cl-defmethod ede-update-version-in-source ((this ede-proj-target-elisp-autoloads) version)
   "In a Lisp file, updated a version string for THIS to VERSION.
 There are standards in Elisp files specifying how the version string
 is found, such as a `-version' variable, or the standard header."
   nil)
 
-(defmethod ede-proj-makefile-insert-dist-dependencies ((this ede-proj-target-elisp-autoloads))
+(cl-defmethod ede-proj-makefile-insert-dist-dependencies ((this ede-proj-target-elisp-autoloads))
   "Insert any symbols that the DIST rule should depend on.
 Emacs Lisp autoload files ship the generated .el files.
 Argument THIS is the target which needs to insert an info file."
@@ -365,19 +402,19 @@ Argument THIS is the target which needs to insert an info file."
   (insert " " (ede-proj-makefile-target-name this))
   )
 
-(defmethod ede-proj-makefile-insert-dist-filepatterns ((this ede-proj-target-elisp-autoloads))
+(cl-defmethod ede-proj-makefile-insert-dist-filepatterns ((this ede-proj-target-elisp-autoloads))
   "Insert any symbols that the DIST rule should distribute.
 Emacs Lisp autoload files ship the generated .el files.
 Argument THIS is the target which needs to insert an info file."
   (insert " " (oref this autoload-file))
   )
 
-(defmethod ede-proj-tweak-autoconf ((this ede-proj-target-elisp-autoloads))
-  "Tweak the configure file (current buffer) to accomodate THIS."
+(cl-defmethod ede-proj-tweak-autoconf ((this ede-proj-target-elisp-autoloads))
+  "Tweak the configure file (current buffer) to accommodate THIS."
   (error "Autoloads not supported in autoconf yet"))
 
-(defmethod ede-proj-flush-autoconf ((this ede-proj-target-elisp-autoloads))
-  "Flush the configure file (current buffer) to accomodate THIS."
+(cl-defmethod ede-proj-flush-autoconf ((this ede-proj-target-elisp-autoloads))
+  "Flush the configure file (current buffer) to accommodate THIS."
   nil)
 
 (provide 'ede/proj-elisp)