diff --git a/.gitignore b/.gitignore index 0cd0943..2d1b934 100644 --- a/.gitignore +++ b/.gitignore @@ -22,6 +22,7 @@ olddoc/Makefile olddoc/Makefile.in .deps/ src/lha +src/version.h src/Makefile src/Makefile.in stamp-h1 diff --git a/Makefile.am b/Makefile.am index e4ea6ef..4d45d8f 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,5 +1,12 @@ ## Process this file with automake to produce Makefile.in AUTOMAKE_OPTIONS = foreign -EXTRA_DIST = README.md README.jp.md header.doc.md header.doc.jp Hacking_of_LHa +EXTRA_DIST = README.md README.jp.md header.doc.md header.doc.jp Hacking_of_LHa autogen.sh build-aux/gen-build-version.sh SUBDIRS= man olddoc src tests + +## Re-run autoconf to regenerate configure and update PACKAGE_VERSION via .tarball-version +dist-hook: + cd $(top_srcdir) && \ + build-aux/gen-build-version.sh --package --check-clean -o .tarball-version && \ + $(AUTOCONF) --force + mv $(top_srcdir)/.tarball-version $(distdir) diff --git a/autogen.sh b/autogen.sh new file mode 100755 index 0000000..99fd77a --- /dev/null +++ b/autogen.sh @@ -0,0 +1,17 @@ +#!/bin/sh + +# Exit on error +set -e + +# Check for dependencies +if ! command -v git &>/dev/null; then + echo "git is required but not found. Exiting." + exit 1 +fi + +# Run autoreconf to generate configure script +autoreconf --force --install --symlink + +# Run configure +mkdir build 2>/dev/null || true +cd build && ../configure "$@" diff --git a/build-aux/gen-build-version.sh b/build-aux/gen-build-version.sh new file mode 100755 index 0000000..970443f --- /dev/null +++ b/build-aux/gen-build-version.sh @@ -0,0 +1,80 @@ +#!/bin/sh +# Print version string derived from Git or .tarball-version +# If called with --package, output a simplified package version string (written to file if -o is used) + +set -e + +top_srcdir=$(dirname $0)/.. + +VERSION_PREFIX="1.14i-ac" +OUTPUT_FOR_PACKAGE=false +OUTPUT_FILE= + +while [ $# -gt 0 ]; do + case "$1" in + --package) + OUTPUT_FOR_PACKAGE=true + shift + ;; + --check-clean) + CHECK_CLEAN=true + shift + ;; + -o) + OUTPUT_FILE="$2" + shift 2 + ;; + *) + echo "Usage: $0 [--package] [-o ]" >&2 + exit 1 + ;; + esac +done + +# Ensure we are inside a clean Git work tree for --package +check_git_clean_for_package() { + if test x"$DIRTY" != x; then + echo "Error: working tree is dirty; commit or stash changes before running with packaging" >&2 + exit 1 + fi + + if test "$IS_INSIDE_WORK_TREE" != true; then + echo "Error: not inside a Git repository" >&2 + exit 1 + fi +} + +output_version() { + if test x"$OUTPUT_FILE" = x && test -f $top_srcdir/.tarball-version; then + version=$(cat $top_srcdir/.tarball-version) + elif test "$OUTPUT_FOR_PACKAGE" = true; then + version="${VERSION_PREFIX}${DATE}" + else + version="${VERSION_PREFIX}${DATE}-${HASH}${DIRTY}" + fi + + if test x"$OUTPUT_FILE" != x; then + echo $version > $OUTPUT_FILE + else + echo $version + fi +} + +# Use Git info to generate full version +if git rev-parse --is-inside-work-tree >/dev/null 2>&1; then + IS_INSIDE_WORK_TREE=true + set -- $(git log -1 --date=format:"%Y%m%d" --pretty=format:"%cd %h") + DATE=$1 HASH=$2 + + DIRTY="" + if ! git diff --quiet || ! git diff --cached --quiet; then + DIRTY="-dirty" + echo "Warning: repository is dirty (has uncommitted changes)" >&2 + fi +fi + +if test "$CHECK_CLEAN" = true; then + check_git_clean_for_package +fi + +output_version diff --git a/configure.ac b/configure.ac index 834fa3e..2faa9c7 100644 --- a/configure.ac +++ b/configure.ac @@ -1,5 +1,6 @@ # Process this file with autoconf to produce a configure script. -AC_INIT([LHa for UNIX], 1.14i-ac20220213, jca02266@gmail.com, lha) +m4_define([VERSION_STRING], m4_esyscmd_s([build-aux/gen-build-version.sh --package])) +AC_INIT([LHa for UNIX], VERSION_STRING, [jca02266@gmail.com], [lha]) AC_DEFINE_UNQUOTED(LHA_CONFIGURE_OPTIONS, "$ac_configure_args", [specified options for the configure script.]) AC_CANONICAL_HOST diff --git a/src/Makefile.am b/src/Makefile.am index 22cb686..38d6b7d 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -5,7 +5,18 @@ lha_SOURCES = append.c bitio.c crcio.c dhuf.c extract.c header.c huf.c \ lhext.c lhlist.c maketbl.c maketree.c patmatch.c shuf.c slide.c \ util.c getopt_long.c getopt_long.h \ pm2.c pm2hist.c pm2tree.c \ - support_utf8.c + support_utf8.c version.h.in lha_LDADD = @LIBOBJS@ EXTRA_DIST = lhdir.h fnmatch.h AM_CPPFLAGS=$(DEF_KCODE) $(SUPPORT_LZHUFF_METHOD) + +BUILT_SOURCES = version.h +CLEANFILES = version.h + +version.h: FORCE + @echo "Generating version.h..." + @BUILD_VERSION=`sh $(top_srcdir)/build-aux/gen-build-version.sh`; \ + sed "s|@BUILD_VERSION@|$$BUILD_VERSION|" $(srcdir)/version.h.in > $@.tmp + @if cmp -s $@.tmp $@; then rm -f $@.tmp; else mv $@.tmp $@; fi + +FORCE: diff --git a/src/lharc.c b/src/lharc.c index d2ec135..74116e2 100644 --- a/src/lharc.c +++ b/src/lharc.c @@ -726,14 +726,16 @@ main(argc, argv) /* ------------------------------------------------------------------------ */ +#include "version.h" + static void print_version() { /* macro PACKAGE_NAME, PACKAGE_VERSION and PLATFORM are defined in config.h by configure script */ fprintf(stdout, "%s version %s (%s)\n", - PACKAGE_NAME, PACKAGE_VERSION, PLATFORM); - + PACKAGE_NAME, BUILD_VERSION, PLATFORM); + if (strlen(LHA_CONFIGURE_OPTIONS) != 0) fprintf(stdout, " configure options: %s\n", LHA_CONFIGURE_OPTIONS); } diff --git a/src/version.h.in b/src/version.h.in new file mode 100644 index 0000000..ef34241 --- /dev/null +++ b/src/version.h.in @@ -0,0 +1 @@ +#define BUILD_VERSION "@BUILD_VERSION@"