Generate version number information from git history.

Due to the svn import structure, a special case is currently implemented
to look for the 1.1.0 branchpoint instead of the most recent tag on the
master branch.  This will be removed after the first release is tagged
on the master branch in git.

Specific details:

autogen.sh: More aggressively clean autoconf cache.
This is needed to ensure the version number is actually regenerated.

Don't generate PACKAGE_PATCHLEVEL or PACKAGE_BUILD variables.  The
genversion program now parses PACKAGE_VERSION directly.

For Mkfiles builds, YASM-VERSION.h is generated and included by the custom
config.h.  This avoids the need to edit config.h for versioning.
This commit is contained in:
Peter Johnson 2011-08-27 09:25:30 -07:00
parent 8281be0c25
commit 0ed2cc4451
23 changed files with 232 additions and 58 deletions

2
.gitignore vendored
View file

@ -62,6 +62,8 @@ x86regtmod.c
nasm-version.c
win64-gas.c
win64-nasm.c
YASM-VERSION-FILE
YASM-VERSION.h
.sw*
*.s
*.asm

View file

@ -10,6 +10,7 @@ SET(BUILD_SHARED_LIBS ON)
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules")
INCLUDE(YasmMacros)
INCLUDE(VersionGen)
OPTION(ENABLE_NLS "Enable message translations" OFF)
@ -26,12 +27,8 @@ IF(NOT CMAKE_BUILD_TYPE)
FORCE)
ENDIF(NOT CMAKE_BUILD_TYPE)
set (YASM_VERSION_MAJOR 1)
set (YASM_VERSION_MINOR 1)
set (YASM_VERSION_SUBMINOR 99)
set (PACKAGE_INTVER "${YASM_VERSION_MAJOR}.${YASM_VERSION_MINOR}.${YASM_VERSION_SUBMINOR}")
set (PACKAGE_BUILD "HEAD")
set (PACKAGE_VERSION ${PACKAGE_BUILD})
VERSION_GEN(PACKAGE_VERSION "${CMAKE_BINARY_DIR}/YASM-VERSION-FILE" "1.1.0")
set (PACKAGE_STRING "yasm ${PACKAGE_VERSION}")
INCLUDE_DIRECTORIES(BEFORE ${CMAKE_BINARY_DIR} ${yasm_SOURCE_DIR})

View file

@ -31,6 +31,7 @@ EXTRA_DIST = config/config.rpath
# libyasm-stdint.h doesn't clean up after itself?
CONFIG_CLEAN_FILES = libyasm-stdint.h
CONFIG_CLEAN_FILES += YASM-VERSION-FILE
EXTRA_DIST += tools/Makefile.inc
EXTRA_DIST += libyasm/Makefile.inc
@ -55,6 +56,7 @@ EXTRA_DIST += BSD.txt
EXTRA_DIST += GNU_GPL-2.0
EXTRA_DIST += GNU_LGPL-2.0
EXTRA_DIST += splint.sh
EXTRA_DIST += YASM-VERSION-GEN.sh
EXTRA_DIST += Mkfiles/Makefile.flat
EXTRA_DIST += Mkfiles/Makefile.dj
EXTRA_DIST += Mkfiles/dj/config.h
@ -122,6 +124,12 @@ EXTRA_DIST += Mkfiles/vc10/re2c/run.bat
# Until this gets fixed in automake
DISTCLEANFILES += libyasm/stamp-h libyasm/stamp-h[0-9]*
dist-hook: YASM-VERSION-FILE
cp YASM-VERSION-FILE $(distdir)/version
YASM-VERSION-FILE: $(top_srcdir)/YASM-VERSION-GEN.sh
$(top_srcdir)/YASM-VERSION-GEN.sh
distclean-local:
-rm -rf results
if HAVE_PYTHON

View file

@ -197,7 +197,7 @@ win64-gas.c: modules/objfmts/coff/win64-gas.mac genmacro
modules/objfmts/coff/coff-objfmt.c: win64-nasm.c win64-gas.c
genversion: modules/preprocs/nasm/genversion.c
genversion: modules/preprocs/nasm/genversion.c YASM-VERSION.h
$(BUILDCC) -IMkfiles -I. -o $@ $<
version.mac: genversion
@ -272,3 +272,8 @@ vsyasm: $(VSYASM_OBJS)
.c.o:
$(CC) -c $(CFLAGS) -o $@ $<
$(YASM_OBJS) $(YTASM_OBJS) $(VSYASM_OBJS): YASM-VERSION.h
YASM-VERSION.h: YASM-VERSION-GEN.sh
sh YASM-VERSION-GEN.sh

