Update copyright year to 2014 by running admin/update-copyright.
[emacs.git] / lisp / cedet / ede / pconf.el
blobdca4b33131a98c7281df8c50b797676c1dd3f0ea
1 ;;; ede/pconf.el --- configure.ac maintenance for EDE
3 ;;; Copyright (C) 1998-2000, 2005, 2008-2014 Free Software Foundation,
4 ;;; Inc.
6 ;; Author: Eric M. Ludlam <zappo@gnu.org>
7 ;; Keywords: project
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
24 ;;; Commentary:
26 ;; Code generator for autoconf configure.ac, and support files.
28 (require 'ede/proj)
29 (require 'ede/autoconf-edit)
30 (defvar compilation-in-progress)
32 (defvar ede-pconf-create-file-query 'ask
33 "Controls if queries are made while creating project files.
34 A value of 'ask means to always ask the user before creating
35 a file, such as AUTHORS. A value of 'never means don't ask, and
36 don't do it. A value of nil means to just do it.")
38 ;;; Code:
39 (defmethod ede-proj-configure-file ((this ede-proj-project))
40 "The configure.ac script used by project THIS."
41 (ede-expand-filename (ede-toplevel this) "configure.ac" t))
43 (defmethod ede-proj-configure-test-required-file ((this ede-proj-project) file)
44 "For project THIS, test that the file FILE exists, or create it."
45 (let ((f (ede-expand-filename (ede-toplevel this) file t)))
46 (when (not (file-exists-p f))
47 (save-excursion
48 (find-file f)
49 (cond ((string= file "AUTHORS")
50 (insert (user-full-name) " <" (user-login-name) ">"))
51 ((string= file "NEWS")
52 (insert "NEWS file for " (ede-name this)))
53 (t (insert "\n")))
54 (save-buffer)
55 (when
56 (and (eq ede-pconf-create-file-query 'ask)
57 (not (eq ede-pconf-create-file-query 'never))
58 (not (y-or-n-p
59 (format "I had to create the %s file for you. Ok? " file)))
60 (error "Quit")))))))
63 (defmethod ede-proj-configure-synchronize ((this ede-proj-project))
64 "Synchronize what we know about project THIS into configure.ac."
65 (let ((b (find-file-noselect (ede-proj-configure-file this)))
66 ;;(td (file-name-directory (ede-proj-configure-file this)))
67 (targs (oref this targets))
68 (postcmd "")
69 (add-missing nil))
70 ;; First, make sure we have a file.
71 (if (not (file-exists-p (ede-proj-configure-file this)))
72 (autoconf-new-program b (oref this name) "Project.ede"))
73 (set-buffer b)
74 ;; Next, verify all targets of all subobjects.
75 (autoconf-set-version (oref this version))
76 (let ((top-level-project-local this))
77 (autoconf-set-output
78 (ede-map-all-subprojects
79 this
80 (lambda (sp)
81 ;; NOTE: don't put in ./Makefile - configure complains.
82 (let ((dir (file-name-as-directory
83 (directory-file-name
84 (ede-subproject-relative-path sp top-level-project-local)))))
85 (when (string= dir "./") (setq dir ""))
86 ;; Use concat, because expand-file-name removes the relativity.
87 (concat dir "Makefile") )))))
89 ;; NOTE TO SELF. TURN THIS INTO THE OFFICIAL LIST
91 (ede-proj-dist-makefile this)
92 ;; Loop over all targets to clean and then add themselves in.
93 (ede-map-all-subprojects
94 this
95 (lambda (sp)
96 (ede-map-targets sp 'ede-proj-flush-autoconf)))
97 (ede-map-all-subprojects
98 this
99 (lambda (sp)
100 (ede-map-targets this 'ede-proj-tweak-autoconf)))
101 ;; Now save
102 (save-buffer)
103 (setq postcmd "autoreconf -i;")
105 ;; Verify a bunch of files that are required by automake.
106 (ede-proj-configure-test-required-file this "AUTHORS")
107 (ede-proj-configure-test-required-file this "NEWS")
108 (ede-proj-configure-test-required-file this "README")
109 (ede-proj-configure-test-required-file this "ChangeLog")
110 ;; Let specific targets get missing files.
111 (mapc 'ede-proj-configure-create-missing targs)
112 ;; Verify that we have a make system.
113 (if (or (not (ede-expand-filename (ede-toplevel this) "Makefile"))
114 ;; Now is this one of our old Makefiles?
115 (with-current-buffer
116 (find-file-noselect
117 (ede-expand-filename (ede-toplevel this)
118 "Makefile" t) t)
119 (goto-char (point-min))
120 ;; Here is the unique piece for our makefiles.
121 (re-search-forward "For use with: make" nil t)))
122 (setq postcmd (concat postcmd "./configure;")))
123 (if (not (string= "" postcmd))
124 (progn
125 (compile postcmd)
127 (while compilation-in-progress
128 (accept-process-output)
129 ;; If sit for indicates that input is waiting, then
130 ;; read and discard whatever it is that is going on.
131 (when (not (sit-for 1))
132 (read-event nil nil .1)
135 (with-current-buffer "*compilation*"
136 (goto-char (point-max))
138 (when (not (string= mode-line-process ":exit [0]"))
139 (error "Configure failed!"))
141 ;; The Makefile is now recreated by configure?
142 (let ((b (get-file-buffer
143 (ede-expand-filename (ede-toplevel this)
144 "Makefile" 'newfile))))
145 ;; This makes sure that if Makefile was loaded, and old,
146 ;; that it gets flushed so we don't keep rebuilding
147 ;; the autoconf system.
148 (if b (kill-buffer b))))
150 ))))
152 (defmethod ede-proj-configure-recreate ((this ede-proj-project))
153 "Delete project THIS's configure script and start over."
154 (if (not (ede-proj-configure-file this))
155 (error "Could not determine configure.ac for %S" (eieio-object-name this)))
156 (let ((b (get-file-buffer (ede-proj-configure-file this))))
157 ;; Destroy all evidence of the old configure.ac
158 (delete-file (ede-proj-configure-file this))
159 (if b (kill-buffer b)))
160 (ede-proj-configure-synchronize this))
162 (defmethod ede-proj-tweak-autoconf ((this ede-proj-target))
163 "Tweak the configure file (current buffer) to accommodate THIS."
164 ;; Check the compilers belonging to THIS, and call the autoconf
165 ;; setup for those compilers.
166 (mapc 'ede-proj-tweak-autoconf (ede-proj-compilers this))
167 (mapc 'ede-proj-tweak-autoconf (ede-proj-linkers this))
170 (defmethod ede-proj-flush-autoconf ((this ede-proj-target))
171 "Flush the configure file (current buffer) to accommodate THIS.
172 By flushing, remove any cruft that may be in the file. Subsequent
173 calls to `ede-proj-tweak-autoconf' can restore items removed by flush."
174 nil)
176 (defmethod ede-proj-configure-add-missing ((this ede-proj-target))
177 "Query if any files needed by THIS provided by automake are missing.
178 Results in --add-missing being passed to automake."
179 nil)
181 (defmethod ede-proj-configure-create-missing ((this ede-proj-target))
182 "Add any missing files for THIS by creating them."
183 nil)
185 (provide 'ede/pconf)
187 ;;; ede/pconf.el ends here