Skip to content

Example of an easy way to specify help in a GNU make Makefile

Notifications You must be signed in to change notification settings

jeffsp/makefile_help

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 

Repository files navigation

Makefile help and .PHONY targets

This Makefile illustrates two techniques:

  1. .PHONY targets are specified directly above the target itself, rather than in a single list at the top of the Makefile.

    When you specify the .PHONY targets in a list at the top of the Makefile, the .PHONY list is very likely to become outdated as you add more targets and forget to add them to the list. By always specifying the .PHONY keyword above phony targets, your .PHONY list always stays up to date.

    .PHONY: target1
    target1:
        @echo "Target 1"
  1. Help text for each .PHONY target is embedded in a comment directly after the .PHONY specification.

    Help is automatically generated by the help target. If the target doesn't require help, simply leave out the comment.

    .PHONY: target1 # Target 1 help text
    ...
    .PHONY: target2 # Target 2 help text
    ...
    .PHONY: target3
    ...
    help: # Generate list of targets with descriptions
        @grep '^.PHONY: .* #' Makefile | sed 's/\.PHONY: \(.*\) # \(.*\)/\1 \2/' | expand -t20

Example Invocation

Here is the output from the 'help' target. Note that target3 help is not listed because it has no help text.

$ make help
target1             Target 1 help text
target2             Target 2 help text
help                Generate list of targets with descriptions

About

Example of an easy way to specify help in a GNU make Makefile

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published