View file

@ -1,3 +1,4 @@
#include "YASM-VERSION.h"
#define yasm__splitpath(path, tail) yasm__splitpath_win(path, tail)
#define yasm__abspath(path) yasm__abspath_win(path)
#define yasm__combpath(from, to) yasm__combpath_win(from, to)
@ -116,23 +117,17 @@
/* Define to the address where bug reports for this package should be sent. */
#define PACKAGE_BUGREPORT "bug-yasm@tortall.net"
/* Define to build version of this package. */
#define PACKAGE_BUILD "HEAD"
/* Define to internal version of this package. */
#define PACKAGE_INTVER "1.1.99"
/* Define to the full name of this package. */
#define PACKAGE_NAME "yasm"
/* Define to the full name and version of this package. */
#define PACKAGE_STRING "yasm HEAD"
/*#define PACKAGE_STRING "yasm HEAD"*/
/* Define to the one symbol short name of this package. */
#define PACKAGE_TARNAME "yasm"
/* Define to the version of this package. */
#define PACKAGE_VERSION "HEAD"
/*#define PACKAGE_VERSION "HEAD"*/
/* Define if the C compiler supports function prototypes. */
#define PROTOTYPES 1

View file

@ -1,3 +1,4 @@
#include "YASM-VERSION.h"
#define yasm__splitpath(path, tail) yasm__splitpath_win(path, tail)
#define yasm__abspath(path) yasm__abspath_win(path)
#define yasm__combpath(from, to) yasm__combpath_win(from, to)
@ -114,23 +115,17 @@
/* Define to the address where bug reports for this package should be sent. */
#define PACKAGE_BUGREPORT "bug-yasm@tortall.net"
/* Define to build version of this package. */
#define PACKAGE_BUILD "HEAD"
/* Define to internal version of this package. */
#define PACKAGE_INTVER "1.1.99"
/* Define to the full name of this package. */
#define PACKAGE_NAME "yasm"
/* Define to the full name and version of this package. */
#define PACKAGE_STRING "yasm HEAD"
/*#define PACKAGE_STRING "yasm HEAD"*/
/* Define to the one symbol short name of this package. */
#define PACKAGE_TARNAME "yasm"
/* Define to the version of this package. */
#define PACKAGE_VERSION "HEAD"
/*#define PACKAGE_VERSION "HEAD"*/
/* Define if the C compiler supports function prototypes. */
#define PROTOTYPES 1

View file

@ -48,7 +48,7 @@
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>..\..\vc10;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>..\..\vc10;../../..;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MinimalRebuild>true</MinimalRebuild>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
@ -73,6 +73,9 @@
<PostBuildEvent>
<Command>run.bat "$(TargetPath)"</Command>
</PostBuildEvent>
<PreBuildEvent>
<Command>runpre.bat</Command>
</PreBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>

View file

@ -0,0 +1,2 @@
cd ..\..\..
YASM-VERSION-GEN.bat

View file

@ -7,6 +7,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libyasm", "libyasm\libyasm.vcxproj", "{29FE7874-1256-4AD6-B889-68E399DC9608}"
ProjectSection(ProjectDependencies) = postProject
{B545983B-8EE0-4A7B-A67A-E749EEAE62A2} = {B545983B-8EE0-4A7B-A67A-E749EEAE62A2}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "modules", "modules\modules.vcxproj", "{D715A3D4-EFAA-442E-AD8B-5B4FF64E1DD6}"
EndProject

View file

@ -1,3 +1,4 @@
#include "YASM-VERSION.h"
#define yasm__splitpath(path, tail) yasm__splitpath_win(path, tail)
#define yasm__abspath(path) yasm__abspath_win(path)
#define yasm__combpath(from, to) yasm__combpath_win(from, to)
@ -114,23 +115,17 @@
/* Define to the address where bug reports for this package should be sent. */
#define PACKAGE_BUGREPORT "bug-yasm@tortall.net"
/* Define to build version of this package. */
#define PACKAGE_BUILD "HEAD"
/* Define to internal version of this package. */
#define PACKAGE_INTVER "1.1.99"
/* Define to the full name of this package. */
#define PACKAGE_NAME "yasm"
/* Define to the full name and version of this package. */
#define PACKAGE_STRING "yasm HEAD"
/*#define PACKAGE_STRING "yasm HEAD"*/
/* Define to the one symbol short name of this package. */
#define PACKAGE_TARNAME "yasm"
/* Define to the version of this package. */
#define PACKAGE_VERSION "HEAD"
/*#define PACKAGE_VERSION "HEAD"*/
/* Define if the C compiler supports function prototypes. */
#define PROTOTYPES 1

