Main - News - Download
VERSIONIZE
by Francesco Borghese

Introduction

Versionize is a simple tool that automatically updates the build number and/or the date and time of compilation of a project.

Usually you'll have a file where you define the version number, the build number, and the date and time of compilation. When you program in C/C++ language, this is usually a header file containing a number of macros defined with the "#define" preprocessor command.

These macro definitions can be recognized by Versionize which can update them as directed by the user.

If Versionize is controlled by the compilation tools, you can have the desired macros automatically updated when the project is being built.

Usually you would want to launch Versionize at the start of the build process to update time and date of compilation and launch it again at the end of the process, so that the build number is updated if the compilation was successful.

Distribution

Versionize is open source so you can use and distribute the code and the executables in any form you like. If you like, I will be happy to include modifications on the code back on the original source so others may benefit from them. Versionize should compile correctly with any C compiler on any platform. Executables for AmigaOS (68k) and Windows are also included in the package. They were tested on AmigaOS 3.x and WindowsXP but should work just everywhere.

Usage

Usage: versionize [opt1...]

Option Description
-b keep backup copy of old header file (default: simply overwrite)
-c specify the command, as defined by the programming language, used to define macros (default: #define)
-d datemacro specify macro used for compilation date (default: BUILD_DATE)
-f filename specify version header file (default: version.h)
-h help on this command; no operation is executed
-l localefile read month and week day names from localefile
-m M M=a update all, M=n build number, M=t date & time (default: M=a)
-n buildmacro specify macro used for build number (default: BUILD_NUMBER)
-t timemacro specify macro used for compilation time (default: BUILD_TIME)
-v specify verbose behaviour (default: no verbose)
-D template format of date string (default: %x)
-T template format of time string (default: %X)

Basic operations

If you don't specify any option when launching Versionize, Versionize tries to open the file version.h in the current path; if Versionize manages to open it, it looks for macros defined with the C preprocessor command #define. In particular it looks for the macros BUILD_NUMBER, BUILD_TIME and BUILD_DATE.

If Versionize can find the BUILD_NUMBER macro, the following characters in that line are interpreted as a number and replaced by that number incremented by one. If Versionize detect that the macro was defined between double quotes, it replicates them so that the string format is preserved. For example if the file version.h contains the line:

#define BUILD_NUMBER 1

this line is replaced with:

#define BUILD_NUMBER 2

If the file version.h contains the line:

#define BUILD_NUMBER "103"

this line is replaced with:

#define BUILD_NUMBER "104"

If Versionize can find the BUILD_TIME macro, the following characters in that line are deleted and replaced by the current time in local format. The local format of time is statically decided at Versionize compilation time (usually it is in hh:mm:ss format). If Versionize detects that the macro was defined between double quotes, it replicates them so that the string format is preserved. For example if the file version.h contains the line:

#define BUILD_TIME 10:23:12

this line is replaced with:

#define BUILD_TIME 10:25:37

if Versionize was launched at around 10:25. If the file version.h contains the line:

#define BUILD_TIME "10:23:12"

this line is replaced with:

#define BUILD_TIME "10:25:37"

If Versionize can find the BUILD_DATE macro, the following characters in that line are deleted and replaced by the current date in local format. The local format of date is statically decided at Versionize compilation time (usually it is in mm/dd/yy format). If Versionize detect that the macro was defined between double quotes, it replicates them so that the string format is preserved. For example if the file version.h contains the line:

#define BUILD_DATE 07/03/04

this line is replaced with:

#define BUILD_DATE 07/05/04

if Versionize was launched on the 5th of July in 2004. If the file version.h contains the line:

#define BUILD_DATE "07/03/04"

this line is replaced with:

#define BUILD_DATE "07/05/04"

Customizing Versionize behaviour

You can specify a number of options to change the default behaviour of Versionize.

You can make Versionize to update macros in a file other than version.h. Just specify the file name (and path, if needed) with the -f option. We suggest to include the macros in a short file to avoid Versionize wasting significative time while processing the file.

You can change the name of the macros that Versionize is trying to update. Just specify any or all of the build number, time and date macros with the -n, -t and -d options.

You can force Versionize to update the build number only or the time and date of compilation only instead of both. Use the "-m n" option to update the build number only and the "-m t" option to update time and date only.

You can change the format in which time and date are displayed. Just specify the desired template strings with the -T and -D options. These strings can contain any number of tokens (see the table below) to customize the output format. The only limit is the size of the template that can be of 256 characters maximum.

You can provide a file that specifies localized names for months, week day and AM/PM equivalent. Use the "-l localefile" option to specify the file name (and path, if needed). See "Localization of Versionize" paragrah if you need details on locale file format.

For example, if we have the file version_defines.h with the following (partial) code:

#define VERSION_BUILDNUMBER "13"
#define VERSION_BUILDDATE "any"
#define VERSION_BUILDTIME "any"

If, on the 7th of July in 2004 at 11:13:27, we execute Versionize with the following command:

versionize -f version_defines.h -m t -d VERSION_BUILDDATE -t VERSION_BUILDTIME -D "Built on %a. %-d %B %Y" -T "%I:%M %p"

the file version_defines.h is modified as following:

#define VERSION_BUILDNUMBER "13"
#define VERSION_BUILDDATE "Built on Wed. 7 July 2004"
#define VERSION_BUILDTIME "11:13 AM"

If soon after we execute Versionize with the following command:

versionize -f version_defines.h -m n -n VERSION_BUILDNUMBER

the file version_defines.h is modified as following:

#define VERSION_BUILDNUMBER "14"
#define VERSION_BUILDDATE "Built on Wed. 7 July 2004"
#define VERSION_BUILDTIME "11:13 AM"

If, on the 7th of July in 2004 at 11:13:27, we execute Versionize on the original version_defines.h with the following command:

versionize -f version_defines.h -m t -d VERSION_BUILDDATE -t VERSION_BUILDTIME -D "Compilato %A %-d %B %Y" -T "%H:%M" -l italian

where italian is the example locale file provided with Versionize, the file version_defines.h is modified as following:

#define VERSION_BUILDNUMBER "13"
#define VERSION_BUILDDATE "Compilato mercoledì 7 luglio 2004"
#define VERSION_BUILDTIME "11:13"

Templates

You can use the following tokens in date and time templates:

Token Meaning
%a short week day name
%A complete week day name
%b short month name
%B complete month name
%c local date and time
%d month day
%H hour (00-23)
%I hour (01-12)
%j year day (001-366)
%m month (01-12)
%M minutes (00-59)
%p local AM/PM equivalent
%S seconds (00-61)
%U week number starting on Sunday (00-53)
%w week day (00-06)
%W week number starting on Monday (00-53)
%x local date
%X local time
%y year number (00-99)
%Y year number (yyyy)
%Z time zone name
%% %
%_ space

Use the %-t format for any token t to prevent zero padding. For example, put %-d in the date template to output the month day from 1 to 31 without zero padding. This behaviour applies for %d, %H, %I, %j, %m, %M, %S, %w, %y and %Y tokens only; using the %-t format on other tokens produces the same result that the %t format produces.

The tokens %a, %A, %b, %B and %p will produce localized output when the "-l localefile" option is used, as specified in the file localefile.

Localization of Versionize

You can provide a file that specifies localized names for months, week day and AM/PM equivalent with the "-l localefile" option. In this file, the following line must be used to define the localized name of nth month (with n between 1 and 12):

COMPLETEMONTH<any spaces>n<any spaces>"localized month name"

The following line must be used to define the localized short name of nth month (with n between 1 and 12):

SHORTMONTH<any spaces>n<any spaces>"localized month short name"

The following line must be used to define the localized name of nth week day (with n between 1 and 7):

COMPLETEWEEKDAY<any spaces>n<any spaces>"localized week day name"

The following line must be used to define the localized short name of nth week day (with n between 1 and 7):

SHORTWEEKDAY<any spaces>n<any spaces>"localized week day short name"

The following line must be used to define the localized name of AM equivalent:

AMEQUIVALENT<any spaces>"localized AM equivalent"

The following line must be used to define the localized name of PM equivalent:

PMEQUIVALENT<any spaces>"localized PM equivalent"

These lines of text can be in any order and interposed with text and comments. Provide ALL the localized strings that you are going to use, because, otherwise, empty strings will replace the tokens. The file italian is provided as example:

COMPLETEMONTH1 "gennaio"
COMPLETEMONTH2 "febbraio"
COMPLETEMONTH3 "marzo"
COMPLETEMONTH4 "aprile"
COMPLETEMONTH5 "maggio"
COMPLETEMONTH6 "giugno"
COMPLETEMONTH7 "luglio"
COMPLETEMONTH8 "agosto"
COMPLETEMONTH9 "settembre"
COMPLETEMONTH10 "ottobre"
COMPLETEMONTH11 "novembre"
COMPLETEMONTH12 "dicembre"
SHORTMONTH1 "gen"
SHORTMONTH2 "feb"
SHORTMONTH3 "mar"
SHORTMONTH4 "apr"
SHORTMONTH5 "mag"
SHORTMONTH6 "giu"
SHORTMONTH7 "lug"
SHORTMONTH8 "ago"
SHORTMONTH9 "set"
SHORTMONTH10 "ott"
SHORTMONTH11 "nov"
SHORTMONTH12 "dic"
COMPLETEWEEKDAY1 "domenica"
COMPLETEWEEKDAY2 "lunedì"
COMPLETEWEEKDAY3 "martedì"
COMPLETEWEEKDAY4 "mercoledì"
COMPLETEWEEKDAY5 "giovedì"
COMPLETEWEEKDAY6 "venerdì"
COMPLETEWEEKDAY7 "sabato"
SHORTWEEKDAY1 "dom"
SHORTWEEKDAY2 "lun"
SHORTWEEKDAY3 "mar"
SHORTWEEKDAY4 "mer"
SHORTWEEKDAY5 "gio"
SHORTWEEKDAY6 "ven"
SHORTWEEKDAY7 "sab"
AMEQUIVALENT "AM"
PMEQUIVALENT "PM"
Main - News - Download