Merge from trunk.
[bpt/emacs.git] / lisp / cedet / ede / pmake.el
index 19c4b26..bd5400b 100644 (file)
@@ -1,7 +1,6 @@
 ;;; ede-pmake.el --- EDE Generic Project Makefile code generator.
 
-;;; Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
-;;; 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
+;; Copyright (C) 1998-2005, 2007-2012  Free Software Foundation, Inc.
 
 ;; Author: Eric M. Ludlam <zappo@gnu.org>
 ;; Keywords: project, make
@@ -262,6 +261,18 @@ Execute BODY in a location where a value can be placed."
      (goto-char (point-max))))
 (put 'ede-pmake-insert-variable-shared 'lisp-indent-function 1)
 
+(defmacro ede-pmake-insert-variable-once (varname &rest body)
+  "Add VARNAME into the current Makefile if it doesn't exist.
+Execute BODY in a location where a value can be placed."
+  `(let ((addcr t) (v ,varname))
+     (unless (re-search-backward (concat "^" v "\\s-*=") nil t)
+       (insert v "=")
+       ,@body
+       (if addcr (insert "\n"))
+       (goto-char (point-max)))
+     ))
+(put 'ede-pmake-insert-variable-once 'lisp-indent-function 1)
+
 ;;; SOURCE VARIABLE NAME CONSTRUCTION
 
 (defsubst ede-pmake-varname (obj)
@@ -324,7 +335,7 @@ NOTE: Not yet in use!  This is part of an SRecode conversion of
 ;
 ;         (oref this variables))
 ;
-;     ;; Add in all variables from the configuration not allready covered.
+;     ;; Add in all variables from the configuration not already covered.
 ;     (mapc (lambda (c)
 ;
 ;           (if (member (car c) conf-done)
@@ -361,7 +372,7 @@ NOTE: Not yet in use!  This is part of an SRecode conversion of
                  (setq conf-done (cons (car c) conf-done))))
            (insert (cdr c) "\n"))
          (oref this variables))
-    ;; Add in all variables from the configuration not allready covered.
+    ;; Add in all variables from the configuration not already covered.
     (mapc (lambda (c)
            (if (member (car c) conf-done)
                nil
@@ -369,10 +380,14 @@ NOTE: Not yet in use!  This is part of an SRecode conversion of
          conf-table))
   (let* ((top "")
         (tmp this))
+    ;; Use relative paths for subdirs.
     (while (ede-parent-project tmp)
       (setq tmp (ede-parent-project tmp)
            top (concat "../" top)))
-    (insert "\ntop=" top))
+    ;; If this is the top, then use CURDIR.
+    (if (and (not (oref this metasubproject)) (string= top ""))
+       (insert "\ntop=\"$(CURDIR)\"/")
+      (insert "\ntop=" top)))
   (insert "\nede_FILES=" (file-name-nondirectory (oref this file)) " "
          (file-name-nondirectory (ede-proj-dist-makefile this)) "\n"))
 
@@ -415,7 +430,7 @@ sources variable."
                      this (oref proj configuration-default)))
         (conf-done nil)
         )
-    ;; Add in all variables from the configuration not allready covered.
+    ;; Add in all variables from the configuration not already covered.
     (mapc (lambda (c)
            (if (member (car c) conf-done)
                nil
@@ -425,14 +440,13 @@ sources variable."
        (link (ede-proj-linkers this))
        (name (ede-proj-makefile-target-name this))
        (src (oref this source)))
+    (ede-proj-makefile-insert-object-variables (car comp) name src)
     (dolist (obj comp)
       (ede-compiler-only-once obj
                              (ede-proj-makefile-insert-variables obj)))
-    (ede-proj-makefile-insert-object-variables (car comp) name src)
-    (while link
-      (ede-linker-only-once (car link)
-       (ede-proj-makefile-insert-variables (car link)))
-      (setq link (cdr link)))))
+    (dolist (linker link)
+      (ede-linker-only-once linker
+                           (ede-proj-makefile-insert-variables linker)))))
 
 (defmethod ede-proj-makefile-insert-automake-pre-variables
   ((this ede-proj-target))
@@ -464,7 +478,7 @@ These are removed with make clean."
 (defmethod ede-proj-makefile-garbage-patterns ((this ede-proj-target))
   "Return a list of patterns that are considered garbage to THIS.
 These are removed with make clean."
-  ;; Get the  the source object from THIS, and use the specified garbage.
+  ;; Get the source object from THIS, and use the specified garbage.
   (let ((src (ede-target-sourcecode this))
        (garb nil))
     (while src
@@ -550,10 +564,7 @@ Argument THIS is the target that should insert stuff."
            (cond ((eq (cdr sv) 'share)
                   ;; This variable may be shared between multiple targets.
                   (if (re-search-backward (concat "\\$(" (car sv) ")")
-                                          (save-excursion
-                                            (beginning-of-line)
-                                            (point))
-                                          t)
+                                          (point-at-bol) t)
                       ;; If its already in the dist target, then skip it.
                       nil
                     (setq sv (car sv))))
@@ -678,5 +689,4 @@ Argument TARGETS are the targets we should depend on for TAGS."
 
 (provide 'ede/pmake)
 
-;; arch-tag: 7ad8e19f-cdee-484c-8caf-f15cb0fc4df2
 ;;; ede/pmake.el ends here