View file

@ -26,6 +26,7 @@
>
<Tool
Name="VCPreBuildEventTool"
CommandLine="runpre.bat"
/>
<Tool
Name="VCCustomBuildTool"
@ -106,6 +107,7 @@
>
<Tool
Name="VCPreBuildEventTool"
CommandLine="runpre.bat"
/>
<Tool
Name="VCCustomBuildTool"

View file

@ -0,0 +1,2 @@
cd ..\..\..
YASM-VERSION-GEN.bat

View file

@ -9,6 +9,7 @@ EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libyasm", "libyasm\libyasm.vcproj", "{29FE7874-1256-4AD6-B889-68E399DC9608}"
ProjectSection(ProjectDependencies) = postProject
{F0E8B707-00C5-4FF2-B8EF-7C39817132A0} = {F0E8B707-00C5-4FF2-B8EF-7C39817132A0}
{B545983B-8EE0-4A7B-A67A-E749EEAE62A2} = {B545983B-8EE0-4A7B-A67A-E749EEAE62A2}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "modules", "modules\modules.vcproj", "{D715A3D4-EFAA-442E-AD8B-5B4FF64E1DD6}"

38
YASM-VERSION-GEN.bat Normal file
View file

@ -0,0 +1,38 @@
@echo off
if exist version goto haveversion
set errorlevel=0
set _my_=
for /f "usebackq tokens=1*" %%f in (`reg query HKCU\Software\TortoiseGit /v MSysGit`) do (set _my_=%%f %%g)
if %errorlevel% neq 0 goto notfound
if "%_my_%" == "" goto notfound
rem Using the shell script version (calling Git) ...
set _gitbin_=%_my_:*REG_SZ=%
for /f "tokens=* delims= " %%a in ("%_gitbin_%") do set _gitbin_=%%a
set OLDPATH=%PATH%
set PATH=%_gitbin_%;%PATH%
"%_gitbin_%\sh" YASM-VERSION-GEN.sh "%_gitbin_%"
set PATH=%OLDPATH%
exit /b
:notfound
rem Could not find Git ...
set _ver_=
for /f "usebackq tokens=2 delims==" %%a in (`%SystemRoot%\system32\find "DEF_VER=" ^<YASM-VERSION-GEN.sh`) do (set _ver_=%%a)
set _ver_=%_ver_:~1%
goto output
:haveversion
set /p _ver_=<version
goto output
:output
set /p _oldver_=<YASM-VERSION-FILE
set _oldver_=%_oldver_:~,-1%
if "%_ver_%" == "%_oldver_%" exit /b
echo %_ver_%
echo %_ver_% > YASM-VERSION-FILE
echo #define PACKAGE_STRING "yasm %_ver_%" > YASM-VERSION.h
echo #define PACKAGE_VERSION "%_ver_%" >> YASM-VERSION.h

52
YASM-VERSION-GEN.sh Executable file
View file

@ -0,0 +1,52 @@
#!/bin/sh
YVF=YASM-VERSION-FILE
DEF_VER=v1.1.0
LF='
'
# First see if there is a version file (included in release tarballs),
# then try git-describe, then default.
if test -f version
then
VN=$(cat version) || VN="$DEF_VER"
elif test -d .git -o -f .git &&
VN=$(git describe --match "v[0-9]*" --abbrev=4 HEAD 2>/dev/null) &&
case "$VN" in
*$LF*) (exit 1) ;;
v0.1.0*)
# Special handling until we get a more recent tag on the
# master branch
MERGE_BASE=$(git merge-base $DEF_VER HEAD 2>/dev/null)
VN1=$(git rev-list $MERGE_BASE..HEAD | wc -l 2>/dev/null)
VN2=$(git rev-list --max-count=1 --abbrev-commit --abbrev=4 HEAD 2>/dev/null)
VN=$(echo "v$DEF_VER-$VN1-g$VN2" | sed -e 's/ //g')
git update-index -q --refresh
test -z "$(git diff-index --name-only HEAD --)" ||
VN="$VN-dirty" ;;
v[0-9]*)
git update-index -q --refresh
test -z "$(git diff-index --name-only HEAD --)" ||
VN="$VN-dirty" ;;
esac
then
VN=$(echo "$VN" | sed -e 's/-/./g');
else
VN="$DEF_VER"
fi
VN=$(expr "$VN" : v*'\(.*\)')
if test -r $YVF
then
VC=$(cat $YVF)
else
VC=unset
fi
test "$VN" = "$VC" || {
echo >&2 "$VN"
echo "$VN" >$YVF
echo "#define PACKAGE_STRING \"yasm $VN\"" > YASM-VERSION.h
echo "#define PACKAGE_VERSION \"$VN\"" >> YASM-VERSION.h
}

