Occasionally it is useful to be able to change the distribution before
it is packaged up. If the dist-hook
rule exists, it is run
after the distribution directory is filled, but before the actual
distribution archives are created. One way to use this is for
removing unnecessary files that get recursively included by specifying
a directory in EXTRA_DIST
:
EXTRA_DIST = doc dist-hook: chmod -R u+w $(distdir)/doc rm -rf `find $(distdir)/doc -type d -name RCS`
The dist-hook
recipe should not assume that the regular files
in the distribution directory are writable; this might not be the case
if one is packaging from a read-only source tree, or when a make
distcheck
is being done. Similarly, the recipe should not assume
that the subdirectories put into the distribution directory as a
result of being listed in EXTRA_DIST
are writable. So, if the
dist-hook
recipe wants to modify the content of an existing
file (or EXTRA_DIST
subdirectory) in the distribution
directory, it should explicitly to make it writable first:
EXTRA_DIST = README doc dist-hook: chmod u+w $(distdir)/README $(distdir)/doc echo "Distribution date: `date`" >> $(distdir)/README rm -f $(distdir)/doc/HACKING
Two variables that come handy when writing dist-hook
rules are
‘$(distdir)’ and ‘$(top_distdir)’.
‘$(distdir)’ points to the directory where the dist
rule
will copy files from the current directory before creating the
tarball. If you are at the top-level directory, then ‘distdir =
$(PACKAGE)-$(VERSION)’. When used from subdirectory named
foo/, then ‘distdir = ../$(PACKAGE)-$(VERSION)/foo’.
‘$(distdir)’ can be either a relative or absolute path; do not
assume a particular form.
‘$(top_distdir)’ always points to the root directory of the distributed tree. At the top level it’s equal to ‘$(distdir)’. In the foo/ subdirectory ‘top_distdir = ../$(PACKAGE)-$(VERSION)’. ‘$(top_distdir)’ can also be either a relative or absolute path.
When packages are nested using AC_CONFIG_SUBDIRS
(see Nesting Packages), then ‘$(distdir)’ and
‘$(top_distdir)’ are relative to the package where ‘make
dist’ was run, not to any sub-packages involved.