proj.el 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679
  1. ;;; ede/proj.el --- EDE Generic Project file driver
  2. ;; Copyright (C) 1998-2003, 2007-2012 Free Software Foundation, Inc.
  3. ;; Author: Eric M. Ludlam <zappo@gnu.org>
  4. ;; Keywords: project, make
  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. ;; EDE defines a method for managing a project. EDE-PROJ aims to be a
  19. ;; generic project file format based on the EIEIO object stream
  20. ;; methods. Changes in the project structure will require Makefile
  21. ;; rebuild. The targets provided in ede-proj can be augmented with
  22. ;; additional target types inherited directly from `ede-proj-target'.
  23. (require 'ede/proj-comp)
  24. (require 'ede/make)
  25. (declare-function ede-proj-makefile-create "ede/pmake")
  26. (declare-function ede-proj-configure-synchronize "ede/pconf")
  27. (autoload 'ede-proj-target-aux "ede/proj-aux"
  28. "Target class for a group of lisp files." nil nil)
  29. (autoload 'ede-proj-target-elisp "ede/proj-elisp"
  30. "Target class for a group of lisp files." nil nil)
  31. (autoload 'ede-proj-target-elisp-autoloads "ede/proj-elisp"
  32. "Target class for generating autoload files." nil nil)
  33. (autoload 'ede-proj-target-scheme "ede/proj-scheme"
  34. "Target class for a group of lisp files." nil nil)
  35. (autoload 'ede-proj-target-makefile-miscelaneous "ede/proj-misc"
  36. "Target class for a group of miscellaneous w/ a special makefile." nil nil)
  37. (autoload 'ede-proj-target-makefile-program "ede/proj-prog"
  38. "Target class for building a program." nil nil)
  39. (autoload 'ede-proj-target-makefile-archive "ede/proj-archive"
  40. "Target class for building an archive of object code." nil nil)
  41. (autoload 'ede-proj-target-makefile-shared-object "ede/proj-shared"
  42. "Target class for building a shared object." nil nil)
  43. (autoload 'ede-proj-target-makefile-info "ede/proj-info"
  44. "Target class for info files." nil nil)
  45. ;;; Class Definitions:
  46. (defclass ede-proj-target (ede-target)
  47. ((auxsource :initarg :auxsource
  48. :initform nil
  49. :type list
  50. :custom (repeat (string :tag "File"))
  51. :label "Auxiliary Source Files"
  52. :group (default source)
  53. :documentation "Auxiliary source files included in this target.
  54. Each of these is considered equivalent to a source file, but it is not
  55. distributed, and each should have a corresponding rule to build it.")
  56. (dirty :initform nil
  57. :type boolean
  58. :documentation "Non-nil when generated files needs updating.")
  59. (compiler :initarg :compiler
  60. :initform nil
  61. :type (or null symbol)
  62. :custom (choice (const :tag "None" nil)
  63. :slotofchoices availablecompilers)
  64. :label "Compiler for building sources"
  65. :group make
  66. :documentation
  67. "The compiler to be used to compile this object.
  68. This should be a symbol, which contains the object defining the compiler.
  69. This enables save/restore to do so by name, permitting the sharing
  70. of these compiler resources, and global customization thereof.")
  71. (linker :initarg :linker
  72. :initform nil
  73. :type (or null symbol)
  74. :custom (choice (const :tag "None" nil)
  75. :slotofchoices availablelinkers)
  76. :label "Linker for combining intermediate object files."
  77. :group make
  78. :documentation
  79. "The linker to be used to link compiled sources for this object.
  80. This should be a symbol, which contains the object defining the linker.
  81. This enables save/restore to do so by name, permitting the sharing
  82. of these linker resources, and global customization thereof.")
  83. ;; Class allocated slots
  84. (phony :allocation :class
  85. :initform nil
  86. :type boolean
  87. :documentation
  88. "A phony target is one where the build target does not relate to a file.
  89. Such targets are always built, but make knows how to deal with them..")
  90. (availablecompilers :allocation :class
  91. :initform nil
  92. :type (or null list)
  93. :documentation
  94. "A list of `ede-compiler' objects.
  95. These are the compilers the user can choose from when setting the
  96. `compiler' slot.")
  97. (availablelinkers :allocation :class
  98. :initform nil
  99. :type (or null list)
  100. :documentation
  101. "A list of `ede-linker' objects.
  102. These are the linkers the user can choose from when setting the
  103. `linker' slot.")
  104. )
  105. "Abstract class for ede-proj targets.")
  106. (defclass ede-proj-target-makefile (ede-proj-target)
  107. ((makefile :initarg :makefile
  108. :initform "Makefile"
  109. :type string
  110. :custom string
  111. :label "Parent Makefile"
  112. :group make
  113. :documentation "File name of generated Makefile.")
  114. (partofall :initarg :partofall
  115. :initform t
  116. :type boolean
  117. :custom boolean
  118. :label "Part of `all:' target"
  119. :group make
  120. :documentation
  121. "Non nil means the rule created is part of the all target.
  122. Setting this to nil creates the rule to build this item, but does not
  123. include it in the ALL`all:' rule.")
  124. (configuration-variables
  125. :initarg :configuration-variables
  126. :initform nil
  127. :type list
  128. :custom (repeat (cons (string :tag "Configuration")
  129. (repeat
  130. (cons (string :tag "Name")
  131. (string :tag "Value")))))
  132. :label "Environment Variables for configurations"
  133. :group make
  134. :documentation "Makefile variables appended to use in different configurations.
  135. These variables are used in the makefile when a configuration becomes active.
  136. Target variables are always renamed such as foo_CFLAGS, then included into
  137. commands where the variable would usually appear.")
  138. (rules :initarg :rules
  139. :initform nil
  140. :type list
  141. :custom (repeat (object :objecttype ede-makefile-rule))
  142. :label "Additional Rules"
  143. :group (make)
  144. :documentation
  145. "Arbitrary rules and dependencies needed to make this target.
  146. It is safe to leave this blank.")
  147. )
  148. "Abstract class for Makefile based targets.")
  149. (defvar ede-proj-target-alist
  150. '(("program" . ede-proj-target-makefile-program)
  151. ("archive" . ede-proj-target-makefile-archive)
  152. ("sharedobject" . ede-proj-target-makefile-shared-object)
  153. ("emacs lisp" . ede-proj-target-elisp)
  154. ("emacs lisp autoloads" . ede-proj-target-elisp-autoloads)
  155. ("info" . ede-proj-target-makefile-info)
  156. ("auxiliary" . ede-proj-target-aux)
  157. ("scheme" . ede-proj-target-scheme)
  158. ("miscellaneous" . ede-proj-target-makefile-miscelaneous)
  159. )
  160. "Alist of names to class types for available project target classes.")
  161. (defun ede-proj-register-target (name class)
  162. "Register a new target class with NAME and class symbol CLASS.
  163. This enables the creation of your target type."
  164. (let ((a (assoc name ede-proj-target-alist)))
  165. (if a
  166. (setcdr a class)
  167. (setq ede-proj-target-alist
  168. (cons (cons name class) ede-proj-target-alist)))))
  169. (defclass ede-proj-project (ede-project)
  170. ((makefile-type :initarg :makefile-type
  171. :initform Makefile
  172. :type symbol
  173. :custom (choice (const Makefile)
  174. ;(const Makefile.in)
  175. (const Makefile.am)
  176. ;(const cook)
  177. )
  178. :documentation "The type of Makefile to generate.
  179. Can be one of 'Makefile, 'Makefile.in, or 'Makefile.am.
  180. If this value is NOT 'Makefile, then that overrides the :makefile slot
  181. in targets.")
  182. (variables :initarg :variables
  183. :initform nil
  184. :type list
  185. :custom (repeat (cons (string :tag "Name")
  186. (string :tag "Value")))
  187. :group (settings)
  188. :documentation "Variables to set in this Makefile.")
  189. (configuration-variables
  190. :initarg :configuration-variables
  191. :initform ("debug" (("DEBUG" . "1")))
  192. :type list
  193. :custom (repeat (cons (string :tag "Configuration")
  194. (repeat
  195. (cons (string :tag "Name")
  196. (string :tag "Value")))))
  197. :group (settings)
  198. :documentation "Makefile variables to use in different configurations.
  199. These variables are used in the makefile when a configuration becomes active.")
  200. (inference-rules :initarg :inference-rules
  201. :initform nil
  202. :custom (repeat
  203. (object :objecttype ede-makefile-rule))
  204. :documentation "Inference rules to add to the makefile.")
  205. (include-file :initarg :include-file
  206. :initform nil
  207. :custom (repeat
  208. (string :tag "Include File"))
  209. :documentation "Additional files to include.
  210. These files can contain additional rules, variables, and customizations.")
  211. (automatic-dependencies
  212. :initarg :automatic-dependencies
  213. :initform t
  214. :type boolean
  215. :custom boolean
  216. :group (default settings)
  217. :documentation
  218. "Non-nil to do implement automatic dependencies in the Makefile.")
  219. (menu :initform
  220. (
  221. [ "Regenerate Makefiles" ede-proj-regenerate t ]
  222. [ "Upload Distribution" ede-upload-distribution t ]
  223. )
  224. )
  225. (metasubproject
  226. :initarg :metasubproject
  227. :initform nil
  228. :type boolean
  229. :custom boolean
  230. :group (default settings)
  231. :documentation
  232. "Non-nil if this is a metasubproject.
  233. Usually, a subproject is determined by a parent project. If multiple top level
  234. projects are grouped into a large project not maintained by EDE, then you need
  235. to set this to non-nil. The only effect is that the `dist' rule will then avoid
  236. making a tar file.")
  237. )
  238. "The EDE-PROJ project definition class.")
  239. ;;; Code:
  240. (defun ede-proj-load (project &optional rootproj)
  241. "Load a project file from PROJECT directory.
  242. If optional ROOTPROJ is provided then ROOTPROJ is the root project
  243. for the tree being read in. If ROOTPROJ is nil, then assume that
  244. the PROJECT being read in is the root project."
  245. (save-excursion
  246. (let ((ret nil)
  247. (subdirs (directory-files project nil "[^.].*" nil)))
  248. (set-buffer (get-buffer-create " *tmp proj read*"))
  249. (unwind-protect
  250. (progn
  251. (insert-file-contents (concat project "Project.ede")
  252. nil nil nil t)
  253. (goto-char (point-min))
  254. (setq ret (read (current-buffer)))
  255. (if (not (eq (car ret) 'ede-proj-project))
  256. (error "Corrupt project file"))
  257. (setq ret (eval ret))
  258. (oset ret file (concat project "Project.ede"))
  259. (oset ret directory project)
  260. (oset ret rootproject rootproj)
  261. )
  262. (kill-buffer " *tmp proj read*"))
  263. (while subdirs
  264. (let ((sd (file-name-as-directory
  265. (expand-file-name (car subdirs) project))))
  266. (if (and (file-directory-p sd)
  267. (ede-directory-project-p sd))
  268. (oset ret subproj
  269. (cons (ede-proj-load sd (or rootproj ret))
  270. (oref ret subproj))))
  271. (setq subdirs (cdr subdirs))))
  272. ret)))
  273. (defun ede-proj-save (&optional project)
  274. "Write out object PROJECT into its file."
  275. (save-excursion
  276. (if (not project) (setq project (ede-current-project)))
  277. (let ((b (set-buffer (get-buffer-create " *tmp proj write*")))
  278. (cfn (oref project file))
  279. (cdir (oref project directory)))
  280. (unwind-protect
  281. (save-excursion
  282. (erase-buffer)
  283. (let ((standard-output (current-buffer)))
  284. (oset project file (file-name-nondirectory cfn))
  285. (slot-makeunbound project :directory)
  286. (object-write project ";; EDE project file."))
  287. (write-file cfn nil)
  288. )
  289. ;; Restore the :file on exit.
  290. (oset project file cfn)
  291. (oset project directory cdir)
  292. (kill-buffer b)))))
  293. (defmethod ede-commit-local-variables ((proj ede-proj-project))
  294. "Commit change to local variables in PROJ."
  295. (ede-proj-save proj))
  296. (defmethod eieio-done-customizing ((proj ede-proj-project))
  297. "Call this when a user finishes customizing this object.
  298. Argument PROJ is the project to save."
  299. (call-next-method)
  300. (ede-proj-save proj))
  301. (defmethod eieio-done-customizing ((target ede-proj-target))
  302. "Call this when a user finishes customizing this object.
  303. Argument TARGET is the project we are completing customization on."
  304. (call-next-method)
  305. (ede-proj-save (ede-current-project)))
  306. (defmethod ede-commit-project ((proj ede-proj-project))
  307. "Commit any change to PROJ to its file."
  308. (ede-proj-save proj))
  309. (defmethod ede-buffer-mine ((this ede-proj-project) buffer)
  310. "Return t if object THIS lays claim to the file in BUFFER."
  311. (let ((f (ede-convert-path this (buffer-file-name buffer))))
  312. (or (string= (file-name-nondirectory (oref this file)) f)
  313. (string= (ede-proj-dist-makefile this) f)
  314. (string-match "Makefile\\(\\.\\(in\\|am\\)\\)?$" f)
  315. (string-match "config\\(ure\\.\\(in\\|ac\\)\\|\\.status\\)?$" f)
  316. (string-match "config.h\\(\\.in\\)?" f)
  317. (member f '("AUTHORS" "NEWS" "COPYING" "INSTALL" "README"))
  318. )))
  319. (defmethod ede-buffer-mine ((this ede-proj-target) buffer)
  320. "Return t if object THIS lays claim to the file in BUFFER."
  321. (or (call-next-method)
  322. (ede-target-buffer-in-sourcelist this buffer (oref this auxsource))))
  323. ;;; EDE command functions
  324. ;;
  325. (defvar ede-proj-target-history nil
  326. "History when querying for a target type.")
  327. (defmethod project-new-target ((this ede-proj-project)
  328. &optional name type autoadd)
  329. "Create a new target in THIS based on the current buffer."
  330. (let* ((name (or name (read-string "Name: " "")))
  331. (type (or type
  332. (completing-read "Type: " ede-proj-target-alist
  333. nil t nil '(ede-proj-target-history . 1))))
  334. (ot nil)
  335. (src (if (and (buffer-file-name)
  336. (if (and autoadd (stringp autoadd))
  337. (string= autoadd "y")
  338. (y-or-n-p (format "Add %s to %s? " (buffer-name) name))))
  339. (buffer-file-name)))
  340. (fcn (cdr (assoc type ede-proj-target-alist)))
  341. )
  342. (when (not fcn)
  343. (error "Unknown target type %s for EDE Project" type))
  344. (setq ot (funcall fcn name :name name
  345. :path (ede-convert-path this default-directory)
  346. :source (if src
  347. (list (file-name-nondirectory src))
  348. nil)))
  349. ;; If we added it, set the local buffer's object.
  350. (if src (progn
  351. (setq ede-object ot)
  352. (ede-apply-object-keymap)))
  353. ;; Add it to the project object
  354. ;;(oset this targets (cons ot (oref this targets)))
  355. ;; New form: Add to the end using fancy eieio function.
  356. ;; @todone - Some targets probably want to be in the front.
  357. ;; How to do that?
  358. ;; @ans - See elisp autoloads for answer
  359. (object-add-to-list this 'targets ot t)
  360. ;; And save
  361. (ede-proj-save this)))
  362. (defmethod project-new-target-custom ((this ede-proj-project))
  363. "Create a new target in THIS for custom."
  364. (let* ((name (read-string "Name: " ""))
  365. (type (completing-read "Type: " ede-proj-target-alist
  366. nil t nil '(ede-proj-target-history . 1))))
  367. (funcall (cdr (assoc type ede-proj-target-alist)) name :name name
  368. :path (ede-convert-path this default-directory)
  369. :source nil)))
  370. (defmethod project-delete-target ((this ede-proj-target))
  371. "Delete the current target THIS from its parent project."
  372. (let ((p (ede-current-project))
  373. (ts (oref this source)))
  374. ;; Loop across all sources. If it exists in a buffer,
  375. ;; clear its object.
  376. (while ts
  377. (let* ((default-directory (oref this path))
  378. (b (get-file-buffer (car ts))))
  379. (if b
  380. (with-current-buffer b
  381. (if (eq ede-object this)
  382. (progn
  383. (setq ede-object nil)
  384. (ede-apply-object-keymap))))))
  385. (setq ts (cdr ts)))
  386. ;; Remove THIS from its parent.
  387. ;; The two vectors should be pointer equivalent.
  388. (oset p targets (delq this (oref p targets)))
  389. (ede-proj-save (ede-current-project))))
  390. (defmethod project-add-file ((this ede-proj-target) file)
  391. "Add to target THIS the current buffer represented as FILE."
  392. (let ((file (ede-convert-path this file))
  393. (src (ede-target-sourcecode this)))
  394. (while (and src (not (ede-want-file-p (car src) file)))
  395. (setq src (cdr src)))
  396. (when src
  397. (setq src (car src))
  398. (cond ((ede-want-file-source-p this file)
  399. (object-add-to-list this 'source file t))
  400. ((ede-want-file-auxiliary-p this file)
  401. (object-add-to-list this 'auxsource file t))
  402. (t (error "`project-add-file(ede-target)' source mismatch error")))
  403. (ede-proj-save))))
  404. (defmethod project-remove-file ((target ede-proj-target) file)
  405. "For TARGET, remove FILE.
  406. FILE must be massaged by `ede-convert-path'."
  407. ;; Speedy delete should be safe.
  408. (object-remove-from-list target 'source (ede-convert-path target file))
  409. (object-remove-from-list target 'auxsource (ede-convert-path target file))
  410. (ede-proj-save))
  411. (defmethod project-update-version ((this ede-proj-project))
  412. "The :version of project THIS has changed."
  413. (ede-proj-save))
  414. (defmethod project-make-dist ((this ede-proj-project))
  415. "Build a distribution for the project based on THIS target."
  416. (let ((pm (ede-proj-dist-makefile this))
  417. (df (project-dist-files this)))
  418. (if (and (file-exists-p (car df))
  419. (not (y-or-n-p "Dist file already exists. Rebuild? ")))
  420. (error "Try `ede-update-version' before making a distribution"))
  421. (ede-proj-setup-buildenvironment this)
  422. (if (ede-proj-automake-p this)
  423. (setq pm (expand-file-name "Makefile"
  424. (file-name-directory pm))))
  425. (compile (concat ede-make-command " -f " pm " dist"))))
  426. (defmethod project-dist-files ((this ede-proj-project))
  427. "Return a list of files that constitutes a distribution of THIS project."
  428. (list
  429. ;; Note to self, keep this first for the above fn to check against.
  430. (concat (oref this name) "-" (oref this version) ".tar.gz")
  431. ))
  432. (defmethod project-compile-project ((proj ede-proj-project) &optional command)
  433. "Compile the entire current project PROJ.
  434. Argument COMMAND is the command to use when compiling."
  435. (let ((pm (ede-proj-dist-makefile proj))
  436. (default-directory (file-name-directory (oref proj file))))
  437. (ede-proj-setup-buildenvironment proj)
  438. (if (ede-proj-automake-p proj)
  439. (setq pm (expand-file-name "Makefile"
  440. (file-name-directory pm))))
  441. (compile (concat ede-make-command" -f " pm " all"))))
  442. ;;; Target type specific compilations/debug
  443. ;;
  444. (defmethod project-compile-target ((obj ede-proj-target) &optional command)
  445. "Compile the current target OBJ.
  446. Argument COMMAND is the command to use for compiling the target."
  447. (project-compile-project (ede-current-project) command))
  448. (defmethod project-compile-target ((obj ede-proj-target-makefile)
  449. &optional command)
  450. "Compile the current target program OBJ.
  451. Optional argument COMMAND is the s the alternate command to use."
  452. (ede-proj-setup-buildenvironment (ede-current-project))
  453. (compile (concat ede-make-command " -f " (oref obj makefile) " "
  454. (ede-proj-makefile-target-name obj))))
  455. (defmethod project-debug-target ((obj ede-proj-target))
  456. "Run the current project target OBJ in a debugger."
  457. (error "Debug-target not supported by %s" (object-name obj)))
  458. (defmethod project-run-target ((obj ede-proj-target))
  459. "Run the current project target OBJ."
  460. (error "Run-target not supported by %s" (object-name obj)))
  461. (defmethod ede-proj-makefile-target-name ((this ede-proj-target))
  462. "Return the name of the main target for THIS target."
  463. (ede-name this))
  464. ;;; Compiler and source code generators
  465. ;;
  466. (defmethod ede-want-file-auxiliary-p ((this ede-target) file)
  467. "Return non-nil if THIS target wants FILE."
  468. ;; By default, all targets reference the source object, and let it decide.
  469. (let ((src (ede-target-sourcecode this)))
  470. (while (and src (not (ede-want-file-auxiliary-p (car src) file)))
  471. (setq src (cdr src)))
  472. src))
  473. (defmethod ede-proj-compilers ((obj ede-proj-target))
  474. "List of compilers being used by OBJ.
  475. If the `compiler' slot is empty, concoct one on a first match found
  476. basis for any given type from the `availablecompilers' slot.
  477. Otherwise, return the `compiler' slot.
  478. Converts all symbols into the objects to be used."
  479. (when (slot-exists-p obj 'compiler)
  480. (let ((comp (oref obj compiler)))
  481. (if comp
  482. ;; Now that we have a pre-set compilers to use, convert tye symbols
  483. ;; into objects for ease of use
  484. (if (listp comp)
  485. (setq comp (mapcar 'symbol-value comp))
  486. (setq comp (list (symbol-value comp))))
  487. (let* ((acomp (oref obj availablecompilers))
  488. (avail (mapcar 'symbol-value acomp))
  489. (st (oref obj sourcetype))
  490. (sources (oref obj source)))
  491. ;; COMP is not specified, so generate a list from the available
  492. ;; compilers list.
  493. (while st
  494. (if (ede-want-any-source-files-p (symbol-value (car st)) sources)
  495. (let ((c (ede-proj-find-compiler avail (car st))))
  496. (if c (setq comp (cons c comp)))))
  497. (setq st (cdr st)))
  498. ;; Provide a good error msg.
  499. (unless comp
  500. (error "Could not find compiler match for source code extension \"%s\".
  501. You may need to add support for this type of file."
  502. (if sources
  503. (file-name-extension (car sources))
  504. "")))
  505. ))
  506. ;; Return the discovered compilers.
  507. comp)))
  508. (defmethod ede-proj-linkers ((obj ede-proj-target))
  509. "List of linkers being used by OBJ.
  510. If the `linker' slot is empty, concoct one on a first match found
  511. basis for any given type from the `availablelinkers' slot.
  512. Otherwise, return the `linker' slot.
  513. Converts all symbols into the objects to be used."
  514. (when (slot-exists-p obj 'linker)
  515. (let ((link (oref obj linker)))
  516. (if link
  517. ;; Now that we have a pre-set linkers to use, convert type symbols
  518. ;; into objects for ease of use
  519. (if (symbolp link)
  520. (setq link (list (symbol-value link)))
  521. (error ":linker is not a symbol. Howd you do that?"))
  522. (let* ((alink (oref obj availablelinkers))
  523. (avail (mapcar 'symbol-value alink))
  524. (st (oref obj sourcetype))
  525. (sources (oref obj source)))
  526. ;; LINKER is not specified, so generate a list from the available
  527. ;; compilers list.
  528. (while st
  529. (if (ede-want-any-source-files-p (symbol-value (car st)) sources)
  530. (let ((c (ede-proj-find-linker avail (car st))))
  531. (if c (setq link (cons c link)))))
  532. (setq st (cdr st)))
  533. (unless link
  534. ;; No linker stands out! Loop over our linkers and pull out
  535. ;; the first that has no source type requirement.
  536. (while (and avail (not (eieio-instance-inheritor-slot-boundp (car avail) 'sourcetype)))
  537. (setq avail (cdr avail)))
  538. (setq link (cdr avail)))))
  539. ;; Return the discovered linkers.
  540. link)))
  541. ;;; Target type specific autogenerating gobbledygook.
  542. ;;
  543. (defun ede-proj-makefile-type (&optional proj)
  544. "Makefile type of the current project PROJ."
  545. (oref (or proj (ede-current-project)) makefile-type))
  546. (defun ede-proj-automake-p (&optional proj)
  547. "Return non-nil if the current project PROJ is automake mode."
  548. (eq (ede-proj-makefile-type proj) 'Makefile.am))
  549. (defun ede-proj-autoconf-p (&optional proj)
  550. "Return non-nil if the current project PROJ is automake mode."
  551. (eq (ede-proj-makefile-type proj) 'Makefile.in))
  552. (defun ede-proj-make-p (&optional proj)
  553. "Return non-nil if the current project PROJ is automake mode."
  554. (eq (ede-proj-makefile-type proj) 'Makefile))
  555. (defmethod ede-proj-dist-makefile ((this ede-proj-project))
  556. "Return the name of the Makefile with the DIST target in it for THIS."
  557. (cond ((eq (oref this makefile-type) 'Makefile.am)
  558. (concat (file-name-directory (oref this file))
  559. "Makefile.am"))
  560. ((eq (oref this makefile-type) 'Makefile.in)
  561. (expand-file-name "Makefile.in"
  562. (file-name-directory (oref this file))))
  563. ((object-assoc "Makefile" 'makefile (oref this targets))
  564. (expand-file-name "Makefile"
  565. (file-name-directory (oref this file))))
  566. (t
  567. (let ((targets (oref this targets)))
  568. (while (and targets
  569. (not (obj-of-class-p
  570. (car targets)
  571. 'ede-proj-target-makefile)))
  572. (setq targets (cdr targets)))
  573. (if targets (oref (car targets) makefile)
  574. (expand-file-name "Makefile"
  575. (file-name-directory (oref this file))))))))
  576. (defun ede-proj-regenerate ()
  577. "Regenerate Makefiles for and edeproject project."
  578. (interactive)
  579. (ede-proj-setup-buildenvironment (ede-current-project) t))
  580. (defmethod ede-proj-makefile-create-maybe ((this ede-proj-project) mfilename)
  581. "Create a Makefile for all Makefile targets in THIS if needed.
  582. MFILENAME is the makefile to generate."
  583. ;; For now, pass through until dirty is implemented.
  584. (require 'ede/pmake)
  585. (if (or (not (file-exists-p mfilename))
  586. (file-newer-than-file-p (oref this file) mfilename))
  587. (ede-proj-makefile-create this mfilename)))
  588. (defmethod ede-proj-setup-buildenvironment ((this ede-proj-project)
  589. &optional force)
  590. "Setup the build environment for project THIS.
  591. Handles the Makefile, or a Makefile.am configure.in combination.
  592. Optional argument FORCE will force items to be regenerated."
  593. (if (not force)
  594. (ede-proj-makefile-create-maybe this (ede-proj-dist-makefile this))
  595. (require 'ede/pmake)
  596. (ede-proj-makefile-create this (ede-proj-dist-makefile this)))
  597. ;; Rebuild all subprojects
  598. (ede-map-subprojects
  599. this (lambda (sproj) (ede-proj-setup-buildenvironment sproj force)))
  600. ;; Autoconf projects need to do other kinds of initializations.
  601. (when (and (ede-proj-automake-p this)
  602. (eq this (ede-toplevel this)))
  603. (require 'ede/pconf)
  604. ;; If the user wants to force this, do it some other way?
  605. (ede-proj-configure-synchronize this)
  606. ;; Now run automake to fill in the blanks, autoconf, and other
  607. ;; auto thingies so that we can just say "make" when done.
  608. )
  609. )
  610. ;;; Lower level overloads
  611. ;;
  612. (defmethod project-rescan ((this ede-proj-project))
  613. "Rescan the EDE proj project THIS."
  614. (let ((root (or (ede-project-root this) this))
  615. )
  616. (setq ede-projects (delq root ede-projects))
  617. (ede-load-project-file (ede-project-root-directory root))
  618. ))
  619. (provide 'ede/proj)
  620. ;;; ede/proj.el ends here