Subversion Repositories DevTools

Rev

Rev 1141 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1139 dpurdie 1
########################################################################
2
# Copyright (C) 2010 Vix-ERG Limited, All rights reserved
3
#
4
# Module name   : MakeNsisDefs.pl
5
# Module type   : Makefile system
6
# Compiler(s)   : Perl
7
# Environment(s): jats
8
#
9
# Description   : Create JATS specific definitions for use within NSIS
10
#
11
# Usage         : See GetOptions
12
#
13
#......................................................................#
14
 
15
require 5.008_002;
16
use strict;
17
use warnings;
18
 
19
use Pod::Usage;
20
use Getopt::Long;
21
 
22
use JatsError;
23
use ReadBuildConfig qw(:All);
24
use JatsMakeInfo;
25
use ConfigurationFile;
26
use FileUtils;
27
use JatsVersionUtils;
28
use JatsEnv;
29
 
30
#
31
#   Global variables
32
#
33
my  $VERSION = "1.0.0";                     # Update this
34
our $GBE_MAKE_TARGET;
35
my $package_name = 'nsis_packager';
36
 
37
#
38
#   Global variables - Options
39
#
40
my $opt_help = 0;
41
my $opt_verbose = 0;
42
my $opt_ofile;
43
my $opt_installer;
44
my $opt_package;
45
my $opt_plain;
46
 
47
#-------------------------------------------------------------------------------
48
# Function        : Main entry point
49
#
50
# Description     : Parse user arguments
51
#                   Generate metrics
52
#
53
# Inputs          : None
54
#
55
# Returns         : Error code
56
#
57
 
58
my $result = GetOptions (
59
                "help:+"        => \$opt_help,              # flag, multiple use allowed
60
                "manual:3"      => \$opt_help,              # flag
61
                "verbose:+"     => \$opt_verbose,           # flag, multiple use allowed
62
                "outfile:s"     => \$opt_ofile,             # String
63
                "installer:s"   => \$opt_installer,         # String
64
                "package:s"     => \$opt_package,           # String
65
                "plain:+"       => \$opt_plain,             # flag
66
                );
67
 
68
                #
69
                #   UPDATE THE DOCUMENTATION AT THE END OF THIS FILE !!!
70
                #
71
 
72
#
73
#   Process help and manual options
74
#
75
pod2usage(-verbose => 0, -message => "Version: $VERSION") if ($opt_help == 1 || ! $result);
76
pod2usage(-verbose => 1)  if ( $opt_help == 2 );
77
pod2usage(-verbose => 2)  if ( $opt_help > 2 );
78
 
79
ErrorConfig( 'name'    =>'MakeNsisDefs',
80
             'verbose' => $opt_verbose,
81
            );
82
 
83
#
84
#   Sanity check
85
#
86
Error ('No output file specified') unless ( $opt_ofile );
87
Error ('No Installer file specified') unless ( $opt_installer );
88
 
89
#
90
#   Init components
91
#
92
InitFileUtils();
93
EnvImport ('GBE_MAKE_TARGET');
94
 
95
#
96
#   Locate the base of the JATS build
97
#   This will be provided by Makefile.gbe
98
#
99
Verbose ("Locate project root directory");
100
ReadMakeInfo();
101
my $interface_path = "$::ScmRoot/$::ScmInterface";
102
 
103
#
104
#   Read in the global build variables
105
#   Allow package name to be manually set
106
#
107
ReadBuildConfig( $interface_path );
108
$ScmBuildPackage = $opt_package if ( $opt_package );
109
 
110
##
111
##   Show what we have got
112
##
113
#DebugDumpData("InterfaceVersion",       $InterfaceVersion);
114
#DebugDumpData("ScmBuildMachType",       $ScmBuildMachType);
115
#DebugDumpData("ScmInterfaceVersion",    $ScmInterfaceVersion);
116
#DebugDumpData("ScmBuildName",           $ScmBuildName);
117
#DebugDumpData("ScmBuildPackage",        $ScmBuildPackage);
118
#DebugDumpData("ScmBuildVersion",        $ScmBuildVersion);
119
#DebugDumpData("ScmBuildProject",        $ScmBuildProject);
120
#DebugDumpData("ScmBuildVersionFull",    $ScmBuildVersionFull);
121
#DebugDumpData("ScmBuildPreviousVersion",$ScmBuildPreviousVersion);
122
#DebugDumpData("ScmSrcDir",              $ScmSrcDir);
123
#DebugDumpData("ScmLocal",               $ScmLocal);
124
#DebugDumpData("ScmDeploymentPatch",     $ScmDeploymentPatch);
125
#DebugDumpData("ScmBuildSrc",            $ScmBuildSrc);
126
#DebugDumpData("ScmExpert",              $ScmExpert);
127
#DebugDumpData("ScmAll",                 $ScmAll);
128
#DebugDumpData("ScmBuildAliases",        \%ScmBuildAliases);
129
#DebugDumpData("ScmBuildProducts",       \%ScmBuildProducts);
130
#DebugDumpData("ScmBuildPlatforms",      \%ScmBuildPlatforms);
131
#DebugDumpData("ScmBuildPkgRules",       \%ScmBuildPkgRules);
132
#DebugDumpData("BUILDPLATFORMS",         \@BUILDPLATFORMS);
133
#DebugDumpData("DEFBUILDPLATFORMS",      \@DEFBUILDPLATFORMS);
134
#DebugDumpData("BUILDTOOLSPATH",         \@BUILDTOOLSPATH);
135
#DebugDumpData("BUILDPLATFORM_PARTS",    \%BUILDPLATFORM_PARTS);
136
#DebugDumpData("BUILDINFO",              \%BUILDINFO);
137
#DebugDumpData("BUILD_KNOWNFILES",       \%BUILD_KNOWNFILES);
138
 
