Subversion Repositories DevTools

Rev

Rev 6490 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
407 dpurdie 1
########################################################################
6242 dpurdie 2
# COPYRIGHT - VIX IP PTY LTD ("VIX"). ALL RIGHTS RESERVED.
407 dpurdie 3
#
4
# Module name   : jats.sh
5
# Module type   : Makefile system
6
# Compiler(s)   : n/a
7
# Environment(s): jats
8
#
9
# Description   : This package extends the JATS toolset at build time
10
#                 It provides additional directives to the JATS makefiles
11
#                 to simplify the directives.
12
#
13
#                 The directive matches up with a run-time tool to
14
#                 do the bulk of the work.
15
#
16
# Operation     : This package adds the JATS directive MakeDebianPackage
17
#                 When used the directive will use GenerateFiles to invoke
18
#                 a script (DebianPackager.pl) to actually do the hard work.
19
#
20
# Syntax        : MakeDebianPackage (<platforms>, Options+);
21
#                 Where Options may be one of:
6242 dpurdie 22
#                   --Script=PackagerScript             - Mandatory. Name of a the packaging script
4188 dpurdie 23
#                   --Name=Name                         - Debian Package name(optional)
24
#                   --Variant=Text                      - Package Variant(optional)
25
#                   --DeployMode                        - Create Deployable packages(optional)
4907 dpurdie 26
#                                                         Default for native targets
4188 dpurdie 27
#                                                         These are:
28
#                                                           * Packaged into the root of target pkg
29
#                                                           * Have P or D in the name
5857 dpurdie 30
#                   --NoDeployMode                      - Create packages that cannot be directly deployed
5215 dpurdie 31
#                                                         Default for embedded devices
6242 dpurdie 32
#                   --TarFile[=TemplateName]            - Create named .tgz file, of the data area [not Debian scripts]
4740 dpurdie 33
#                   --TarFile                           - Same as --TarFile=PACKAGE_VERSION_PLATFORM_TYPE or PACKAGE_VERSION_PLATFORM
6242 dpurdie 34
#                   --TarOnly                           - Suppress the Debian Build
5215 dpurdie 35
#                   --NoArch                            - Marks the package as having no specific architecture
6242 dpurdie 36
#                   
37
#
38
#               Templates may contain:
39
#                   PACKAGE
40
#                   VARIANT
41
#                   VERSION
42
#                   PLATFORM
43
#                   TYPE
44
#                   ARCH
4740 dpurdie 45
#                       
407 dpurdie 46
#......................................................................#
47
 
409 alewis 48
require 5.006_001;
407 dpurdie 49
#use strict;
50
use warnings;
6242 dpurdie 51
#use PackagerUtils;
407 dpurdie 52
 
