pconf.el 6.8 KB

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