Subversion Repositories DevTools

Rev

Rev 7398 | 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)
6738 dpurdie 25
#                   --VersionPrefix=Text                - Prefixes the version with the passed text(optional)
26
#                   --ExtDesc=Text                      - Stored in the variable $opt_extdesc availabe in the
27
#                                                         packaging script(optional)
4188 dpurdie 28
#                   --DeployMode                        - Create Deployable packages(optional)
4907 dpurdie 29
#                                                         Default for native targets
4188 dpurdie 30
#                                                         These are:
31
#                                                           * Packaged into the root of target pkg
32
#                                                           * Have P or D in the name
5857 dpurdie 33
#                   --NoDeployMode                      - Create packages that cannot be directly deployed
5215 dpurdie 34
#                                                         Default for embedded devices
6937 dpurdie 35
#                   --NoArch                            - Marks the package as having no specific architecture
36
#                                                         
6242 dpurdie 37
#                   --TarFile[=TemplateName]            - Create named .tgz file, of the data area [not Debian scripts]
4740 dpurdie 38
#                   --TarFile                           - Same as --TarFile=PACKAGE_VERSION_PLATFORM_TYPE or PACKAGE_VERSION_PLATFORM
6242 dpurdie 39
#                   --TarOnly                           - Suppress the Debian Build
40
#                   
6937 dpurdie 41
#                   --ZipFile[=TemplateName]            - Create named .zip file, of the data area [not Debian scripts]
42
#                   --ZipFile                           - Same as --TarFile=PACKAGE_VERSION_PLATFORM_TYPE or PACKAGE_VERSION_PLATFORM
43
#                   --ZipOnly                           - Suppress the Debian Build
44
#                   
7398 dpurdie 45
#                   --ImageOnly                         - Only generate the filesystem image. No Tar, NoZip, NoDebian ...
46
#                   --DirectPkg                         - Construct directly into the pkg directory within the output . No Tar, NoZip, NoDebian ...
6242 dpurdie 47
#
7398 dpurdie 48
#
6242 dpurdie 49
#               Templates may contain:
50
#                   PACKAGE
51
#                   VARIANT
52
#                   VERSION
53
#                   PLATFORM
54
#                   TYPE
55
#                   ARCH
4740 dpurdie 56
#                       
407 dpurdie 57
#......................................................................#
58
 
409 alewis 59
require 5.006_001;
407 dpurdie 60
#use strict;
61
use warnings;
6242 dpurdie 62
#use PackagerUtils;
407 dpurdie 63
 
