:type '(repeat regexp)
:group 'pcmpl-gnu)
+(defcustom pcmpl-gnu-makefile-includes t
+ "If non-nil, `pcomplete/make' completes on targets in included files."
+ :type 'boolean
+ :group 'pcmpl-gnu
+ :version 27.1
+ :safe 'booleanp)
+
;; Functions:
;;;###autoload
"Return a list of possible makefile names."
(pcomplete-entries (mapconcat 'identity pcmpl-gnu-makefile-regexps "\\|")))
+(defun pcmpl-gnu-make-targets (targets)
+ "Add to TARGETS the list of makefile targets in the current buffer.
+Return the new list."
+ (goto-char (point-min))
+ (while (re-search-forward
+ "^\\s-*\\([^\n#%.$][^:=\n]*\\)\\s-*:[^=]" nil t)
+ (setq targets (nconc (split-string (match-string-no-properties 1))
+ targets)))
+ targets)
+
+(defun pcmpl-gnu-make-includes ()
+ "Return a list of all included file names in the current buffer."
+ (let (filenames)
+ (goto-char (point-min))
+ (while (search-forward-regexp "^include +\\(.*\\)$" nil t)
+ (push (match-string-no-properties 1) filenames))
+ filenames))
+
+(defun pcmpl-gnu-make-all-targets (makefile targets)
+ "Add to TARGETS the list of target names in MAKEFILE and files it includes.
+Return the new list."
+ (with-temp-buffer
+ (with-demoted-errors ;Could be a directory or something.
+ (insert-file-contents makefile))
+
+ (let ((filenames (when pcmpl-gnu-makefile-includes (pcmpl-gnu-make-includes))))
+ (setq targets (pcmpl-gnu-make-targets targets))
+ (dolist (file filenames)
+ (when (file-readable-p file)
+ (setq targets (pcmpl-gnu-make-all-targets file targets))))
+ ))
+ targets)
+
(defun pcmpl-gnu-make-rule-names ()
- "Return a list of possible make rule names in MAKEFILE."
+ "Return a list of possible make targets in a makefile in the current directory."
(let* ((minus-f (member "-f" pcomplete-args))
(makefile (or (cadr minus-f)
(cond
rules)
(if (not (file-readable-p makefile))
(unless minus-f (list "-f"))
- (with-temp-buffer
- (ignore-errors ;Could be a directory or something.
- (insert-file-contents makefile))
- (while (re-search-forward
- (concat "^\\s-*\\([^\n#%.$][^:=\n]*\\)\\s-*:[^=]") nil t)
- (setq rules (append (split-string (match-string 1)) rules))))
+ (setq rules (pcmpl-gnu-make-all-targets makefile rules))
(pcomplete-uniquify-list rules))))
(defcustom pcmpl-gnu-tarfile-regexp