139
#
140
#   Create the required file and insert data
141
#
142
my $fh = ConfigurationFile::New( $opt_ofile, '--Type=NSIS' );
143
$fh->HeaderSimple( 'MakeNsisDefs',
144
                   'NSIS Version Definitions' );
145
 
146
writeCmt( $fh, 'Build Package Information');
147
writeDef ($fh, 'GBE_BUILDNAME', $ScmBuildName );
148
writeDef ($fh, 'GBE_PACKAGE',   $ScmBuildPackage );
149
writeDef ($fh, 'GBE_VERSION',   $ScmBuildVersion );
150
writeDef ($fh, 'GBE_VERSION_FULL', $ScmBuildVersionFull );
151
writeDef ($fh, 'GBE_PROJECT',   $ScmBuildProject );
152
writeDef ($fh, 'GBE_BUILDDATE', my $ltime = localtime() );
153
writeDef ($fh, 'GBE_BUILDTIME', strip_zeros(time()) );
154
 
155
writeCmt( $fh, 'Build Version Information');
156
my ($major, $minor, $patch, $build, $raw_patch) = SplitVersion($ScmBuildVersion);
157
$build = strip_zeros( $build );
158
writeDef ($fh, 'GBE_MAJOR', $major );
159
writeDef ($fh, 'GBE_MINOR', $minor );
160
writeDef ($fh, 'GBE_PATCH', $patch );
161
writeDef ($fh, 'GBE_BUILD', $build );
162
 
163
unless ( $opt_plain )
164
{
165
    writeCmt( $fh, 'Versioning information for the generated EXE',
166
                'User MUST provide:',
167
                '     FileDescription',
168
                'User CAN provide:',
169
                '     ProductName',
170
                '     Comments',
171
                '     Other Random Fields');
172
    writeCmd( $fh,  'VIProductVersion', "$major.$minor.$patch.$build");
173
    writeCmd( $fh,  'VIAddVersionKey',  'CompanyName', 'Vix ERG');
174
    writeCmd( $fh,  '#VIAddVersionKey',  'FileDescription', 'Describe the Installer');
175
    writeCmd( $fh,  'VIAddVersionKey',  'LegalTrademarks', 'Vix ERG is a Vix Technology company');
176
    writeCmd( $fh,  'VIAddVersionKey',  'LegalCopyright', 'Vix ERGĀ©');
177
    writeCmd( $fh,  'VIAddVersionKey',  'FileVersion', "$major.$minor.$patch.$build");
178
}
179
 
180
#
181
#   Provide path information to important parts of the build system
182
#
183
writeCmt( $fh, 'Paths to build directories');
184
writeDef( $fh, 'GBE_ROOT', WindowsPath($ScmRoot) );
185
writeDef( $fh, 'GBE_INTERFACE', WindowsPath($interface_path) );
186
writeDef( $fh, 'GBE_LOCAL', WindowsPath("$ScmRoot/$ScmLocal") );
187
 
188
#
189
#   Some are added at runtime
190
#
191
writeCmt( $fh, 'Added at runtime',
192
               '!define GBE_BINDIR xxx',
193
               '!define GBE_OBJDIR xxx',
194
               '!define GBE_LIBDIR xxx',
195
               '!define GBE_TARGET xxx',
196
               '!define GBE_TYPE xxx',
197
               );
198
 
199
#
200
#   For each link package that is present provide
201
#       package path
202
#       package version
203
#
204
my $my_entry;
205
writeCmt( $fh, 'Paths to external dependent packages');
206
foreach my $entry (@{$ScmBuildPkgRules{$GBE_MAKE_TARGET} })
207
{
208
    $my_entry = $entry if ( $entry->{'NAME'} eq $package_name );
209
    next unless ( $entry->{'TYPE'} eq 'link' );
210
    writeCmt( $fh, "Package: $entry->{'NAME'}");
211
    writeDef( $fh, 'GBE_PKG_PATH_' . $entry->{'NAME'}, WindowsPath($entry->{'ROOT'}) );
212
    writeDef( $fh, 'GBE_PKG_VERSION_' . $entry->{'NAME'}, $entry->{'DVERSION'} );
213
}
214
 
