| 227 |
dpurdie |
1 |
#! /usr/bin/perl
|
|
|
2 |
########################################################################
|
|
|
3 |
# Copyright (C) 1998-2004 ERG Limited, All rights reserved
|
|
|
4 |
#
|
|
|
5 |
# Module name : gen_winrc.pl
|
|
|
6 |
# Module type : Makefile system
|
|
|
7 |
# Compiler(s) : n/a
|
|
|
8 |
# Environment(s):
|
|
|
9 |
#
|
|
|
10 |
# Description : A script to generate a RC file
|
|
|
11 |
# The script will:
|
|
|
12 |
# Take user options
|
|
|
13 |
#
|
|
|
14 |
# Create a .rc file
|
|
|
15 |
#
|
|
|
16 |
#
|
|
|
17 |
# Version Who Date Description
|
|
|
18 |
# 1.0.0 DDP 20-Jul-04 Created
|
|
|
19 |
#
|
|
|
20 |
#......................................................................#
|
|
|
21 |
|
| 255 |
dpurdie |
22 |
require 5.006_001;
|
| 227 |
dpurdie |
23 |
use strict;
|
|
|
24 |
use warnings;
|
|
|
25 |
|
|
|
26 |
use JatsError;
|
|
|
27 |
use Getopt::Long;
|
|
|
28 |
use Pod::Usage; # required for help support
|
|
|
29 |
use Cwd;
|
|
|
30 |
|
|
|
31 |
my $VERSION = "1.1.0"; # Update this
|
|
|
32 |
|
|
|
33 |
#
|
|
|
34 |
# Options
|
|
|
35 |
#
|
|
|
36 |
my $opt_outfile;
|
|
|
37 |
my $opt_version;
|
|
|
38 |
my $opt_comment;
|
|
|
39 |
my $opt_product;
|
|
|
40 |
my $opt_name;
|
|
|
41 |
my $opt_description;
|
|
|
42 |
my $opt_defs_only;
|
|
|
43 |
my $opt_icon;
|
|
|
44 |
|
|
|
45 |
my $opt_help = 0;
|
|
|
46 |
my $opt_manual = 0;
|
|
|
47 |
my $opt_debug = $ENV{'GBE_DEBUG'} || 0; # Allow global debug
|
|
|
48 |
my $opt_verbose = $ENV{'GBE_VERBOSE'} || 0; # Allow global verbose
|
|
|
49 |
|
|
|
50 |
|
|
|
51 |
#
|
|
|
52 |
# Global variables
|
|
|
53 |
#
|
|
|
54 |
my $file_version;
|
|
|
55 |
my $product_version;
|
|
|
56 |
|
|
|
57 |
my $current_time = localtime;
|
|
|
58 |
my ($sec,$min,$hour,$mday,$mon,$lyear,$wday,$yday,$isdst) = localtime();
|
|
|
59 |
my $year = $lyear + 1900;
|
|
|
60 |
|
|
|
61 |
#-------------------------------------------------------------------------------
|
|
|
62 |
# Entry : Main program entry
|
|
|
63 |
#
|
|
|
64 |
# Inputs : Options and arguments on the command line
|
|
|
65 |
#
|
|
|
66 |
my $result = GetOptions (
|
|
|
67 |
"help+" => \$opt_help,
|
|
|
68 |
"manual" => \$opt_manual,
|
|
|
69 |
"verbose+" => \$opt_verbose,
|
|
|
70 |
|
|
|
71 |
"out:s" => \$opt_outfile,
|
|
|
72 |
"version:s" => \$opt_version,
|
|
|
73 |
"comment:s" => \$opt_comment,
|
|
|
74 |
"product:s" => \$opt_product,
|
|
|
75 |
"name:s" => \$opt_name,
|
|
|
76 |
"description:s" => \$opt_description,
|
|
|
77 |
"definitions" => \$opt_defs_only,
|
|
|
78 |
"icon:s" => \$opt_icon,
|
|
|
79 |
|
|
|
80 |
);
|
|
|
81 |
|
|
|
82 |
#
|
|
|
83 |
# UPDATE THE DOCUMENTATION AT THE END OF THIS FILE !!!
|
|
|
84 |
#
|
|
|
85 |
|
|
|
86 |
#
|
|
|
87 |
# Process help and manual options
|
|
|
88 |
#
|
|
|
89 |
pod2usage(-verbose => 0, -message => "Version: $VERSION") if ($opt_help == 1 || ! $result);
|
|
|
90 |
pod2usage(-verbose => 1) if ($opt_help == 2 );
|
|
|
91 |
pod2usage(-verbose => 2) if ($opt_manual || $opt_help > 2);
|
|
|
92 |
|
|
|
93 |
#
|
|
|
94 |
# Configure the Error reporting process now that we have the user options
|
|
|
95 |
#
|
|
|
96 |
ErrorConfig( 'name' =>'GENRC', 'verbose' => $opt_verbose );
|
|
|
97 |
|
|
|
98 |
#
|
|
|
99 |
# Validate user options
|
|
|
100 |
# Not expecting any user arguments, other than options, so spit if any are found
|
|
|
101 |
#
|
|
|
102 |
Error ("Unexpected command line arguments present" )
|
|
|
103 |
if ( $#ARGV >= 0 );
|
|
|
104 |
|
|
|
105 |
#
|
|
|
106 |
# Sanity test of user arguments
|
|
|
107 |
#
|
|
|
108 |
Error ("No output file specified") unless ( $opt_outfile );
|
|
|
109 |
Error ("No version specified") unless ( $opt_version );
|
|
|
110 |
Error ("No name specified") unless ( $opt_name );
|
|
|
111 |
|
|
|
112 |
#
|
|
|
113 |
# Process arguments
|
|
|
114 |
#
|
|
|
115 |
# File and product versions
|
|
|
116 |
# These appear to be comma delemited numbers
|
|
|
117 |
# Base this in the user version string
|
|
|
118 |
# Allow for build number embedded in the patch number
|
|
|
119 |
# Allow for 4 field version number
|
|
|
120 |
#
|
|
|
121 |
# Allow for nn.nn.nn - Force nn.nn.nn.0
|
|
|
122 |
# and nn.nn.nn.nn
|
|
|
123 |
#
|
|
|
124 |
|
|
|
125 |
my ($major, $minor, $patch, $build ) = split ('\.', $opt_version);
|
|
|
126 |
|
|
|
127 |
#
|
|
|
128 |
# Decode the patch number and extract the build number
|
|
|
129 |
# Need to know the the length of the user string to decode
|
|
|
130 |
# Those less than three digits are build 0
|
|
|
131 |
#
|
|
|
132 |
if ( ! defined ($build) )
|
|
|
133 |
{
|
|
|
134 |
$build = 0;
|
|
|
135 |
if ( length( $patch) >= 4 )
|
|
|
136 |
{
|
|
|
137 |
$build = substr( $patch, -3 ,3);
|
|
|
138 |
$patch = substr( $patch, 0 ,length($patch)-3);
|
|
|
139 |
}
|
|
|
140 |
}
|
|
|
141 |
|
|
|
142 |
$product_version = $file_version = "$major, $minor, $patch, $build";
|
|
|
143 |
|
|
|
144 |
#
|
|
|
145 |
# Generate the output file
|
|
|
146 |
#
|
|
|
147 |
open ( RC, ">$opt_outfile" ) || Error ("Cannot open output: $opt_outfile");
|
|
|
148 |
|
|
|
149 |
#--------- Auto-generated Configuration -------------------------------------
|
|
|
150 |
# -*- mode: perl; tabs: 8; -*-
|
|
|
151 |
#
|
|
|
152 |
# -- Please do not edit this file. --
|
|
|
153 |
#
|
|
|
154 |
# Generated from GBE_BUILDLIB=${ARGV[1]} (version $BuildVersion)
|
|
|
155 |
# on $CurrentTime
|
|
|
156 |
#
|
|
|
157 |
# Makelib configuration file
|
|
|
158 |
#
|
|
|
159 |
|
|
|
160 |
|
|
|
161 |
prc ("/////////////////////////////////////////////////////////////////////////////");
|
|
|
162 |
prc ("//");
|
|
|
163 |
prc ("// GENERATED FILE. DO NOT EDIT");
|
|
|
164 |
prc ("//");
|
|
|
165 |
prc ("// Generated on: $current_time");
|
|
|
166 |
prc ("//");
|
|
|
167 |
prc ("//");
|
|
|
168 |
prc ("");
|
|
|
169 |
prc ("#include \"afxres.h\"");
|
|
|
170 |
prc ("");
|
|
|
171 |
prc ("");
|
|
|
172 |
pdefs ("RC_STR_EMPTY" , "" );
|
|
|
173 |
pdefs ("RC_STR_COMPANY" , "ERG Group" );
|
|
|
174 |
pdefs ("RC_STR_PRODUCTNAME" , $opt_product );
|
|
|
175 |
pdefs ("RC_STR_COMMENT" , $opt_comment );
|
|
|
176 |
pdefs ("RC_STR_DESCRIPTION" , $opt_description );
|
|
|
177 |
pdefs ("RC_STR_NAME" , $opt_name );
|
|
|
178 |
pdefs ("RC_STR_VERSION" , $product_version );
|
|
|
179 |
pdef ("RC_NUM_VERSION" , $product_version );
|
|
|
180 |
pdefs ("RC_STR_COPYRIGHT" , "Copyright ERG Group $year" );
|
|
|
181 |
prc ('#ifdef _DEBUG');
|
|
|
182 |
pdefs ("RC_STR_SPECIAL" , "Debug Version" );
|
|
|
183 |
prc ('#else');
|
|
|
184 |
pdefs ("RC_STR_SPECIAL" , "Production Version" );
|
|
|
185 |
prc ('#endif');
|
|
|
186 |
prc ("");
|
|
|
187 |
|
|
|
188 |
unless ( $opt_defs_only )
|
|
|
189 |
{
|
|
|
190 |
prc ('');
|
|
|
191 |
prc ('VS_VERSION_INFO VERSIONINFO');
|
|
|
192 |
prc (' FILEVERSION RC_NUM_VERSION');
|
|
|
193 |
prc (' PRODUCTVERSION RC_NUM_VERSION');
|
|
|
194 |
prc (' FILEFLAGSMASK 0x3fL');
|
|
|
195 |
prc ('#ifdef _DEBUG');
|
|
|
196 |
prc (' FILEFLAGS 0x1L');
|
|
|
197 |
prc ('#else');
|
|
|
198 |
prc (' FILEFLAGS 0x0L');
|
|
|
199 |
prc ('#endif');
|
|
|
200 |
prc (' FILEOS 0x40004L');
|
|
|
201 |
prc (' FILETYPE 0x1L');
|
|
|
202 |
prc (' FILESUBTYPE 0x0L');
|
|
|
203 |
prc ('BEGIN');
|
|
|
204 |
prc (' BLOCK "StringFileInfo"');
|
|
|
205 |
prc (' BEGIN');
|
|
|
206 |
prc (' BLOCK "0c0904b0"');
|
|
|
207 |
prc (' BEGIN');
|
|
|
208 |
prc (' VALUE "Comments", RC_STR_COMMENT');
|
|
|
209 |
prc (' VALUE "CompanyName", RC_STR_COMPANY');
|
|
|
210 |
prc (' VALUE "FileDescription", RC_STR_DESCRIPTION');
|
|
|
211 |
prc (' VALUE "FileVersion", RC_STR_VERSION');
|
|
|
212 |
prc (' VALUE "InternalName", RC_STR_NAME');
|
|
|
213 |
prc (' VALUE "LegalCopyright", RC_STR_COPYRIGHT');
|
|
|
214 |
prc (' VALUE "LegalTrademarks", RC_STR_EMPTY');
|
|
|
215 |
prc (' VALUE "OriginalFilename", RC_STR_EMPTY');
|
|
|
216 |
prc (' VALUE "PrivateBuild", RC_STR_EMPTY');
|
|
|
217 |
prc (' VALUE "ProductName", RC_STR_PRODUCTNAME');
|
|
|
218 |
prc (' VALUE "ProductVersion", RC_STR_EMPTY');
|
|
|
219 |
prc (' VALUE "SpecialBuild", RC_STR_SPECIAL');
|
|
|
220 |
prc (' END');
|
|
|
221 |
prc (' END');
|
|
|
222 |
prc (' BLOCK "VarFileInfo"');
|
|
|
223 |
prc (' BEGIN');
|
|
|
224 |
prc (' VALUE "Translation", 0xc09, 1200');
|
|
|
225 |
prc (' END');
|
|
|
226 |
prc ('END');
|
|
|
227 |
prc ('');
|
|
|
228 |
|
|
|
229 |
if ( $opt_icon )
|
|
|
230 |
{
|
|
|
231 |
prc ('');
|
|
|
232 |
prc ('/////////////////////////////////////////////////////////////////////////////');
|
|
|
233 |
prc ('//');
|
|
|
234 |
prc ('// Icon');
|
|
|
235 |
prc ('//');
|
|
|
236 |
prc ('// Icon with lowest ID value placed first to ensure application icon');
|
|
|
237 |
prc ('// remains consistent on all systems.');
|
|
|
238 |
prc ("101 ICON DISCARDABLE \"$opt_icon\"");
|
|
|
239 |
prc ('');
|
|
|
240 |
}
|
|
|
241 |
}
|
|
|
242 |
|
|
|
243 |
prc ("// End of File //////////////////////////////////////////////////////////////");
|
|
|
244 |
|
|
|
245 |
close (RC);
|
|
|
246 |
exit 0;
|
|
|
247 |
|
|
|
248 |
#-------------------------------------------------------------------------------
|
|
|
249 |
# Function : prc
|
|
|
250 |
#
|
|
|
251 |
# Description : Print a line to the RC file
|
|
|
252 |
#
|
|
|
253 |
# Inputs : Line to print
|
|
|
254 |
#
|
|
|
255 |
# Returns :
|
|
|
256 |
#
|
|
|
257 |
sub prc
|
|
|
258 |
{
|
|
|
259 |
print RC "@_\n";
|
|
|
260 |
}
|
|
|
261 |
|
|
|
262 |
sub pdefs
|
|
|
263 |
{
|
|
|
264 |
my ($arg, $val) = @_;
|
|
|
265 |
$val = "" unless ( $val );
|
|
|
266 |
print RC "#define $arg \"$val\\0\"\n";
|
|
|
267 |
|
|
|
268 |
}
|
|
|
269 |
|
|
|
270 |
sub pdef
|
|
|
271 |
{
|
|
|
272 |
my ($arg, $val) = @_;
|
|
|
273 |
print RC "#define $arg $val\n";
|
|
|
274 |
}
|
|
|
275 |
|
|
|
276 |
|
|
|
277 |
=pod
|
|
|
278 |
|
|
|
279 |
=head1 NAME
|
|
|
280 |
|
|
|
281 |
gen_winrc.pl - Generate a Windows RC file
|
|
|
282 |
|
|
|
283 |
=head1 SYNOPSIS
|
|
|
284 |
|
|
|
285 |
gen_winrc.pl [arguments] ...
|
|
|
286 |
|
|
|
287 |
Arguments:
|
|
|
288 |
-help - brief help message
|
|
|
289 |
-help -help - Detailed help message
|
|
|
290 |
-man - Full documentation
|
|
|
291 |
-verbose - Verbose information
|
|
|
292 |
|
|
|
293 |
Mandatory
|
|
|
294 |
-out file - Name of the output file
|
|
|
295 |
-version nn.nn.nn - Release version
|
|
|
296 |
-name string - Program Name
|
|
|
297 |
|
|
|
298 |
Optional
|
|
|
299 |
-comment string - Comment string
|
|
|
300 |
-description string - Description string
|
|
|
301 |
-definitions - Only generate the definitions
|
|
|
302 |
-icon filename - The name of an icon file
|
|
|
303 |
|
|
|
304 |
=head1 OPTIONS
|
|
|
305 |
|
|
|
306 |
=over 8
|
|
|
307 |
|
|
|
308 |
=item B<-help>
|
|
|
309 |
|
|
|
310 |
Print a brief help message and exits.
|
|
|
311 |
|
|
|
312 |
=item B<-help -help>
|
|
|
313 |
|
|
|
314 |
Print a detailed help message with an explanation for each option.
|
|
|
315 |
|
|
|
316 |
=item B<-man>
|
|
|
317 |
|
|
|
318 |
Prints the manual page and exits.
|
|
|
319 |
|
|
|
320 |
=item B<-verbose>
|
|
|
321 |
|
|
|
322 |
Increase the level of debugging information displayed. This option may be used
|
|
|
323 |
multiple times.
|
|
|
324 |
|
|
|
325 |
=item B<-out file>
|
|
|
326 |
|
|
|
327 |
Specifies the name of the output file. The option is mandatory.
|
|
|
328 |
|
|
|
329 |
=item B<-version nn.nn.nn>
|
|
|
330 |
|
|
|
331 |
Specify the version to include include in the resource file. This must be of
|
|
|
332 |
the form nn.nn.nn, where nn is a decimal digit.
|
|
|
333 |
|
|
|
334 |
Within a JATS makefile the value of $ScmBuildVersion may be used.
|
|
|
335 |
|
|
|
336 |
The option is mandatory.
|
|
|
337 |
|
|
|
338 |
=item B<-name string>
|
|
|
339 |
|
|
|
340 |
Specify the name of the program. The option is mandatory.
|
|
|
341 |
|
|
|
342 |
Within a JATS makefile the value of $ScmBuildPackage may be used.
|
|
|
343 |
|
|
|
344 |
=item B<-comment string>
|
|
|
345 |
|
|
|
346 |
Specify an optional comment string. If the string contains whitespace then item
|
|
|
347 |
should be enclosed in quotes.
|
|
|
348 |
|
|
|
349 |
=item B<-description string>
|
|
|
350 |
|
|
|
351 |
Specify an optional description string. If the string contains whitespace then item
|
|
|
352 |
should be enclosed in quotes.
|
|
|
353 |
|
|
|
354 |
=item B<-definitions>
|
|
|
355 |
|
|
|
356 |
This option will only write out a file that contains the definitions. The body
|
|
|
357 |
of the resource script will not be generated. The file that is generated may
|
|
|
358 |
be included within another resource file.
|
|
|
359 |
|
|
|
360 |
=item B<-icon filename>
|
|
|
361 |
|
|
|
362 |
This option will add the specified icon file to the resource being created.
|
|
|
363 |
The icon will appear against the DLL.
|
|
|
364 |
|
|
|
365 |
=back
|
|
|
366 |
|
|
|
367 |
=head1 DESCRIPTION
|
|
|
368 |
|
|
|
369 |
B<This program> will generate a basic Windows resource file to contains the
|
|
|
370 |
program name and version number. The resulting file may then be included in
|
|
|
371 |
another resource file, or used directly to generate a basic program resource.
|
|
|
372 |
|
|
|
373 |
=head1 EXAMPLE
|
|
|
374 |
|
|
|
375 |
=head2 Used within makefile.pl - Basic
|
|
|
376 |
|
|
|
377 |
GenerateFiles ('WIN32', "--Tool=gen_winrc.pl",
|
|
|
378 |
"-out --GeneratedCommon(prog.rc)",
|
|
|
379 |
"-version=$ScmBuildVersion",
|
|
|
380 |
"-comment='This is a comment'",
|
|
|
381 |
"-name=$ScmBuildPackage",
|
|
|
382 |
"-description='This is a description'",
|
|
|
383 |
"--NoWarn" );
|
|
|
384 |
|
|
|
385 |
Prog ( '*' , "MyProg", @OBJS );
|
|
|
386 |
Prog ( 'WIN32', "MyProg", "--Resource=prog.rc" );
|
|
|
387 |
|
|
|
388 |
The resource script will be generated with basic information. It can then be
|
|
|
389 |
added to the program or DLL as required.
|
|
|
390 |
|
|
|
391 |
=cut
|