Subversion Repositories DevTools

Rev

Rev 2434 | 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   : nsisDirective.pm
5
# Module type   : Makefile system
6
# Compiler(s)   : Perl
7
# Environment(s): jats
8
#
9
# Description   : Provides the 'nsisDirective' directive to JATS
10
#
11
# Usage         : See Below
12
#
13
#......................................................................#
14
 
15
require 5.008_002;
16
use strict;
17
use warnings;
18
use JatsError;
19
 
20
our $ScmPlatform;                       # Target Platform
21
 
2314 dpurdie 22
 
23
#
24
#   Directive specific globals
25
#
2326 dpurdie 26
my $MakeNsisPackage_count = 1;          # Suffix for multiple generated files
2314 dpurdie 27
my %MakeNsisPackage_names;              # Hash of used output names
28
 
1139 dpurdie 29
#-------------------------------------------------------------------------------
30
# Function        : MakeNsisPackage
31
#
32
# Description     : This directive supports the building of Windows Installers
33
#                   using NSIS. This is a script driven application
34
#
35
# Inputs          : $platform   - Pltaform selector
36
#                   @elements   - Options and arguments
37
#
38
#                   Valid Options and Arguments
39
#                       --Script=Name           - Specifies the script to use
40
#                                                 Multiple allowed
41
#                       --Verbose=n             - Specifies verbosity
42
#                       --Output=Name           - Specifies the output EXE
43
#                                                 Defaults to useful name
44
#                       --Define=Name=Value     - Send to compiler
45
#                       --Package=Name          - Use this package name instead
46
#                                                 of the build's name.
47
#                                                 Not suggested
48
#                       --Plain                 - No frills
2326 dpurdie 49
#                       --NoPackage             - Do not package the installer
6419 dpurdie 50
#                       --RecipeTag=name        - Tag this recipe
51
#                       --PkgArch=arch          - Override default architecture
52
#                                                 Default WIN32 or X64
1139 dpurdie 53
#
54
#
55
# Returns         : Will not return on error
56
#
57
 
