]> git.ipfire.org Git - thirdparty/xz.git/commitdiff
FIXME *** Build: Add support for git_commit_info.sh
authorLasse Collin <lasse.collin@tukaani.org>
Mon, 7 Apr 2025 14:38:32 +0000 (17:38 +0300)
committerLasse Collin <lasse.collin@tukaani.org>
Mon, 7 Apr 2025 14:38:32 +0000 (17:38 +0300)
Using $(RECURSIVE_TARGETS) might apply to too many targets. At the same
time, it isn't enough: Each library/program or file that depends on
git_commit_version.h should ensure that the file is up to date without
trying to update it in parallel (and then corrupting it).
Now if one configures the tree and runs "make -C src", the header
isn't generated and the build fails.

Makefile.am
configure.ac

index fc54f477e1f83c40c2dd5c4d1b59fbc94d8c840f..2d3320c372ae89c65e9d91f998580f3702c4c396 100644 (file)
@@ -53,6 +53,7 @@ EXTRA_DIST = \
        PACKAGERS \
        TODO \
        autogen.sh \
+       build-aux/git_commit_info.sh \
        build-aux/license-check.sh \
        build-aux/manconv.sh \
        build-aux/version.sh \
@@ -71,6 +72,22 @@ manfiles = \
        src/scripts/xzless.1 \
        src/scripts/xzmore.1
 
+
+# When .git dir and the git tool are available, put commit information
+# into git_commit_info.h. It is used in version strings.
+CLEANFILES = git_commit_info.h
+
+git_commit_info.h:
+       $(AM_V_GEN) \
+       $(SHELL) $(srcdir)/build-aux/git_commit_info.sh "$(srcdir)" $@
+
+.PHONY: git_commit_info.h
+
+if COND_GIT_COMMIT_INFO
+$(RECURSIVE_TARGETS): git_commit_info.h
+endif
+
+
 # Create ChangeLog using "git log".
 # Convert the man pages to plain text (ASCII only) format.
 dist-hook:
index 80d6d3387f45376cfbec44783718386513fcd373..40747e32055ad93c248aa4688c00e85fd57c7e7b 100644 (file)
@@ -1362,6 +1362,29 @@ AS_IF([test "$GCC" = yes], [
 ])
 
 
+###############################################################################
+# Conditionally include Git commit version in the version string.
+###############################################################################
+
+# git_commit_info.sh checks that .git and the git tool are available.
+# The check below for .git is to keep builds from tarballs slightly cleaner.
+AC_ARG_ENABLE([git-commit-info],
+       AS_HELP_STRING([--disable-git-commit-info],
+               [Do not include Git commit information in the version string
+               when building from a Git repository.]),
+       [],
+       [AS_IF([test -d "$srcdir/.git"],
+               [enable_git_commit_info=yes],
+               [enable_git_commit_info=no])])
+
+AS_IF([test "x$enable_git_commit_info" = xyes],
+       [AC_DEFINE([HAVE_GIT_COMMIT_INFO_H], [1],
+               [Define to 1 if git_commit_info.h is generated.])])
+
+AM_CONDITIONAL([COND_GIT_COMMIT_INFO],
+       [test "x$enable_git_commit_info" = xyes])
+
+
 ###############################################################################
 # Create the makefiles and config.h
 ###############################################################################