| 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
|
| 5857 |
dpurdie |
30 |
# --NoDeployMode - Create packages that cannot 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 |
#
|
| 6088 |
dpurdie |
122 |
Error ("MakeDebianPackage: Not supported on a GENERIC target") if ( $ScmPlatform eq 'GENERIC' );
|
| 407 |
dpurdie |
123 |
Error ("MakeDebianPackage: Script name not defined") unless ( $script );
|
| 417 |
dpurdie |
124 |
Error ("MakeDebianPackage: --Script option can only be used once") if ( $script_set > 1 );
|
|
|
125 |
Error ("MakeDebianPackage: --Name option can only be used once") if ( $name_set > 1 );
|
|
|
126 |
Error ("MakeDebianPackage: --Variant option can only be used once") if ( $variant_set > 1 );
|
| 407 |
dpurdie |
127 |
|
| 417 |
dpurdie |
128 |
#
|
|
|
129 |
# Build up the build name
|
|
|
130 |
# Add variant to base name.
|
|
|
131 |
#
|
|
|
132 |
if ( $build_variant )
|
|
|
133 |
{
|
|
|
134 |
$build_name .= '-' . $build_variant;
|
|
|
135 |
}
|
| 407 |
dpurdie |
136 |
|
|
|
137 |
#
|
|
|
138 |
# Sanity check the package name and version
|
|
|
139 |
# Debian has strict requirements than JATS
|
|
|
140 |
# Name: Lower case letters (a-z), digits (0-9), plus (+) and minus (-) signs, and periods (.).
|
|
|
141 |
# Release Manager does not allow '.'
|
|
|
142 |
# Version: alphanumerics and the characters . + - : (full stop, plus, hyphen, colon) and should start with a digit
|
|
|
143 |
#
|
| 409 |
alewis |
144 |
# Allow ( and cleanup )
|
|
|
145 |
# ERGxxxxx -> erg-xxx
|
| 427 |
dpurdie |
146 |
# VIXxxxxx -> vix-xxx
|
|
|
147 |
# Whitespace -> -
|
| 409 |
alewis |
148 |
# _ -> -
|
| 427 |
dpurdie |
149 |
# Remove multiple '-' characters
|
|
|
150 |
# Lowercase all text
|
| 409 |
alewis |
151 |
#
|
|
|
152 |
my $cvt = 0;
|
|
|
153 |
$cvt = 1 if ( $build_name =~ s/^ERG/erg-/ );
|
| 3923 |
dpurdie |
154 |
$cvt = 2 if ( $build_name =~ s/^VIX/vix-/ );
|
|
|
155 |
$cvt = 3 if ( $build_name =~ s~\s~-~g );
|
|
|
156 |
$cvt = 4 if ( $build_name =~ s~_~-~g );
|
|
|
157 |
$cvt = 5 if ( $build_name =~ s~--+~-~g );
|
| 427 |
dpurdie |
158 |
if ( $build_name =~ m/[A-Z]/ )
|
|
|
159 |
{
|
| 3923 |
dpurdie |
160 |
$cvt = 6;
|
| 427 |
dpurdie |
161 |
$build_name = lc $build_name;
|
|
|
162 |
}
|
| 407 |
dpurdie |
163 |
|
| 409 |
alewis |
164 |
Warning ("Package Name converted to debian friendly form: $build_name")
|
|
|
165 |
if ( $cvt );
|
|
|
166 |
|
| 413 |
dpurdie |
167 |
unless ( $build_name =~ m/^[a-z][-+a-z0-9]+$/ )
|
| 407 |
dpurdie |
168 |
{
|
|
|
169 |
Error ("Package Name does not conform to Debian Requirements",
|
| 413 |
dpurdie |
170 |
"Must be at least two characters long",
|
|
|
171 |
"Must start with an alphabetic character",
|
| 407 |
dpurdie |
172 |
"Must only contain: (a-z) (0-9) and -",
|
|
|
173 |
"Provided Name: $::ScmBuildPackage");
|
|
|
174 |
}
|
|
|
175 |
|
|
|
176 |
unless ( $::ScmBuildVersionFull =~ m/^[0-9][-+:.A-Za-z0-9]+$/ )
|
|
|
177 |
{
|
|
|
178 |
Error ("Package Version does not conform to Debian Requirements",
|
|
|
179 |
"Must only contain: (a-zA-Z) (0-9), - and .",
|
| 5215 |
dpurdie |
180 |
"Must start with a number",
|
| 407 |
dpurdie |
181 |
);
|
|
|
182 |
}
|
|
|
183 |
|
|
|
184 |
#
|
|
|
185 |
# Create the name of the target package
|
|
|
186 |
# The form of the name is of a fixed form.
|
|
|
187 |
#
|
|
|
188 |
# Note: "_" used since this is the format of dpkg-name
|
| 4188 |
dpurdie |
189 |
# Note: dpkg-name generates: Name _ Version _ Architecture [ _ Type ]
|
| 407 |
dpurdie |
190 |
#
|
|
|
191 |
#
|
| 4188 |
dpurdie |
192 |
my $PkgType = $deploy_mode ? ( '_' . '$(GBE_TYPE)' ) : '' ;
|
| 5215 |
dpurdie |
193 |
my $PkgArch = $::ScmPlatform;
|
|
|
194 |
if ($noArch)
|
|
|
195 |
{
|
|
|
196 |
$PkgArch = 'all';
|
|
|
197 |
$PkgType = '';
|
|
|
198 |
push @optArgs, "-NoArch";
|
|
|
199 |
}
|
|
|
200 |
my $DebianPkgName = "${build_name}_${::ScmBuildVersionFull}_${PkgArch}${PkgType}.deb";
|
| 4740 |
dpurdie |
201 |
push @outputFiles, $DebianPkgName;
|
|
|
202 |
|
| 407 |
dpurdie |
203 |
#
|
| 4740 |
dpurdie |
204 |
# Create name for the optional TGZ file
|
|
|
205 |
# Allow use to specify parts of the name symbolically
|
|
|
206 |
#
|
|
|
207 |
if ($tarFileName)
|
|
|
208 |
{
|
|
|
209 |
if ($tarFileName eq 'DEFAULT')
|
|
|
210 |
{
|
|
|
211 |
$tarFileName = 'PACKAGE_VERSION_PLATFORM';
|
| 5215 |
dpurdie |
212 |
if ($deploy_mode && ! $noArch)
|
| 4740 |
dpurdie |
213 |
{
|
|
|
214 |
$tarFileName .= '_TYPE';
|
|
|
215 |
}
|
|
|
216 |
}
|
|
|
217 |
|
|
|
218 |
$tarFileName =~ s~PACKAGE~${build_name}~g;
|
|
|
219 |
$tarFileName =~ s~VERSION~${::ScmBuildVersionFull}~g;
|
| 5215 |
dpurdie |
220 |
$tarFileName =~ s~PLATFORM~${PkgArch}~g;
|
| 4740 |
dpurdie |
221 |
$tarFileName =~ s~TYPE~\$(GBE_TYPE)~;
|
|
|
222 |
$tarFileName .= '.tgz';
|
|
|
223 |
push @outputFiles, $tarFileName;
|
|
|
224 |
push @optArgs, "-TarFile=--GeneratedProg{$tarFileName}";
|
|
|
225 |
}
|
|
|
226 |
|
|
|
227 |
#
|
| 407 |
dpurdie |
228 |
# Simply use Generate Files
|
|
|
229 |
# With lots of options
|
|
|
230 |
#
|
|
|
231 |
Src ( '*', $script );
|
|
|
232 |
GenerateFiles ('*', "--Tool=DebianPackager.pl", # Associated tool
|
|
|
233 |
"-DebianPackage=--Prerequisite($script)", # Packager script
|
|
|
234 |
"--AutoGenerate", # Build when needed
|
|
|
235 |
"--UnknownPreq", # Always build
|
|
|
236 |
"--Clean", # Script supports jats clean
|
|
|
237 |
"--Text=Debian Package", # Display when building
|
|
|
238 |
|
|
|
239 |
'--Var(BuildName)', # Target Package
|
|
|
240 |
'--Var(BuildVersion)', # Target Version
|
|
|
241 |
'--Var(Platform)', # Target platform
|
|
|
242 |
'--Var(Product)', # Target product
|
|
|
243 |
'--Var(Target)', # Underlying Target
|
|
|
244 |
'--Var(Type)', # Build Type
|
|
|
245 |
|
|
|
246 |
'--Var(Verbose)', # Verbose operation
|
|
|
247 |
|
|
|
248 |
'--Var(InterfaceDir)', # Interface Directory
|
|
|
249 |
'--Var(InterfaceIncDir)',
|
|
|
250 |
'--Var(InterfaceLibDir)',
|
|
|
251 |
'--Var(InterfaceBinDir)',
|
|
|
252 |
|
|
|
253 |
'--Var(LibDir)', # My Artifacts
|
|
|
254 |
'--Var(BinDir)',
|
|
|
255 |
|
|
|
256 |
'--Var(PackageDir)', # My Package
|
|
|
257 |
'--Var(PackageLibDir)', # My Package Library
|
|
|
258 |
'--Var(PackageBinDir)', # My Package Bin
|
|
|
259 |
'--Var(PackagePkgDir)', # My Package/pkg.target
|
|
|
260 |
|
|
|
261 |
'--Var(LocalIncDir)', # Installed Artifacts
|
|
|
262 |
'--Var(LocalLibDir)',
|
|
|
263 |
'--Var(LocalBinDir)',
|
| 3921 |
dpurdie |
264 |
'--Var(PkgArch)',
|
| 407 |
dpurdie |
265 |
|
| 417 |
dpurdie |
266 |
"-Name=$build_name", # Base Package Name
|
| 427 |
dpurdie |
267 |
"-Variant=$build_variant", # Variant Name
|
| 4188 |
dpurdie |
268 |
"-Output=--GeneratedProg{$DebianPkgName}",# Specify output file
|
| 4740 |
dpurdie |
269 |
@optArgs, # Optional args - tarfile
|
| 407 |
dpurdie |
270 |
);
|
|
|
271 |
|
|
|
272 |
#
|
|
|
273 |
# The Packager has created a binary in the 'PROG' directory
|
|
|
274 |
# Lets package it as a program.
|
|
|
275 |
#
|
| 4188 |
dpurdie |
276 |
if ($deploy_mode)
|
|
|
277 |
{
|
| 4740 |
dpurdie |
278 |
PackageFile ('*', @outputFiles );
|
| 4188 |
dpurdie |
279 |
}
|
|
|
280 |
else
|
|
|
281 |
{
|
| 4740 |
dpurdie |
282 |
PackageProg ('*', @outputFiles );
|
| 4188 |
dpurdie |
283 |
}
|
| 407 |
dpurdie |
284 |
}
|
|
|
285 |
|
|
|
286 |
1;
|