Subversion Repositories DevTools

Rev

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

Rev Author Line No. Line
407 dpurdie 1
########################################################################
6861 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:
6857 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
6857 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
6861 dpurdie 34
#                   --TarOnly                           - Suppress the Debian Build
5215 dpurdie 35
#                   --NoArch                            - Marks the package as having no specific architecture
6857 dpurdie 36
#                   
37
#
38
#               Templates may contain:
39
#                   PACKAGE
40
#                   VARIANT
41
#                   VERSION
42
#                   PLATFORM
43
#                   TYPE
6863 dpurdie 44
#                   ARCH
4740 dpurdie 45
#                       
407 dpurdie 46
#......................................................................#
47
 
409 alewis 48
require 5.006_001;
407 dpurdie 49
#use strict;
50
use warnings;
6861 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;
6861 dpurdie 74
 
4907 dpurdie 75
    my $deploy_mode = GetGlobalOption('DEBIAN_PACKAGE_DEPLOYABLE', 0);
417 dpurdie 76
 
6861 dpurdie 77
    my $tarOnly;
4740 dpurdie 78
    my $tarFileName = '';
79
    my @outputFiles;
80
    my @optArgs;
5215 dpurdie 81
    my $noArch;
4740 dpurdie 82
 
6861 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
    {
6861 dpurdie 94
        push @arglist, $_;
95
 
6857 dpurdie 96
        if ( m/^--Script=(.+)/i ) {
6861 dpurdie 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;
407 dpurdie 102
 
6861 dpurdie 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
 
6857 dpurdie 113
        } elsif ( m/^--Name=(.+)/i ) {
417 dpurdie 114
            $build_name = $1;
115
            $name_set++;
116
 
6857 dpurdie 117
        } elsif ( m/^--Variant=(.+)/i ) {
417 dpurdie 118
            $build_variant = $1;
119
            $variant_set++;
4188 dpurdie 120
 
6857 dpurdie 121
        } elsif ( m/^--(No)?DeployMode/i ) {
122
            $deploy_mode = ! defined($1);
4907 dpurdie 123
 
6857 dpurdie 124
        } elsif ( m/^--NoArch$/i ) {
5215 dpurdie 125
            $noArch = 1;
126
 
6861 dpurdie 127
        } elsif ( m/^--TarOnly$/i ) {
128
            $tarOnly = 1;
129
 
6857 dpurdie 130
        } elsif ( m/^--TarFile(=(.*))?/i ) {
131
            $tarFileName = defined($1) ? $2 : 'DEFAULT';
4740 dpurdie 132
 
407 dpurdie 133
        } elsif ( m/^--/ ) {
6861 dpurdie 134
            ReportError("MakeDebianPackage. Unknown option: $_");
407 dpurdie 135
 
136
        } else {
6861 dpurdie 137
            ReportError("MakeDebianPackage. Unknown argument: $_");
407 dpurdie 138
        }
139
    }
140
 
141
    #
142
    #   Sanity test
143
    #
6861 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
    #
6861 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
6857 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
 
6861 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
 
6861 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)' ) : '' ;
6857 dpurdie 224
    my $PkgArch = GetGlobalOption('PACKAGE_ARCH', $::ScmPlatform);
6863 dpurdie 225
    my $Platform = $::ScmPlatform;
226
        if ($noArch) {
6857 dpurdie 227
            $PkgArch = 'all';
6863 dpurdie 228
            $Platform = 'all';
6857 dpurdie 229
            $PkgType = '';
230
            push @optArgs, "-NoArch";
231
        }
6863 dpurdie 232
 
233
    my $PkgName = "${build_name}_${::ScmBuildVersionFull}_${Platform}${PkgType}.deb";
6857 dpurdie 234
    push @outputFiles,  $PkgName;
235
    push @optArgs, "-PkgArch=$PkgArch";
4740 dpurdie 236
 
407 dpurdie 237
    #
4740 dpurdie 238
    #   Create name for the optional TGZ file
6857 dpurdie 239
    #       Allow user to specify parts of the name symbolically
4740 dpurdie 240
    #
241
    if ($tarFileName)
