...

Text file src/github.com/datawire/ambassador/v2/build-aux/help.mk

Documentation: github.com/datawire/ambassador/v2/build-aux

     1# Copyright 2018 Datawire. All rights reserved.
     2#
     3# Makefile snippet to auto-generate a `make help` rule.
     4#
     5## Eager inputs ##
     6#  (none)
     7## Lazy inputs ##
     8#  - Variable: help.body ?= …
     9## Outputs ##
    10#  - .PHONY Target: help
    11## common.mk targets ##
    12#  (none)
    13#
    14## Basic Example ##
    15#
    16#     # Copyright 2018 Datawire. All rights reserved.
    17#
    18#     .DEFAULT_GOAL = help
    19#     include build-aux/help.mk
    20#
    21#     my-rule: ## A description of my-rule
    22#     my-rule: dep1 dep2
    23#             recipe
    24#     .PHONY: my-rule
    25#
    26#     my-other-rule: ## (Category) A description of my-other-rule
    27#     my-other-rule: dep1 dep2
    28#             recipe
    29#     .PHONY: my-other-rule
    30#
    31# The double "##" is important.  It is also important that there be no
    32# dependencies between the ":" and the "##"; any ammount of whitespace
    33# is acceptable, though.  The "##" may optionally be followed by a
    34# category in parenthesis.
    35#
    36## Advanced example ##
    37#
    38#     # Copyright 2018 Datawire. All rights reserved.
    39#
    40#     .DEFAULT_GOAL = help
    41#     include build-aux/help.mk
    42#
    43#     define help.body
    44#     This is a short little paragraph that goes between the "Usage:"
    45#     header and the "TARGETS:" footer that can give more information.
    46#     It can contain any kind of 'quotes' or shell
    47#     "meta"-`characters`.  Make $(variables) do get expanded, though.
    48#     endef
    49#
    50#     my-rule: ## A description of my-rule
    51#     my-rule: dep1 dep2
    52#             recipe
    53#     .PHONY: my-rule
    54#
    55# Because your editor's syntax-highlighting might be unhappy with
    56# things inside of help.body, you may prefix lines with "#" or "# ".
    57ifeq ($(words $(filter $(abspath $(lastword $(MAKEFILE_LIST))),$(abspath $(MAKEFILE_LIST)))),1)
    58include $(dir $(lastword $(MAKEFILE_LIST)))prelude.mk
    59
    60# Usage: $(call _help.genbody.line,VAR)
    61_help.genbody.line = $(if $(filter-out undefined,$(origin $1)),  $1 = $($1))
    62
    63# Usage: $(call _help.genbody,CUR,VARSLEFT)
    64_help.genbody = $(if $2,$(call _help.genbody,$1$(if $(and $1,$(call _help.genbody.line,$(firstword $2))),$(NL))$(call _help.genbody.line,$(firstword $2)),$(wordlist 2,$(words $2),$2)),$1)
    65
    66help.body.vars = NAME VERSION KUBECONFIG
    67help.body ?= $(call _help.genbody,,$(help.body.vars))
    68
    69# If a target doesn't specify a category name, then we use $(NAME) as
    70# the category name.  We used to use "-", but the en_US.UTF-8 locale
    71# ignores non-letter characters.  So showing "-" in the category
    72# column for non-categorized targets meant that `sort` would be
    73# looking at the second column for those rows, which would,
    74# potentially split the non-categorized targets:
    75#
    76#    TARGETS:
    77#      -            check-e2e        Check: oauth e2e tests
    78#      -            check-intercept  Check: apictl traffic intercept
    79#      (Common)     build            Build the software
    80#      (Common)     check            Check whether the software works; run the tests
    81#      (Common)     clean            Delete all files that are normally created by building the software
    82#      (Common)     clobber          Delete all files that this Makefile can re-generate
    83#      (Common)     format           Apply automatic formatting+cleanup to source code
    84#      (Common)     help             Show this message
    85#      (Common)     lint             Perform static analysis of the software
    86#      (Go)         go-fmt           Fixup the code with `go fmt`
    87#      (Go)         go-get           Download Go dependencies
    88#      (Go)         go-lint          Check the code with `golangci-lint`
    89#      (Go)         go-test          Check the code with `go test`
    90#      -            release-bin      Upload binaries to S3
    91#      -            release          Cut a release; upload binaries to S3 and Docker images to $$RELEASE_REGISTRY
    92#      -            release-docker   Upload Docker images to $$RELEASE_REGISTRY
    93#
    94# Using $(NAME) (falling back to "this project", since `help.mk`
    95# doesn't assume you set NAME) as the default category name solves
    96# this, and makes it clear what no-category means (since all
    97# build-aux.git targets now declare a category).
    98
    99help:  ## (Common) Show this message
   100	@echo 'Usage: make [TARGETS...]'
   101	@echo
   102	@printf '%s\n' $(call quote.shell,$(help.body)) | sed -e 's/^# //' -e 's/^#//'
   103	@echo
   104	@echo TARGETS:
   105	@sed -En 's/^([^#]*) *: *[#]# *(\([^)]*\))? */\2	\1	/p' $(sort $(abspath $(MAKEFILE_LIST))) | sed 's/^	/($(or $(NAME),this project))&/' | column -t -s '	' | sed 's/^/  /' | sort
   106.PHONY: help
   107
   108endif

View as plain text