Subversion Repositories DevTools

Rev

Rev 4941 | Details | Compare with Previous | Last modification | View Log | RSS feed

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