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