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