summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--automake.head.mk59
-rw-r--r--automake.tail.mk139
-rw-r--r--build-aux/Makefile.README.txt (renamed from automake.txt)44
-rw-r--r--build-aux/Makefile.each.head/.gitignore0
-rw-r--r--build-aux/Makefile.each.head/00-dist.mk20
-rw-r--r--build-aux/Makefile.each.tail/.gitignore0
-rw-r--r--build-aux/Makefile.each.tail/10-std.mk46
-rw-r--r--build-aux/Makefile.head.mk63
-rw-r--r--build-aux/Makefile.once.head/.gitignore0
-rw-r--r--build-aux/Makefile.once.head/00-dist.mk44
-rw-r--r--build-aux/Makefile.once.head/10-std.mk39
-rw-r--r--build-aux/Makefile.once.tail/.gitignore0
-rw-r--r--build-aux/Makefile.once.tail/00-dist.mk27
-rw-r--r--build-aux/Makefile.tail.mk51
14 files changed, 315 insertions, 217 deletions
diff --git a/automake.head.mk b/automake.head.mk
deleted file mode 100644
index c79da83..0000000
--- a/automake.head.mk
+++ /dev/null
@@ -1,59 +0,0 @@
-# Copyright (C) 2015-2016 Luke Shumaker
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU Affero General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU Affero General Public License for more details.
-#
-# You should have received a copy of the GNU Affero General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-_am = am_
-
-_am_noslash = $(patsubst %/.,%,$(patsubst %/,%,$1))
-# These are all $(call _am_func,parent,child)
-#_am_relto = $(if $2,$(shell realpath -sm --relative-to='$1' $2))
-_am_is_subdir = $(filter $(abspath $1)/%,$(abspath $2)/.)
-_am_relto_helper = $(if $(call _am_is_subdir,$1,$2),$(patsubst $1/%,%,$(addsuffix /.,$2)),$(addprefix ../,$(call _am_relto_helper,$(patsubst %/,%,$(dir $1)),$2)))
-_am_relto = $(call _am_noslash,$(call _am_relto_helper,$(call _am_noslash,$(abspath $1)),$(call _am_noslash,$(abspath $2))))
-# Note that _am_is_subdir says that a directory is a subdirectory of
-# itself.
-_am_path = $(call _am_relto,.,$1)
-am_path = $(foreach p,$1,$(call _am_relto,$p))
-
-## Declare the default target
-all: build
-.PHONY: all
-
-## Set topoutdir, outdir, and srcdir (assumes that topsrcdir is
-## already set, and that $(topoutdir)/config.mk has been included)
-ifeq ($(topoutdir),)
-topoutdir := $(call _am_path,$(dir $(lastword $(filter %/config.mk config.mk,$(MAKEFILE_LIST)))))
-endif
- outdir := $(call _am_path,$(dir $(lastword $(filter-out %.mk,$(MAKEFILE_LIST)))))
- srcdir := $(call _am_path,$(topsrcdir)/$(call _am_relto,$(topoutdir),$(outdir)))
-
-_am_included_makefiles := $(_am_included_makefiles) $(call _am_path,$(outdir)/Makefile)
-
-## Empty variables for use by each Makefile
-$(_am)subdirs =
-$(_am)depdirs =
-
-$(_am)src_files =
-$(_am)gen_files =
-$(_am)cfg_files =
-$(_am)out_files =
-$(_am)sys_files =
-
-$(_am)clean_files =
-$(_am)slow_files =
-
-ifeq ($(_am_NO_ONCE),)
-include $(topsrcdir)/common.once.head.mk
-endif
-include $(topsrcdir)/common.each.head.mk
diff --git a/automake.tail.mk b/automake.tail.mk
deleted file mode 100644
index a24820b..0000000
--- a/automake.tail.mk
+++ /dev/null
@@ -1,139 +0,0 @@
-# Copyright (C) 2015-2016 Luke Shumaker
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU Affero General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU Affero General Public License for more details.
-#
-# You should have received a copy of the GNU Affero General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-include $(topsrcdir)/common.each.tail.mk
-
-
-# Aggregate variables
-
-# Add some more defaults to the *_files variables
-$(_am)clean_files += $($(_am)gen_files) $($(_am)cfg_files) $($(_am)out_files)
-
-# Now namespace the *_files variables
-define _am_save_variables
-_am_src_files/$(outdir) = $(addprefix $(srcdir)/,$($(_am)src_files))
-_am_gen_files/$(outdir) = $(addprefix $(srcdir)/,$($(_am)gen_files))
-_am_cfg_files/$(outdir) = $(addprefix $(outdir)/,$($(_am)cfg_files))
-_am_out_files/$(outdir) = $(addprefix $(outdir)/,$($(_am)out_files))
-_am_sys_files/$(outdir) = $(addprefix $(DESTDIR),$($(_am)sys_files))
-_am_clean_files/$(outdir) = $(addprefix $(outdir)/,$($(_am)clean_files))
-_am_slow_files/$(outdir) = $(addprefix $(outdir)/,$($(_am)slow_files))
-_am_subdirs/$(outdir) = $($(_am)subdirs)
-endef
-$(eval $(_am_save_variables))
-
-# And add them to the $(parent)_*_files variables (if applicable)
-define _am_add_subdir
-_am_src_files/%(outdir) += $(_am_src_files/%(subdir))
-_am_gen_files/%(outdir) += $(_am_gen_files/%(subdir))
-_am_cfg_files/%(outdir) += $(_am_cfg_files/%(subdir))
-_am_out_files/%(outdir) += $(_am_out_files/%(subdir))
-_am_sys_files/%(outdir) += $(_am_sys_files/%(subdir))
-_am_clean_files/%(outdir) += $(_am_clean_files/%(subdir))
-_am_slow_files/%(outdir) += $(_am_slow_files/%(subdir))
-endef
-$(foreach subdir,$(call _am_path,$(addprefix $(outdir)/,$($(_am)subdirs))),$(eval $(subst %(outdir),$(outdir),$(subst %(subdir),$(subdir),$(value _am_add_subdir)))))
-
-_am_outdirs := $(_am_outdirs) $(outdir)
-
-
-# Do some per-directory magic
-
-_am_phony = build install uninstall mostlyclean clean distclean maintainer-clean check
-
-.PHONY: $(addprefix $(outdir)/,$(_am_phony))
-
-$(addprefix $(outdir)/,uninstall mostlyclean clean distclean maintainer-clean)::
- $(RM) -- $(sort $(_am_$(@F)/$(@D)))
- $(RMDIRS) $(sort $(dir $(_am_$(@F)/$(@D)))) 2>/dev/null || $(TRUE)
-
-# 'build' and 'install' must be defined later, because the
-# am_*_files/* variables might not be complete yet.
-
-
-# Include Makefiles from other directories
-
-define _am_nl
-
-
-endef
-
-$(foreach _am_NO_ONCE,y,\
- $(foreach makefile,$(foreach dir,$($(_am)subdirs) $($(_am)depdirs),$(call _am_path,$(outdir)/$(dir)/Makefile)),\
- $(eval include $(filter-out $(_am_included_makefiles),$(makefile)))))
-
-
-# This only gets evaluated once, after all of the other Makefiles are read
-ifeq ($(_am_NO_ONCE),)
-# Empty directory-level variables
-outdir = /bogus
-srcdir = /bogus
-
-$(_am)subdirs =
-$(_am)depdirs =
-
-$(_am)src_files =
-$(_am)gen_files =
-$(_am)cfg_files =
-$(_am)out_files =
-$(_am)sys_files =
-$(_am)clean_files =
-$(_am)slow_files =
-
-_am_clean_files/$(topoutdir) += $(topoutdir)/$(PACKAGE)-$(VERSION).tar.gz
-$(addprefix $(topoutdir)/,mostlyclean clean distclean maintainer-clean) ::
- $(RM) -r -- $(topoutdir)/$(PACKAGE)-$(VERSION)
-
-define _am_directory_rules
-# Constructive phony targets
-$(outdir)/build : $(_am_out_files/%(outdir))
-$(outdir)/install: $(_am_sys_files/%(outdir))
-# Destructive phony targets
-_am_uninstall/%(outdir) = $(_am_sys_files/%(outdir))
-_am_mostlyclean/%(outdir) = $(filter-out $(_am_slow_files/%(outdir)) $(_am_cfg_files/%(outdir)) $(_am_gen_files/%(outdir)) $(_am_src_files/%(outdir)),$(_am_clean_files/%(outdir)))
-_am_clean/%(outdir) = $(filter-out $(_am_cfg_files/%(outdir)) $(_am_gen_files/%(outdir)) $(_am_src_files/%(outdir)),$(_am_clean_files/%(outdir)))
-_am_distclean/%(outdir) = $(filter-out $(_am_gen_files/%(outdir)) $(_am_src_files/%(outdir)),$(_am_clean_files/%(outdir)))
-_am_maintainer-clean/%(outdir) = $(filter-out $(_am_src_files/%(outdir)),$(_am_clean_files/%(outdir)))
-endef
-$(foreach outdir,$(_am_outdirs),$(eval $(subst %(outdir),$(outdir),$(value _am_directory_rules))))
-
-# Add the `dist` target
-.PHONY: dist
-dist: $(topoutdir)/$(PACKAGE)-$(VERSION).tar.gz
-$(topoutdir)/$(PACKAGE)-$(VERSION).tar.gz: $(topoutdir)/$(PACKAGE)-$(VERSION)
- $(TAR) czf $@ -C $(<D) $(<F)
-_am_copyfile = $(MKDIRS) $(dir $2) && $(CP) -T $1 $2
-_am_addfile = $(call _am_copyfile,$3,$2/$(call _am_relto,$1,$3))
-$(topoutdir)/$(PACKAGE)-$(VERSION): $(_am_src_files/$(topoutdir)) $(_am_gen_files/$(topoutdir))
- $(RM) -r $@
- @PS4='' && set -x && \
- $(MKDIR) $(@D)/tmp.$(@F).$$$$ && \
- $(foreach f,$^,$(call _am_addfile,$(topsrcdir),$(@D)/tmp.$(@F).$$$$,$f) &&) \
- $(MV) $(@D)/tmp.$(@F).$$$$ $@ || $(RM) -r $(@D)/tmp.$(@F).$$$$
-
-include $(topsrcdir)/common.once.tail.mk
-
-# For some reason I can't explain, RM doesn't really get set with ?=
-CP ?= cp
-MKDIR ?= mkdir
-MKDIRS ?= mkdir -p
-MV ?= mv
-RM = rm -f
-RMDIRS ?= rmdir -p
-TAR ?= tar
-TRUE ?= true
-
-.PHONY: noop
-endif
diff --git a/automake.txt b/build-aux/Makefile.README.txt
index c9834d3..e06ba52 100644
--- a/automake.txt
+++ b/build-aux/Makefile.README.txt
@@ -41,24 +41,13 @@ 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
- # adjust the number of `../` segments as appropriate
- include $(dir $(lastword $(MAKEFILE_LIST)))/../../config.mk
- include $(topsrcdir)/automake.head.mk
+ topoutdir ?= ...
+ topsrcdir ?= ...
+ include $(topsrcdir)/build-aux/Makefile.head.mk
# your makefile
- include $(topsrcdir)/automake.tail.mk
-
-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
+ include $(topsrcdir)/build-aux/Makefile.tail.mk
And in the top-level source directory, Write your own helper makefiles
that get included:
@@ -145,10 +134,27 @@ between directories:
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`.
+I like to have the first (non-comment) line in a Makefile be:
+
+ include $(dir $(lastword $(MAKEFILE_LIST)))/../../config.mk
+
+(adjusting the number of `../` sequences as nescessary). Then, my
+(user-editable) `config.mk` is of the form:
+
+ ifeq ($(topsrcdir),)
+ topoutdir := $(patsubst %/,%,$(dir $(lastword $(MAKEFILE_LIST))))
+ topsrcdir := $(topoutdir)
+
+ # your configuration
+
+ endif
+
+If the package has a `./configure` script, then I have it modifiy
+topsrcdir as necessary, as well as modifying whatever other parts of
+the configuration. All of the configuration lives in `config.mk`;
+`./configure` doesn't modify any `Makefile`s, it just generates
+`config.mk`, and copies (or (sym?)link?) every `$(srcdir)/Makefile` to
+`$(outdir)/Makefile`.
----
Copyright (C) 2016 Luke Shumaker
diff --git a/build-aux/Makefile.each.head/.gitignore b/build-aux/Makefile.each.head/.gitignore
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/build-aux/Makefile.each.head/.gitignore
diff --git a/build-aux/Makefile.each.head/00-dist.mk b/build-aux/Makefile.each.head/00-dist.mk
new file mode 100644
index 0000000..a094305
--- /dev/null
+++ b/build-aux/Makefile.each.head/00-dist.mk
@@ -0,0 +1,20 @@
+# Copyright (C) 2015-2016 Luke Shumaker
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+ifeq ($(outdir),$(topoutdir))
+std.clean_files += $(addprefix $(dist.pkgname)-*,$(dist.exts) .tar /)
+endif
+
+$(outdir)/dist: $(addprefix $(topoutdir)/$(dist.pkgname)-$(dist.version),$(dist.exts))
diff --git a/build-aux/Makefile.each.tail/.gitignore b/build-aux/Makefile.each.tail/.gitignore
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/build-aux/Makefile.each.tail/.gitignore
diff --git a/build-aux/Makefile.each.tail/10-std.mk b/build-aux/Makefile.each.tail/10-std.mk
new file mode 100644
index 0000000..5150a71
--- /dev/null
+++ b/build-aux/Makefile.each.tail/10-std.mk
@@ -0,0 +1,46 @@
+# Copyright (C) 2015-2016 Luke Shumaker
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+# Add some more defaults to the *_files variables
+std.clean_files += $(std.gen_files) $(std.cfg_files) $(std.out_files)
+
+# Fix each variable at its current value to avoid any weirdness
+$(foreach c,src gen cfg out sys clean slow,$(eval std.$c_files := $$(std.$c_files)))
+
+# Make each of the standard variables relative to the correct directory
+std.src_files := $(patsubst ./%,%,$(addprefix $(srcdir)/,$(std.src_files)))
+std.gen_files := $(patsubst ./%,%,$(addprefix $(srcdir)/,$(std.gen_files)))
+std.cfg_files := $(patsubst ./%,%,$(addprefix $(outdir)/,$(std.cfg_files)))
+std.out_files := $(patsubst ./%,%,$(addprefix $(outdir)/,$(std.out_files)))
+std.sys_files := $(addprefix $(DESTDIR),$(std.sys_files))
+std.clean_files := $(patsubst ./%,%,$(addprefix $(outdir)/,$(std.clean_files)))
+std.slow_files := $(patsubst ./%,%,$(addprefix $(outdir)/,$(std.slow_files)))
+
+# Creative targets
+$(outdir)/build : $(std.out_files)
+$(outdir)/install : $(std.sys_files)
+$(outdir)/installdirs: $(sort $(dir $(std.sys_files)))
+
+# Destructive targets
+_std.uninstall/$(outdir) := $(std.sys_files)
+_std.mostlyclean/$(outdir) := $(filter-out $(std.slow_files) $(std.cfg_files) $(std.gen_files) $(std.src_files),$(std.clean_files))
+_std.clean/$(outdir) := $(filter-out $(std.cfg_files) $(std.gen_files) $(std.src_files),$(std.clean_files))
+_std.distclean/$(outdir) := $(filter-out $(std.gen_files) $(std.src_files),$(std.clean_files))
+_std.maintainer-clean/$(outdir) := $(filter-out $(std.src_files),$(std.clean_files))
+$(addprefix $(outdir)/,uninstall mostlyclean clean distclean maintainer-clean): %: %-hook
+ $(RM) -- $(sort $(filter-out %/,$(_std.$(@F)/$(@D))))
+ $(RM) -r -- $(sort $(filter %/,$(_std.$(@F)/$(@D))))
+ $(RMDIR_P) $(sort $(dir $(_std.$(@F)/$(@D)))) 2>/dev/null || $(TRUE)
+$(foreach t,uninstall mostlyclean clean distclean maintainer-clean, $(outdir)/$t-hook)::
+.PHONY: $(foreach t,uninstall mostlyclean clean distclean maintainer-clean, $(outdir)/$t-hook)
diff --git a/build-aux/Makefile.head.mk b/build-aux/Makefile.head.mk
new file mode 100644
index 0000000..63a3462
--- /dev/null
+++ b/build-aux/Makefile.head.mk
@@ -0,0 +1,63 @@
+# Copyright (C) 2015-2016 Luke Shumaker
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# This bit only gets evaluated once, at the very beginning
+ifeq ($(_at.NO_ONCE),)
+
+ifeq ($(topsrcdir),)
+$(error topsrcdir must be set before including Makefile.head.mk)
+endif
+ifeq ($(topoutdir),)
+$(error topoutdir must be set before including Makefile.head.mk)
+endif
+
+_at.noslash = $(patsubst %/.,%,$(patsubst %/,%,$1))
+# These are all $(call _at.func,parent,child)
+#at.relto = $(if $2,$(shell realpath -sm --relative-to='$1' $2))
+_at.is_subdir = $(filter $(abspath $1)/%,$(abspath $2)/.)
+_at.relto_helper = $(if $(call _at.is_subdir,$1,$2),$(patsubst $1/%,%,$(addsuffix /.,$2)),$(addprefix ../,$(call _at.relto_helper,$(patsubst %/,%,$(dir $1)),$2)))
+_at.relto = $(call _at.noslash,$(call _at.relto_helper,$(call _at.noslash,$(abspath $1)),$(call _at.noslash,$(abspath $2))))
+at.relto = $(foreach p,$2,$(call _at.relto,$1,$p))
+# Note that _at.is_subdir says that a directory is a subdirectory of
+# itself.
+at.path = $(call at.relto,.,$1)
+
+define at.nl
+
+
+endef
+
+_at.rest = $(wordlist 2,$(words $1),$1)
+_at.reverse = $(if $1,$(call _at.reverse,$(_at.rest))) $(firstword $1)
+
+at.dirlocal += at.subdirs
+at.dirlocal += at.depdirs
+
+include $(sort $(wildcard $(topsrcdir)/build-aux/Makefile.once.head/*.mk))
+
+endif # _at.NO_ONCE
+
+# This bit gets evaluated for each Makefile
+
+## Set outdir and srcdir (assumes that topoutdir and topsrcdir are
+## already set)
+outdir := $(call at.path,$(dir $(lastword $(filter-out %.mk,$(MAKEFILE_LIST)))))
+srcdir := $(call at.path,$(topsrcdir)/$(call _at.relto,$(topoutdir),$(outdir)))
+
+_at.included_makefiles := $(_at.included_makefiles) $(call at.path,$(outdir)/Makefile)
+
+$(foreach v,$(at.dirlocal),$(eval $v=))
+
+include $(sort $(wildcard $(topsrcdir)/build-aux/Makefile.each.head/*.mk))
diff --git a/build-aux/Makefile.once.head/.gitignore b/build-aux/Makefile.once.head/.gitignore
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/build-aux/Makefile.once.head/.gitignore
diff --git a/build-aux/Makefile.once.head/00-dist.mk b/build-aux/Makefile.once.head/00-dist.mk
new file mode 100644
index 0000000..d5bfcd3
--- /dev/null
+++ b/build-aux/Makefile.once.head/00-dist.mk
@@ -0,0 +1,44 @@
+# Copyright (C) 2015-2016 Luke Shumaker
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# Developer configuration
+
+dist.exts ?= .tar.gz
+dist.pkgname ?= $(PACKAGE)
+dist.version ?= $(VERSION)
+
+ifeq ($(dist.pkgname),)
+$(error dist.pkgname must be set)
+endif
+ifeq ($(dist.version),)
+$(error dist.version must be set)
+endif
+
+# User configuration
+
+CP ?= cp
+GZIP ?= gzip
+MKDIR ?= mkdir
+MKDIR_P ?= mkdir -p
+MV ?= mv
+RM ?= rm -f
+TAR ?= tar
+
+GZIPFLAGS ?= $(GZIP_ENV)
+GZIP_ENV ?= --best
+
+# Implementation
+
+at.phony += dist
diff --git a/build-aux/Makefile.once.head/10-std.mk b/build-aux/Makefile.once.head/10-std.mk
new file mode 100644
index 0000000..3e058ec
--- /dev/null
+++ b/build-aux/Makefile.once.head/10-std.mk
@@ -0,0 +1,39 @@
+# Copyright (C) 2015-2016 Luke Shumaker
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# Declare the default target
+all: build
+.PHONY: all noop
+
+# Standard creative PHONY targets
+at.phony += build install installdirs
+# Standard destructive PHONY targets
+at.phony += uninstall mostlyclean clean distclean maintainer-clean
+
+at.dirlocal += std.src_files
+at.dirlocal += std.gen_files
+at.dirlocal += std.cfg_files
+at.dirlocal += std.out_files
+at.dirlocal += std.sys_files
+at.dirlocal += std.clean_files
+at.dirlocal += std.slow_files
+
+# User configuration
+
+DESTDIR ?=
+
+RM ?= rm -f
+RMDIR_P ?= rmdir -p
+TRUE ?= true
diff --git a/build-aux/Makefile.once.tail/.gitignore b/build-aux/Makefile.once.tail/.gitignore
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/build-aux/Makefile.once.tail/.gitignore
diff --git a/build-aux/Makefile.once.tail/00-dist.mk b/build-aux/Makefile.once.tail/00-dist.mk
new file mode 100644
index 0000000..b8b7733
--- /dev/null
+++ b/build-aux/Makefile.once.tail/00-dist.mk
@@ -0,0 +1,27 @@
+# Copyright (C) 2015-2016 Luke Shumaker
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+_dist.copyfile = $(MKDIR_P) $(dir $2) && $(CP) -T $1 $2
+_dist.addfile = $(call _dist.copyfile,$3,$2/$(call at.relto,$1,$3))
+$(topoutdir)/$(dist.pkgname)-$(dist.version): $(foreach v,$(filter std.src_files/% std.gen_files/%,$(.VARIABLES)),$($v))
+ $(RM) -r $@ $(@D)/tmp.$(@F)
+ $(MKDIR) $(@D)/tmp.$(@F)
+ $(foreach f,$^,$(call _dist.addfile,$(topsrcdir),$(@D)/tmp.$(@F),$f)$(at.nl))
+ $(MV) $(@D)/tmp.$(@F) $@ || $(RM) -r $(@D)/tmp.$(@F)
+
+$(topoutdir)/$(dist.pkgname)-$(dist.version).tar: $(topoutdir)/$(dist.pkgname)-$(dist.version)
+ $(TAR) cf $@ -C $(<D) $(<F)
+$(topoutdir)/$(dist.pkgname)-$(dist.version).tar.gz: $(topoutdir)/$(dist.pkgname)-$(dist.version).tar
+ $(GZIP) $(GZIPFLAGS) < $< > $@
diff --git a/build-aux/Makefile.tail.mk b/build-aux/Makefile.tail.mk
new file mode 100644
index 0000000..dfbad5a
--- /dev/null
+++ b/build-aux/Makefile.tail.mk
@@ -0,0 +1,51 @@
+# Copyright (C) 2015-2016 Luke Shumaker
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# This bit gets evaluated for each Makefile processed
+
+include $(call _at.reverse,$(sort $(wildcard $(topsrcdir)/build-aux/Makefile.each.tail/*.mk)))
+
+at.subdirs := $(patsubst ./%,%,$(addprefix $(outdir)/,$(at.subdirs)))
+at.depdirs := $(patsubst ./%,%,$(addprefix $(outdir)/,$(at.depdirs)))
+
+# Move all of the dirlocal variables to their namespaced version
+$(foreach v,$(at.dirlocal),$(eval $v/$(outdir) := $$($v)))
+$(foreach v,$(at.dirlocal),$(eval undefine $v))
+
+# Remember that this is a directory that we've visited
+_at.outdirs := $(_at.outdirs) $(outdir)
+
+# Generic phony target declarations:
+# mark them phony
+.PHONY: $(addprefix $(outdir)/,$(at.phony))
+# have them depend on subdirs
+$(foreach t,$(at.phony),$(eval $(outdir)/$t: $(addsuffix /$t,$(at.subdirs/$(outdir)))))
+
+# Include Makefiles from other directories
+$(foreach _at.NO_ONCE,y,\
+ $(foreach makefile,$(call at.path,$(addsuffix /Makefile,$(at.subdirs/$(outdir)) $(at.depdirs/$(outdir)))),\
+ $(eval include $(filter-out $(_at.included_makefiles),$(makefile)))))
+
+# This bit only gets evaluated once, after all of the other Makefiles are read
+ifeq ($(_at.NO_ONCE),)
+
+outdir = /bogus
+srcdir = /bogus
+
+$(foreach v,$(at.dirlocal),$(eval $v=))
+
+include $(call _at.reverse,$(sort $(wildcard $(topsrcdir)/build-aux/Makefile.once.tail/*.mk)))
+
+endif # _at.NO_ONCE