Subversion Repositories DevTools

Rev

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