automake: The dist Hook

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