Subversion Repositories DevTools

Rev

Rev 227 | Rev 267 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

#! /usr/bin/perl
########################################################################
# Copyright (C) 1998-2004 ERG Limited, All rights reserved
#
# Module name   : gen_winrc.pl
# Module type   : Makefile system
# Compiler(s)   : n/a
# Environment(s):
#
# Description   : A script to generate a RC file
#                 The script will:
#                   Take user options
#
#                   Create a .rc file
#
#
# Version   Who      Date        Description
# 1.0.0     DDP      20-Jul-04   Created
#
#......................................................................#

require 5.006_001;
use strict;
use warnings;

use JatsError;
use Getopt::Long;
use Pod::Usage;                             # required for help support
use Cwd;

my $VERSION = "1.1.0";                      # Update this

#
#   Options
#
my $opt_outfile;
my $opt_version;
my $opt_comment;
my $opt_product;
my $opt_name;
my $opt_description;
my $opt_defs_only;
my $opt_icon;

my $opt_help = 0;
my $opt_manual = 0;
my $opt_debug   = $ENV{'GBE_DEBUG'}     || 0;      # Allow global debug
my $opt_verbose = $ENV{'GBE_VERBOSE'}   || 0;      # Allow global verbose


#
#   Global variables
#
my $file_version;
my $product_version;

my $current_time = localtime;
my ($sec,$min,$hour,$mday,$mon,$lyear,$wday,$yday,$isdst) = localtime();
my $year = $lyear + 1900;

#-------------------------------------------------------------------------------
# Entry           : Main program entry
#
# Inputs          : Options and arguments on the command line
#
my $result = GetOptions (
                "help+"         => \$opt_help,
                "manual"        => \$opt_manual,
                "verbose+"      => \$opt_verbose,

                "out:s"         => \$opt_outfile,
                "version:s"     => \$opt_version,
                "comment:s"     => \$opt_comment,
                "product:s"     => \$opt_product,
                "name:s"        => \$opt_name,
                "description:s" => \$opt_description,
                "definitions"   => \$opt_defs_only,
                "icon:s"        => \$opt_icon,
                
                );

                #
                #   UPDATE THE DOCUMENTATION AT THE END OF THIS FILE !!!
                #

#
#   Process help and manual options
#
pod2usage(-verbose => 0, -message => "Version: $VERSION")  if ($opt_help == 1  || ! $result);
pod2usage(-verbose => 1)  if ($opt_help == 2 );
pod2usage(-verbose => 2)  if ($opt_manual || $opt_help > 2);

#
#   Configure the Error reporting process now that we have the user options
#
ErrorConfig( 'name'    =>'GENRC', 'verbose' => $opt_verbose );