58
sub MakeNsisPackage
59
{
60
    my( $platforms, @elements ) = @_;
61
    my @scripts;
62
    my $vlevel = 2;
63
    my $ofile;
64
    my @defines;
65
    my @genargs;
66
    my $package = $ScmBuildPackage;
2326 dpurdie 67
    my $noPackage;
6419 dpurdie 68
    my @passThroughArgs;
69
    my $pkgArch = GetGlobalOption('PACKAGE_ARCH', 'WIN32');
1139 dpurdie 70
 
71
    return if ( ! ActivePlatform($platforms) );
72
 
73
    #
74
    #   Parse the command line arguments
75
    #
76
    foreach ( @elements )
77
    {
78
        if ( m~^--Script=(.+)~i ) {
79
            push @scripts, $1;
80
 
81
        } elsif  ( m~^--Verbose=(\d+)~i ) {
82
            $vlevel = $1;
83
 
84
        } elsif  ( m~^--Output=(.+)~i ) {
85
            $ofile = $1;
86
 
87
        } elsif  ( m~^--Define=(.+)~i ) {
88
            push @defines, $1;
89
 
90
        } elsif  ( m~^--Plain~i ) {
91
            push @genargs, '-Plain';
92
 
93
        } elsif  ( m~^--Package=(.+)~i ) {
94
            push @genargs, '-Package=' . $1;
95
            $package = $1;
2326 dpurdie 96
 
97
        } elsif  ( m~^--NoPackage~i ) {
98
            $noPackage = 1;
1139 dpurdie 99
 
6419 dpurdie 100
        } elsif  ( m~^--RecipeTag=~i ) {
101
            push @passThroughArgs, $_;
102
 
103
        } elsif  ( m~^--PkgArch=(.+)~i ) {
104
            $pkgArch = $1;
105
 
106
 
1139 dpurdie 107
        } else {
108
            Warning ("nsisDirective: Unknown option ignored: $_");
109
        }
110
    }
111
 
112
    #
113
    #   Sanity Tests
114
    #
115
    Error ("nsisDirective: No script specified" ) unless ( @scripts );
6419 dpurdie 116
    Error ("PkgArch is not specified") unless (defined $pkgArch && (length($pkgArch)  > 0));
1139 dpurdie 117
    $vlevel = 4 if ( $vlevel > 4 );
118
    $vlevel = 0 if ( $vlevel < 0 );
119
 
120
    #
121
    #   Create a 'nice' executable name, unless one has been provided
122
    #   Could have ${GBE_TYPE} suffix, but other windows installers don't
123
    #
124
    #   Note: Fix platform to WIN32 incase the installer is based on other
125
    #         platforms (ie: VS2005) as that would be most confusing.
126
    #         Could be based on machine type.
127
    #
6419 dpurdie 128
    $ofile = "$package-$ScmBuildVersion.$ScmBuildProject-$pkgArch"
2314 dpurdie 129
        unless ( $ofile );
130
    $ofile .= '.exe'
131
        unless ( $ofile =~ m~\.exe$~i );
132
    Error ("MakeNsisPackage. Multiple packages with the same name: $ofile")
133
        if ( exists $MakeNsisPackage_names{$ofile} );
1139 dpurdie 134
 
135
    #
2314 dpurdie 136
    #   Create unique file name for the jats-generated file
2326 dpurdie 137
    #   Include the name of the first script
2314 dpurdie 138
    #
2326 dpurdie 139
    my $dfile = $scripts[0];
140
    $dfile =~ s~^.*/~~;
141
    $dfile =~ s~\..*?$~~;
142
    $dfile = 'JatsNsisDefs'. $MakeNsisPackage_count++ . '_' . $dfile . '.nsh';
2314 dpurdie 143
    $MakeNsisPackage_names{$ofile} = $dfile;
144
 
145
    #
1139 dpurdie 146
    #   Create build time values in a file suitable for NSIS to include
147
    #
6419 dpurdie 148
    push @genargs, '-PkgArch=' . $pkgArch;
1139 dpurdie 149
    GenerateFiles ('*', '--Tool=MakeNsisDefs.pl',
150
                   '-installer=' . $ofile,
151
                   @genargs,
2314 dpurdie 152
                   '-out=--Generated('.$dfile.')' );
1139 dpurdie 153
 
154
    #
2434 dpurdie 155
    #   Invoke 'makensis' to do the hard work
1139 dpurdie 156
    #
157
    GenerateFiles ('*', 'makensis' ,
2434 dpurdie 158
                        $noPackage ? '--NoGenerate' : '--AutoGenerate',
159
                        '--Text=' . $ofile,
6419 dpurdie 160
                        @passThroughArgs,
1139 dpurdie 161
                        '--NoVarTag',
162
                        '--UnknownPreq',
163
                        '--CreatedProg='. $ofile,
164
                        '/NOCONFIG',
165
                        '/NOCD',
166
                        '--Var(BinDir,--tag=/DGBE_BINDIR)',
167
                        '--Var(ObjDir,--tag=/DGBE_OBJDIR)',
168
                        '--Var(Target,--tag=/DGBE_TARGET)',
169
                        '--Var(Type,--tag=/DGBE_TYPE)',
170
                        (map { '/D' . $_ } @defines),
171
                        '/V' . $vlevel,
2314 dpurdie 172
                        '--Prerequisite('.$dfile.')',
1139 dpurdie 173
                        map { '--Prerequisite('.$_. ')' } @scripts,
174
                        );
175
 
176
    # Package up the EXE
177
    #
2326 dpurdie 178
    PackageFile ('*', $ofile )
179
        unless $noPackage;
1139 dpurdie 180
 
181
}
182
 
2314 dpurdie 183
1;