Function: makefile-mode

makefile-mode is an autoloaded, interactive and byte-compiled function defined in make-mode.el.gz.

Signature

(makefile-mode)

Documentation

Major mode for editing standard Makefiles.

If you are editing a file for a different make, try one of the variants makefile-automake-mode, makefile-gmake-mode, makefile-makepp-mode, makefile-bsdmake-mode or, makefile-imake-mode. All but the last should be correctly chosen based on the file name, except if it is *.mk. This function ends by invoking the function(s) makefile-mode-hook.

It is strongly recommended to use font-lock-mode(var)/font-lock-mode(fun), because that provides additional parsing information. This is used for example to see that a rule action echo foo: bar is a not rule dependency, despite the colon.

C-M-i completion-at-point
C-c : makefile-insert-target-ref
C-c C-\ makefile-backslash-region
C-c C-b makefile-switch-to-browser
C-c C-c comment-region
C-c C-f makefile-pickup-filenames-as-targets
C-c C-p makefile-pickup-everything
C-c C-u makefile-create-up-to-date-overview
C-c RET C-a makefile-automake-mode
C-c RET C-b makefile-bsdmake-mode
C-c RET C-g makefile-gmake-mode
C-c RET C-p makefile-makepp-mode
C-c RET RET makefile-mode
C-c RET TAB makefile-imake-mode
C-c TAB makefile-insert-gmake-function
M-n makefile-next-dependency
M-p makefile-previous-dependency
M-q fill-paragraph

Makefile mode can be configured by modifying the following variables:

makefile-target-colon:
    The string that gets appended to all target names
    inserted by makefile-insert-target.
    ":" or "::" are quite common values.

makefile-macro-assign:
   The string that gets appended to all macro names
   inserted by makefile-insert-macro.
   The normal value should be " = ", since this is what
   standard make expects. However, newer makes such as dmake
   allow a larger variety of different macro assignments, so you
   might prefer to use " += " or " := " .

makefile-tab-after-target-colon:
   If you want a TAB (instead of a space) to be appended after the
   target colon, then set this to a non-nil value.

makefile-pickup-everything-picks-up-filenames-p:
   If this variable is set to a non-nil value then
   makefile-pickup-everything also picks up filenames as targets
   (i.e. it calls makefile-pickup-filenames-as-targets), otherwise
   filenames are omitted.

makefile-cleanup-continuations(var)/makefile-cleanup-continuations(fun):
   If this variable is set to a non-nil value then Makefile mode
   will assure that no line in the file ends with a backslash
   (the continuation character) followed by any whitespace.
   This is done by silently removing the trailing whitespace, leaving
   the backslash itself intact.
   IMPORTANT: Please note that enabling this option causes Makefile mode
   to MODIFY A FILE WITHOUT YOUR CONFIRMATION when "it seems necessary".

makefile-special-targets-list:
   List of special targets. You will be offered to complete
   on one of those in the minibuffer whenever you enter a ..
   at the beginning of a line in Makefile mode.

Probably introduced at or before Emacs version 19.29.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/make-mode.el.gz
;;; ------------------------------------------------------------
;;; The mode function itself.
;;; ------------------------------------------------------------

;;;###autoload
(define-derived-mode makefile-mode prog-mode "Makefile"
  "Major mode for editing standard Makefiles.

If you are editing a file for a different make, try one of the
variants `makefile-automake-mode', `makefile-gmake-mode',
`makefile-makepp-mode', `makefile-bsdmake-mode' or,
`makefile-imake-mode'.  All but the last should be correctly
chosen based on the file name, except if it is *.mk.  This
function ends by invoking the function(s) `makefile-mode-hook'.

It is strongly recommended to use `font-lock-mode', because that
provides additional parsing information.  This is used for
example to see that a rule action `echo foo: bar' is a not rule
dependency, despite the colon.

\\{makefile-mode-map}

Makefile mode can be configured by modifying the following variables:

`makefile-target-colon':
    The string that gets appended to all target names
    inserted by `makefile-insert-target'.
    \":\" or \"::\" are quite common values.

`makefile-macro-assign':
   The string that gets appended to all macro names
   inserted by `makefile-insert-macro'.
   The normal value should be \" = \", since this is what
   standard make expects.  However, newer makes such as dmake
   allow a larger variety of different macro assignments, so you
   might prefer to use \" += \" or \" := \" .

`makefile-tab-after-target-colon':
   If you want a TAB (instead of a space) to be appended after the
   target colon, then set this to a non-nil value.

`makefile-pickup-everything-picks-up-filenames-p':
   If this variable is set to a non-nil value then
   `makefile-pickup-everything' also picks up filenames as targets
   (i.e. it calls `makefile-pickup-filenames-as-targets'), otherwise
   filenames are omitted.

`makefile-cleanup-continuations':
   If this variable is set to a non-nil value then Makefile mode
   will assure that no line in the file ends with a backslash
   (the continuation character) followed by any whitespace.
   This is done by silently removing the trailing whitespace, leaving
   the backslash itself intact.
   IMPORTANT: Please note that enabling this option causes Makefile mode
   to MODIFY A FILE WITHOUT YOUR CONFIRMATION when \"it seems necessary\".

`makefile-special-targets-list':
   List of special targets.  You will be offered to complete
   on one of those in the minibuffer whenever you enter a `.'.
   at the beginning of a line in Makefile mode."
  (add-hook 'completion-at-point-functions
            #'makefile-completions-at-point nil t)
  (add-hook 'write-file-functions
	    'makefile-warn-suspicious-lines nil t)
  (add-hook 'write-file-functions
	    'makefile-warn-continuations nil t)
  (add-hook 'write-file-functions
	    'makefile-cleanup-continuations nil t)
  (make-local-variable 'makefile-target-table)
  (make-local-variable 'makefile-macro-table)
  (make-local-variable 'makefile-has-prereqs)
  (make-local-variable 'makefile-need-target-pickup)
  (make-local-variable 'makefile-need-macro-pickup)

  ;; Font lock.
  (setq-local font-lock-defaults
	      ;; Set SYNTAX-BEGIN to backward-paragraph to avoid
	      ;; slow-down near the end of a large buffer, due to
	      ;; `parse-partial-sexp' trying to parse all the way till
	      ;; the beginning of buffer.
	      '(makefile-font-lock-keywords
		nil nil
		((?$ . "."))
		backward-paragraph))
  (setq-local syntax-propertize-function
	      makefile-syntax-propertize-function)

  ;; Add-log.
  (setq-local add-log-current-defun-function
	      'makefile-add-log-defun)

  ;; Imenu.
  (setq-local imenu-generic-expression
	      makefile-imenu-generic-expression)

  ;; Dabbrev.
  (setq-local dabbrev-abbrev-skip-leading-regexp "\\$")

  ;; Other abbrevs.
  (setq local-abbrev-table makefile-mode-abbrev-table)

  ;; Filling.
  (setq-local fill-paragraph-function 'makefile-fill-paragraph)

  ;; Comment stuff.
  (setq-local comment-start "#")
  (setq-local comment-end "")
  (setq-local comment-start-skip "#+[ \t]*")

  ;; Make sure TAB really inserts \t.
  (setq-local indent-line-function 'indent-to-left-margin)

  ;; Real TABs are important in makefiles
  (setq indent-tabs-mode t))