Subversion Repositories DevTools

Rev

Rev 1143 | 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 );
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;
250
foreach my $entry (@{$ScmBuildPkgRules{$GBE_MAKE_TARGET} })
251
{
252
    my $tdir = $entry->{'ROOT'} . '/tools/scripts/nsis';
253
    if ( -d $tdir )
254
    {
255
        push @nsis_tools, $tdir;
256
    }
257
}
258
writeCmt( $fh, "Extend NSIS Include Search Path");
259
writeCmd( $fh, '!addincludedir', WindowsPath($_) ) foreach @nsis_tools;
260
 
261
#
262
#   Specify the output file
263
#   This will be written directly into the output package
264
#
265
writeCmt( $fh, 'Set output file');
266
writeCmd( $fh,'OutFile', WindowsPath("\${GBE_BINDIR}/$opt_installer") );
267
 
268
unless ( $opt_plain )
269
{
270
    writeCmt( $fh, 'Name, Branding and Caption');
271
    writeCmd( $fh, 'Name', "$ScmBuildPackage ($ScmBuildVersionFull)" );
1145 dpurdie 272
    writeCmd( $fh, 'BrandingText', $CompanyName );
1139 dpurdie 273
    writeCmd( $fh, 'Caption', $ScmBuildPackage );
274
}
275
 
276
$fh->Write( "\n");
277
$fh->Close();
278
 
279
#-------------------------------------------------------------------------------
280
# Function        : writeDef
281
#
282
# Description     : Write a Text definition to the output file
283
#
284
# Inputs          : $fh         - File Handle
285
#                   $name       - Name of variable
286
#                   $text       - Text
287
#
288
# Returns         : 
289
#
290
sub writeDef
291
{
292
    my ($fh, $name, $text ) = @_;
293
    $fh->WriteLn( "!define $name \"$text\"" );
294
}
295
 
296
#-------------------------------------------------------------------------------
297
# Function        : writeCmd
298
#
299
# Description     : Write a Cmd to the output file
300
#
301
# Inputs          : $fh         - File Handle
302
#                   $cmd        - Name of command
303
#                   @text       - text items to quote
304
#
305
# Returns         : 
306
#
307
sub writeCmd
308
{
309
    my ($fh, $cmd, @text ) = @_;
310
    $fh->Write( $cmd );
311
    $fh->Write( " \"" . $_ . "\"" ) foreach ( @text );
312
    $fh->Write( "\n" );
313
}
314
 
315
#-------------------------------------------------------------------------------
316
# Function        : writeCmt
317
#
318
# Description     : Write a writeCmt block
319
#
320
# Inputs          : $fh         - File Handle
321
#                   @text       - Lines to output in a writeCmt
322
#
323
# Returns         : 
324
#
325
sub writeCmt
326
{
327
    my ($fh, @text ) = @_;
328
 
329
    $fh->Write( "\n");
330
    $fh->Comment( "\n");
331
    $fh->Comment( $_ . "\n") foreach ( @text );
332
    $fh->Comment( "\n");
333
}
334
 
335
 
336
#-------------------------------------------------------------------------------
337
# Function        : stip_zeros
338
#
339
# Description     : Remove leading 0's from a string
340
#
341
# Inputs          : A string
342
#
343
# Returns         : A string without leading zeros
344
#
345
sub strip_zeros
346
{
347
    my ($text) = @_;
348
 
349
    $text =~ s~^0*~~;
350
    $text = '0' unless ( $text );
351
    return $text;
352
}
353
 
354
#-------------------------------------------------------------------------------
355
# Function        : WindowsPath
356
#
357
# Description     : Convert a path into one that is suitable for Windows
358
#                       Must be absolue
359
#                       Must have \
360
#
361
# Inputs          : $path       - Path to clean
362
#
363
# Returns         : Cleaned path
364
#
365
sub WindowsPath
366
{
367
    my ($path) = @_;
368
    $path = FullPath($path) unless ($path =~ m~^\$~);
369
    $path =~ tr~/~\\~s;
370
    return $path;
371
}
372
 
373
 
374