215
#
216
#   Define the base of the data files provided with this package
217
#
218
writeCmt( $fh, "NSIS_PACKAGER data files");
219
if ( $my_entry )
220
{
221
    my $path = ($my_entry->{'TYPE'} eq 'link' ) ? $my_entry->{'ROOT'} : $interface_path;
222
    writeDef( $fh, 'GBE_NSISDATA', WindowsPath("$path/etc") );
223
}
224
else
225
{
226
    Error ("Internal: Cannot find myself in referenced packages",
227
           "Perhaps the package name has been changed",
228
           "Looking for: $package_name");
229
}
230
 
231
#
232
#   Determine if there are any suitable NSIS plugin dirs
233
#   Scan interface and packages
234
#
235
my @nsis_tools;
236
foreach my $entry (@{$ScmBuildPkgRules{$GBE_MAKE_TARGET} })
237
{
238
    my $tdir = $entry->{'ROOT'} . '/tools/scripts/nsis';
239
    if ( -d $tdir )
240
    {
241
        push @nsis_tools, $tdir;
242
    }
243
}
244
writeCmt( $fh, "Extend NSIS Include Search Path");
245
writeCmd( $fh, '!addincludedir', WindowsPath($_) ) foreach @nsis_tools;
246
 
247
#
248
#   Specify the output file
249
#   This will be written directly into the output package
250
#
251
writeCmt( $fh, 'Set output file');
252
writeCmd( $fh,'OutFile', WindowsPath("\${GBE_BINDIR}/$opt_installer") );
253
 
254
unless ( $opt_plain )
255
{
256
    writeCmt( $fh, 'Name, Branding and Caption');
257
    writeCmd( $fh, 'Name', "$ScmBuildPackage ($ScmBuildVersionFull)" );
258
    writeCmd( $fh, 'BrandingText', 'Vix ERG' );
259
    writeCmd( $fh, 'Caption', $ScmBuildPackage );
260
}
261
 
262
$fh->Write( "\n");
263
$fh->Close();
264
 
265
#-------------------------------------------------------------------------------
266
# Function        : writeDef
267
#
268
# Description     : Write a Text definition to the output file
269
#
270
# Inputs          : $fh         - File Handle
271
#                   $name       - Name of variable
272
#                   $text       - Text
273
#
274
# Returns         : 
275
#
276
sub writeDef
277
{
278
    my ($fh, $name, $text ) = @_;
279
    $fh->WriteLn( "!define $name \"$text\"" );
280
}
281
 
282
#-------------------------------------------------------------------------------
283
# Function        : writeCmd
284
#
285
# Description     : Write a Cmd to the output file
286
#
287
# Inputs          : $fh         - File Handle
288
#                   $cmd        - Name of command
289
#                   @text       - text items to quote
290
#
291
# Returns         : 
292
#
293
sub writeCmd
294
{
295
    my ($fh, $cmd, @text ) = @_;
296
    $fh->Write( $cmd );
297
    $fh->Write( " \"" . $_ . "\"" ) foreach ( @text );
298
    $fh->Write( "\n" );
299
}
300
 
301
#-------------------------------------------------------------------------------
302
# Function        : writeCmt
303
#
304
# Description     : Write a writeCmt block
305
#
306
# Inputs          : $fh         - File Handle
307
#                   @text       - Lines to output in a writeCmt
308
#
309
# Returns         : 
310
#
311
sub writeCmt
312
{
313
    my ($fh, @text ) = @_;
314
 
315
    $fh->Write( "\n");
316
    $fh->Comment( "\n");
317
    $fh->Comment( $_ . "\n") foreach ( @text );
318
    $fh->Comment( "\n");
319
}
320
 
321
 
322
#-------------------------------------------------------------------------------
323
# Function        : stip_zeros
324
#
325
# Description     : Remove leading 0's from a string
326
#
327
# Inputs          : A string
328
#
329
# Returns         : A string without leading zeros
330
#
331
sub strip_zeros
332
{
333
    my ($text) = @_;
334
 
335
    $text =~ s~^0*~~;
336
    $text = '0' unless ( $text );
337
    return $text;
338
}
339
 
340
#-------------------------------------------------------------------------------
341
# Function        : WindowsPath
342
#
343
# Description     : Convert a path into one that is suitable for Windows
344
#                       Must be absolue
345
#                       Must have \
346
#
347
# Inputs          : $path       - Path to clean
348
#
349
# Returns         : Cleaned path
350
#
351
sub WindowsPath
352
{
353
    my ($path) = @_;
354
    $path = FullPath($path) unless ($path =~ m~^\$~);
355
    $path =~ tr~/~\\~s;
356
    return $path;
357
}
358
 
359
 
360