Subversion Repositories DevTools

Rev

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