build-aux is a collection of Makefile .mk
snippets (and associated
utilities). Each of the .mk
snippets is written to be as
independent from the others as possible, but integrate well by
following common conventions. You may pick-and-choose which to
include simply by writing include build-aux/NAME.mk
in your
Makefile
.
Each .mk
snippet starts with a reference header-comment
identifying:
- any eager-evaluated inputs (mostly variables)
- any lazy-evaluated inputs (mostly variables)
- any outputs (targets, variables)
- which targets from other snippets it hooks in to (mostly hooking
in to
common.mk
targets)
Eager inputs need to be defined before loading the snippet; lazy
inputs can be defined later. See [conventions.mk
][./conventions.md]
for more information on the reference header-comment.
For the most part, you don't need to worry about dependencies between
.mk
files; each file will automatically include
the others it
depends on. However, if you would like to use an output from one
snippet as an eager input to another, then you do need to worry about
include order; if you would like to use kubernaut-ui.mk
to set
KUBECONFIG
for teleproxy.mk
, then you will need to make sure you
include kubernaut-ui.mk
before you include teleproxy.mk
. You
don't need to worry about including a file twice; this is safe, as
they all have C-header-style include guards.
Most (but not all) of the snippets include common.mk
, which
-
Configures Make to use sane settings (since the default settings are set for historical compatibility, not the "right thing").
-
Defines several
$(call …)
-able helper functions, likejoinlist
,path.trimprefix
, orquote.shell
. Seecommon.mk
itself for the full list, and documentation on how to use them. -
Declares several utility variables:
GOOS
,GOARCH
: Operating system name, and CPU architecture.GO
is included in the variable names to indicate that they use the same names asgo env
(as opposed to usinguname -s
/uname -m
names, or something else). Most of the time, these are the host OS or architecture. But, when inside of recipes for files inbin_OS_ARCH/
directories, they are set to that OS and architecture.NL
: a single newline character, since that's hard to type in MakeSPACE
: a single space character, since that's hard to type in Make
-
Declares several high-level common targets, like
make build
,make clean
, ormake check
. Seecommon.mk
itself for the full list. By defining a list of common user-facing targets, the rest of the snippets can hook in to that and provide a uniform interface. With the exception ofmake check
(which is special, see below), yourMakefile
can extend any of these by adding dependencies to the target name. For example, to havemake build
build thefoo
file, you could write:build: foo
or to have
make lint
run theflake8
Python linter, you could writelint: flake8 flake8: flake8 mypackage/ .PHONY: flake8
or
lint: flake8 mypackage/
The former has the advantage that it allows you to add multiple hooks on to
lint
(so it's the only method that build-aux snippets use), and also allows flake8 to run in parallel with other linters set up by build-aux snippets.make check
is special in how it works. Instead of writingcheck: my-test # WRONG
you write
test-suite.tap: my-test.tap # CORRECT
See
testing.md
for information about writing the recipe formy-test.tap
.Because of the special semantics around
$(GOOS)
and$(GOARCH)
inbin_OS_ARCH/
directories,common.mk
goes ahead and hasmake clean
runrm -rf -- bin_*
. Because ofmake check
's use oftest-suite.tap
,common.mk
also goes head and hasmake clean
runrm -f test-suite.tap
.With the exceptions of
make check
andmake clean
,common.mk
only provides empty definitions; it is up to yourMakefile
, or other.mk
snippets to make these rules actually do something.
The snippet help.mk
adds a make help
target, that display
information about your project (customizable by setting the
help.body
variable from your Makefile
), and a table of all of the
make FOO
targets that Make knows about. Any targets you write in
your Makefile
that you think should be visible can be added to this
listing by writing a magic comment:
frob: ## Frobnicate the splorks
See help.mk
itself for full documentation.