53
#-------------------------------------------------------------------------------
54
# Function        : MakeDebianPackage
55
#
56
# Description     : Create a Debian Package
57
#
4188 dpurdie 58
# Inputs          : See above
407 dpurdie 59
#
4188 dpurdie 60
# Returns         : Nothing 
407 dpurdie 61
#
62
sub MakeDebianPackage
63
{
64
    my( $platforms, @elements ) = @_;
65
    Debug2( "MakeDebianPackage($platforms, @elements)" );
66
    return if ( ! ActivePlatform($platforms) );
67
 
68
    my $build_name =  $::ScmBuildPackage;
69
    my $build_version = $::ScmBuildVersionFull;
417 dpurdie 70
    my $build_variant = '';
407 dpurdie 71
 
417 dpurdie 72
    my $name_set=0;
73
    my $variant_set=0;
6242 dpurdie 74
 
4907 dpurdie 75
    my $deploy_mode = GetGlobalOption('DEBIAN_PACKAGE_DEPLOYABLE', 0);
417 dpurdie 76
 
6242 dpurdie 77
    my $tarOnly;
4740 dpurdie 78
    my $tarFileName = '';
79
    my @outputFiles;
80
    my @optArgs;
5215 dpurdie 81
    my $noArch;
4740 dpurdie 82
 
6242 dpurdie 83
    my @arglist;
84
    my $rpmScript;
85
    my $debianScript;
407 dpurdie 86
    my $script;
87
 
88
    #
89
    #   Collect user arguments
90
    #   They are all processed within the toolset
91
    #
92
    foreach ( @elements )
93
    {
6242 dpurdie 94
        push @arglist, $_;
407 dpurdie 95
 
6242 dpurdie 96
        if ( m/^--Script=(.+)/i ) {
97
            ReportError ("MakeDebianPackage: --Script. Debian script name already set") if $debianScript;
98
            ReportError ("MakeDebianPackage: --Script. RPM script name already set") if $rpmScript;
99
            $debianScript = $1;
100
            $rpmScript = $1;
101
            pop @arglist;
102
 
103
        } elsif ( m/^--RpmScript=(.+)/i ) {
104
            ReportError ("MakeDebianPackage: --RpmScript. RPM script name already set") if $rpmScript;
105
            $rpmScript = $1;
106
            pop @arglist;
107
 
108
        } elsif ( m/^--DebianScript=(.+)/i ) {
109
            ReportError ("MakeDebianPackage: --DebianScript. Debian script name already set") if $debianScript;
110
            $debianScript = $1;
111
            pop @arglist;
112
 
113
        } elsif ( m/^--Name=(.+)/i ) {
417 dpurdie 114
            $build_name = $1;
115
            $name_set++;
116
 
6242 dpurdie 117
        } elsif ( m/^--Variant=(.+)/i ) {
417 dpurdie 118
            $build_variant = $1;
119
            $variant_set++;
4188 dpurdie 120
 
6242 dpurdie 121
        } elsif ( m/^--(No)?DeployMode/i ) {
122
            $deploy_mode = ! defined($1);
4907 dpurdie 123
 
6242 dpurdie 124
        } elsif ( m/^--NoArch$/i ) {
5215 dpurdie 125
            $noArch = 1;
126
 
6242 dpurdie 127
        } elsif ( m/^--TarOnly$/i ) {
128
            $tarOnly = 1;
129
 
130
        } elsif ( m/^--TarFile(=(.*))?/i ) {
131
            $tarFileName = defined($1) ? $2 : 'DEFAULT';
4740 dpurdie 132
 
407 dpurdie 133
        } elsif ( m/^--/ ) {
6242 dpurdie 134
            ReportError("MakeDebianPackage. Unknown option: $_");
407 dpurdie 135
 
136
        } else {
6242 dpurdie 137
            ReportError("MakeDebianPackage. Unknown argument: $_");
407 dpurdie 138
        }
139
    }
140
 
141
    #
142
    #   Sanity test
143
    #
6242 dpurdie 144
    ReportError ("MakeDebianPackage: Not supported on a GENERIC target") if ( $ScmPlatform eq 'GENERIC' );
145
    ReportError ("MakeDebianPackage: Script name not defined") unless ( $debianScript || $rpmScript );
146
    ReportError ("MakeDebianPackage: --Name option can only be used once") if ( $name_set > 1 );
147
    ReportError ("MakeDebianPackage: --Variant option can only be used once") if ( $variant_set > 1 );
148
    ErrorDoExit();
407 dpurdie 149
 
417 dpurdie 150
    #
6242 dpurdie 151
    #   Determine what we are really doing
152
    #       Under Redhat we will generate an RPM
153
    #
154
    if ( ActivePlatform('PKG_RPM') ) {
155
        return unless (defined $rpmScript);
156
        return MakeRpmPackage ($platforms, "--Script=$rpmScript", @arglist );
157
    }
158
 
159
    return unless (defined $debianScript);
160
    $script = $debianScript;
161
    ErrorDoExit();
162
 
163
 
164
    #
165
    #   If the platform cannot generate a native installer then (silently) ignore the request
166
    #   unless the user has specified a --TarOnly
167
    #
168
    my $canGenerateInstaller = ActivePlatform('PKG_DEB');
169
    if ( !$canGenerateInstaller && !$tarOnly) {
170
        Verbose ("MakeDebianPackage: Installer not builadble for this platform");
171
        return;
172
    }
173
 
174
    #
417 dpurdie 175
    #   Build up the build name
176
    #       Add variant to base name.
177
    #
178
    if ( $build_variant )
179
    {
180
        $build_name .= '-' . $build_variant;
181
    }
407 dpurdie 182
 
183
    #
184
    #   Sanity check the package name and version
6242 dpurdie 185
    #   Debian has stricter requirements than JATS
407 dpurdie 186
    #       Name:    Lower case letters (a-z), digits (0-9), plus (+) and minus (-) signs, and periods (.).
187
    #                Release Manager does not allow '.'
188
    #       Version: alphanumerics and the characters . + - : (full stop, plus, hyphen, colon) and should start with a digit
189
    #
409 alewis 190
    #   Allow ( and cleanup )
191
    #       ERGxxxxx    -> erg-xxx
427 dpurdie 192
    #       VIXxxxxx    -> vix-xxx
193
    #       Whitespace   -> -
409 alewis 194
    #       _           -> -
427 dpurdie 195
    #       Remove multiple '-' characters
196
    #       Lowercase all text
409 alewis 197
    #
407 dpurdie 198
 
6242 dpurdie 199
    #
200
    #   Convert the build_name to a form that is Debian complient
201
    #
202
    $build_name = canonicalName ($build_name, 'Debian');
409 alewis 203
 
6242 dpurdie 204
    #
205
    #   Sanity test the version information
206
    #   
407 dpurdie 207
    unless ( $::ScmBuildVersionFull =~ m/^[0-9][-+:.A-Za-z0-9]+$/ )
208
    {
209
        Error ("Package Version does not conform to Debian Requirements",
210
               "Must only contain: (a-zA-Z) (0-9), - and .",
5215 dpurdie 211
               "Must start with a number",
407 dpurdie 212
               );
213
    }
214
 
215
    #
216
    #   Create the name of the target package
217
    #   The form of the name is of a fixed form.
218
    #
219
    #   Note: "_" used since this is the format of dpkg-name
4188 dpurdie 220
    #   Note: dpkg-name generates: Name _ Version _ Architecture [ _ Type ]
407 dpurdie 221
    #
222
    #
4188 dpurdie 223
    my $PkgType = $deploy_mode ? ( '_' . '$(GBE_TYPE)' ) : '' ;
6242 dpurdie 224
    my $PkgArch = GetGlobalOption('PACKAGE_ARCH', $::ScmPlatform);
225
    my $Platform = $::ScmPlatform;
226
        if ($noArch) {
227
            $PkgArch = 'all';
228
            $Platform = 'all';
229
            $PkgType = '';
230
            push @optArgs, "-NoArch";
231
        }
4740 dpurdie 232
 
6242 dpurdie 233
    my $PkgName = "${build_name}_${::ScmBuildVersionFull}_${Platform}${PkgType}.deb";
234
    push @optArgs, "-PkgArch=$PkgArch";
6531 dpurdie 235
    unless ($tarOnly) {
236
        push (@outputFiles, $PkgName);
237
        push @optArgs, "-Output=--GeneratedProg{$PkgName}";
238
    }
6242 dpurdie 239
 
407 dpurdie 240
    #
4740 dpurdie 241
    #   Create name for the optional TGZ file
6242 dpurdie 242
    #       Allow user to specify parts of the name symbolically
4740 dpurdie 243
    #
244
    if ($tarFileName)
245
    {
246
        if ($tarFileName eq 'DEFAULT')
247
        {
248
            $tarFileName = 'PACKAGE_VERSION_PLATFORM';
5215 dpurdie 249
            if ($deploy_mode && ! $noArch)
4740 dpurdie 250
            {
251
                $tarFileName .= '_TYPE';
252
            }
253
        }
254
 
6242 dpurdie 255
        if ($noArch) {
256
            $PkgArch = 'all';
257
        }
258
 
4740 dpurdie 259
        $tarFileName =~ s~PACKAGE~${build_name}~g;
260
        $tarFileName =~ s~VERSION~${::ScmBuildVersionFull}~g;
6242 dpurdie 261
        $tarFileName =~ s~PLATFORM~${Platform}~g;
262
        $tarFileName =~ s~ARCH~${PkgArch}~g;
4740 dpurdie 263
        $tarFileName =~ s~TYPE~\$(GBE_TYPE)~;
6242 dpurdie 264
        $tarFileName .= '.tgz' unless $tarFileName =~ m~\.tgz$~;
4740 dpurdie 265
        push @outputFiles,  $tarFileName;
6242 dpurdie 266
 
6531 dpurdie 267
        push @optArgs, "-TarFile=--GeneratedProg{$tarFileName}";
268
#        push @optArgs, "-TarFile=$tarFileName";
6242 dpurdie 269
        push (@optArgs, '-TarOnly' ) if $tarOnly;
4740 dpurdie 270
    }
271
 
272
    #
407 dpurdie 273
    #   Simply use Generate Files
6242 dpurdie 274
    #       With lots of options
407 dpurdie 275
    #
276
    Src ( '*', $script );
277
    GenerateFiles ('*', "--Tool=DebianPackager.pl",               # Associated tool
278
                        "--AutoGenerate",                         # Build when needed
279
                        "--UnknownPreq",                          # Always build
280
                        "--Clean",                                # Script supports jats clean
281
                        "--Text=Debian Package",                  # Display when building
282
 
283
                        '--Var(BuildName)',                       # Target Package
284
                        '--Var(BuildVersion)',                    # Target Version
285
                        '--Var(Platform)',                        # Target platform
286
                        '--Var(Product)',                         # Target product
287
                        '--Var(Target)',                          # Underlying Target
288
                        '--Var(Type)',                            # Build Type
289
 
290
                        '--Var(Verbose)',                         # Verbose operation
291
 
292
                        '--Var(InterfaceDir)',                    # Interface Directory
293
                        '--Var(InterfaceIncDir)',
294
                        '--Var(InterfaceLibDir)',
295
                        '--Var(InterfaceBinDir)',
296
 
297
                        '--Var(LibDir)',                          # My Artifacts
298
                        '--Var(BinDir)',
299
 
300
                        '--Var(PackageDir)',                      # My Package
301
                        '--Var(PackageLibDir)',                   # My Package Library
302
                        '--Var(PackageBinDir)',                   # My Package Bin
303
                        '--Var(PackagePkgDir)',                   # My Package/pkg.target
304
 
305
                        '--Var(LocalIncDir)',                     # Installed Artifacts
306
                        '--Var(LocalLibDir)',
307
                        '--Var(LocalBinDir)',
308
 
6242 dpurdie 309
                        "-genDeb",                                # Type to generate
310
                        "-Script=--Prerequisite($script)",        # Packager script
311
                        "-Name=$build_name",                      # Massaged Package Name
427 dpurdie 312
                        "-Variant=$build_variant",                # Variant Name
6242 dpurdie 313
                        @optArgs,                                 # Optional args
407 dpurdie 314
                        );
315
 
316
    #
317
    #   The Packager has created a binary in the 'PROG' directory
318
    #   Lets package it as a program.
319
    #
6242 dpurdie 320
    if ($deploy_mode) {
4740 dpurdie 321
        PackageFile ('*', @outputFiles );
4188 dpurdie 322
    }
6242 dpurdie 323
    else {
4740 dpurdie 324
        PackageProg ('*', @outputFiles );
4188 dpurdie 325
    }
407 dpurdie 326
}
327
 
328
1;