Subversion Repositories DevTools

Rev

Rev 1145 | Rev 4941 | 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 );
223
    next unless ( $entry->{'TYPE'} eq 'link' );
224
    writeCmt( $fh, "Package: $entry->{'NAME'}");
225
    writeDef( $fh, 'GBE_PKG_PATH_' . $entry->{'NAME'}, WindowsPath($entry->{'ROOT'}) );
226
    writeDef( $fh, 'GBE_PKG_VERSION_' . $entry->{'NAME'}, $entry->{'DVERSION'} );
227
}
228
 
229
#
230
#   Define the base of the data files provided with this package
231
#
232
writeCmt( $fh, "NSIS_PACKAGER data files");
233
if ( $my_entry )
234
{
235
    my $path = ($my_entry->{'TYPE'} eq 'link' ) ? $my_entry->{'ROOT'} : $interface_path;
236
    writeDef( $fh, 'GBE_NSISDATA', WindowsPath("$path/etc") );
237
}
238
else
239
{
240
    Error ("Internal: Cannot find myself in referenced packages",
241
           "Perhaps the package name has been changed",
242
           "Looking for: $package_name");
243
}
244
 
245
#
246
#   Determine if there are any suitable NSIS plugin dirs
247
#   Scan interface and packages
248
#
249
my @nsis_tools;
1443 dpurdie 250
my @nsis_plugins;
1139 dpurdie 251
foreach my $entry (@{$ScmBuildPkgRules{$GBE_MAKE_TARGET} })
252
{
253
    my $tdir = $entry->{'ROOT'} . '/tools/scripts/nsis';
1443 dpurdie 254
    push @nsis_tools, $tdir if ( -d $tdir );
255
 
256
    my $pdir = $entry->{'ROOT'} . '/tools/bin/win32/nsis';
257
    push @nsis_plugins, $pdir if ( -d $pdir );
1139 dpurdie 258
}
259
writeCmt( $fh, "Extend NSIS Include Search Path");
260
writeCmd( $fh, '!addincludedir', WindowsPath($_) ) foreach @nsis_tools;
1443 dpurdie 261
writeCmd( $fh, '!addplugindir', WindowsPath($_) ) foreach @nsis_plugins;
1139 dpurdie 262
 
263
#
264
#   Specify the output file
265
#   This will be written directly into the output package
266
#
267
writeCmt( $fh, 'Set output file');
268
writeCmd( $fh,'OutFile', WindowsPath("\${GBE_BINDIR}/$opt_installer") );
269
 
270
unless ( $opt_plain )
271
{
272
    writeCmt( $fh, 'Name, Branding and Caption');
273
    writeCmd( $fh, 'Name', "$ScmBuildPackage ($ScmBuildVersionFull)" );
1145 dpurdie 274
    writeCmd( $fh, 'BrandingText', $CompanyName );
1139 dpurdie 275
    writeCmd( $fh, 'Caption', $ScmBuildPackage );
276
}
277
 
278
$fh->Write( "\n");
279
$fh->Close();
280
 
281
#-------------------------------------------------------------------------------
282
# Function        : writeDef
283
#
284
# Description     : Write a Text definition to the output file
285
#
286
# Inputs          : $fh         - File Handle
287
#                   $name       - Name of variable
288
#                   $text       - Text
289
#
290
# Returns         : 
291
#
292
sub writeDef
293
{
294
    my ($fh, $name, $text ) = @_;
295
    $fh->WriteLn( "!define $name \"$text\"" );
296
}
297
 
298
#-------------------------------------------------------------------------------
299
# Function        : writeCmd
300
#
301
# Description     : Write a Cmd to the output file
302
#
303
# Inputs          : $fh         - File Handle
304
#                   $cmd        - Name of command
305
#                   @text       - text items to quote
306
#
307
# Returns         : 
308
#
309
sub writeCmd
310
{
311
    my ($fh, $cmd, @text ) = @_;
312
    $fh->Write( $cmd );
313
    $fh->Write( " \"" . $_ . "\"" ) foreach ( @text );
314
    $fh->Write( "\n" );
315
}
316
 
317
#-------------------------------------------------------------------------------
318
# Function        : writeCmt
319
#
320
# Description     : Write a writeCmt block
321
#
322
# Inputs          : $fh         - File Handle
323
#                   @text       - Lines to output in a writeCmt
324
#
325
# Returns         : 
326
#
327
sub writeCmt
328
{
329
    my ($fh, @text ) = @_;
330
 
331
    $fh->Write( "\n");
332
    $fh->Comment( "\n");
333
    $fh->Comment( $_ . "\n") foreach ( @text );
334
    $fh->Comment( "\n");
335
}
336
 
337
 
338
#-------------------------------------------------------------------------------
339
# Function        : stip_zeros
340
#
341
# Description     : Remove leading 0's from a string
342
#
343
# Inputs          : A string
344
#
345
# Returns         : A string without leading zeros
346
#
347
sub strip_zeros
348
{
349
    my ($text) = @_;
350
 
351
    $text =~ s~^0*~~;
352
    $text = '0' unless ( $text );
353
    return $text;
354
}
355
 
356
#-------------------------------------------------------------------------------
357
# Function        : WindowsPath
358
#
359
# Description     : Convert a path into one that is suitable for Windows
360
#                       Must be absolue
361
#                       Must have \
362
#
363
# Inputs          : $path       - Path to clean
364
#
365
# Returns         : Cleaned path
366
#
367
sub WindowsPath
368
{
369
    my ($path) = @_;
370
    $path = FullPath($path) unless ($path =~ m~^\$~);
371
    $path =~ tr~/~\\~s;
372
    return $path;
373
}
374
 
375
 
376