Rev 267 | Rev 289 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
#! perl######################################################################### Copyright ( C ) 2004 ERG Limited, All rights reserved## Module name : jats.sh# Module type : Makefile system# Compiler(s) : n/a# Environment(s): jats## Description : Provide varions functions used by the BuildVersion# directive.## Use only within buildlib.pl as this package assumes# a great deal about its environment.## Usage:## Version Who Date Description##......................................................................#require 5.006_001;use strict;use warnings;our $Clobber;our $CurrentYear;our $CurrentTime;our $Srcdir;our $BuildVersion;our $BUILDNAME;our $BUILDNAME_PACKAGE;our $BUILDNAME_VERSION;our $BUILDNAME_PROJECT;package BuildVersion;use JatsError;use JatsSystem;use JatsVersionUtils;use ConfigurationFile;our (@ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS, $VERSION);use Exporter;$VERSION = 1.00;@ISA = qw(Exporter);# Symbols to autoexport (:DEFAULT tag)@EXPORT = qw( BuildVersionCBuildVersionCdefsBuildVersionCSharpBuildVersionWinRCBuildVersionProperties);#-------------------------------------------------------------------------------# Function : BuildVersionCSharp## Description : Generate a C# versionn information file to allow# insertion of data into an assembly## Inputs : $FileName - Output filename (Optional)## Returns :#sub BuildVersionCSharp{my ( $fname ) = @_;$fname = 'AssemblyVersionInfo.cs' unless $fname;## Store the files location for use at runtime# It will be a file that is 'known' to JATS#$fname = ::BuildAddKnownFile ( $Srcdir, $fname );return if ( $Clobber ); # clobber mode ?## Determine the build version#my ($major, $minor, $patch, $build, $raw_patch) = SplitVersion($BUILDNAME_VERSION);my $vstring = "$major.$minor.$patch.$build";my $fh = ConfigurationFile::New( $fname, '--Type=CSharp' );$fh->HeaderSimple( "buildlib (Version $BuildVersion)","CSharp Assembly Version Definition" );$fh->Write( "\n" );$fh->Write( "using System.Reflection;\n" );$fh->Write( "using System.Runtime.CompilerServices;\n" );$fh->Write( "\n" );$fh->Write( "[assembly: AssemblyCompany(\"ERG Group\")]\n" );$fh->Write( "[assembly: AssemblyProduct(\"$BUILDNAME_PACKAGE\")]\n" );$fh->Write( "[assembly: AssemblyCopyright(\"ERG Group $CurrentYear\")]\n" );$fh->Write( "[assembly: AssemblyTrademark(\"\")]\n" );$fh->Write( "\n");$fh->Comment( "\n");$fh->Comment( "Version information for an assembly consists of the following four values:\n");$fh->Comment( "\n");$fh->Comment( " Major Version -ERG:Major\n");$fh->Comment( " Minor Version - ERG:Minor\n");$fh->Comment( " Build Number - ERG:Patch\n");$fh->Comment( " Revision - ERG:Build Number\n");$fh->Comment( "\n");$fh->Write( "\n");$fh->Write( "[assembly: AssemblyVersion(\"$vstring\")]\n" );$fh->Write( "\n");$fh->Close();}#-------------------------------------------------------------------------------# Function : BuildVersionWinRC## Description : Create a Windows RC file to describe the build version# This file may be used directly## Inputs : $FileName - Output filename (Optional)# @opts - Options# --Definitions# --Icon=path# --Comment=text# --Description=text# --Product=text# --Version=text (Internal Use)# --PkgName=text (Internal Use)# --ToolUse (Internal Use)# Returns : Nothing#sub BuildVersionWinRC{my ( $fname, @opts ) = @_;my $icon;my $defs;my $product = '';my $version = $BUILDNAME_VERSION || '';my $pkg_name = $BUILDNAME_PACKAGE || '';my $comment = "Build Date: $CurrentTime";my $description = '';my $used_by_tool = '';## Process options#foreach ( @opts ){if ( m~^--Icon=(.+)~ ) {$icon = $1;} elsif ( m~^--Definitions~ ) {$defs = 1;} elsif ( m~^--Comment=(.+)~ ) {$comment = $1;} elsif ( m~^--Description=(.+)~ ) {$description = $1;} elsif ( m~^--Product=(.+)~ ) {$product = $1;} elsif ( m~^--Version=(.+)~ ) {$version = $1;} elsif ( m~^--PkgName=(.+)~ ) {$pkg_name = $1;} elsif ( m~^--ToolUse~ ) {$used_by_tool = 1;} else {Error ("WinRC Style Version. Unknown option: $_");}}## Setup defaults#$fname = 'version.rc' unless $fname;Error ("WinRC: No Build Version provided") unless ( $version );Error ("WinRC: No Build Package Name provided") unless ( $pkg_name );## Store the files location for use at runtime# It will be a file that is 'known' to JATS#unless ( $used_by_tool ){$fname = ::BuildAddKnownFile ( $Srcdir, $fname );return if ( $Clobber ); # clobber mode ?}Message ("Creating Windows Resource File: $fname" );## Determine the build version#my ($major, $minor, $patch, $build, $raw_patch) = SplitVersion($version);my $product_version = "$major, $minor, $patch, $build";## Create the file#my $fh = ConfigurationFile::New( $fname, '--Type=C++' );$fh->HeaderSimple( "buildlib (Version $BuildVersion)","Windows Resource Version Definition" );sub prc{return "@_\n";}sub pdefs{my ($arg, $val) = @_;Error ("Undefined value for $arg") unless ( defined $val );return "#define $arg \"$val\\0\"\n";}sub pdef{my ($arg, $val) = @_;Error ("Undefined value for $arg") unless ( defined $val );return "#define $arg $val\n";}$fh->Write(prc (""));# $fh->Write(prc ("#include \"afxres.h\""));# $fh->Write(prc (""));$fh->Write(prc (""));$fh->Write(pdefs ("RC_STR_EMPTY" , "" ));$fh->Write(pdefs ("RC_STR_COMPANY" , "ERG Group" ));$fh->Write(pdefs ("RC_STR_PRODUCTNAME" , $product ));$fh->Write(pdefs ("RC_STR_COMMENT" , $comment ));$fh->Write(pdefs ("RC_STR_DESCRIPTION" , $description ));$fh->Write(pdefs ("RC_STR_NAME" , $pkg_name ));$fh->Write(pdefs ("RC_STR_VERSION" , $product_version ));$fh->Write(pdef ("RC_NUM_VERSION" , $product_version ));$fh->Write(pdefs ("RC_STR_COPYRIGHT" , "Copyright ERG Group $CurrentYear" ));$fh->Write(prc ('#ifdef _DEBUG'));$fh->Write(pdefs ("RC_STR_SPECIAL" , "Debug Version" ));$fh->Write(prc ('#else'));$fh->Write(pdefs ("RC_STR_SPECIAL" , "Production Version" ));$fh->Write(prc ('#endif'));$fh->Write(prc (""));unless ( $defs ){$fh->Write(prc ('#define VS_VERSION_INFO 1'));$fh->Write(prc (''));$fh->Write(prc ('VS_VERSION_INFO VERSIONINFO'));$fh->Write(prc (' FILEVERSION RC_NUM_VERSION'));$fh->Write(prc (' PRODUCTVERSION RC_NUM_VERSION'));$fh->Write(prc (' FILEFLAGSMASK 0x3fL'));$fh->Write(prc ('#ifdef _DEBUG'));$fh->Write(prc (' FILEFLAGS 0x1L'));$fh->Write(prc ('#else'));$fh->Write(prc (' FILEFLAGS 0x0L'));$fh->Write(prc ('#endif'));$fh->Write(prc (' FILEOS 0x40004L'));$fh->Write(prc (' FILETYPE 0x1L'));$fh->Write(prc (' FILESUBTYPE 0x0L'));$fh->Write(prc ('BEGIN'));$fh->Write(prc (' BLOCK "StringFileInfo"'));$fh->Write(prc (' BEGIN'));$fh->Write(prc (' BLOCK "0c0904b0"'));$fh->Write(prc (' BEGIN'));$fh->Write(prc (' VALUE "Comments", RC_STR_COMMENT'));$fh->Write(prc (' VALUE "CompanyName", RC_STR_COMPANY'));$fh->Write(prc (' VALUE "FileDescription", RC_STR_DESCRIPTION'));$fh->Write(prc (' VALUE "FileVersion", RC_STR_VERSION'));$fh->Write(prc (' VALUE "InternalName", RC_STR_NAME'));$fh->Write(prc (' VALUE "LegalCopyright", RC_STR_COPYRIGHT'));$fh->Write(prc (' VALUE "LegalTrademarks", RC_STR_EMPTY'));$fh->Write(prc (' VALUE "OriginalFilename", RC_STR_NAME'));$fh->Write(prc (' VALUE "PrivateBuild", RC_STR_EMPTY'));$fh->Write(prc (' VALUE "ProductName", RC_STR_PRODUCTNAME'));$fh->Write(prc (' VALUE "ProductVersion", RC_STR_VERSION'));$fh->Write(prc (' VALUE "SpecialBuild", RC_STR_SPECIAL'));$fh->Write(prc (' END'));$fh->Write(prc (' END'));$fh->Write(prc (' BLOCK "VarFileInfo"'));$fh->Write(prc (' BEGIN'));$fh->Write(prc (' VALUE "Translation", 0xc09, 1200'));$fh->Write(prc (' END'));$fh->Write(prc ('END'));$fh->Write(prc (''));if ( $icon ){$fh->Write(prc (''));$fh->Write(prc ('/////////////////////////////////////////////////////////////////////////////'));$fh->Write(prc ('//'));$fh->Write(prc ('// Icon'));$fh->Write(prc ('//'));$fh->Write(prc ('// Icon with lowest ID value placed first to ensure application icon'));$fh->Write(prc ('// remains consistent on all systems.'));$fh->Write(prc ("101 ICON DISCARDABLE \"$icon\""));$fh->Write(prc (''));}}$fh->Close();}#-------------------------------------------------------------------------------# Function : BuildVersionC## Description : Create a "C" style version.c and version.h file## Inputs : $Prefix - Text to prefix generated variables with# Used to avoid namespace conflicts# $Type - Type of version to create# Only allowed value is 'array'## Returns :#sub BuildVersionC{my( $Prefix, $Type ) = @_;my $ver;if ( $Clobber ) # clobber mode ?{## Clobber common version.c and version.h#System( "$::GBE_BIN/rm -f $Srcdir/version.c $Srcdir/version.h" );return;}## Default prefix is none# Set to a defined, bet empty, string#$Prefix = "" if ( ! defined( $Prefix ) );$Type = "" if ( ! defined( $Type ) );# src/version.c#..open( VERSIONC, ">$Srcdir/version.c" ) ||Error( "cannot create $Srcdir/version.c" );print VERSIONC"/* Please do not edit this file.\n" ." * It was auto-generated by Buildlib ($BuildVersion) on $::CurrentTime\n" ." */\n" ."#include \"version.h\"\n";print VERSIONC"\n" ."static char what[] = \"@(#) $BUILDNAME $::CurrentDate ERG\";\n" ."\n";my @PACKAGEVERS = PackageEntry::GetPackageVersionList();if ( $Type eq "array" ){ # new styleprint VERSIONC"static const char *pkgarray[] = \n" ."{\n";foreach $ver ( @PACKAGEVERS ) {print VERSIONC " \"$ver\",\n";}print VERSIONC" 0\n","};\n\n";print VERSIONC"\nconst char *\n$Prefix"."VersionString(void)\n" ."{\n"." return \"$BUILDNAME\";\n" ."}\n" ."\nconst char **\n$Prefix"."PkgStrings(void)\n" ."{\n"." return pkgarray;\n" ."}\n" ."\nconst char *\n$Prefix"."GetModuleInfo(void)\n" ."{\n" ." return \"$BUILDNAME_PACKAGE ($BUILDNAME_VERSION.$BUILDNAME_PROJECT) @PACKAGEVERS\";\n" ."}\n";}else{ # old styleprint VERSIONC"\nconst char *\n$Prefix"."VersionString(void)\n" ."{\n"." return \"$BUILDNAME @PACKAGEVERS\";\n" ."}\n" ."\nconst char *\n$Prefix"."GetModuleInfo(void)\n" ."{\n" ." return \"$BUILDNAME_PACKAGE ($BUILDNAME_VERSION.$BUILDNAME_PROJECT) @PACKAGEVERS\";\n" ."}\n";}close VERSIONC;# src/version.h#..open( VERSIONH, ">$Srcdir/version.h" ) ||Error( "cannot create $Srcdir/version.h" );print VERSIONH"#ifndef VERSION_H_INCLUDED\n" ."#define VERSION_H_INCLUDED\n" ."/* Please do not edit this file.\n" ." * It was auto-generated by Buildlib ($BuildVersion) on $::CurrentTime\n" ." */\n\n" ."#define BUILDNAME \"$BUILDNAME\"\n" ."#define BUILDDATE \"$::CurrentTime\"\n" ."\n";print VERSIONH"#ifdef __cplusplus\n" ." extern \"C\" { /* force C calling convention when using C++ */\n" ."#endif\n" ."\n";if ( $Type eq "array" ){ # extended interfaceprint VERSIONH"extern const char ** $Prefix"."PkgStrings(void);\n";}print VERSIONH"extern const char * $Prefix"."VersionString(void);\n"."extern const char * $Prefix"."GetModuleInfo(void);\n";print VERSIONH"\n" ."#ifdef __cplusplus\n" ." } /* extern \"C\" */\n" ."#endif\n" ."\n";print VERSIONH"\n#endif /*VERSION_H_INCLUDED*/\n";close VERSIONH;}#-------------------------------------------------------------------------------# Function : BuildVersionCdefs## Description : Generate a "C" style version definitions file# This file simply contains definitions## Inputs : $Mode - File suffix# $ModePrefix - Tag for all generated definitions## Returns :#sub BuildVersionCdefs{my ( $Mode, $ModePrefix ) = @_;my $fname = "version_$Mode.h";if ( $Clobber ) # clobber mode ?{System( "$::GBE_BIN/rm -f $Srcdir/$fname" );return;}## Generate version_defs.h# This file contains ONLY definitions. It may be used by assembler# programs (that support a preprocessor) to access version information## Allow for a user supplied filename fragment that will be used within# all the definitions with in the file.#my ($major, $minor, $patch, $build, $raw_patch) = SplitVersion($BUILDNAME_VERSION);my @PACKAGEVERS = PackageEntry::GetPackageVersionList();## Base names on a user supplied value or a default#my $vtag = uc( "VERSION$ModePrefix" );my $guard_name = uc($fname);$guard_name =~ s~\.~_~g;open( VERSIOND, ">$Srcdir/$fname" ) ||Error( "cannot create $Srcdir/$fname" );print VERSIOND"#ifndef $guard_name\n" ."#define $guard_name\n" ."/* Please do not edit this file.\n" ." * It was auto-generated by Buildlib ($BuildVersion) on $::CurrentTime\n" ." */\n\n" ."\n"."#define ${vtag}_BUILDNAME \"$BUILDNAME\"\n"."#define ${vtag}_BUILDDATE \"$::CurrentTime\"\n"."\n"."#define ${vtag}_PACKAGE \"$BUILDNAME_PACKAGE\"\n"."#define ${vtag}_VERSION \"$BUILDNAME_VERSION\"\n"."#define ${vtag}_MAJOR_STR \"$major\"\n"."#define ${vtag}_MINOR_STR \"$minor\"\n"."#define ${vtag}_PATCH_STR \"$patch\"\n"."#define ${vtag}_BUILD_STR \"$build\"\n"."#define ${vtag}_PATCHBUILD_STR \"$raw_patch\"\n"."#define ${vtag}_PROJECT \"$BUILDNAME_PROJECT\"\n"."#define ${vtag}_MAJOR " . strip_zeros($major) . "\n"."#define ${vtag}_MINOR " . strip_zeros($minor) . "\n"."#define ${vtag}_PATCH " . strip_zeros($patch) . "\n"."#define ${vtag}_BUILD " . strip_zeros($build) . "\n"."#define ${vtag}_PATCHBUILD " . strip_zeros($raw_patch) . "\n"."#define ${vtag}_ALL \"$BUILDNAME_PACKAGE ($BUILDNAME_VERSION.$BUILDNAME_PROJECT) @PACKAGEVERS\"\n"."#define ${vtag}_BUILDTIME " . strip_zeros(time()) . "\n"."\n"."#endif /* $guard_name */\n";close VERSIOND;}#-------------------------------------------------------------------------------# Function : BuildVersionProperties## Description : Generate a "Java" style version definitions file# This is a simple properties file## Inputs : $FileName - Output filename (Optional)# $Prefix - Tag for all generated definitions## Returns :#sub BuildVersionProperties{my ( $fname, $Prefix ) = @_;## Default name of the file#$fname = 'version.properties' unless $fname;## Store the files location for use at runtime# It will be a file that is 'known' to JATS#$fname = ::BuildAddKnownFile ( $Srcdir, $fname );return if ( $Clobber ); # clobber mode ?## Generate version properties file## This file contains ONLY definitions. It may be included by the ANT# builds. Its not intended to be imported by the java code## Allow for a user supplied property prefix# Not really needed as#my $vtag = '';$vtag = $Prefix . '.' if $Prefix;my ($major, $minor, $patch, $build, $raw_patch) = SplitVersion($BUILDNAME_VERSION);my @PACKAGEVERS = PackageEntry::GetPackageVersionList();## Create properties in the same form as for "C" definitions# Note:# The 'ALL' is in a format used by other software. Do not change#open( VERSIOND, ">$fname" ) ||Error( "cannot create $fname" );print VERSIOND"# Please do not edit this file.\n" ."# It was auto-generated by Buildlib ($BuildVersion) on $::CurrentTime\n" ."#\n" ."${vtag}BUILDNAME = $BUILDNAME\n"."${vtag}BUILDDATE = $::CurrentTime\n"."\n"."${vtag}PACKAGE = $BUILDNAME_PACKAGE\n"."${vtag}VERSION = $BUILDNAME_VERSION\n"."${vtag}MAJOR_STR = $major\n"."${vtag}MINOR_STR = $minor\n"."${vtag}PATCH_STR = $patch\n"."${vtag}BUILD_STR = $build\n"."${vtag}PATCHBUILD_STR = $raw_patch\n"."${vtag}PROJECT = $BUILDNAME_PROJECT\n"."${vtag}MAJOR = " . strip_zeros($major) . "\n"."${vtag}MINOR = " . strip_zeros($minor) . "\n"."${vtag}PATCH = " . strip_zeros($patch) . "\n"."${vtag}BUILD = " . strip_zeros($build) . "\n"."${vtag}PATCHBUILD = " . strip_zeros($raw_patch) . "\n"."${vtag}ALL = $BUILDNAME_PACKAGE ($BUILDNAME_VERSION.$BUILDNAME_PROJECT) @PACKAGEVERS\n"."${vtag}BUILDTIME = " . strip_zeros(time()) . "\n"."\n";## Create a set of definitions for each dependent package#print VERSIOND "# Dependent Packages and Versions\n"."#\n";foreach my $tag ( PackageEntry::GetPackageList() ){my ($name, $version, $type) = PackageEntry::GetPackageData($tag);# push @attributes, "build=\"true\"" if $type =~ /Build/i;print VERSIOND "${vtag}PACKAGE.$name=$version\n";}close VERSIOND;}#-------------------------------------------------------------------------------# Function : stip_zeros## Description : Remove leading 0's from a string## Inputs : A string## Returns : A string without leading zeros#sub strip_zeros{my ($text) = @_;$text =~ s~^0*~~;$text = '0' unless ( $text );return $text;}1;