1 ;;; project-am.el --- A project management scheme based on automake files.
3 ;;; Copyright (C) 1998, 1999, 2000, 2003, 2005, 2007, 2008, 2009
4 ;;; Free Software Foundation, Inc.
6 ;; Author: Eric M. Ludlam <zappo@gnu.org>
8 ;; Keywords: project, make
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software: you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation, either version 3 of the License, or
15 ;; (at your option) any later version.
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
27 ;; The GNU Automake tool is the first step towards having a really
28 ;; good project management system. It provides a simple and concise
29 ;; look at what is actually in a project, and records it in a simple
32 ;; project-am uses the structure defined in all good GNU projects with
33 ;; the Automake file as it's base template, and then maintains that
34 ;; information during edits, automatically updating the automake file
39 ;; ;; Compatibility for makefile mode.
40 ;; (condition-case nil
41 ;; (require 'makefile "make-mode")
42 ;; (error (require 'make-mode "make-mode")))
44 ;; ;; Requiring the .el files prevents incomplete builds.
45 ;; (require 'eieio "eieio.el")
46 ;; (require 'ede "ede.el"))
51 (require 'ede
/makefile-edit
)
53 (declare-function autoconf-parameters-for-macro
"ede/autoconf-edit")
54 (eval-when-compile (require 'compile
))
57 (defgroup project-am nil
58 "File and tag browser frame."
63 (defcustom project-am-compile-project-command nil
64 "*Default command used to compile a project."
68 (defcustom project-am-compile-target-command
(concat ede-make-command
" -k %s")
69 "*Default command used to compile a project."
73 (defcustom project-am-debug-target-function
'gdb
74 "*Default Emacs command used to debug a target."
76 :type
'sexp
) ; make this be a list some day
78 (defconst project-am-type-alist
79 '(("bin" project-am-program
"bin_PROGRAMS" t
)
80 ("sbin" project-am-program
"sbin_PROGRAMS" t
)
81 ("noinstbin" project-am-program
"noinst_PROGRAMS" t
)
82 ("checkbin" project-am-program
"check_PROGRAMS" t
)
83 ("lib" project-am-lib
"lib_LIBS" t
)
84 ("libraries" project-am-lib
"lib_LIBRARIES" t
)
85 ("librariesnoinst" project-am-lib
"noinst_LIBRARIES" t
)
86 ("pkglibraries" project-am-lib
"pkglib_LIBRARIES" t
)
87 ("checklibs" project-am-lib
"check_LIBRARIES" t
)
88 ("ltlibraries" project-am-lib
"lib_LTLIBRARIES" t
)
89 ("ltlibrariesnoinst" project-am-lib
"noinst_LTLIBRARIES" t
)
90 ("pkgltlibraries" project-am-lib
"pkglib_LTLIBRARIES" t
)
91 ("checkltlibs" project-am-lib
"check_LTLIBRARIES" t
)
92 ("headernoinst" project-am-header-noinst
"noinst_HEADERS")
93 ("headerinst" project-am-header-inst
"include_HEADERS")
94 ("headerpkg" project-am-header-pkg
"pkginclude_HEADERS")
95 ("headerpkg" project-am-header-chk
"check_HEADERS")
96 ("texinfo" project-am-texinfo
"info_TEXINFOS" t
)
97 ("man" project-am-man
"man_MANS")
98 ("lisp" project-am-lisp
"lisp_LISP")
99 ;; for other global files track EXTRA_
100 ("extrabin" project-am-program
"EXTRA_PROGRAMS" t
)
101 ("builtsrcs" project-am-built-src
"BUILT_SOURCES")
102 ("extradist" project-am-extra-dist
"EXTRA_DIST")
103 ;; Custom libraries targets?
104 ;; ("ltlibcustom" project-am-lib ".*?_LTLIBRARIES" t)
106 "Alist of type names and the type of object to create for them.
107 Each entry is of th form:
108 (EMACSNAME CLASS AUToMAKEVAR INDIRECT)
109 where EMACSNAME is a name for Emacs to use.
110 CLASS is the EDE target class to represent the target.
111 AUTOMAKEVAR is the Automake variable to identify. This cannot be a
113 INDIRECT is optional. If it is non-nil, then the variable in
114 question lists other variables that need to be looked up.")
116 (defclass project-am-target
(ede-target)
118 "Base target class for everything in project-am.")
120 (defclass project-am-objectcode
(project-am-target)
121 ((source :initarg
:source
:documentation
"List of source files."))
122 "A target which creates object code, like a C program or library.")
124 (defclass project-am-program
(project-am-objectcode)
125 ((ldadd :initarg
:ldadd
:documentation
"Additional LD args."
127 "A top level program to build")
129 (defclass project-am-header
(project-am-target)
131 "A group of misc source files, such as headers.")
133 (defclass project-am-header-noinst
(project-am-header)
135 "A group of header files that are not installed.")
137 (defclass project-am-header-inst
(project-am-header)
139 "A group of header files that are not installed.")
141 (defclass project-am-header-pkg
(project-am-header)
143 "A group of header files that are not installed.")
145 (defclass project-am-header-chk
(project-am-header)
147 "A group of header files that are not installed.")
149 (defclass project-am-lib
(project-am-objectcode)
151 "A top level library to build")
153 (defclass project-am-lisp
(project-am-target)
155 "A group of Emacs Lisp programs to byte compile.")
157 (defclass project-am-texinfo
(project-am-target)
158 ((include :initarg
:include
160 :documentation
"Additional texinfo included in this one."))
161 "A top level texinfo file to build.")
163 (defclass project-am-man
(project-am-target)
165 "A top level man file to build.")
167 ;; For generic files tracker like EXTRA_DIST
168 (defclass project-am-built-src
(project-am-target)
170 "A group of Emacs Lisp programs to byte compile.")
172 (defclass project-am-extra-dist
(project-am-target)
174 "A group of Emacs Lisp programs to byte compile.")
176 (defclass project-am-makefile
(ede-project)
177 ((targets :initarg
:targets
179 :documentation
"Top level targets in this makefile.")
180 (configureoutputfiles
183 "List of files output from configure system.")
185 "Encode one makefile.")
188 (defmethod project-add-file ((ot project-am-target
))
189 "Add the current buffer into a project.
190 OT is the object target. DIR is the directory to start in."
191 (let* ((target (if ede-object
(error "Already assocated w/ a target")
192 (let ((amf (project-am-load default-directory
)))
193 (if (not amf
) (error "No project file"))
194 (completing-read "Target: "
195 (object-assoc-list 'name
198 ;; The input target might be new. See if we can find it.
199 (amf (ede-load-project-file (oref ot path
)))
200 (ot (object-assoc target
'name
(oref amf targets
)))
201 (ofn (file-name-nondirectory (buffer-file-name))))
205 target
(project-am-preferred-target-type (buffer-file-name)))))
206 (ede-with-projectfile ot
207 (makefile-move-to-macro (project-am-macro ot
))
209 (makefile-end-of-command)
211 (makefile-fill-paragraph nil
)
214 (setq ede-object ot
)))
216 (defmethod project-remove-file ((ot project-am-target
) fnnd
)
217 "Remove the current buffer from any project targets."
218 (ede-with-projectfile ot
219 (makefile-move-to-macro (project-am-macro ot
))
220 (if (and buffer-read-only vc-mode
221 (y-or-n-p "Checkout Makefile.am from VC? "))
222 (vc-toggle-read-only t
))
224 (makefile-navigate-macro (concat " *" (regexp-quote (ede-name fnnd
))))
225 (replace-match "" t t nil
0)
226 (makefile-fill-paragraph nil
)
229 (setq ede-object nil
))
231 (defmethod project-edit-file-target ((obj project-am-target
))
232 "Edit the target associated w/ this file."
233 (find-file (concat (oref obj path
) "Makefile.am"))
234 (goto-char (point-min))
235 (makefile-move-to-macro (project-am-macro obj
))
236 (if (= (point-min) (point))
237 (re-search-forward (ede-target-name obj
))))
239 (defmethod project-new-target ((proj project-am-makefile
)
241 "Create a new target named NAME.
242 Argument TYPE is the type of target to insert. This is a string
243 matching something in `project-am-type-alist' or type class symbol.
244 Despite the fact that this is a method, it depends on the current
245 buffer being in order to provide a smart default target type."
246 (let* ((name (or name
(read-string "Name: " "")))
248 (completing-read "Type: "
249 project-am-type-alist
251 (cond ((eq major-mode
'texinfo-mode
)
253 ((eq major-mode
'nroff-mode
)
255 ((eq major-mode
'emacs-lisp-mode
)
258 (ntype (assoc type project-am-type-alist
))
260 (setq ot
(apply (car (cdr ntype
)) name
:name name
261 :path
(expand-file-name default-directory
) nil
))
262 (if (not ot
) (error "Error creating target object %S" ntype
))
263 (ede-with-projectfile ot
264 (goto-char (point-min))
266 (makefile-next-dependency)
267 (if (= (point) (point-min))
268 (goto-char (point-max))
272 ;; Add the new target sources macro (if needed)
273 (if (project-am-macro ot
)
274 (makefile-insert-macro (project-am-macro ot
)))
275 ;; Add to the list of objects.
276 (goto-char (point-min))
277 (makefile-move-to-macro (car (cdr (cdr ntype
))))
278 (if (= (point) (point-min))
280 (if (re-search-forward makefile-macroassign-regex nil t
)
281 (progn (forward-line -
1)
284 ;; If the above search fails, thats ok. We'd just want to be at
287 (makefile-insert-macro (car (cdr (cdr ntype
))))))
288 (makefile-end-of-command)
289 (insert " " (ede-target-name ot
))
291 ;; Rescan the object in this makefile.
292 (project-rescan ede-object
))))
294 ;(defun project-am-rescan-toplevel ()
295 ; "Rescan all projects in which the current buffer resides."
297 ; (let* ((tlof (project-am-find-topmost-level default-directory))
298 ; (tlo (project-am-load tlof))
299 ; (ede-deep-rescan t)) ; scan deep in this case.
300 ; ;; tlo is the top level object for whatever file we are in
301 ; ;; or nil. If we have an object, call the rescan method.
302 ; (if tlo (project-am-rescan tlo))))
307 ;; This should be handled at the EDE level, calling a method of the
310 (defmethod project-compile-project ((obj project-am-target
) &optional command
)
311 "Compile the entire current project.
312 Argument COMMAND is the command to use when compiling."
317 ;; This interactive statement was taken from compile, and I'll
318 ;; use the same command history too.
320 (if (not project-am-compile-project-command
)
321 (setq project-am-compile-project-command compile-command
))
322 (if (or compilation-read-command current-prefix-arg
)
323 (read-from-minibuffer "Project compile command: "
325 ;; This is compile project after all.
326 project-am-compile-project-command
327 nil nil
'(compile-history .
1))
328 project-am-compile-project-command
))))
329 ;; When compile a project, we might be in a subdirectory,
330 ;; so we have to make sure we move all the way to the top.
331 (let* ((default-directory (project-am-find-topmost-level default-directory
)))
334 (defmethod project-compile-project ((obj project-am-makefile
)
336 "Compile the entire current project.
337 Argument COMMAND is the command to use when compiling."
342 ;; This interactive statement was taken from compile, and I'll
343 ;; use the same command history too.
345 (if (not project-am-compile-project-command
)
346 (setq project-am-compile-project-command compile-command
))
347 (if (or compilation-read-command current-prefix-arg
)
348 (read-from-minibuffer "Project compile command: "
350 ;; This is compile project after all.
351 project-am-compile-project-command
352 nil nil
'(compile-history .
1))
353 project-am-compile-project-command
))))
354 ;; When compile a project, we might be in a subdirectory,
355 ;; so we have to make sure we move all the way to the top.
356 (let* ((default-directory (project-am-find-topmost-level default-directory
)))
359 (defmethod project-compile-target ((obj project-am-target
) &optional command
)
360 "Compile the current target.
361 Argument COMMAND is the command to use for compiling the target."
363 (if (not project-am-compile-project-command
)
364 (setq project-am-compile-project-command compile-command
))
368 (if compilation-read-command
369 (read-from-minibuffer "Project compile command: "
371 ;; This is compile project after all.
374 project-am-compile-target-command
375 (project-compile-target-command
377 project-am-compile-target-command
)
379 '(compile-history .
1))
381 project-am-compile-project-command
383 project-am-compile-target-command
384 (project-compile-target-command ede-object
))))))
385 ;; We better be in the right place when compiling a specific target.
388 (defmethod project-debug-target ((obj project-am-objectcode
))
389 "Run the current project target in a debugger."
390 (let ((tb (get-buffer-create " *padt*"))
396 (setq default-directory dd
)
397 (setq cmd
(read-from-minibuffer
399 (concat (symbol-name project-am-debug-target-function
)
400 " " (ede-target-name obj
))))
401 (funcall project-am-debug-target-function cmd
))
404 (defmethod project-make-dist ((this project-am-target
))
405 "Run the current project in the debugger."
407 (if (not project-am-compile-project-command
)
408 (setq project-am-compile-project-command compile-command
))
409 (project-compile-project this
(concat project-am-compile-project-command
412 ;;; Project loading and saving
414 (defun project-am-load (project &optional rootproj
)
415 "Read an automakefile PROJECT into our data structure.
416 Make sure that the tree down to our makefile is complete so that there
417 is cohesion in the project. Return the project file (or sub-project).
418 If a given set of projects has already been loaded, then do nothing
419 but return the project for the directory given.
420 Optional ROOTPROJ is the root EDE project."
421 ;; @TODO - rationalize this to the newer EDE way of doing things.
422 (setq project
(expand-file-name project
))
423 (let* ((ede-constructing t
)
424 (fn (project-am-find-topmost-level (file-name-as-directory project
)))
426 (trimmed (if (string-match (regexp-quote fn
)
428 (replace-match "" t t project
)
431 (setq amo
(object-assoc (expand-file-name "Makefile.am" fn
)
434 (error "Synchronous error in ede/project-am objects")
435 (let ((project-am-constructing t
))
436 (setq amo
(project-am-load-makefile fn
))))
439 ;; Now scan down from amo, and find the current directory
440 ;; from the PROJECT file.
441 (while (< 0 (length trimmed
))
442 (if (string-match "\\([a-zA-Z0-9.-]+\\)/" trimmed
)
443 (setq subdir
(match-string 0 trimmed
)
444 trimmed
(replace-match "" t t trimmed
))
445 (error "Error scanning down path for project"))
446 (setq amo
(project-am-subtree
448 (expand-file-name "Makefile.am"
449 (expand-file-name subdir fn
)))
450 fn
(expand-file-name subdir fn
)))
454 (defun project-am-find-topmost-level (dir)
455 "Find the topmost automakefile starting with DIR."
457 (while (or (file-exists-p (concat newdir
"Makefile.am"))
458 (file-exists-p (concat newdir
"configure.ac"))
459 (file-exists-p (concat newdir
"configure.in"))
461 (setq dir newdir newdir
462 (file-name-directory (directory-file-name newdir
))))
463 (expand-file-name dir
)))
465 (defmacro project-am-with-makefile-current
(dir &rest forms
)
466 "Set the Makefile.am in DIR to be the current buffer.
467 Run FORMS while the makefile is current.
468 Kill the makefile if it was not loaded before the load."
469 `(let* ((fn (expand-file-name "Makefile.am" ,dir
))
471 (kb (get-file-buffer fn
)))
472 (if (not (file-exists-p fn
))
476 ;; We need to find-file this thing, but don't use
477 ;; any semantic features.
478 (let ((semantic-init-hook nil
))
479 (setq fb
(find-file-noselect fn
)))
483 (if (not kb
) (kill-buffer (current-buffer))))))))
484 (put 'project-am-with-makefile-current
'lisp-indent-function
1)
486 (add-hook 'edebug-setup-hook
488 (def-edebug-spec project-am-with-makefile-current
492 (defun project-am-load-makefile (path)
493 "Convert PATH into a project Makefile, and return its project object.
494 It does not check for existing project objects. Use `project-am-load'."
495 (project-am-with-makefile-current path
496 (if (and ede-object
(project-am-makefile-p ede-object
))
498 (let* ((pi (project-am-package-info path
))
499 (pn (or (nth 0 pi
) (project-am-last-dir fn
)))
500 (ver (or (nth 1 pi
) "0.0"))
503 (ampf (project-am-makefile
506 :mailinglist
(or bug
"")
508 (oset ampf
:directory
(file-name-directory fn
))
509 (oset ampf configureoutputfiles cof
)
510 (make-local-variable 'ede-object
)
511 (setq ede-object ampf
)
512 ;; Move the rescan after we set ede-object to prevent recursion
513 (project-rescan ampf
)
517 (defmethod ede-find-target ((amf project-am-makefile
) buffer
)
518 "Fetch the target belonging to BUFFER."
519 (or (call-next-method)
520 (let ((targ (oref amf targets
))
521 (sobj (oref amf subproj
))
523 (while (and targ
(not obj
))
524 (if (ede-buffer-mine (car targ
) buffer
)
525 (setq obj
(car targ
)))
526 (setq targ
(cdr targ
)))
527 (while (and sobj
(not obj
))
528 (setq obj
(project-am-buffer-object (car sobj
) buffer
)
532 (defmethod project-targets-for-file ((proj project-am-makefile
))
533 "Return a list of targets the project PROJ."
536 (defun project-am-scan-for-targets (currproj dir
)
537 "Scan the current Makefile.am for targets.
538 CURRPROJ is the current project being scanned.
539 DIR is the directory to apply to new targets."
540 (let* ((otargets (oref currproj targets
))
545 ;; Map all the different types
547 (let ((macro (nth 2 typecar
))
548 (class (nth 1 typecar
))
549 (indirect (nth 3 typecar
))
550 ;(name (car typecar))
553 ;; Map all the found objects
554 (mapc (lambda (lstcar)
555 (setq tmp
(object-assoc lstcar
'name otargets
))
557 (setq tmp
(apply class lstcar
:name lstcar
560 (setq ntargets
(cons tmp ntargets
)))
561 (makefile-macro-file-list macro
))
562 ;; Non-indirect will have a target whos sources
563 ;; are actual files, not names of other targets.
564 (let ((files (makefile-macro-file-list macro
)))
566 (setq tmp
(object-assoc macro
'name otargets
))
568 (setq tmp
(apply class macro
:name macro
571 (setq ntargets
(cons tmp ntargets
))
575 project-am-type-alist
)
578 (defmethod project-rescan ((this project-am-makefile
))
579 "Rescan the makefile for all targets and sub targets."
580 (project-am-with-makefile-current (file-name-directory (oref this file
))
581 ;;(message "Scanning %s..." (oref this file))
582 (let* ((pi (project-am-package-info (oref this directory
)))
587 (osubproj (oref this subproj
))
589 ;; If DIST_SUBDIRS doesn't exist, then go for the
590 ;; static list of SUBDIRS. The DIST version should
591 ;; contain SUBDIRS plus extra stuff.
592 (makefile-macro-file-list "DIST_SUBDIRS")
593 (makefile-macro-file-list "SUBDIRS")))
594 (csubprojexpanded nil
)
596 ;; Targets are excluded here because they require
597 ;; special attention.
598 (dir (expand-file-name default-directory
))
600 (ntargets (project-am-scan-for-targets this dir
))
603 (and pn
(string= (directory-file-name
604 (oref this directory
))
606 (project-am-find-topmost-level
607 (oref this directory
))))
609 (and pv
(oset this version pv
))
610 (and bug
(oset this mailinglist bug
))
611 (oset this configureoutputfiles cof
))
613 ; ;; LISP is different. Here there is only one kind of lisp (that I know of
614 ; ;; anyway) so it doesn't get mapped when it is found.
615 ; (if (makefile-move-to-macro "lisp_LISP")
616 ; (let ((tmp (project-am-lisp "lisp"
619 ; (project-rescan tmp)
620 ; (setq ntargets (cons tmp ntargets))))
622 ;; Now that we have this new list, chuck the old targets
623 ;; and replace it with the new list of targets I just created.
624 (oset this targets
(nreverse ntargets
))
625 ;; We still have a list of targets. For all buffers, make sure
626 ;; their object still exists!
631 (let ((var (makefile-extract-varname-from-text sp
))
634 (setq csubprojexpanded
(cons sp csubprojexpanded
))
635 ;; If it is a variable, expand that variable, and keep going.
636 (let ((varexp (makefile-macro-file-list var
)))
638 (setq csubprojexpanded
(cons V csubprojexpanded
)))))
642 ;; Ok, now lets look at all our sub-projects.
644 (let* ((subdir (file-name-as-directory
646 sp
(file-name-directory (oref this
:file
)))))
647 (submake (expand-file-name
650 (if (string= submake
(oref this
:file
))
651 nil
;; don't recurse.. please!
653 ;; For each project id found, see if we need to recycle,
654 ;; and if we do not, then make a new one. Check the deep
655 ;; rescan value for behavior patterns.
656 (setq tmp
(object-assoc
662 ;; In case of problem, ignore it.
663 (project-am-load-makefile subdir
)
665 ;; If we have tmp, then rescan it only if deep mode.
667 (project-rescan tmp
)))
668 ;; Tac tmp onto our list of things to keep, but only
671 ;;(message "Adding %S" (object-print tmp))
672 (setq nsubproj
(cons tmp nsubproj
)))))
674 (nreverse csubprojexpanded
))
675 (oset this subproj nsubproj
)
676 ;; All elements should be updated now.
680 (defmethod project-rescan ((this project-am-program
))
681 "Rescan object THIS."
682 (oset this
:source
(makefile-macro-file-list (project-am-macro this
)))
683 (oset this
:ldadd
(makefile-macro-file-list
684 (concat (oref this
:name
) "_LDADD"))))
686 (defmethod project-rescan ((this project-am-lib
))
687 "Rescan object THIS."
688 (oset this
:source
(makefile-macro-file-list (project-am-macro this
))))
690 (defmethod project-rescan ((this project-am-texinfo
))
691 "Rescan object THIS."
692 (oset this
:include
(makefile-macro-file-list (project-am-macro this
))))
694 (defmethod project-rescan ((this project-am-man
))
695 "Rescan object THIS."
696 (oset this
:source
(makefile-macro-file-list (project-am-macro this
))))
698 (defmethod project-rescan ((this project-am-lisp
))
699 "Rescan the lisp sources."
700 (oset this
:source
(makefile-macro-file-list (project-am-macro this
))))
702 (defmethod project-rescan ((this project-am-header
))
703 "Rescan the Header sources for object THIS."
704 (oset this
:source
(makefile-macro-file-list (project-am-macro this
))))
706 (defmethod project-rescan ((this project-am-built-src
))
707 "Rescan built sources for object THIS."
708 (oset this
:source
(makefile-macro-file-list "BUILT_SOURCES")))
710 (defmethod project-rescan ((this project-am-extra-dist
))
711 "Rescan object THIS."
712 (oset this
:source
(makefile-macro-file-list "EXTRA_DIST")))
713 ;; NOTE: The below calls 'file' then checks that it is some sort of
714 ;; text file. The file command may not be available on all platforms
715 ;; and some files may not exist yet. (ie - auto-generated)
719 ;; ;; prevent garbage to be parsed, could we use :aux ?
720 ;; (if (and (not (member f (oref this :source)))
721 ;; (string-match-p "ASCII\\|text"
722 ;; (shell-command-to-string
723 ;; (concat "file " f))))
724 ;; (oset this :source (cons f (oref this :source)))))
725 ;; (makefile-macro-file-list "EXTRA_DIST")))
727 (defmethod project-am-macro ((this project-am-objectcode
))
728 "Return the default macro to 'edit' for this object type."
729 (concat (subst-char-in-string ?- ?_
(oref this
:name
)) "_SOURCES"))
731 (defmethod project-am-macro ((this project-am-header-noinst
))
732 "Return the default macro to 'edit' for this object."
735 (defmethod project-am-macro ((this project-am-header-inst
))
736 "Return the default macro to 'edit' for this object."
739 (defmethod project-am-macro ((this project-am-header-pkg
))
740 "Return the default macro to 'edit' for this object."
741 "pkginclude_HEADERS")
743 (defmethod project-am-macro ((this project-am-header-chk
))
744 "Return the default macro to 'edit' for this object."
747 (defmethod project-am-macro ((this project-am-texinfo
))
748 "Return the default macro to 'edit' for this object type."
749 (concat (file-name-sans-extension (oref this
:name
)) "_TEXINFOS"))
751 (defmethod project-am-macro ((this project-am-man
))
752 "Return the default macro to 'edit' for this object type."
755 (defmethod project-am-macro ((this project-am-lisp
))
756 "Return the default macro to 'edit' for this object."
759 (defun project-am-buffer-object (amf buffer
)
760 "Return an object starting with AMF associated with BUFFER.
761 nil means that this buffer belongs to no-one."
764 (if (ede-buffer-mine amf buffer
)
766 (let ((targ (oref amf targets
))
767 (sobj (oref amf subproj
))
769 (while (and targ
(not obj
))
770 (if (ede-buffer-mine (car targ
) buffer
)
771 (setq obj
(car targ
)))
772 (setq targ
(cdr targ
)))
773 (while (and sobj
(not obj
))
774 (setq obj
(project-am-buffer-object (car sobj
) buffer
)
778 (defmethod ede-buffer-mine ((this project-am-makefile
) buffer
)
779 "Return t if object THIS lays claim to the file in BUFFER."
780 (let ((efn (expand-file-name (buffer-file-name buffer
))))
781 (or (string= (oref this
:file
) efn
)
782 (string-match "/configure\\.ac$" efn
)
783 (string-match "/configure\\.in$" efn
)
784 (string-match "/configure$" efn
)
785 ;; Search output files.
787 (dolist (f (oref this configureoutputfiles
))
788 (when (string-match (concat (regexp-quote f
) "$") efn
)
793 (defmethod ede-buffer-mine ((this project-am-objectcode
) buffer
)
794 "Return t if object THIS lays claim to the file in BUFFER."
795 (member (file-name-nondirectory (buffer-file-name buffer
))
796 (oref this
:source
)))
798 (defmethod ede-buffer-mine ((this project-am-texinfo
) buffer
)
799 "Return t if object THIS lays claim to the file in BUFFER."
800 (let ((bfn (buffer-file-name buffer
)))
801 (or (string= (oref this
:name
) (file-name-nondirectory bfn
))
802 (member (file-name-nondirectory bfn
) (oref this
:include
)))))
804 (defmethod ede-buffer-mine ((this project-am-man
) buffer
)
805 "Return t if object THIS lays claim to the file in BUFFER."
806 (string= (oref this
:name
) (buffer-file-name buffer
)))
808 (defmethod ede-buffer-mine ((this project-am-lisp
) buffer
)
809 "Return t if object THIS lays claim to the file in BUFFER."
810 (member (file-name-nondirectory (buffer-file-name buffer
))
811 (oref this
:source
)))
813 (defmethod project-am-subtree ((ampf project-am-makefile
) subdir
)
814 "Return the sub project in AMPF specified by SUBDIR."
815 (object-assoc (expand-file-name subdir
) 'file
(oref ampf subproj
)))
817 (defmethod project-compile-target-command ((this project-am-target
))
818 "Default target to use when compiling a given target."
819 ;; This is a pretty good default for most.
822 (defmethod project-compile-target-command ((this project-am-objectcode
))
823 "Default target to use when compiling an object code target."
826 (defmethod project-compile-target-command ((this project-am-texinfo
))
827 "Default target t- use when compling a texinfo file."
828 (let ((n (oref this
:name
)))
829 (if (string-match "\\.texi?\\(nfo\\)?" n
)
830 (setq n
(replace-match ".info" t t n
)))
834 ;;; Generic useful functions
836 (defun project-am-last-dir (file)
837 "Return the last part of a directory name.
838 Argument FILE is the file to extract the end directory name from."
839 (let* ((s (file-name-directory file
))
840 (d (directory-file-name s
))
842 (file-name-nondirectory d
))
845 (defun project-am-preferred-target-type (file)
846 "For FILE, return the preferred type for that file."
847 (cond ((string-match "\\.texi?\\(nfo\\)$" file
)
849 ((string-match "\\.[0-9]$" file
)
851 ((string-match "\\.el$" file
)
854 project-am-program
)))
856 (defmethod ede-buffer-header-file((this project-am-objectcode
) buffer
)
857 "There are no default header files."
858 (or (call-next-method)
859 (let ((s (oref this source
))
861 (while (and s
(not found
))
862 ;; Add more logic here if applicable.
863 (if (string-match "\\.\\(h\\|H\\|hh\\|hpp\\)" (car s
))
864 (setq found
(car s
)))
868 (defmethod ede-documentation ((this project-am-texinfo
))
869 "Return a list of files that provides documentation.
870 Documentation is not for object THIS, but is provided by THIS for other
871 files in the project."
872 (let* ((src (append (oref this source
)
873 (oref this include
)))
874 (proj (ede-target-parent this
))
875 (dir (oref proj directory
))
877 ;; Loop over all entries and expand
880 (expand-file-name (car src
) dir
)
882 (setq src
(cdr src
)))
887 ;;; Configure.in queries.
889 (defvar project-am-autoconf-file-options
890 '("configure.in" "configure.ac")
891 "List of possible configure files to look in for project info.")
893 (defun project-am-autoconf-file (dir)
894 "Return the name of the autoconf file to use in DIR."
896 (dolist (L project-am-autoconf-file-options
)
897 (when (file-exists-p (expand-file-name L dir
))
898 (setq ans
(expand-file-name L dir
))))
901 (defmacro project-am-with-config-current
(file &rest forms
)
902 "Set the Configure FILE in the top most directory above DIR as current.
903 Run FORMS in the configure file.
904 Kill the Configure buffer if it was not already in a buffer."
906 (let ((fb (generate-new-buffer ,file
)))
909 (insert-file-contents ,file
)
913 (put 'project-am-with-config-current
'lisp-indent-function
1)
915 (add-hook 'edebug-setup-hook
917 (def-edebug-spec project-am-with-config-current
920 (defmacro project-am-extract-shell-variable
(var)
921 "Extract the value of the shell variable VAR from a shell script."
923 (goto-char (point-min))
924 (when (re-search-forward (concat "^" (regexp-quote var
) "\\s-*=\\s-*")
926 (buffer-substring-no-properties (point) (point-at-eol)))))
928 (defun project-am-extract-package-info (dir)
929 "Extract the package information for directory DIR."
930 (let ((conf-in (project-am-autoconf-file dir
))
931 (conf-sh (expand-file-name "configure" dir
))
932 (name (file-name-nondirectory
933 (directory-file-name dir
)))
939 ;; Try configure.in or configure.ac
941 (require 'ede
/autoconf-edit
)
942 (project-am-with-config-current conf-in
943 (let ((aci (autoconf-parameters-for-macro "AC_INIT"))
944 (aia (autoconf-parameters-for-macro "AM_INIT_AUTOMAKE"))
945 (acf (autoconf-parameters-for-macro "AC_CONFIG_FILES"))
946 (aco (autoconf-parameters-for-macro "AC_OUTPUT"))
949 ;; AC init has more than 1 parameter
951 (setq name
(nth 0 aci
)
954 ;; The init automake has more than 1 parameter
956 (setq name
(nth 0 aia
)
960 ;; AC_CONFIG_FILES, or AC_OUTPUT lists everything that
961 ;; should be detected as part of this PROJECT, but not in a
962 ;; particular TARGET.
963 (let ((outfiles (cond (aco (list (car aco
)))
965 (if (> (length outfiles
) 1)
966 (setq configfiles outfiles
)
967 (setq configfiles
(split-string (car outfiles
) " " t
)))
971 ;; Else, try the script
972 ((file-exists-p conf-sh
)
973 (project-am-with-config-current conf-sh
974 (setq name
(project-am-extract-shell-variable "PACKAGE_NAME")
975 ver
(project-am-extract-shell-variable "PACKAGE_VERSION")
978 ;; Don't know what else....
982 (list name ver bugrep configfiles
)
985 (defun project-am-package-info (dir)
986 "Get the package information for directory topmost project dir over DIR.
987 Calcultes the info with `project-am-extract-package-info'."
988 (let ((top (ede-toplevel)))
989 (when top
(setq dir
(oref top
:directory
)))
990 (project-am-extract-package-info dir
)))
992 (provide 'ede
/project-am
)
994 ;;; ede/project-am.el ends here