Subversion Repositories DevTools

Rev

Rev 6856 | Rev 6861 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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