Subversion Repositories DevTools

Rev

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