Subversion Repositories DevTools

Rev

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