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