Subversion Repositories DevTools

Rev

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