242
    {
243
        if ($tarFileName eq 'DEFAULT')
244
        {
245
            $tarFileName = 'PACKAGE_VERSION_PLATFORM';
5215 dpurdie 246
            if ($deploy_mode && ! $noArch)
4740 dpurdie 247
            {
248
                $tarFileName .= '_TYPE';
249
            }
250
        }
251
 
6857 dpurdie 252
        if ($noArch) {
253
            $PkgArch = 'all';
254
        }
255
 
4740 dpurdie 256
        $tarFileName =~ s~PACKAGE~${build_name}~g;
257
        $tarFileName =~ s~VERSION~${::ScmBuildVersionFull}~g;
6863 dpurdie 258
        $tarFileName =~ s~PLATFORM~${Platform}~g;
259
        $tarFileName =~ s~ARCH~${PkgArch}~g;
4740 dpurdie 260
        $tarFileName =~ s~TYPE~\$(GBE_TYPE)~;
6857 dpurdie 261
        $tarFileName .= '.tgz' unless $tarFileName =~ m~\.tgz$~;
4740 dpurdie 262
        push @outputFiles,  $tarFileName;
6857 dpurdie 263
 
264
        #push @optArgs, "-TarFile=--GeneratedProg{$tarFileName}";
265
        push @optArgs, "-TarFile=$tarFileName";
6861 dpurdie 266
        push (@optArgs, '-TarOnly' ) if $tarOnly;
4740 dpurdie 267
    }
268
 
269
    #
407 dpurdie 270
    #   Simply use Generate Files
6857 dpurdie 271
    #       With lots of options
407 dpurdie 272
    #
273
    Src ( '*', $script );
274
    GenerateFiles ('*', "--Tool=DebianPackager.pl",               # Associated tool
275
                        "--AutoGenerate",                         # Build when needed
276
                        "--UnknownPreq",                          # Always build
277
                        "--Clean",                                # Script supports jats clean
278
                        "--Text=Debian Package",                  # Display when building
279
 
280
                        '--Var(BuildName)',                       # Target Package
281
                        '--Var(BuildVersion)',                    # Target Version
282
                        '--Var(Platform)',                        # Target platform
283
                        '--Var(Product)',                         # Target product
284
                        '--Var(Target)',                          # Underlying Target
285
                        '--Var(Type)',                            # Build Type
286
 
287
                        '--Var(Verbose)',                         # Verbose operation
288
 
289
                        '--Var(InterfaceDir)',                    # Interface Directory
290
                        '--Var(InterfaceIncDir)',
291
                        '--Var(InterfaceLibDir)',
292
                        '--Var(InterfaceBinDir)',
293
 
294
                        '--Var(LibDir)',                          # My Artifacts
295
                        '--Var(BinDir)',
296
 
297
                        '--Var(PackageDir)',                      # My Package
298
                        '--Var(PackageLibDir)',                   # My Package Library
299
                        '--Var(PackageBinDir)',                   # My Package Bin
300
                        '--Var(PackagePkgDir)',                   # My Package/pkg.target
301
 
302
                        '--Var(LocalIncDir)',                     # Installed Artifacts
303
                        '--Var(LocalLibDir)',
304
                        '--Var(LocalBinDir)',
305
 
6857 dpurdie 306
                        "-genDeb",                                # Type to generate
307
                        "-Script=--Prerequisite($script)",        # Packager script
308
                        "-Name=$build_name",                      # Massaged Package Name
427 dpurdie 309
                        "-Variant=$build_variant",                # Variant Name
6857 dpurdie 310
                        "-Output=--GeneratedProg{$PkgName}",      # Specify output file
311
                        @optArgs,                                 # Optional args
407 dpurdie 312
                        );
313
 
314
    #
315
    #   The Packager has created a binary in the 'PROG' directory
316
    #   Lets package it as a program.
317
    #
6857 dpurdie 318
    if ($deploy_mode) {
4740 dpurdie 319
        PackageFile ('*', @outputFiles );
4188 dpurdie 320
    }
6857 dpurdie 321
    else {
4740 dpurdie 322
        PackageProg ('*', @outputFiles );
4188 dpurdie 323
    }
407 dpurdie 324
}
325
 
326
1;