64
#-------------------------------------------------------------------------------
65
# Function        : MakeDebianPackage
66
#
67
# Description     : Create a Debian Package
68
#
4188 dpurdie 69
# Inputs          : See above
407 dpurdie 70
#
4188 dpurdie 71
# Returns         : Nothing 
407 dpurdie 72
#
73
sub MakeDebianPackage
74
{
75
    my( $platforms, @elements ) = @_;
76
    Debug2( "MakeDebianPackage($platforms, @elements)" );
77
    return if ( ! ActivePlatform($platforms) );
78
 
79
    my $build_name =  $::ScmBuildPackage;
80
    my $build_version = $::ScmBuildVersionFull;
417 dpurdie 81
    my $build_variant = '';
6738 dpurdie 82
    my $build_version_prefix = '';
83
    my $build_extdesc = '';
407 dpurdie 84
 
417 dpurdie 85
    my $name_set=0;
86
    my $variant_set=0;
6738 dpurdie 87
    my $version_prefix_set=0;
88
    my $extdesc_set=0;
6242 dpurdie 89
 
4907 dpurdie 90
    my $deploy_mode = GetGlobalOption('DEBIAN_PACKAGE_DEPLOYABLE', 0);
417 dpurdie 91
 
6242 dpurdie 92
    my $tarOnly;
4740 dpurdie 93
    my $tarFileName = '';
6937 dpurdie 94
 
95
    my $zipOnly;
96
    my $zipFileName = '';
97
 
7398 dpurdie 98
    my $imageOnly;
99
    my $directPkg;
100
 
4740 dpurdie 101
    my @outputFiles;
102
    my @optArgs;
5215 dpurdie 103
    my $noArch;
4740 dpurdie 104
 
6242 dpurdie 105
    my @arglist;
106
    my $rpmScript;
107
    my $debianScript;
407 dpurdie 108
    my $script;
109
 
110
    #
111
    #   Collect user arguments
112
    #   They are all processed within the toolset
113
    #
114
    foreach ( @elements )
115
    {
6242 dpurdie 116
        push @arglist, $_;
407 dpurdie 117
 
6242 dpurdie 118
        if ( m/^--Script=(.+)/i ) {
119
            ReportError ("MakeDebianPackage: --Script. Debian script name already set") if $debianScript;
120
            ReportError ("MakeDebianPackage: --Script. RPM script name already set") if $rpmScript;
121
            $debianScript = $1;
122
            $rpmScript = $1;
123
            pop @arglist;
124
 
125
        } elsif ( m/^--RpmScript=(.+)/i ) {
126
            ReportError ("MakeDebianPackage: --RpmScript. RPM script name already set") if $rpmScript;
127
            $rpmScript = $1;
128
            pop @arglist;
129
 
130
        } elsif ( m/^--DebianScript=(.+)/i ) {
131
            ReportError ("MakeDebianPackage: --DebianScript. Debian script name already set") if $debianScript;
132
            $debianScript = $1;
133
            pop @arglist;
134
 
135
        } elsif ( m/^--Name=(.+)/i ) {
417 dpurdie 136
            $build_name = $1;
137
            $name_set++;
138
 
6242 dpurdie 139
        } elsif ( m/^--Variant=(.+)/i ) {
417 dpurdie 140
            $build_variant = $1;
141
            $variant_set++;
4188 dpurdie 142
 
6738 dpurdie 143
        } elsif ( m/^--VersionPrefix=(.+)/i ) {
144
            $build_version_prefix = $1;
145
            $version_prefix_set++;
146
 
147
        } elsif ( m/^--ExtDesc=(.+)/i ) {
148
            $build_extdesc = $1;
149
            $extdesc_set++;
150
 
6242 dpurdie 151
        } elsif ( m/^--(No)?DeployMode/i ) {
152
            $deploy_mode = ! defined($1);
4907 dpurdie 153
 
6242 dpurdie 154
        } elsif ( m/^--NoArch$/i ) {
5215 dpurdie 155
            $noArch = 1;
156
 
6242 dpurdie 157
        } elsif ( m/^--TarOnly$/i ) {
158
            $tarOnly = 1;
159
 
160
        } elsif ( m/^--TarFile(=(.*))?/i ) {
161
            $tarFileName = defined($1) ? $2 : 'DEFAULT';
6937 dpurdie 162
 
163
        } elsif ( m/^--ZipOnly$/i ) {
164
            $zipOnly = 1;
165
 
166
        } elsif ( m/^--ZipFile(=(.*))?/i ) {
167
            $zipFileName = defined($1) ? $2 : 'DEFAULT';
7398 dpurdie 168
 
169
        } elsif ( m/^--ImageOnly$/i ) {
170
            $imageOnly = 1;
171
 
172
        } elsif ( m/^--DirectPkg$/i ) {
173
            $directPkg = 1;
4740 dpurdie 174
 
407 dpurdie 175
        } elsif ( m/^--/ ) {
6242 dpurdie 176
            ReportError("MakeDebianPackage. Unknown option: $_");
407 dpurdie 177
 
178
        } else {
6242 dpurdie 179
            ReportError("MakeDebianPackage. Unknown argument: $_");
407 dpurdie 180
        }
181
    }
182
 
183
    #
184
    #   Sanity test
185
    #
7402 dpurdie 186
    ReportError ("MakeDebianPackage: Not supported on a GENERIC target") if ( $ScmPlatform eq 'GENERIC' && !($zipOnly || $tarOnly || $imageOnly || $directPkg)  );
6242 dpurdie 187
    ReportError ("MakeDebianPackage: Script name not defined") unless ( $debianScript || $rpmScript );
188
    ReportError ("MakeDebianPackage: --Name option can only be used once") if ( $name_set > 1 );
189
    ReportError ("MakeDebianPackage: --Variant option can only be used once") if ( $variant_set > 1 );
6738 dpurdie 190
    ReportError ("MakeDebianPackage: --VersionPrefix option can only be used once") if ( $version_prefix_set > 1 );
191
    ReportError ("MakeDebianPackage: --ExtDesc option can only be used once") if ( $extdesc_set > 1 );
7398 dpurdie 192
    ReportError ("MakeDebianPackage: --DirectPkg cannot be used with Tar options") if ( $directPkg && ($tarOnly || $tarFileName)  );
193
    ReportError ("MakeDebianPackage: --DirectPkg cannot be used with Zip options") if ( $directPkg && ($zipOnly || $zipFileName)  );
194
    ReportError ("MakeDebianPackage: --ImageOnly cannot be used with Tar options") if ( $imageOnly && ($tarOnly || $tarFileName)  );
195
    ReportError ("MakeDebianPackage: --ImageOnly cannot be used with Zip options") if ( $imageOnly && ($zipOnly || $zipFileName)  );
196
    ReportError ("MakeDebianPackage: --ZipOnly used without --ZipFile") if ( ($zipOnly && ! $zipFileName)  );
197
    ReportError ("MakeDebianPackage: --TarOnly used without --TarFile") if ( ($tarOnly && ! $tarFileName)  );
198
    ReportError ("MakeDebianPackage: --DirectPkg cannot be used with --ImageOnly") if ( $directPkg && $imageOnly );
6242 dpurdie 199
    ErrorDoExit();
407 dpurdie 200
 
417 dpurdie 201
    #
6242 dpurdie 202
    #   Determine what we are really doing
203
    #       Under Redhat we will generate an RPM
204
    #
205
    if ( ActivePlatform('PKG_RPM') ) {
206
        return unless (defined $rpmScript);
207
        return MakeRpmPackage ($platforms, "--Script=$rpmScript", @arglist );
208
    }
209
 
210
    return unless (defined $debianScript);
211
    $script = $debianScript;
212
    ErrorDoExit();
213
 
214
 
215
    #
216
    #   If the platform cannot generate a native installer then (silently) ignore the request
217
    #   unless the user has specified a --TarOnly
218
    #
219
    my $canGenerateInstaller = ActivePlatform('PKG_DEB');
6937 dpurdie 220
    if ( !$canGenerateInstaller && !$tarOnly && !zipOnly) {
6242 dpurdie 221
        Verbose ("MakeDebianPackage: Installer not builadble for this platform");
222
        return;
223
    }
224
 
225
    #
417 dpurdie 226
    #   Build up the build name
227
    #       Add variant to base name.
228
    #
229
    if ( $build_variant )
230
    {
231
        $build_name .= '-' . $build_variant;
232
    }
6738 dpurdie 233
 
234
    #
235
    #   Build up the version 
236
    #       Add the version prefix to the base version
237
    if ( $build_version_prefix )
238
    {
239
        $build_version = $build_version_prefix . '-' . $build_version;
240
    }
407 dpurdie 241
 
242
    #
243
    #   Sanity check the package name and version
6242 dpurdie 244
    #   Debian has stricter requirements than JATS
407 dpurdie 245
    #       Name:    Lower case letters (a-z), digits (0-9), plus (+) and minus (-) signs, and periods (.).
246
    #                Release Manager does not allow '.'
247
    #       Version: alphanumerics and the characters . + - : (full stop, plus, hyphen, colon) and should start with a digit
248
    #
409 alewis 249
    #   Allow ( and cleanup )
250
    #       ERGxxxxx    -> erg-xxx
427 dpurdie 251
    #       VIXxxxxx    -> vix-xxx
252
    #       Whitespace   -> -
409 alewis 253
    #       _           -> -
427 dpurdie 254
    #       Remove multiple '-' characters
255
    #       Lowercase all text
409 alewis 256
    #
407 dpurdie 257
 
6242 dpurdie 258
    #
259
    #   Convert the build_name to a form that is Debian complient
260
    #
261
    $build_name = canonicalName ($build_name, 'Debian');
409 alewis 262
 
6242 dpurdie 263
    #
264
    #   Sanity test the version information
265
    #   
6738 dpurdie 266
    unless ( $build_version =~ m/^[0-9][-+:.A-Za-z0-9]+$/ )
407 dpurdie 267
    {
268
        Error ("Package Version does not conform to Debian Requirements",
269
               "Must only contain: (a-zA-Z) (0-9), - and .",
5215 dpurdie 270
               "Must start with a number",
407 dpurdie 271
               );
272
    }
273
 
274
    #
275
    #   Create the name of the target package
276
    #   The form of the name is of a fixed form.
277
    #
278
    #   Note: "_" used since this is the format of dpkg-name
4188 dpurdie 279
    #   Note: dpkg-name generates: Name _ Version _ Architecture [ _ Type ]
407 dpurdie 280
    #
281
    #
4188 dpurdie 282
    my $PkgType = $deploy_mode ? ( '_' . '$(GBE_TYPE)' ) : '' ;
6992 sdenys 283
    my $PkgArch = GetGlobalOption('PACKAGE_ARCH', $::ScmTarget);
6242 dpurdie 284
    my $Platform = $::ScmPlatform;
285
        if ($noArch) {
286
            $PkgArch = 'all';
287
            $Platform = 'all';
288
            $PkgType = '';
289
            push @optArgs, "-NoArch";
290
        }
4740 dpurdie 291
 
6738 dpurdie 292
    my $PkgName = "${build_name}_${build_version}_${Platform}${PkgType}.deb";
6242 dpurdie 293
    push @optArgs, "-PkgArch=$PkgArch";
7398 dpurdie 294
    unless ($tarOnly || $zipOnly || $imageOnly || $directPkg) {
6535 dpurdie 295
        push (@outputFiles, $PkgName);
296
        push @optArgs, "-Output=--GeneratedProg{$PkgName}";
297
    }
6242 dpurdie 298
 
407 dpurdie 299
    #
4740 dpurdie 300
    #   Create name for the optional TGZ file
6242 dpurdie 301
    #       Allow user to specify parts of the name symbolically
4740 dpurdie 302
    #
303
    if ($tarFileName)
304
    {
305
        if ($tarFileName eq 'DEFAULT')
306
        {
307
            $tarFileName = 'PACKAGE_VERSION_PLATFORM';
5215 dpurdie 308
            if ($deploy_mode && ! $noArch)
4740 dpurdie 309
            {
310
                $tarFileName .= '_TYPE';
311
            }
312
        }
313
 
6242 dpurdie 314
        if ($noArch) {
315
            $PkgArch = 'all';
316
        }
317
 
4740 dpurdie 318
        $tarFileName =~ s~PACKAGE~${build_name}~g;
6738 dpurdie 319
        $tarFileName =~ s~VERSION~${build_version}~g;
6242 dpurdie 320
        $tarFileName =~ s~PLATFORM~${Platform}~g;
321
        $tarFileName =~ s~ARCH~${PkgArch}~g;
4740 dpurdie 322
        $tarFileName =~ s~TYPE~\$(GBE_TYPE)~;
6242 dpurdie 323
        $tarFileName .= '.tgz' unless $tarFileName =~ m~\.tgz$~;
4740 dpurdie 324
        push @outputFiles,  $tarFileName;
6242 dpurdie 325
 
6535 dpurdie 326
        push @optArgs, "-TarFile=--GeneratedProg{$tarFileName}";
327
#        push @optArgs, "-TarFile=$tarFileName";
6242 dpurdie 328
        push (@optArgs, '-TarOnly' ) if $tarOnly;
4740 dpurdie 329
    }
330
 
331
    #
6937 dpurdie 332
    #   Create name for the optional ZIP file
333
    #       Allow user to specify parts of the name symbolically
334
    #
335
    if ($zipFileName) {
336
        if ($zipFileName eq 'DEFAULT') {
337
            $zipFileName = 'PACKAGE_VERSION_PLATFORM';
338
            if ($deploy_mode && ! $noArch) {
339
                $zipFileName .= '_TYPE';
340
            }
341
        }
342
 
343
        if ($noArch) {
344
            $PkgArch = 'all';
345
        }
346
 
347
        $zipFileName =~ s~PACKAGE~${build_name}~g;
348
        $zipFileName =~ s~VERSION~${build_version}~g;
349
        $zipFileName =~ s~PLATFORM~${Platform}~g;
350
        $zipFileName =~ s~ARCH~${PkgArch}~g;
351
        $zipFileName =~ s~TYPE~\$(GBE_TYPE)~;
352
        $zipFileName .= '.zip' unless $zipFileName =~ m~\.zip$~;
353
        push @outputFiles,  $zipFileName;
354
 
355
        push @optArgs, "-ZipFile=--GeneratedProg{$zipFileName}";
356
        push (@optArgs, '-ZipOnly' ) if $zipOnly;
357
    }
358
 
359
    #
7398 dpurdie 360
    #   Only generating an image
361
    #   No output files created
362
    #   
363
    if ($imageOnly) {
364
        push (@optArgs, '-ImageOnly' );
365
        push (@optArgs, '--NoGenerate' );
366
    }
367
    if ($directPkg) {
368
        push (@optArgs, '-DirectPkg' );
369
        push (@optArgs, '--NoGenerate' );
370
    }
371
 
372
    #
407 dpurdie 373
    #   Simply use Generate Files
6242 dpurdie 374
    #       With lots of options
407 dpurdie 375
    #
376
    Src ( '*', $script );
377
    GenerateFiles ('*', "--Tool=DebianPackager.pl",               # Associated tool
378
                        "--AutoGenerate",                         # Build when needed
379
                        "--UnknownPreq",                          # Always build
380
                        "--Clean",                                # Script supports jats clean
381
                        "--Text=Debian Package",                  # Display when building
382
 
383
                        '--Var(BuildName)',                       # Target Package
384
                        '--Var(BuildVersion)',                    # Target Version
385
                        '--Var(Platform)',                        # Target platform
386
                        '--Var(Product)',                         # Target product
387
                        '--Var(Target)',                          # Underlying Target
388
                        '--Var(Type)',                            # Build Type
389
 
390
                        '--Var(Verbose)',                         # Verbose operation
391
 
392
                        '--Var(InterfaceDir)',                    # Interface Directory
393
                        '--Var(InterfaceIncDir)',
394
                        '--Var(InterfaceLibDir)',
395
                        '--Var(InterfaceBinDir)',
396
 
397
                        '--Var(LibDir)',                          # My Artifacts
398
                        '--Var(BinDir)',
399
 
400
                        '--Var(PackageDir)',                      # My Package
401
                        '--Var(PackageLibDir)',                   # My Package Library
402
                        '--Var(PackageBinDir)',                   # My Package Bin
403
                        '--Var(PackagePkgDir)',                   # My Package/pkg.target
404
 
405
                        '--Var(LocalIncDir)',                     # Installed Artifacts
406
                        '--Var(LocalLibDir)',
407
                        '--Var(LocalBinDir)',
408
 
6242 dpurdie 409
                        "-genDeb",                                # Type to generate
410
                        "-Script=--Prerequisite($script)",        # Packager script
411
                        "-Name=$build_name",                      # Massaged Package Name
6738 dpurdie 412
                        "-Version=$build_version",                # Massaged Version
427 dpurdie 413
                        "-Variant=$build_variant",                # Variant Name
6738 dpurdie 414
                        "-VersionPrefix=$build_version_prefix",   # Version Prefix
415
                        "-ExtDesc=$build_extdesc",                # External Description of Package
6242 dpurdie 416
                        @optArgs,                                 # Optional args
407 dpurdie 417
                        );
418
 
419
    #
420
    #   The Packager has created a binary in the 'PROG' directory
421
    #   Lets package it as a program.
422
    #
6242 dpurdie 423
    if ($deploy_mode) {
4740 dpurdie 424
        PackageFile ('*', @outputFiles );
4188 dpurdie 425
    }
6242 dpurdie 426
    else {
4740 dpurdie 427
        PackageProg ('*', @outputFiles );
4188 dpurdie 428
    }
407 dpurdie 429
}
430
 
431
1;