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