Subversion Repositories DevTools

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

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