Commit | Line | Data |
---|---|---|
acc33231 CY |
1 | ;;; ede/pconf.el --- configure.ac maintenance for EDE |
2 | ||
114f9c96 | 3 | ;;; Copyright (C) 1998, 1999, 2000, 2005, 2008, 2009, 2010 |
acc33231 CY |
4 | ;;; Free Software Foundation, Inc. |
5 | ||
6 | ;; Author: Eric M. Ludlam <zappo@gnu.org> | |
7 | ;; Keywords: project | |
8 | ||
9 | ;; This file is part of GNU Emacs. | |
10 | ||
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. | |
15 | ||
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. | |
20 | ||
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/>. | |
23 | ||
24 | ;;; Commentary: | |
25 | ;; | |
26 | ;; Code generator for autoconf configure.ac, and support files. | |
27 | ||
28 | (require 'ede/proj) | |
29 | (require 'ede/autoconf-edit) | |
30 | (defvar compilation-in-progress) | |
31 | ||
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.") | |
37 | ||
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)) | |
42 | ||
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." | |
67d3ffe4 CY |
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"))))))) | |
acc33231 CY |
61 | |
62 | ||
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 relativeness. | |
87 | (concat dir "Makefile") ))))) | |
88 | ;; | |
89 | ;; NOTE TO SELF. TURN THIS INTO THE OFFICIAL LIST | |
90 | ;; | |
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) | |
fa63f49c | 103 | (setq postcmd "autoreconf -i;") |
67d3ffe4 | 104 | |
acc33231 CY |
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? | |
0816d744 SM |
115 | (with-current-buffer |
116 | (find-file-noselect | |
117 | (ede-expand-filename (ede-toplevel this) | |
118 | "Makefile" t) t) | |
acc33231 CY |
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) | |
126 | ||
127 | (while compilation-in-progress | |
128 | (accept-process-output) | |
129 | (sit-for 1)) | |
130 | ||
0816d744 | 131 | (with-current-buffer "*compilation*" |
acc33231 CY |
132 | (goto-char (point-max)) |
133 | ||
134 | (when (not (string= mode-line-process ":exit [0]")) | |
135 | (error "Configure failed!")) | |
136 | ||
137 | ;; The Makefile is now recreated by configure? | |
138 | (let ((b (get-file-buffer | |
139 | (ede-expand-filename (ede-toplevel this) | |
140 | "Makefile" 'newfile)))) | |
141 | ;; This makes sure that if Makefile was loaded, and old, | |
142 | ;; that it gets flushed so we don't keep rebuilding | |
143 | ;; the autoconf system. | |
144 | (if b (kill-buffer b)))) | |
145 | ||
146 | )))) | |
147 | ||
148 | (defmethod ede-proj-configure-recreate ((this ede-proj-project)) | |
149 | "Delete project THISes configure script and start over." | |
150 | (if (not (ede-proj-configure-file this)) | |
151 | (error "Could not determine configure.ac for %S" (object-name this))) | |
152 | (let ((b (get-file-buffer (ede-proj-configure-file this)))) | |
153 | ;; Destroy all evidence of the old configure.ac | |
154 | (delete-file (ede-proj-configure-file this)) | |
155 | (if b (kill-buffer b))) | |
156 | (ede-proj-configure-synchronize this)) | |
157 | ||
158 | (defmethod ede-proj-tweak-autoconf ((this ede-proj-target)) | |
159 | "Tweak the configure file (current buffer) to accomodate THIS." | |
160 | ;; Check the compilers belonging to THIS, and call the autoconf | |
161 | ;; setup for those compilers. | |
162 | (mapc 'ede-proj-tweak-autoconf (ede-proj-compilers this)) | |
163 | (mapc 'ede-proj-tweak-autoconf (ede-proj-linkers this)) | |
164 | ) | |
165 | ||
166 | (defmethod ede-proj-flush-autoconf ((this ede-proj-target)) | |
167 | "Flush the configure file (current buffer) to accomodate THIS. | |
168 | By flushing, remove any cruft that may be in the file. Subsequent | |
169 | calls to `ede-proj-tweak-autoconf' can restore items removed by flush." | |
170 | nil) | |
171 | ||
172 | (defmethod ede-proj-configure-add-missing ((this ede-proj-target)) | |
173 | "Query if any files needed by THIS provided by automake are missing. | |
174 | Results in --add-missing being passed to automake." | |
175 | nil) | |
176 | ||
177 | (defmethod ede-proj-configure-create-missing ((this ede-proj-target)) | |
178 | "Add any missing files for THIS by creating them." | |
179 | nil) | |
180 | ||
181 | (provide 'ede/pconf) | |
182 | ||
3999968a | 183 | ;; arch-tag: 8d514f68-2abe-4b35-8b4e-bea4fd0c3eab |
acc33231 | 184 | ;;; ede/pconf.el ends here |