View file

@ -73,7 +73,8 @@ if test ! -d "config"; then
mkdir config
fi
rm -f stamp-h.in
rm -rf autom4te.cache
rm -f configure config.h config.status config.log stamp-h.in
#echo " gettextize -f --no-changelog"
#echo "N" | gettextize -f --no-changelog || exit 1
echo " aclocal $ACLOCAL_FLAGS"

View file

@ -0,0 +1,78 @@
# Redistribution and use is allowed according to the terms of the BSD license.
#
# Copyright (c) 2011 Peter Johnson
macro (VERSION_GEN _version _version_file _default_version)
set (_vn "v${_default_version}")
# First see if there is a version file (included in release tarballs),
# then try git-describe, then default.
if (EXISTS "${CMAKE_SOURCE_DIR}/version")
file (STRINGS "${CMAKE_SOURCE_DIR}/version" _version_strs LIMIT_COUNT 1)
list (GET _version_strs 0 _version_strs0)
if (NOT (${_version_strs0} STREQUAL ""))
set (_vn "v${_version_strs0}")
endif (${_version_strs0})
elseif (EXISTS "${CMAKE_SOURCE_DIR}/.git")
execute_process (COMMAND git describe --match "v[0-9]*" --abbrev=4 HEAD
RESULT_VARIABLE _git_result
OUTPUT_VARIABLE _git_vn
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
if (_git_result EQUAL 0)
# Special handling until we get a more recent tag on the master
# branch
if (_git_vn MATCHES "^v0[.]1[.]0")
execute_process (COMMAND git merge-base v${_default_version} HEAD
OUTPUT_VARIABLE _merge_base
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
#message (STATUS "Merge base: ${_merge_base}")
execute_process (COMMAND git rev-list ${_merge_base}..HEAD
OUTPUT_VARIABLE _rev_list
ERROR_QUIET)
string (REGEX MATCHALL "[^\n]*\n" _rev_list_lines "${_rev_list}")
#message (STATUS "Rev list: ${_rev_list_lines}")
list (LENGTH _rev_list_lines _vn1)
execute_process (COMMAND git rev-list --max-count=1 --abbrev-commit --abbrev=4 HEAD
OUTPUT_VARIABLE _vn2
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
set (_git_vn "v${_default_version}-${_vn1}-g${_vn2}")
endif (_git_vn MATCHES "^v0[.]1[.]0")
# Append -dirty if there are local changes
execute_process (COMMAND git update-index -q --refresh)
execute_process (COMMAND git diff-index --name-only HEAD --
OUTPUT_VARIABLE _git_vn_dirty)
if (_git_vn_dirty)
set (_git_vn "${_git_vn}-dirty")
endif (_git_vn_dirty)
# Substitute . for - in the result
string (REPLACE "-" "." _vn "${_git_vn}")
endif (_git_result EQUAL 0)
endif (EXISTS "${CMAKE_SOURCE_DIR}/version")
# Strip leading "v" from version
#message (STATUS "_vn: ${_vn}")
string (REGEX REPLACE "^v*(.+)" "\\1" _vn "${_vn}")
# Update version file if required
if (EXISTS ${_version_file})
file (STRINGS ${_version_file} _version_strs LIMIT_COUNT 1)
list (GET _version_strs 0 _vc)
else (EXISTS ${_version_file})
set (_vc "unset")
endif (EXISTS ${_version_file})
if (NOT ("${_vn}" STREQUAL "${_vc}"))
file (WRITE ${_version_file} "${_vn}")
endif (NOT ("${_vn}" STREQUAL "${_vc}"))
# Set output version variable
set (${_version} ${_vn})
endmacro (VERSION_GEN)

View file

@ -29,12 +29,6 @@
/* Define to the address where bug reports for this package should be sent. */
#define PACKAGE_BUGREPORT "bug-yasm@tortall.net"
/* Define to internal version of this package. */
#define PACKAGE_INTVER "@PACKAGE_INTVER@"
/* Define to build version of this package. */
#define PACKAGE_BUILD "@PACKAGE_BUILD@"
/* Define to the full name of this package. */
#define PACKAGE_NAME "yasm"

View file

@ -4,7 +4,9 @@
# autoconf setup
#
AC_PREREQ(2.53)
AC_INIT([yasm], [HEAD], [bug-yasm@tortall.net])
AC_INIT([yasm],
m4_esyscmd([./YASM-VERSION-GEN.sh && tr -d '\n' <YASM-VERSION-FILE]),
[bug-yasm@tortall.net])
#AC_CONFIG_SRCDIR([src/main.c])
AC_CONFIG_AUX_DIR(config)
AC_CONFIG_HEADER([config.h])
@ -12,10 +14,6 @@ AC_CONFIG_HEADER([config.h])
AM_INIT_AUTOMAKE([1.9.6 foreign])
AM_MAINTAINER_MODE
AC_DEFINE(PACKAGE_INTVER, ["1.1.99"],
[Define to internal version of this package.])
AC_DEFINE(PACKAGE_BUILD, ["HEAD"], [Define to build version of this package.])
#
# autoconf command-line options
#

View file

@ -223,7 +223,7 @@ static opt_option options[] =
/* version message */
/*@observer@*/ static const char *version_msg[] = {
PACKAGE_NAME " " PACKAGE_INTVER "." PACKAGE_BUILD,
PACKAGE_STRING,
"Compiled on " __DATE__ ".",
"Copyright (c) 2001-2010 Peter Johnson and other Yasm developers.",
"Run yasm --license for licensing overview and summary."

View file

@ -215,7 +215,7 @@ static opt_option options[] =
/* version message */
/*@observer@*/ static const char *version_msg[] = {
PACKAGE_NAME " " PACKAGE_INTVER "." PACKAGE_BUILD,
PACKAGE_STRING,
"Compiled on " __DATE__ ".",
"Copyright (c) 2001-2010 Peter Johnson and other Yasm developers.",
"Run yasm --license for licensing overview and summary."

View file

@ -212,9 +212,9 @@ static opt_option options[] =
/* version message */
/*@observer@*/ static const char *version_msg[] = {
PACKAGE_NAME " " PACKAGE_INTVER "." PACKAGE_BUILD,
PACKAGE_STRING,
"Compiled on " __DATE__ ".",
"Copyright (c) 2001-2010 Peter Johnson and other Yasm developers.",
"Copyright (c) 2001-2011 Peter Johnson and other Yasm developers.",
"Run yasm --license for licensing overview and summary."
};

View file

@ -36,14 +36,19 @@ int
main(int argc, char *argv[])
{
FILE *out;
int major, minor, subminor;
int major, minor, subminor, patchlevel, matched;
if (argc != 2) {
fprintf(stderr, "Usage: %s <outfile>\n", argv[0]);
return EXIT_FAILURE;
}
if (sscanf(PACKAGE_INTVER, "%d.%d.%d", &major, &minor, &subminor) != 3) {
matched = sscanf(PACKAGE_VERSION, "%d.%d.%d.%d", &major, &minor, &subminor,
&patchlevel);
if (matched == 3)
patchlevel = 0;
else if (matched != 4) {
fprintf(stderr, "Version tokenizing error\n");
return EXIT_FAILURE;
}
@ -61,17 +66,15 @@ main(int argc, char *argv[])
fprintf(out, "%%define __YASM_MAJOR__ %d\n", major);
fprintf(out, "%%define __YASM_MINOR__ %d\n", minor);
fprintf(out, "%%define __YASM_SUBMINOR__ %d\n", subminor);
if (!isdigit(PACKAGE_BUILD[0]))
fprintf(out, "%%define __YASM_BUILD__ 0\n");
else
fprintf(out, "%%define __YASM_BUILD__ %d\n", atoi(PACKAGE_BUILD));
fprintf(out, "%%define __YASM_BUILD__ %d\n", patchlevel);
fprintf(out, "%%define __YASM_PATCHLEVEL__ %d\n", patchlevel);
/* Version id (hex number) */
fprintf(out, "%%define __YASM_VERSION_ID__ 0%02x%02x%02x00h\n", major,
minor, subminor);
fprintf(out, "%%define __YASM_VERSION_ID__ 0%02x%02x%02x%02xh\n", major,
minor, subminor, patchlevel);
/* Version string - version sans build */
fprintf(out, "%%define __YASM_VER__ \"%s\"\n", PACKAGE_INTVER);
/* Version string */
fprintf(out, "%%define __YASM_VER__ \"%s\"\n", PACKAGE_VERSION);
fclose(out);
return EXIT_SUCCESS;