| 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
|
| 427 |
dpurdie |
113 |
# VIXxxxxx -> vix-xxx
|
|
|
114 |
# Whitespace -> -
|
| 409 |
alewis |
115 |
# _ -> -
|
| 427 |
dpurdie |
116 |
# Remove multiple '-' characters
|
|
|
117 |
# Lowercase all text
|
| 409 |
alewis |
118 |
#
|
|
|
119 |
my $cvt = 0;
|
|
|
120 |
$cvt = 1 if ( $build_name =~ s/^ERG/erg-/ );
|
| 3923 |
dpurdie |
121 |
$cvt = 2 if ( $build_name =~ s/^VIX/vix-/ );
|
|
|
122 |
$cvt = 3 if ( $build_name =~ s~\s~-~g );
|
|
|
123 |
$cvt = 4 if ( $build_name =~ s~_~-~g );
|
|
|
124 |
$cvt = 5 if ( $build_name =~ s~--+~-~g );
|
| 427 |
dpurdie |
125 |
if ( $build_name =~ m/[A-Z]/ )
|
|
|
126 |
{
|
| 3923 |
dpurdie |
127 |
$cvt = 6;
|
| 427 |
dpurdie |
128 |
$build_name = lc $build_name;
|
|
|
129 |
}
|
| 407 |
dpurdie |
130 |
|
| 409 |
alewis |
131 |
Warning ("Package Name converted to debian friendly form: $build_name")
|
|
|
132 |
if ( $cvt );
|
|
|
133 |
|
| 413 |
dpurdie |
134 |
unless ( $build_name =~ m/^[a-z][-+a-z0-9]+$/ )
|
| 407 |
dpurdie |
135 |
{
|
|
|
136 |
Error ("Package Name does not conform to Debian Requirements",
|
| 413 |
dpurdie |
137 |
"Must be at least two characters long",
|
|
|
138 |
"Must start with an alphabetic character",
|
| 407 |
dpurdie |
139 |
"Must only contain: (a-z) (0-9) and -",
|
|
|
140 |
"Provided Name: $::ScmBuildPackage");
|
|
|
141 |
}
|
|
|
142 |
|
|
|
143 |
unless ( $::ScmBuildVersionFull =~ m/^[0-9][-+:.A-Za-z0-9]+$/ )
|
|
|
144 |
{
|
|
|
145 |
Error ("Package Version does not conform to Debian Requirements",
|
|
|
146 |
"Must only contain: (a-zA-Z) (0-9), - and .",
|
|
|
147 |
"Must sart with a number",
|
|
|
148 |
);
|
|
|
149 |
}
|
|
|
150 |
|
|
|
151 |
#
|
|
|
152 |
# Create the name of the target package
|
|
|
153 |
# The form of the name is of a fixed form.
|
|
|
154 |
#
|
|
|
155 |
# Note: "_" used since this is the format of dpkg-name
|
|
|
156 |
# Note: dpkg-name generates: Name _ Version _ Architecture
|
|
|
157 |
#
|
|
|
158 |
#
|
|
|
159 |
my $DebianPkgName = "${build_name}_${::ScmBuildVersionFull}_${::ScmPlatform}.deb";
|
|
|
160 |
|
|
|
161 |
#
|
|
|
162 |
# Simply use Generate Files
|
|
|
163 |
# With lots of options
|
|
|
164 |
#
|
|
|
165 |
Src ( '*', $script );
|
|
|
166 |
GenerateFiles ('*', "--Tool=DebianPackager.pl", # Associated tool
|
|
|
167 |
"-DebianPackage=--Prerequisite($script)", # Packager script
|
|
|
168 |
"--AutoGenerate", # Build when needed
|
|
|
169 |
"--UnknownPreq", # Always build
|
|
|
170 |
"--Clean", # Script supports jats clean
|
|
|
171 |
"--Text=Debian Package", # Display when building
|
|
|
172 |
|
|
|
173 |
'--Var(BuildName)', # Target Package
|
|
|
174 |
'--Var(BuildVersion)', # Target Version
|
|
|
175 |
'--Var(Platform)', # Target platform
|
|
|
176 |
'--Var(Product)', # Target product
|
|
|
177 |
'--Var(Target)', # Underlying Target
|
|
|
178 |
'--Var(Type)', # Build Type
|
|
|
179 |
|
|
|
180 |
'--Var(Verbose)', # Verbose operation
|
|
|
181 |
|
|
|
182 |
'--Var(InterfaceDir)', # Interface Directory
|
|
|
183 |
'--Var(InterfaceIncDir)',
|
|
|
184 |
'--Var(InterfaceLibDir)',
|
|
|
185 |
'--Var(InterfaceBinDir)',
|
|
|
186 |
|
|
|
187 |
'--Var(LibDir)', # My Artifacts
|
|
|
188 |
'--Var(BinDir)',
|
|
|
189 |
|
|
|
190 |
'--Var(PackageDir)', # My Package
|
|
|
191 |
'--Var(PackageLibDir)', # My Package Library
|
|
|
192 |
'--Var(PackageBinDir)', # My Package Bin
|
|
|
193 |
'--Var(PackagePkgDir)', # My Package/pkg.target
|
|
|
194 |
|
|
|
195 |
'--Var(LocalIncDir)', # Installed Artifacts
|
|
|
196 |
'--Var(LocalLibDir)',
|
|
|
197 |
'--Var(LocalBinDir)',
|
| 3921 |
dpurdie |
198 |
'--Var(PkgArch)',
|
| 407 |
dpurdie |
199 |
|
| 417 |
dpurdie |
200 |
"-Name=$build_name", # Base Package Name
|
| 427 |
dpurdie |
201 |
"-Variant=$build_variant", # Variant Name
|
| 407 |
dpurdie |
202 |
"-Output=--GeneratedProg($DebianPkgName)",# Specify output file
|
|
|
203 |
);
|
|
|
204 |
|
|
|
205 |
#
|
|
|
206 |
# The Packager has created a binary in the 'PROG' directory
|
|
|
207 |
# Lets package it as a program.
|
|
|
208 |
#
|
|
|
209 |
PackageProg ('*', $DebianPkgName );
|
|
|
210 |
}
|
|
|
211 |
|
|
|
212 |
1;
|