-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generate AC_INIT version number by script
Generate the version number used in Autotools builds via script instead of manual editing. This script mimics what the avrdude top-level CMakeLists.txt does for composing AVRDUDE_FULL_VERSION. However, unlike the cmake based builds, this does not print the commit hash in the "avrdude --help" message (yet).
- Loading branch information
Showing
5 changed files
with
151 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Helps update the version number automatically if using GNU make. | ||
include Makefile | ||
|
||
AUTORECONF ?= autoreconf | ||
AUTORECONF_OPTS ?= -vis | ||
|
||
script_version := $(shell $(top_srcdir)/build-helpers/package-version $(top_srcdir) version-stamp) | ||
ifneq ($(PACKAGE_VERSION),$(script_version)) | ||
$(info autoconf and script versions do not match: $(PACKAGE_VERSION) vs $(script_version)) | ||
$(info Removing autom4te.cache and related files and re-running autoreconf) | ||
dummy1 := $(shell rm -rf $(top_srcdir)/autom4te.cache) | ||
dummy2 := $(shell $(AUTORECONF) $(AUTORECONF_OPTS) $(top_srcdir)) | ||
endif | ||
|
||
# vim: syntax=make |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
#!/bin/sh | ||
# Syntax: | ||
# $0 <path-to-top_srcdir> <version-stamp-file> | ||
# | ||
# <path-to-top_srcdir> may be relative | ||
# <version-stamp-file> is relative to the dist top_srcdir | ||
# | ||
# Test this script by running | ||
# rm -rf autom4te.cache/ && autoreconf -vis . && sed -n "/^# Generated by GNU/p" configure | ||
# | ||
# If we run into an error, we cannot abort the "autoreconf" run by | ||
# exiting with a non-0 error code. (We do exit non-0 in that case | ||
# anyway for help when testing this script.) | ||
# The only thing we can do to report an error is to write to stderr | ||
# and to write a version number to stdout which indicates an error. | ||
|
||
# Parse the command line arguments | ||
prog="$(basename "$0")" | ||
top_srcdir="${1-.}" | ||
test -d "$top_srcdir" || { \ | ||
echo "$prog: Error: Could not change to top_srcdir '$1'" >&2; \ | ||
echo "version_error_1" | ${TR-tr} -d '\012' | ||
exit 2; \ | ||
} | ||
version_stamp="${2-version-stamp}" | ||
|
||
# echo "$prog: Error: Some error happend." >&2 | ||
# echo "version_error_2" | ${TR-tr} -d '\012' | ||
# exit 2 | ||
|
||
# Is this a dist source tree? | ||
# If so, use the version number from the version_stamp file. | ||
if test -f "$top_srcdir/$version_stamp"; then | ||
cat "$top_srcdir/$version_stamp" | ${TR-tr} -d '\012' | ||
exit | ||
fi | ||
|
||
# Is this part of a git checkout or an expanded github snapshot tarball? | ||
test -f "$top_srcdir/../CMakeLists.txt" || { \ | ||
echo "$prog: Error: top-level avrdude CMakeLists.txt file not found" >&2; \ | ||
echo "version_error_3" | ${TR-tr} -d '\012' | ||
exit 2; \ | ||
} | ||
|
||
if PROJECT_VERSION="$(${SED-sed} -n 's/project(avrdude\s\{1,\}VERSION\s\{1,\}\([0-9\.]\{1,\}\)\s\{1,\}.*/\1/p' "$top_srcdir/../CMakeLists.txt")"; then | ||
: | ||
else | ||
echo "$prog: Error: Could not parse top-level avrdude 'CMakeLists.txt'." >&2 | ||
echo "version_error_4" | ${TR-tr} -d '\012' | ||
exit 2 | ||
fi | ||
|
||
# If GIT_DIR is set, use it. If not, try "$top_srcdir/../.git". | ||
test -n "$GIT_DIR" || { \ | ||
GIT_DIR="$top_srcdir/../.git"; \ | ||
export GIT_DIR; \ | ||
} | ||
|
||
# Working with a git source tree | ||
if test -d "$GIT_DIR"; then | ||
GIT_COMMIT_HASH="$(${GIT-git} log -1 --format=%h)" || { \ | ||
echo "$prog: Error: Cannot run 'git log' for commit hash" >&2; \ | ||
echo "version_error_5" | ${TR-tr} -d '\012'; \ | ||
exit 2; \ | ||
} | ||
GIT_COMMIT_DATE="$(${GIT-git} log -1 --format=%ad --date=format:%Y%m%d)" || { \ | ||
echo "$prog: Error: Cannot run 'git log' for commit date" >&2; \ | ||
echo "version_error_6" | ${TR-tr} -d '\012'; \ | ||
exit 2; \ | ||
} | ||
GIT_TAG_HASH="$(${GIT-git} log -1 --tags --format=%h)" || { \ | ||
echo "$prog: Error: Cannot run 'git log' for tag hash" >&2; \ | ||
echo "version_error_7" | ${TR-tr} -d '\012'; \ | ||
exit 2; \ | ||
} | ||
if test "x$GIT_COMMIT_HASH" = "x$GIT_TAG_HASH"; then | ||
echo "${PROJECT_VERSION}" | ${TR-tr} -d '\012' | ||
exit | ||
else | ||
echo "${PROJECT_VERSION}-${GIT_COMMIT_DATE}" | ${TR-tr} -d '\012' | ||
exit | ||
fi | ||
else | ||
# Building a github release or snapshot tarball | ||
echo "${PROJECT_VERSION}-nogit" | ${TR-tr} -d '\012' | ||
exit | ||
fi | ||
|
||
# If everything else has failed, call this version "devel" | ||
echo "devel" | ${TR-tr} -d '\012' | ||
exit 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
BUILD_SCRIPT_DIR = build-helpers | ||
|
||
# Check that package version matches git version before creating dist tarballs | ||
dist-hook: git-version-check git-version-stamp | ||
distcheck-hook: git-version-check | ||
|
||
# Note: We cannot run autoreconf from here, because we would need some way to | ||
# restart the whole dist process from the start and there is none. | ||
EXTRA_DIST += $(top_srcdir)/$(BUILD_SCRIPT_DIR)/package-version | ||
git-version-check: | ||
@cur_ver=`$(top_srcdir)/$(BUILD_SCRIPT_DIR)/package-version $(top_srcdir) version-stamp`; \ | ||
if test "x$${cur_ver}" = "x$(PACKAGE_VERSION)"; then :; else \ | ||
echo "ERROR: Recorded PACKAGE_VERSION and current version do not match:"; \ | ||
echo " current version: $${cur_ver}"; \ | ||
echo " recorded PACKAGE_VERSION: $(PACKAGE_VERSION)"; \ | ||
rm -rf "$(top_srcdir)/autom4te.cache"; \ | ||
echo "Update PACKAGE_VERSION by running autoreconf(1)."; \ | ||
exit 1; \ | ||
fi | ||
|
||
# Version stamp files can only exist in tarball source trees. | ||
# | ||
# So there is no need to generate them anywhere else or to clean them | ||
# up anywhere. | ||
git-version-stamp: | ||
echo "$(PACKAGE_VERSION)" > "$(distdir)/version-stamp" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters