pmake.el 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693
  1. ;;; ede-pmake.el --- EDE Generic Project Makefile code generator.
  2. ;; Copyright (C) 1998-2005, 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. ;; Code generator for Makefiles.
  19. ;;
  20. ;; Here is how it should work:
  21. ;; 1) Collect information about the project and targets
  22. ;; 2) Insert header into the Makefile
  23. ;; 3) Insert basic variables (target/source)
  24. ;; 4) Conditional
  25. ;; a) Makefile
  26. ;; 1) Insert support variables (compiler variables, etc)
  27. ;; 2) Insert VERSION and DISTDIR
  28. ;; 3) Specify top build dir if necessary
  29. ;; 4) Specify compile/link commands (c, etc)
  30. ;; 5) Specify dependency files
  31. ;; 6) Specify all: target
  32. ;; 7) Include dependency files
  33. ;; 8) Insert commonized target specify rules
  34. ;; 9) Insert clean: and dist: rules
  35. ;; b) Automake file
  36. ;; 1) Insert distribution source variables for targets
  37. ;; 2) Insert user requested rules
  38. (eval-when-compile (require 'cl))
  39. (require 'ede/proj)
  40. (require 'ede/proj-obj)
  41. (require 'ede/proj-comp)
  42. (declare-function ede-srecode-setup "ede/srecode")
  43. (declare-function ede-srecode-insert "ede/srecode")
  44. ;;; Code:
  45. (defmethod ede-proj-makefile-create ((this ede-proj-project) mfilename)
  46. "Create a Makefile for all Makefile targets in THIS.
  47. MFILENAME is the makefile to generate."
  48. (require 'ede/srecode)
  49. (let ((mt nil)
  50. (isdist (string= mfilename (ede-proj-dist-makefile this)))
  51. (depth 0)
  52. (orig-buffer nil)
  53. (buff-to-kill nil)
  54. )
  55. ;; Find out how deep this project is.
  56. (let ((tmp this))
  57. (while (setq tmp (ede-parent-project tmp))
  58. (setq depth (1+ depth))))
  59. ;; Collect the targets that belong in a makefile.
  60. (mapc
  61. (lambda (obj)
  62. (if (and (obj-of-class-p obj 'ede-proj-target-makefile)
  63. (string= (oref obj makefile) mfilename))
  64. (setq mt (cons obj mt))))
  65. (oref this targets))
  66. ;; Fix the order so things compile in the right direction.
  67. (setq mt (nreverse mt))
  68. ;; Add in the header part of the Makefile*
  69. (save-excursion
  70. (setq orig-buffer (get-file-buffer mfilename))
  71. (set-buffer (setq buff-to-kill (find-file-noselect mfilename)))
  72. (goto-char (point-min))
  73. (if (and
  74. (not (eobp))
  75. (not (looking-at "# Automatically Generated \\w+ by EDE.")))
  76. (if (not (y-or-n-p (format "Really replace %s? " mfilename)))
  77. (error "Not replacing Makefile"))
  78. (message "Replace EDE Makefile"))
  79. (erase-buffer)
  80. (ede-srecode-setup)
  81. ;; Insert a giant pile of stuff that is common between
  82. ;; one of our Makefiles, and a Makefile.in
  83. (ede-srecode-insert
  84. "file:ede-empty"
  85. "MAKETYPE"
  86. (with-slots (makefile-type) this
  87. (cond ((eq makefile-type 'Makefile) "make")
  88. ((eq makefile-type 'Makefile.in) "autoconf")
  89. ((eq makefile-type 'Makefile.am) "automake")
  90. (t (error ":makefile-type in project invalid")))))
  91. ;; Just this project's variables
  92. (ede-proj-makefile-insert-variables this)
  93. ;; Space
  94. (insert "\n")
  95. (cond
  96. ((eq (oref this makefile-type) 'Makefile)
  97. ;; Make sure the user has the right kind of make
  98. (ede-make-check-version)
  99. (let* ((targ (if isdist (oref this targets) mt))
  100. (sp (oref this subproj))
  101. (df (apply 'append
  102. (mapcar (lambda (tg)
  103. (ede-proj-makefile-dependency-files tg))
  104. targ))))
  105. ;; Distribution variables
  106. (ede-compiler-begin-unique
  107. (mapc 'ede-proj-makefile-insert-variables targ))
  108. ;; Only add the distribution stuff in when depth != 0
  109. (let ((top (ede-toplevel this))
  110. (tmp this)
  111. (subdir ""))
  112. (insert "VERSION=" (oref top version) "\n"
  113. "DISTDIR=$(top)" (oref top name) "-$(VERSION)")
  114. (while (ede-parent-project tmp)
  115. (setq subdir
  116. (concat
  117. "/"
  118. (file-name-nondirectory
  119. (directory-file-name
  120. (file-name-directory (oref tmp file))))
  121. subdir)
  122. tmp (ede-parent-project tmp)))
  123. (insert subdir "\n"))
  124. ;; Some built in variables for C code
  125. (if df
  126. (let ((tc depth))
  127. (insert "top_builddir = ")
  128. (while (/= 0 tc)
  129. (setq tc (1- tc))
  130. (insert "..")
  131. (if (/= tc 0) (insert "/")))
  132. (insert "\n")))
  133. (insert "\n")
  134. ;; Create a variable with all the dependency files to include
  135. ;; These methods borrowed from automake.
  136. (if (and (oref this automatic-dependencies) df)
  137. (progn
  138. (insert "DEP_FILES="
  139. (mapconcat (lambda (f)
  140. (concat ".deps/"
  141. (file-name-nondirectory
  142. (file-name-sans-extension
  143. f)) ".P"))
  144. df " "))))
  145. ;;
  146. ;; Insert ALL Rule
  147. ;;
  148. (insert "\n\nall:")
  149. (mapc (lambda (c)
  150. (if (and (slot-exists-p c 'partofall) (oref c partofall))
  151. ;; Only insert this rule if it is a part of ALL.
  152. (insert " " (ede-proj-makefile-target-name c))))
  153. targ)
  154. (mapc (lambda (c)
  155. (insert " " (ede-name c))
  156. )
  157. sp)
  158. (insert "\n\n")
  159. ;;
  160. ;; Add in the include files
  161. ;;
  162. (mapc (lambda (c)
  163. (insert "include " c "\n\n"))
  164. (oref this include-file))
  165. ;; Some C inference rules
  166. ;; Dependency rules borrowed from automake.
  167. ;;
  168. ;; NOTE: This is GNU Make specific.
  169. (if (and (oref this automatic-dependencies) df)
  170. (insert "DEPS_MAGIC := $(shell mkdir .deps > /dev/null "
  171. "2>&1 || :)\n"
  172. "-include $(DEP_FILES)\n\n"))
  173. ;;
  174. ;; General makefile rules stored in the individual targets
  175. ;;
  176. (ede-compiler-begin-unique
  177. (ede-proj-makefile-insert-rules this)
  178. (mapc 'ede-proj-makefile-insert-rules targ))
  179. ;;
  180. ;; phony targets for sub projects
  181. ;;
  182. (mapc 'ede-proj-makefile-insert-subproj-rules sp)
  183. ;;
  184. ;; Distribution rules such as CLEAN and DIST
  185. ;;
  186. (when isdist
  187. (ede-proj-makefile-tags this mt)
  188. (ede-proj-makefile-insert-dist-rules this)))
  189. (save-buffer))
  190. ((eq (oref this makefile-type) 'Makefile.in)
  191. (error "Makefile.in is not supported"))
  192. ((eq (oref this makefile-type) 'Makefile.am)
  193. (require 'ede/pconf)
  194. ;; Basic vars needed:
  195. (ede-proj-makefile-automake-insert-subdirs this)
  196. (ede-proj-makefile-automake-insert-extradist this)
  197. ;; Distribution variables
  198. (let ((targ (if isdist (oref this targets) mt)))
  199. (ede-compiler-begin-unique
  200. (mapc 'ede-proj-makefile-insert-automake-pre-variables targ))
  201. (ede-compiler-begin-unique
  202. (mapc 'ede-proj-makefile-insert-source-variables targ))
  203. (ede-compiler-begin-unique
  204. (mapc 'ede-proj-makefile-insert-automake-post-variables targ))
  205. (ede-compiler-begin-unique
  206. (ede-proj-makefile-insert-user-rules this))
  207. (insert "\n# End of Makefile.am\n")
  208. (save-buffer))
  209. )
  210. (t (error "Unknown makefile type when generating Makefile")))
  211. ;; Put the cursor in a nice place
  212. (goto-char (point-min)))
  213. ;; If we have an original buffer, then don't kill it.
  214. (when (not orig-buffer)
  215. (kill-buffer buff-to-kill))
  216. ))
  217. ;;; VARIABLE insertion
  218. ;;
  219. (defun ede-pmake-end-of-variable ()
  220. "Move to the end of the variable declaration under point."
  221. (end-of-line)
  222. (while (= (preceding-char) ?\\)
  223. (forward-char 1)
  224. (end-of-line))
  225. )
  226. (defmacro ede-pmake-insert-variable-shared (varname &rest body)
  227. "Add VARNAME into the current Makefile.
  228. Execute BODY in a location where a value can be placed."
  229. `(let ((addcr t) (v ,varname))
  230. (if (save-excursion
  231. (goto-char (point-max))
  232. (re-search-backward (concat "^" v "\\s-*=") nil t))
  233. (progn
  234. (goto-char (match-end 0))
  235. (ede-pmake-end-of-variable)
  236. (if (< (current-column) 40)
  237. (if (and (/= (preceding-char) ?=)
  238. (/= (preceding-char) ? ))
  239. (insert " "))
  240. (insert "\\\n "))
  241. (setq addcr nil))
  242. (insert v "="))
  243. ,@body
  244. (if addcr (insert "\n"))
  245. (goto-char (point-max))))
  246. (put 'ede-pmake-insert-variable-shared 'lisp-indent-function 1)
  247. (defmacro ede-pmake-insert-variable-once (varname &rest body)
  248. "Add VARNAME into the current Makefile if it doesn't exist.
  249. Execute BODY in a location where a value can be placed."
  250. `(let ((addcr t) (v ,varname))
  251. (unless (re-search-backward (concat "^" v "\\s-*=") nil t)
  252. (insert v "=")
  253. ,@body
  254. (if addcr (insert "\n"))
  255. (goto-char (point-max)))
  256. ))
  257. (put 'ede-pmake-insert-variable-once 'lisp-indent-function 1)
  258. ;;; SOURCE VARIABLE NAME CONSTRUCTION
  259. (defsubst ede-pmake-varname (obj)
  260. "Convert OBJ into a variable name name.
  261. Change . to _ in the variable name."
  262. (let ((name (oref obj name)))
  263. (while (string-match "\\." name)
  264. (setq name (replace-match "_" nil t name)))
  265. name))
  266. (defmethod ede-proj-makefile-sourcevar ((this ede-proj-target))
  267. "Return the variable name for THIS's sources."
  268. (concat (ede-pmake-varname this) "_YOU_FOUND_A_BUG"))
  269. ;;; DEPENDENCY FILE GENERATOR LISTS
  270. ;;
  271. (defmethod ede-proj-makefile-dependency-files ((this ede-proj-target))
  272. "Return a list of source files to convert to dependencies.
  273. Argument THIS is the target to get sources from."
  274. nil)
  275. ;;; GENERIC VARIABLES
  276. ;;
  277. (defmethod ede-proj-makefile-configuration-variables ((this ede-proj-project)
  278. configuration)
  279. "Return a list of configuration variables from THIS.
  280. Use CONFIGURATION as the current configuration to query."
  281. (cdr (assoc configuration (oref this configuration-variables))))
  282. (defmethod ede-proj-makefile-insert-variables-new ((this ede-proj-project))
  283. "Insert variables needed by target THIS.
  284. NOTE: Not yet in use! This is part of an SRecode conversion of
  285. EDE that is in progress."
  286. ; (let ((conf-table (ede-proj-makefile-configuration-variables
  287. ; this (oref this configuration-default)))
  288. ; (conf-done nil))
  289. ;
  290. ; (ede-srecode-insert-with-dictionary
  291. ; "declaration:ede-vars"
  292. ;
  293. ; ;; Insert all variables, and augment them with details from
  294. ; ;; the current configuration.
  295. ; (mapc (lambda (c)
  296. ;
  297. ; (let ((ldict (srecode-dictionary-add-section-dictionary
  298. ; dict "VARIABLE"))
  299. ; )
  300. ; (srecode-dictionary-set-value ldict "NAME" (car c))
  301. ; (if (assoc (car c) conf-table)
  302. ; (let ((vdict (srecode-dictionary-add-section-dictionary
  303. ; ldict "VALUE")))
  304. ; (srecode-dictionary-set-value
  305. ; vdict "VAL" (cdr (assoc (car c) conf-table)))
  306. ; (setq conf-done (cons (car c) conf-done))))
  307. ; (let ((vdict (srecode-dictionary-add-section-dictionary
  308. ; ldict "VALUE")))
  309. ; (srecode-dictionary-set-value vdict "VAL" (cdr c))))
  310. ; )
  311. ;
  312. ; (oref this variables))
  313. ;
  314. ; ;; Add in all variables from the configuration not already covered.
  315. ; (mapc (lambda (c)
  316. ;
  317. ; (if (member (car c) conf-done)
  318. ; nil
  319. ; (let* ((ldict (srecode-dictionary-add-section-dictionary
  320. ; dict "VARIABLE"))
  321. ; (vdict (srecode-dictionary-add-section-dictionary
  322. ; ldict "VALUE"))
  323. ; )
  324. ; (srecode-dictionary-set-value ldict "NAME" (car c))
  325. ; (srecode-dictionary-set-value vdict "VAL" (cdr c))))
  326. ; )
  327. ;
  328. ; conf-table)
  329. ;
  330. ;; @TODO - finish off this function, and replace the below fcn
  331. ; ))
  332. )
  333. (defmethod ede-proj-makefile-insert-variables ((this ede-proj-project))
  334. "Insert variables needed by target THIS."
  335. (let ((conf-table (ede-proj-makefile-configuration-variables
  336. this (oref this configuration-default)))
  337. (conf-done nil))
  338. ;; Insert all variables, and augment them with details from
  339. ;; the current configuration.
  340. (mapc (lambda (c)
  341. (insert (car c) "=")
  342. (if (assoc (car c) conf-table)
  343. (progn
  344. (insert (cdr (assoc (car c) conf-table)) " ")
  345. (setq conf-done (cons (car c) conf-done))))
  346. (insert (cdr c) "\n"))
  347. (oref this variables))
  348. ;; Add in all variables from the configuration not already covered.
  349. (mapc (lambda (c)
  350. (if (member (car c) conf-done)
  351. nil
  352. (insert (car c) "=" (cdr c) "\n")))
  353. conf-table))
  354. (let* ((top "")
  355. (tmp this))
  356. ;; Use relative paths for subdirs.
  357. (while (ede-parent-project tmp)
  358. (setq tmp (ede-parent-project tmp)
  359. top (concat "../" top)))
  360. ;; If this is the top, then use CURDIR.
  361. (if (and (not (oref this metasubproject)) (string= top ""))
  362. (insert "\ntop=\"$(CURDIR)\"/")
  363. (insert "\ntop=" top)))
  364. (insert "\nede_FILES=" (file-name-nondirectory (oref this file)) " "
  365. (file-name-nondirectory (ede-proj-dist-makefile this)) "\n"))
  366. (defmethod ede-proj-makefile-insert-source-variables ((this ede-proj-target)
  367. &optional
  368. moresource)
  369. "Insert the source variables needed by THIS.
  370. Optional argument MORESOURCE is a list of additional sources to add to the
  371. sources variable."
  372. (let ((sv (ede-proj-makefile-sourcevar this)))
  373. ;; This variable may be shared between targets
  374. (ede-pmake-insert-variable-shared (cond ((listp sv) (car sv))
  375. (t sv))
  376. (insert (mapconcat (lambda (a) a) (oref this source) " "))
  377. (if moresource
  378. (insert " \\\n " (mapconcat (lambda (a) a) moresource " ") "")))))
  379. (defmethod ede-proj-makefile-insert-variables ((this ede-proj-target) &optional
  380. moresource)
  381. "Insert variables needed by target THIS.
  382. Optional argument MORESOURCE is a list of additional sources to add to the
  383. sources variable."
  384. (ede-proj-makefile-insert-source-variables this moresource)
  385. )
  386. (defmethod ede-proj-makefile-configuration-variables ((this ede-proj-target-makefile)
  387. configuration)
  388. "Return a list of configuration variables from THIS.
  389. Use CONFIGURATION as the current configuration to query."
  390. (cdr (assoc configuration (oref this configuration-variables))))
  391. (defmethod ede-proj-makefile-insert-variables ((this ede-proj-target-makefile)
  392. &optional moresource)
  393. "Insert variables needed by target THIS.
  394. Optional argument MORESOURCE is a list of additional sources to add to the
  395. sources variable."
  396. (call-next-method)
  397. (let* ((proj (ede-target-parent this))
  398. (conf-table (ede-proj-makefile-configuration-variables
  399. this (oref proj configuration-default)))
  400. (conf-done nil)
  401. )
  402. ;; Add in all variables from the configuration not already covered.
  403. (mapc (lambda (c)
  404. (if (member (car c) conf-done)
  405. nil
  406. (insert (car c) "=" (cdr c) "\n")))
  407. conf-table))
  408. (let ((comp (ede-proj-compilers this))
  409. (link (ede-proj-linkers this))
  410. (name (ede-proj-makefile-target-name this))
  411. (src (oref this source)))
  412. (ede-proj-makefile-insert-object-variables (car comp) name src)
  413. (dolist (obj comp)
  414. (ede-compiler-only-once obj
  415. (ede-proj-makefile-insert-variables obj)))
  416. (dolist (linker link)
  417. (ede-linker-only-once linker
  418. (ede-proj-makefile-insert-variables linker)))))
  419. (defmethod ede-proj-makefile-insert-automake-pre-variables
  420. ((this ede-proj-target))
  421. "Insert variables needed by target THIS in Makefile.am before SOURCES."
  422. nil)
  423. (defmethod ede-proj-makefile-insert-automake-post-variables
  424. ((this ede-proj-target))
  425. "Insert variables needed by target THIS in Makefile.am after SOURCES."
  426. nil)
  427. ;;; GARBAGE PATTERNS
  428. ;;
  429. (defmethod ede-proj-makefile-garbage-patterns ((this ede-proj-project))
  430. "Return a list of patterns that are considered garbage to THIS.
  431. These are removed with make clean."
  432. (let ((mc (ede-map-targets
  433. this (lambda (c) (ede-proj-makefile-garbage-patterns c))))
  434. (uniq nil))
  435. (setq mc (sort (apply 'append mc) 'string<))
  436. ;; Filter out duplicates from the targets.
  437. (while mc
  438. (if (and (car uniq) (string= (car uniq) (car mc)))
  439. nil
  440. (setq uniq (cons (car mc) uniq)))
  441. (setq mc (cdr mc)))
  442. (nreverse uniq)))
  443. (defmethod ede-proj-makefile-garbage-patterns ((this ede-proj-target))
  444. "Return a list of patterns that are considered garbage to THIS.
  445. These are removed with make clean."
  446. ;; Get the source object from THIS, and use the specified garbage.
  447. (let ((src (ede-target-sourcecode this))
  448. (garb nil))
  449. (while src
  450. (setq garb (append (oref (car src) garbagepattern) garb)
  451. src (cdr src)))
  452. garb))
  453. ;;; RULES
  454. ;;
  455. (defmethod ede-proj-makefile-insert-subproj-rules ((this ede-proj-project))
  456. "Insert a rule for the project THIS which should be a subproject."
  457. (insert ".PHONY:" (ede-name this))
  458. (newline)
  459. (insert (ede-name this) ":")
  460. (newline)
  461. (insert "\t$(MAKE) -C " (directory-file-name (ede-subproject-relative-path this)))
  462. (newline)
  463. (newline)
  464. )
  465. (defmethod ede-proj-makefile-insert-rules ((this ede-proj-project))
  466. "Insert rules needed by THIS target."
  467. (mapc 'ede-proj-makefile-insert-rules (oref this inference-rules))
  468. )
  469. (defmethod ede-proj-makefile-insert-dist-dependencies ((this ede-proj-project))
  470. "Insert any symbols that the DIST rule should depend on.
  471. Argument THIS is the project that should insert stuff."
  472. (mapc 'ede-proj-makefile-insert-dist-dependencies (oref this targets))
  473. )
  474. (defmethod ede-proj-makefile-insert-dist-dependencies ((this ede-proj-target))
  475. "Insert any symbols that the DIST rule should depend on.
  476. Argument THIS is the target that should insert stuff."
  477. nil)
  478. (defmethod ede-proj-makefile-insert-dist-filepatterns ((this ede-proj-target))
  479. "Insert any symbols that the DIST rule should depend on.
  480. Argument THIS is the target that should insert stuff."
  481. (ede-proj-makefile-insert-dist-dependencies this)
  482. )
  483. (defmethod ede-proj-makefile-automake-insert-subdirs ((this ede-proj-project))
  484. "Insert a SUBDIRS variable for Automake."
  485. (proj-comp-insert-variable-once "SUBDIRS"
  486. (ede-map-subprojects
  487. this (lambda (sproj)
  488. (insert " " (ede-subproject-relative-path sproj))
  489. ))))
  490. (defmethod ede-proj-makefile-automake-insert-extradist ((this ede-proj-project))
  491. "Insert the EXTRADIST variable entries needed for Automake and EDE."
  492. (proj-comp-insert-variable-once "EXTRA_DIST" (insert "Project.ede")))
  493. (defmethod ede-proj-makefile-insert-dist-rules ((this ede-proj-project))
  494. "Insert distribution rules for THIS in a Makefile, such as CLEAN and DIST."
  495. (let ((junk (ede-proj-makefile-garbage-patterns this))
  496. tmp)
  497. ;; Build CLEAN, DIST, TAG, and other rules here.
  498. (if junk
  499. (insert "\nclean:\n"
  500. "\trm -f "
  501. (mapconcat (lambda (c) c) junk " ")
  502. "\n\n"))
  503. ;; @TODO: ^^^ Clean should also recurse. ^^^
  504. (insert ".PHONY: dist\n")
  505. (insert "\ndist:")
  506. (ede-proj-makefile-insert-dist-dependencies this)
  507. (insert "\n")
  508. (unless (or (ede-subproject-p this)
  509. (oref this metasubproject))
  510. ;; Only delete if we are the toplevel project.
  511. (insert "\trm -rf $(DISTDIR)\n"))
  512. (insert "\tmkdir $(DISTDIR)\n") ;We may need a -p, but I think not.
  513. (setq tmp (oref this targets))
  514. (insert "\tcp")
  515. (while tmp
  516. (let ((sv (ede-proj-makefile-sourcevar (car tmp))))
  517. (if (listp sv)
  518. ;; Handle special case variables.
  519. (cond ((eq (cdr sv) 'share)
  520. ;; This variable may be shared between multiple targets.
  521. (if (re-search-backward (concat "\\$(" (car sv) ")")
  522. (point-at-bol) t)
  523. ;; If its already in the dist target, then skip it.
  524. nil
  525. (setq sv (car sv))))
  526. (t (setq sv (car sv)))))
  527. (if (stringp sv)
  528. (insert " $(" sv ")"))
  529. (ede-proj-makefile-insert-dist-filepatterns (car tmp))
  530. (setq tmp (cdr tmp))))
  531. (insert " $(ede_FILES) $(DISTDIR)\n")
  532. ;; Call our sub projects.
  533. (ede-map-subprojects
  534. this (lambda (sproj)
  535. (let ((rp (directory-file-name (ede-subproject-relative-path sproj))))
  536. (insert "\t$(MAKE) -C " rp " $(MFLAGS) DISTDIR=$(DISTDIR)/" rp
  537. " dist"
  538. "\n"))))
  539. ;; Tar up the stuff.
  540. (unless (or (ede-subproject-p this)
  541. (oref this metasubproject))
  542. (insert "\ttar -cvzf $(DISTDIR).tar.gz $(DISTDIR)\n"
  543. "\trm -rf $(DISTDIR)\n"))
  544. ;; Make sure the Makefile is ok.
  545. (insert "\n"
  546. (file-name-nondirectory (buffer-file-name)) ": "
  547. (file-name-nondirectory (oref this file)) "\n"
  548. ;; "$(EMACS) -batch Project.ede -l ede -f ede-proj-regenerate"
  549. "\t@echo Makefile is out of date! "
  550. "It needs to be regenerated by EDE.\n"
  551. "\t@echo If you have not modified Project.ede, you can"
  552. " use 'touch' to update the Makefile time stamp.\n"
  553. "\t@false\n\n"
  554. "\n\n# End of Makefile\n")))
  555. (defmethod ede-proj-makefile-insert-rules ((this ede-proj-target))
  556. "Insert rules needed by THIS target."
  557. nil)
  558. (defmethod ede-proj-makefile-insert-rules ((this ede-proj-target-makefile))
  559. "Insert rules needed by THIS target."
  560. (mapc 'ede-proj-makefile-insert-rules (oref this rules))
  561. (let ((c (ede-proj-compilers this)))
  562. (when c
  563. (mapc 'ede-proj-makefile-insert-rules c)
  564. (if (oref this phony)
  565. (insert ".PHONY: " (ede-proj-makefile-target-name this) "\n"))
  566. (insert (ede-proj-makefile-target-name this) ": "
  567. (ede-proj-makefile-dependencies this) "\n")
  568. (ede-proj-makefile-insert-commands this)
  569. )))
  570. (defmethod ede-proj-makefile-insert-commands ((this ede-proj-target-makefile))
  571. "Insert the commands needed by target THIS.
  572. For targets, insert the commands needed by the chosen compiler."
  573. (mapc 'ede-proj-makefile-insert-commands (ede-proj-compilers this))
  574. (when (object-assoc t :uselinker (ede-proj-compilers this))
  575. (mapc 'ede-proj-makefile-insert-commands (ede-proj-linkers this))))
  576. (defmethod ede-proj-makefile-insert-user-rules ((this ede-proj-project))
  577. "Insert user specified rules needed by THIS target.
  578. This is different from `ede-proj-makefile-insert-rules' in that this
  579. function won't create the building rules which are auto created with
  580. automake."
  581. (mapc 'ede-proj-makefile-insert-user-rules (oref this inference-rules)))
  582. (defmethod ede-proj-makefile-insert-user-rules ((this ede-proj-target))
  583. "Insert user specified rules needed by THIS target."
  584. (mapc 'ede-proj-makefile-insert-rules (oref this rules)))
  585. (defmethod ede-proj-makefile-dependencies ((this ede-proj-target-makefile))
  586. "Return a string representing the dependencies for THIS.
  587. Some compilers only use the first element in the dependencies, others
  588. have a list of intermediates (object files), and others don't care.
  589. This allows customization of how these elements appear."
  590. (let* ((c (ede-proj-compilers this))
  591. (io (eval (cons 'or (mapcar 'ede-compiler-intermediate-objects-p c))))
  592. (out nil))
  593. (if io
  594. (progn
  595. (while c
  596. (setq out
  597. (concat out "$(" (ede-compiler-intermediate-object-variable
  598. (car c)
  599. (ede-proj-makefile-target-name this)) ")")
  600. c (cdr c)))
  601. out)
  602. (let ((sv (ede-proj-makefile-sourcevar this))
  603. (aux (oref this auxsource)))
  604. (setq out
  605. (if (and (stringp sv) (not (string= sv "")))
  606. (concat "$(" sv ")")
  607. ""))
  608. (while aux
  609. (setq out (concat out " " (car aux)))
  610. (setq aux (cdr aux)))
  611. out))))
  612. ;; Tags
  613. (defmethod ede-proj-makefile-tags ((this ede-proj-project) targets)
  614. "Insert into the current location rules to make recursive TAGS files.
  615. Argument THIS is the project to create tags for.
  616. Argument TARGETS are the targets we should depend on for TAGS."
  617. (insert "tags: ")
  618. (let ((tg targets))
  619. ;; Loop over all source variables and insert them
  620. (while tg
  621. (insert "$(" (ede-proj-makefile-sourcevar (car tg)) ") ")
  622. (setq tg (cdr tg)))
  623. (insert "\n")
  624. (if targets
  625. (insert "\tetags $^\n"))
  626. ;; Now recurse into all subprojects
  627. (setq tg (oref this subproj))
  628. (while tg
  629. (insert "\t$(MAKE) -C " (ede-subproject-relative-path (car tg)) " $(MFLAGS) $@\n")
  630. (setq tg (cdr tg)))
  631. (insert "\n")))
  632. (provide 'ede/pmake)
  633. ;;; ede/pmake.el ends here