diff options
Diffstat (limited to 'automake.txt')
-rw-r--r-- | automake.txt | 93 |
1 files changed, 73 insertions, 20 deletions
diff --git a/automake.txt b/automake.txt index 22a0b84..c9834d3 100644 --- a/automake.txt +++ b/automake.txt @@ -10,6 +10,34 @@ differently. Yeah, I need a new name for it. High-level overview ------------------- +Now, what this does for you is: + +It makes it _easy_ to write non-recursive Makefiles--and ones that are +similar to plain recursive Makefiles, at that! (search for the paper +"Recursive Make Considered Harmful") As harmful as recursive make is, +it's historically been difficult to to write non-recursive Makefiles. +This makes it easy. + +It also makes it easy to follow the GNU standards for your makefiles: +it takes care of this entire table of .PHONY targets for you: + +| this | and this | are aliases for this | +|------+------------------+--------------------------------------------------------| +| all | build | $(outdir)/build | +| | install | $(outdir)/install | +| | uninstall | $(outdir)/uninstall | +| | mostlyclean | $(outdir)/mostlyclean | +| | clean | $(outdir)/clean | +| | distclean | $(outdir)/distclean | +| | maintainer-clean | $(outdir)/maintainer-clean | +| | check | $(outdir)/check (not implemented for you) | +| | dist | $(topoutdir)/$(PACKAGE)-$(VERSION).tar.gz (not .PHONY) | + +(You are still responsible for implementing the `$(outdir)/check` +target in each of your Makefiles.) + +What you have to do is: + In each source directory, you write a `Makefile`, very similarly to if you were writing for plain GNU Make, with @@ -21,30 +49,42 @@ you were writing for plain GNU Make, with include $(topsrcdir)/automake.tail.mk -Write your own `common.{each,once}.{head,tail}.mk` files that get -included: +And in the top-level output directory, you write a `config.mk` with: + + ifeq ($(topsrcdir),) + # have your ./configure script adjust topsrcdir if doing an + # out-of-tree build + topsrcdir := $(patsubst %/,%,$(dir $(lastword $(MAKEFILE_LIST)))) + + # your configuration + + endif + +And in the top-level source directory, Write your own helper makefiles +that get included: - `common.once.head.mk`: before parsing any of your Makefiles - `common.each.head.mk`: before parsing each of your Makefiles - `common.each.tail.mk`: after parsing each of your Makefiles - `common.each.tail.mk`: after parsing all of your Makefiles -Here is a table of all of the .PHONY targets that automake takes care -of for you: - -| this | and this | are aliases for this | -|------+------------------+--------------------------------------------------------| -| all | build | $(outdir)/build | -| | install | $(outdir)/install | -| | uninstall | $(outdir)/uninstall | -| | mostlyclean | $(outdir)/mostlyclean | -| | clean | $(outdir)/clean | -| | distclean | $(outdir)/distclean | -| | maintainer-clean | $(outdir)/maintainer-clean | -| | check | $(outdir)/check (not implemented for you) | -| | dist | $(topoutdir)/$(PACKAGE)-$(VERSION).tar.gz (not .PHONY) | - -You are responsible for implementing the `$(outdir)/check` target in -each of your Makefiles. +The `common.*.mk` makefiles are nice for including generic pattern +rules and variables that aren't specific to a directory. + +You're probably thinking that this sounds too good to be true! +Unfortunately, there are two major deviations from writing a plain +recursive Makefile: + + 1. all targets and prerequisites (including .PHONY targets!) need to + be prefixed with + `$(srcdir)`/`$(outdir)`/`$(topsrcdir)`/`$(topoutdir)`. + * sub-gotcha: this means that if a pattern rule has a + prerequisite that may be in srcdir or outdir, then it must be + specified twice, once for each case. + 2. if a prerequisite is in a directory "owned" by another Makefile, + you must filter the pathname through `am_path`: + `$(call am_path,YOUR_PATH)`. Further, that path must NOT contain + a `..` segment; if you need to refer to a sibling directory, do it + relative to `$(topoutdir)` or `$(topsrcdir)`. Telling automake about your program ----------------------------------- @@ -53,6 +93,11 @@ You tell automake what to do for you by setting some variables. They are all prefixed with `am_`; this prefix may be changed by editing the `_am` variable at the top of `automake.head.mk`. +The exception to this is the `am_path` variable, which is a macro that +is used to make a list of filenames relative to the appropriate +directory, because unlike normal GNU (Auto)Make, `$(outdir)` isn't +nescessarily equal to `.`. See above. + There are several commands that generate files; simply record the list of files that each command generates as the following variable variables: @@ -97,9 +142,17 @@ between directories: | | files in this directory, things in the dependency | | | directory will not be built. | +Tips, notes +----------- + +If you have a `./configure` script, don't have it modify the +`Makefile`s; have everything you need modified be in +`$(topoutdir)/config.mk` and have it generate that; then have it copy +(or (sym?)link?) every `$(srcdir)/Makefile` into `$(outdir)/Makefile`. + ---- Copyright (C) 2016 Luke Shumaker This documentation file is placed into the public domain. If that is not possible in your legal system, I grant you permission to use it in -absolutely every way that I can legally do so. +absolutely every way that I can legally grant to you. |