Initial Commit
[packages] / xemacs-packages / ede / ede-pconf.el
1 ;;; ede-pconf.el --- configure.in maintenance for EDE
2
3 ;;  Copyright (C) 1998, 1999, 2000, 2005  Eric M. Ludlam
4
5 ;; Author: Eric M. Ludlam <zappo@gnu.org>
6 ;; Keywords: project
7 ;; RCS: $Id: ede-pconf.el,v 1.1 2007-11-26 15:22:07 michaels Exp $
8
9 ;; This software is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
12 ;; any later version.
13
14 ;; This software is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 ;; GNU General Public License for more details.
18
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
21 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 ;; Boston, MA 02110-1301, USA.
23
24 ;;; Commentary:
25 ;; 
26 ;; Code generator for autoconf configure.in, and support files.
27
28 (require 'ede-proj)
29 (require 'autoconf-edit)
30
31 ;;; Code:
32 (defmethod ede-proj-configure-file ((this ede-proj-project))
33   "The configure.in script used by project THIS."
34   (ede-expand-filename (ede-toplevel this) "configure.in" t))
35
36 (defmethod ede-proj-configure-test-required-file ((this ede-proj-project) file)
37   "For project THIS, test that the file FILE exists, or create it."
38   (if (not (ede-expand-filename (ede-toplevel this) file))
39       (save-excursion
40         (find-file (ede-expand-filename (ede-toplevel this) file t))
41         (cond ((string= file "AUTHORS")
42                (insert (user-full-name) " <" (user-login-name) ">"))
43               ((string= file "NEWS")
44                (insert "NEWS file for " (ede-name this)))
45               (t (insert "\n")))
46         (save-buffer)
47         (if (not (y-or-n-p
48                   (format "I had to create the %s file for you.  Ok? " file)))
49             (error "Quit")))))
50
51
52 (defmethod ede-proj-configure-synchronize ((this ede-proj-project))
53   "Synchronize what we know about project THIS into configure.in."
54   (let ((b (find-file-noselect (ede-proj-configure-file this)))
55         (td (file-name-directory (ede-proj-configure-file this)))
56         (targs (oref this targets))
57         (postcmd "")
58         (add-missing nil))
59     ;; First, make sure we have a file.
60     (if (not (file-exists-p (ede-proj-configure-file this)))
61         (autoconf-new-program b (oref this name) "Project.ede"))
62     (set-buffer b)
63     ;; Next, verify all targets of all subobjects.
64     (autoconf-set-version (oref this version))
65     (autoconf-set-output '("Makefile"))
66      ;;
67      ;; NOTE TO SELF.  TURN THIS INTO THE OFFICIAL LIST
68      ;;
69     (ede-proj-dist-makefile this)
70     ;; Loop over all targets to clean and then add themselves in.
71     (ede-map-targets this 'ede-proj-flush-autoconf)
72     (ede-map-targets this 'ede-proj-tweak-autoconf)
73     ;; Now save
74     (save-buffer)
75     ;; Verify aclocal
76     (if (not (file-exists-p (ede-expand-filename (ede-toplevel this)
77                                                  "aclocal.m4" t)))
78         (setq postcmd "aclocal;autoconf;autoheader;")
79       ;; Verify the configure script...
80       (if (not (ede-expand-filename (ede-toplevel this)
81                                     "configure"))
82           (setq postcmd "autoconf;autoheader;")
83         (if (not (ede-expand-filename (ede-toplevel this) "config.h.in"))
84             (setq postcmd "autoheader;"))))
85     ;; Verify Makefile.in, and --add-missing files (cheaply)
86     (setq add-missing (ede-map-any-target-p this
87                                             'ede-proj-configure-add-missing))
88     (if (not (ede-expand-filename (ede-toplevel this) "Makefile.in"))
89         (progn
90           (setq postcmd (concat postcmd "automake"))
91           (if (or (not (ede-expand-filename (ede-toplevel this) "COPYING"))
92                   add-missing)
93               (setq postcmd (concat postcmd " --add-missing")))
94           (setq postcmd (concat postcmd ";")))
95       (if (or (not (ede-expand-filename (ede-toplevel this) "COPYING"))
96               add-missing)
97           (setq postcmd (concat postcmd "automake --add-missing;"))))
98     ;; Verify a bunch of files that are required by automake.
99     (ede-proj-configure-test-required-file this "AUTHORS")
100     (ede-proj-configure-test-required-file this "NEWS")
101     (ede-proj-configure-test-required-file this "README")
102     (ede-proj-configure-test-required-file this "ChangeLog")
103     ;; Let specific targets get missing files.
104     (mapc 'ede-proj-configure-create-missing targs)
105     ;; Verify that we have a make system.
106     (if (or (not (ede-expand-filename (ede-toplevel this) "Makefile"))
107             ;; Now is this one of our old Makefiles?
108             (save-excursion
109               (set-buffer (find-file-noselect
110                            (ede-expand-filename (ede-toplevel this)
111                                                 "Makefile" t) t))
112               (goto-char (point-min))
113               ;; Here is the unique piece for our makefiles.
114               (re-search-forward "For use with: make" nil t)))
115         (setq postcmd (concat postcmd "./configure;")))
116     (if (not (string= "" postcmd))
117         (progn
118           (compile postcmd)
119           (switch-to-buffer "*Help*")
120           (toggle-read-only -1)
121           (erase-buffer)
122           (insert "Preparing build environment
123
124 Rerun the previous ede command when automake and autoconf are completed.")
125           (goto-char (point-min))
126           (let ((b (get-file-buffer
127                     (ede-expand-filename (ede-toplevel this)
128                                          "Makefile"))))
129             ;; This makes sure that if Makefile was loaded, and old,
130             ;; that it gets flushed so we don't keep rebuilding
131             ;; the autoconf system.
132             (if b (kill-buffer b)))
133           (error "Preparing build environment: Rerun your command when done")
134           ))))
135
136 (defmethod ede-proj-configure-recreate ((this ede-proj-project))
137   "Delete project THISes configure script and start over."
138   (if (not (ede-proj-configure-file this))
139       (error "Could not determine configure.in for %S" (object-name this)))
140   (let ((b (get-file-buffer (ede-proj-configure-file this))))
141     ;; Destroy all evidence of the old configure.in
142     (delete-file (ede-proj-configure-file this))
143     (if b (kill-buffer b)))
144   (ede-proj-configure-synchronize this))
145
146 (defmethod ede-proj-tweak-autoconf ((this ede-proj-target))
147   "Tweak the configure file (current buffer) to accomodate THIS."
148   ;; Check the compilers belonging to THIS, and call the autoconf
149   ;; setup for those compilers.
150   (mapc 'ede-proj-tweak-autoconf (ede-proj-compilers this)))
151
152 (defmethod ede-proj-flush-autoconf ((this ede-proj-target))
153   "Flush the configure file (current buffer) to accomodate THIS.
154 By flushing, remove any cruft that may be in the file.  Subsequent
155 calls to `ede-proj-tweak-autoconf' can restore items removed by flush."
156   nil)
157
158 (defmethod ede-proj-configure-add-missing ((this ede-proj-target))
159   "Query if any files needed by THIS provided by automake are missing.
160 Results in --add-missing being passed to automake."
161   nil)
162
163 (defmethod ede-proj-configure-create-missing ((this ede-proj-target))
164   "Add any missing files for THIS by creating them."
165   nil)
166
167 (provide 'ede-pconf)
168
169 ;;; ede-pconf.el ends here