Basil L. Contovounesios wrote: > >> dist-hook: > >> echo '$(VERSION)' > $(distdir)/.tarball-version > >> > >> whereas the other writes the target directly. > > > > Here it does so because the file is inside a temporary directory. If > > the "make dist" rule fails, the user has to remove the temporary directory > > entirely anyway, and that will also take care of the empty file. > > Does this imply that writing to a temporary file first is never needed > under distdir?
No. It's never needed under $(distdir) *if* the Makefile rule fails when the command fails. > I'm thinking of the examples in (info "(gnulib) gitlog-to-changelog") > for instance, which generate $(distdir)/ChangeLog in two steps. Is it possible to simplify gen-ChangeLog: $(AM_V_GEN)if test -e $(srcdir)/.git; then \ LC_ALL=en_US.UTF-8 TZ=UTC0 \ $(top_srcdir)/build-aux/gitlog-to-changelog \ --srcdir=$(srcdir) > $(distdir)/ChangeLog.tmp && \ mv -f $(distdir)/ChangeLog.tmp $(distdir)/ChangeLog; \ fi to gen-ChangeLog: $(AM_V_GEN)if test -e $(srcdir)/.git; then \ LC_ALL=en_US.UTF-8 TZ=UTC0 \ $(top_srcdir)/build-aux/gitlog-to-changelog \ --srcdir=$(srcdir) > $(distdir)/ChangeLog; \ fi ? If the disk is full, the former rule will package an empty ChangeLog, whereas the latter rule will package a truncated ChangeLog. Neither is good. What is desired, is that "make dist" fails in this situation. That is: gen-ChangeLog: $(AM_V_GEN)if test -e $(srcdir)/.git; then \ LC_ALL=en_US.UTF-8 TZ=UTC0 \ $(top_srcdir)/build-aux/gitlog-to-changelog \ --srcdir=$(srcdir) > $(distdir)/ChangeLog \ || exit 1; \ fi And then, once we make sure that "make dist" fails, it does not matter whether we use an intermediate file or not — because, as I wrote earlier, the user will have to 'rm -rf' the distdir manually anyway. 2025-01-10 Bruno Haible <br...@clisp.org> gitlog-to-changelog: Recommend more reliable Makefile rule idiom. Reported by Basil L. Contovounesios <ba...@contovou.net>. * doc/gitlog-to-changelog.texi: Make the gen-ChangeLog rule fail if the ChangeLog file cannot be created or if the disk is full. Drop the use of an intermediate file, not needed under $(distdir). diff --git a/doc/gitlog-to-changelog.texi b/doc/gitlog-to-changelog.texi index c58d59d8d2..9b65da9b28 100644 --- a/doc/gitlog-to-changelog.texi +++ b/doc/gitlog-to-changelog.texi @@ -32,8 +32,8 @@ $(AM_V_GEN)if test -e $(srcdir)/.git; then \ LC_ALL=en_US.UTF-8 TZ=UTC0 \ $(top_srcdir)/build-aux/gitlog-to-changelog \ - --srcdir=$(srcdir) > $(distdir)/ChangeLog.tmp && \ - mv -f $(distdir)/ChangeLog.tmp $(distdir)/ChangeLog; \ + --srcdir=$(srcdir) > $(distdir)/ChangeLog \ + || exit 1; \ fi @end example @@ -55,8 +55,8 @@ $(AM_V_GEN)if test -e $(srcdir)/.git; then \ $(top_srcdir)/build-aux/gitlog-to-changelog \ --srcdir=$(srcdir) --commit-timezone \ - > $(distdir)/ChangeLog.tmp && \ - mv -f $(distdir)/ChangeLog.tmp $(distdir)/ChangeLog; \ + > $(distdir)/ChangeLog \ + || exit 1; \ fi @end example @@ -100,7 +100,7 @@ --srcdir=$(srcdir) \ "$$amend_git_log" -- 'v$(gen_start_ver)~..' && \ printf '\n\nSee the source repo for older entries.\n'; \ - @} > $(distdir)/ChangeLog.tmp && \ - mv -f $(distdir)/ChangeLog.tmp $(distdir)/ChangeLog; \ + @} > $(distdir)/ChangeLog \ + || exit 1; \ fi @end example