#
#   Validate user options
#   Not expecting any user arguments, other than options, so spit if any are found
#
Error ("Unexpected command line arguments present" )
    if ( $#ARGV >= 0 );

#
#   Sanity test of user arguments
#
Error ("No output file specified")  unless ( $opt_outfile );
Error ("No version specified")      unless ( $opt_version );
Error ("No name specified")         unless ( $opt_name );

#
#   Process arguments
#
#   File and product versions
#       These appear to be comma delemited numbers
#       Base this in the user version string
#       Allow for build number embedded in the patch number
#       Allow for 4 field version number
#
#   Allow for   nn.nn.nn                - Force nn.nn.nn.0
#   and         nn.nn.nn.nn
#

my ($major, $minor, $patch, $build ) = split ('\.', $opt_version);

    #
    #   Decode the patch number and extract the build number
    #   Need to know the the length of the user string to decode
    #   Those less than three digits are build 0
    #
    if ( ! defined ($build) )
    {
        $build = 0;
        if ( length( $patch) >= 4 )
        {
            $build = substr( $patch, -3 ,3);
            $patch = substr( $patch,  0 ,length($patch)-3);
        }
    }

$product_version = $file_version =  "$major, $minor, $patch, $build";

#
#   Generate the output file
#
open ( RC, ">$opt_outfile" ) || Error ("Cannot open output: $opt_outfile");

#--------- Auto-generated Configuration -------------------------------------
# -*- mode: perl; tabs: 8; -*-
#
#                   -- Please do not edit this file. --
#
# Generated from GBE_BUILDLIB=${ARGV[1]} (version $BuildVersion)
#           on   $CurrentTime
#
# Makelib configuration file
#


prc     ("/////////////////////////////////////////////////////////////////////////////");
prc     ("//");
prc     ("//    GENERATED FILE. DO NOT EDIT");
prc     ("//");
prc     ("//    Generated on: $current_time");
prc     ("//");
prc     ("//");
prc     ("");
prc     ("#include \"afxres.h\"");
prc     ("");
prc     ("");
pdefs   ("RC_STR_EMPTY"         , "" );
pdefs   ("RC_STR_COMPANY"       , "ERG Group" );
pdefs   ("RC_STR_PRODUCTNAME"   , $opt_product );
pdefs   ("RC_STR_COMMENT"       , $opt_comment );
pdefs   ("RC_STR_DESCRIPTION"   , $opt_description );
pdefs   ("RC_STR_NAME"          , $opt_name );
pdefs   ("RC_STR_VERSION"       , $product_version );
pdef    ("RC_NUM_VERSION"       , $product_version );
pdefs   ("RC_STR_COPYRIGHT"     , "Copyright ERG Group $year" );
prc     ('#ifdef _DEBUG');
pdefs   ("RC_STR_SPECIAL"       , "Debug Version" );
prc     ('#else');
pdefs   ("RC_STR_SPECIAL"       , "Production Version" );
prc     ('#endif');
prc     ("");

unless ( $opt_defs_only )
{
    prc     ('');
    prc     ('VS_VERSION_INFO VERSIONINFO');
    prc     (' FILEVERSION      RC_NUM_VERSION');
    prc     (' PRODUCTVERSION   RC_NUM_VERSION');
    prc     (' FILEFLAGSMASK 0x3fL');
    prc     ('#ifdef _DEBUG');
    prc     (' FILEFLAGS 0x1L');
    prc     ('#else');
    prc     (' FILEFLAGS 0x0L');
    prc     ('#endif');
    prc     (' FILEOS 0x40004L');
    prc     (' FILETYPE 0x1L');
    prc     (' FILESUBTYPE 0x0L');
    prc     ('BEGIN');
    prc     ('    BLOCK "StringFileInfo"');
    prc     ('    BEGIN');
    prc     ('        BLOCK "0c0904b0"');
    prc     ('        BEGIN');
    prc     ('            VALUE "Comments",         RC_STR_COMMENT');
    prc     ('            VALUE "CompanyName",      RC_STR_COMPANY');
    prc     ('            VALUE "FileDescription",  RC_STR_DESCRIPTION');
    prc     ('            VALUE "FileVersion",      RC_STR_VERSION');
    prc     ('            VALUE "InternalName",     RC_STR_NAME');
    prc     ('            VALUE "LegalCopyright",   RC_STR_COPYRIGHT');
    prc     ('            VALUE "LegalTrademarks",  RC_STR_EMPTY');
    prc     ('            VALUE "OriginalFilename", RC_STR_EMPTY');
    prc     ('            VALUE "PrivateBuild",     RC_STR_EMPTY');
    prc     ('            VALUE "ProductName",      RC_STR_PRODUCTNAME');
    prc     ('            VALUE "ProductVersion",   RC_STR_EMPTY');
    prc     ('            VALUE "SpecialBuild",     RC_STR_SPECIAL');
    prc     ('        END');
    prc     ('    END');
    prc     ('        BLOCK "VarFileInfo"');
    prc     ('        BEGIN');
    prc     ('            VALUE "Translation", 0xc09, 1200');
    prc     ('        END');
    prc     ('END');
    prc     ('');

    if ( $opt_icon )
    {
    prc     ('');
    prc     ('/////////////////////////////////////////////////////////////////////////////');
    prc     ('//');
    prc     ('// Icon');
    prc     ('//');
    prc     ('// Icon with lowest ID value placed first to ensure application icon');
    prc     ('// remains consistent on all systems.');
    prc     ("101       ICON    DISCARDABLE     \"$opt_icon\"");
    prc     ('');
    }
}

prc     ("// End of File //////////////////////////////////////////////////////////////");

close (RC);
exit 0;

#-------------------------------------------------------------------------------
# Function        : prc
#
# Description     : Print a line to the RC file
#
# Inputs          : Line to print
#
# Returns         :
#
sub prc
{
    print RC "@_\n";
}

sub pdefs
{
    my ($arg, $val) = @_;
    $val = "" unless ( $val );
    print RC "#define $arg \"$val\\0\"\n";

}

sub pdef
{
    my ($arg, $val) = @_;
    print RC "#define $arg $val\n";
}


=pod

=head1 NAME

gen_winrc.pl - Generate a Windows RC file

=head1 SYNOPSIS

 gen_winrc.pl [arguments] ...

 Arguments:
    -help                   - brief help message
    -help -help             - Detailed help message
    -man                    - Full documentation
    -verbose                - Verbose information

   Mandatory
    -out file               - Name of the output file
    -version nn.nn.nn       - Release version
    -name string            - Program Name

  Optional
    -comment string         - Comment string
    -description string     - Description string
    -definitions            - Only generate the definitions
    -icon filename          - The name of an icon file

=head1 OPTIONS

=over 8

=item B<-help>

Print a brief help message and exits.

=item B<-help -help>

Print a detailed help message with an explanation for each option.

=item B<-man>

Prints the manual page and exits.

=item B<-verbose>

Increase the level of debugging information displayed. This option may be used
multiple times.

=item B<-out file>

Specifies the name of the output file. The option is mandatory.

=item B<-version nn.nn.nn>

Specify the version to include include in the resource file. This must be of
the form nn.nn.nn, where nn is a decimal digit.

Within a JATS makefile the value of $ScmBuildVersion may be used.

The option is mandatory.

=item B<-name string>

Specify the name of the program. The option is mandatory.

Within a JATS makefile the value of $ScmBuildPackage may be used.

=item B<-comment string>

Specify an optional comment string. If the string contains whitespace then item
should be enclosed in quotes.

=item B<-description string>

Specify an optional description string. If the string contains whitespace then item
should be enclosed in quotes.

=item B<-definitions>

This option will only write out a file that contains the definitions. The body
of the resource script will not be generated. The file that is generated may
be included within another resource file.

=item B<-icon filename>

This option will add the specified icon file to the resource being created.
The icon will appear against the DLL.

=back

=head1 DESCRIPTION

B<This program> will generate a basic Windows resource file to contains the
program name and version number. The resulting file may then be included in
another resource file, or used directly to generate a basic program resource.

=head1 EXAMPLE

=head2 Used within makefile.pl - Basic

    GenerateFiles ('WIN32', "--Tool=gen_winrc.pl",
                            "-out --GeneratedCommon(prog.rc)",
                            "-version=$ScmBuildVersion",
                            "-comment='This is a comment'",
                            "-name=$ScmBuildPackage",
                            "-description='This is a description'",
                            "--NoWarn" );

    Prog          ( '*'    , "MyProg", @OBJS );
    Prog          ( 'WIN32', "MyProg", "--Resource=prog.rc" );

The resource script will be generated with basic information. It can then be
added to the program or DLL as required.

=cut