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