This repository has been archived by the owner on Dec 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mud2
executable file
·401 lines (340 loc) · 12.3 KB
/
mud2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
#!/usr/bin/perl
#
# mud2 - MeeGo Unified Distribution
# ~~~~
#
# Help with packaging and distributing Maemo/MeeGo applications.
#
# Package a Qt Creator project into something suitable for sending to:
# * maemo.org Extras Autobuilder
# * meego.com Harmattan OBS
#
# Copyright (c) Andrew Flegg 2011. Released under the Artistic License.
# mailto:[email protected]
# Copyright (c) Assaf Paz 2012. Released under the Artistic License.
# mailto:[email protected]
use strict;
use warnings;
use Text::Wrap;
use Cwd;
$Text::Wrap::columns = 72;
# -- Identify the project...
#
my @pros = <*.pro>;
die "Found multiple .pro files in current directory\n" unless @pros == 1;
my ($package) = $pros[0] =~ m!(.*)\.pro;
my $debianPackage = $package;
my $meegoPackage = $package;
open(IN, "<$pros[0]") or die "Unable to read $pros[0]\n";
while (<IN>) {
chomp;
$debianPackage = lc($1) if /^\s*TARGET\s*=\s*([\w-]+)\s*$/;
$meegoPackage = lc($1) if /^\s*PACKAGE\s*=\s*([\w\.-]+)\s*$/;
}
close(IN);
# -- Target for the output...
#
my $dir = "../$package-build-mud";
mkdir $dir;
# -- What packaging is available...
#
my $pkgDebianFremantle = -d "qtc_packaging/debian_fremantle";
my $pkgDebianHarmattan = -d "qtc_packaging/debian_harmattan";
my $pkgDebianUbuntu = -d "qtc_packaging/debian_ubuntu";
my $pkgMeeGo = 0;
# -- Build source tarball...
#
# -- Build packages...
#
&createNativeDebian('ubuntu_oneiric');
&createNativeDebian('ubuntu_precise');
&createDebian('fremantle', '1.0', 0, sub {
my ($version) = @_;
&write('5', "$dir/fremantle/debian/compat");
system("tar", "cvzf", "$dir/fremantle/${package}_${version}.orig.tar.gz",
"--exclude-vcs",
"--exclude=qtc_packaging",
".",
"-C", "$dir/fremantle",
"debian");
# TODO Create as a patch
}, 1) if $pkgDebianFremantle;
&createDebian('harmattan', '3.0 (quilt)', 0, sub {
my ($version) = @_;
system("tar", "cvzf", "$dir/harmattan/${package}_${version}.debian.tar.gz",
"-C", "$dir/harmattan",
"--exclude-vcs",
"debian");
system("tar", "cvzf", "$dir/harmattan/${package}_${version}.orig.tar.gz",
"--exclude-vcs",
"--exclude=debian",
"--exclude=qtc_packaging",
".");
}) if $pkgDebianHarmattan;
&createSpec('meego', sub {
# TODO Unsupported
}) if $pkgMeeGo;
exit;
# ===========================================================================
# createSpec - Make the .spec file ready for RPM
# ---------------------------------------------------------------------------
sub createSpec {
my ($dist, $content) = @_;
&$content;
}
# ===========================================================================
# createDebian - Clone the debian directory and resolve it ready for updates
# ---------------------------------------------------------------------------
sub createDebian {
my ($dist, $format, $is_signed, $content, $create_changes) = @_;
# -- Copy the source and rationalise the debian folder...
#
&createDist($dist);
system("cp", "-Lr", "qtc_packaging/debian_$dist", "$dir/$dist/debian");
mkdir "$dir/$dist/debian/source";
&write($format, "$dir/$dist/debian/source/format");
# -- Fix debian/rules...
#
my $rules = &read("$dir/$dist/debian/rules");
my $configureStamp = &readMakefile($rules, 'configure-stamp');
my $buildStamp = &readMakefile($rules, 'build-stamp');
my $clean = &readMakefile($rules, 'clean');
# Add qmake
unless ($rules =~ m!^\tqmake PREFIX=/usr$!m) {
$rules =~ s!^(configure-stamp:.*[\r\n]*\tdh_testdir\s*$)
!$1\n\tqmake PREFIX=/usr\n!xm;
print "+++ Adding qmake\n";
}
# Add $(MAKE)
unless ($buildStamp =~ /^\t\$\(MAKE\)\s*$/m) {
$rules =~ s!^(build-stamp:.*[\r\n]*\tdh_testdir\s*$)
!$1\n\t\$(MAKE)\n!xm;
print "+++ Adding make\n";
}
# Make it "-$(MAKE) clean" as the makefile won't exist at first
$rules =~ s/^\t(\$\(MAKE\)\s+clean\s*)$/\t-$1/mg and
print "+++ Fixing clean\n";
# Enable dh_shlibdeps
unless ($rules =~ /^\tdh_shlibdeps\s*$/m) {
$rules =~ s!^(\tdh_installdeb\s*$)
!$1\n\tdh_shlibdeps\n!xm;
print "+++ Adding dh_shlibdeps\n";
}
&write($rules, "$dir/$dist/debian/rules");
# -- Read control file
#
my $maintainer = "TBC <foo\@example.com>";
my $build_depends = "debhelper (>= 5), libqt4-dev";
my $description = "TBD";
my $control_file = "qtc_packaging/debian_$dist/control";
my $section = "";
my $priority = "";
my $homepage = "";
open(CONTROL_FILE, "<$control_file") or die "Unable to read $control_file\n";
while (<CONTROL_FILE>) {
chomp;
$section = $1 if /^\s*Section\s*:\s*(.+)\s*$/;
$priority = $1 if /^\s*Priority\s*:\s*(.+)\s*$/;
$maintainer = $1 if /^\s*Maintainer\s*:\s*(.+)\s*$/;
$build_depends = $1 if /^\s*Build-Depends\s*:\s*(.+)\s*$/;
$description = $1 if /^\s*Description\s*:\s*(.+)\s*$/;
$homepage = $1 if /^\s*Homepage*:\s*(.+)\s*$/;
}
close(CONTROL_FILE);
# -- Read changelog file
#
my $changelog = "";
my $date = "";
my $changelog_file = "qtc_packaging/debian_$dist/changelog";
my $version = "";
my $distribution = "";
open(CHANGELOG_FILE, "<$changelog_file") or die "Unable to read $changelog_file\n";
while (<CHANGELOG_FILE>) {
chomp;
if ($version eq "" and /^[^(]+\(([^)]+)\)\s+([^;]+);/)
{
$version = $1;
$distribution = $2;
next;
}
$changelog .= " ".$1."\n" if /^\s*(\*.+)\s*$/;
if (/^\s*--.+\s+((Sun|Mon|Tue|Wed|Thu|Fri|Sat),\s+.+)$/)
{
$date = $1;
last if /^\s*--/;
}
}
close(CHANGELOG_FILE);
# -- Execute custom content modifications...
#
&$content($version);
# -- Create the DSC file...
#
&mkDsc("$dir/$dist", $format, $version, $maintainer, $build_depends, $homepage, $is_signed);
# -- Create the .changes file...
#
$create_changes && &mkChanges("$dir/$dist", "${package}_${version}_any.changes", $version, $maintainer, $description, $date, $changelog, $distribution, $section, $priority, $is_signed);
}
sub createNativeDebian {
my ($dist) = @_;
# -- Read changelog file
#
my $changelog_file = "qtc_packaging/debian_$dist/changelog";
my $version = "";
open(CHANGELOG_FILE, "<$changelog_file") or die "Unable to read $changelog_file\n";
while (<CHANGELOG_FILE>) {
chomp;
if ($version eq "" and /^[^(]+\(([^)]+)\)\s+[^;]+;/)
{
$version = $1;
last;
}
}
close(CHANGELOG_FILE);
# -- Copy the source and rationalise the debian folder...
#
&createDist($dist);
my $cwd = getcwd;
system("cp", "-r", "$cwd", "$dir/$dist/$package-$version") == 0 or die "Failed to copy $cwd";
system("cp", "-r", "qtc_packaging/debian_$dist", "$dir/$dist/$package-$version/debian") == 0 or die "Failed to copy debian files";
chdir("$dir/$dist/$package-$version") or die "Failed to chdir to $dir/$dist/$package-$version";
my $rc = system("debuild", "-S");
chdir($cwd);
$rc == 0 or die "Failed to create package for $dist";
}
# ===========================================================================
# createDist - Clone the source ready for packaging/distribution
# ---------------------------------------------------------------------------
sub createDist {
my ($dist) = @_;
system("rm", "-rf", "$dir/$dist");
mkdir "$dir/$dist";
}
# ===========================================================================
# mkDsc - Create a Debian DSC file
# ---------------------------------------------------------------------------
sub mkDsc {
my ($dir, $format, $version, $maintainer, $build_depends, $homepage, $is_signed) = @_;
my $dsc = "${package}_${version}.dsc";
open(DSC, ">$dir/$dsc.unsigned") or die "Unable to write $dir/$dsc: $!\n";
print DSC <<EOH;
Format: $format
Source: $debianPackage
Binary: $debianPackage
Architecture: any
Version: $version
Maintainer: $maintainer
Homepage: $homepage
Standards-Version: 3.7.3
Build-Depends: $build_depends
EOH
my $checksums = "Checksums-Sha1: \n";
my $checksums256 = "Checksums-Sha256: \n";
my $files = "Files: \n";
foreach my $file (<$dir/*>) {
next unless -f $file && $file !~ /\.dsc(\.unsigned)*$/;
chomp(my $sha1 = `sha1sum "$file" | cut -d' ' -f1`);
chomp(my $sha256 = `sha256sum "$file" | cut -d' ' -f1`);
chomp(my $md5 = `md5sum "$file" | cut -d' ' -f1`);
my $size = -s $file;
$file =~ s!.*/([^/]+)$!$1!;
$checksums .= " $sha1 $size $file\n";
$checksums256 .= " $sha256 $size $file\n";
$files .= " $md5 $size $file\n";
}
print DSC $checksums;
print DSC $checksums256;
print DSC $files."\n";
close(DSC) or die "Unable to close $dir/$dsc: $!\n";
if ($is_signed)
{
`gpg --output $dir/$dsc --clearsign $dir/$dsc.unsigned`;
unlink "$dir/$dsc.unsigned";
}
else
{
rename "$dir/$dsc.unsigned", "$dir/$dsc"
}
}
# ===========================================================================
# mkChanges - Create a Debian .changes file
# ---------------------------------------------------------------------------
sub mkChanges {
my ($dir, $changes, $version, $maintainer, $description, $date, $changelog, $distribution, $section, $priority, $is_signed) = @_;
open(CHANGES, ">$dir/$changes.unsigned") or die "Unable to write $dir/$changes: $!\n";
print CHANGES <<EOH;
Format: 1.8
Date: $date
Source: $package
Binary: $package
Architecture: source
Version: $version
Distribution: $distribution
Urgency: low
Maintainer: $maintainer
Changed-By: $maintainer
Description:
$package - $description
Changes:
$package ($version) $distribution; urgency=low
.
EOH
print CHANGES $changelog;
my $checksums = "Checksums-Sha1: \n";
my $checksums256 = "Checksums-Sha256: \n";
my $files = "Files: \n";
foreach my $file (<$dir/*>) {
next unless -f $file && $file !~ /\.changes(\.unsigned)*$/;
chomp(my $sha1 = `sha1sum "$file" | cut -d' ' -f1`);
chomp(my $sha256 = `sha256sum "$file" | cut -d' ' -f1`);
chomp(my $md5 = `md5sum "$file" | cut -d' ' -f1`);
my $size = -s $file;
$file =~ s!.*/([^/]+)$!$1!;
$checksums .= " $sha1 $size $file\n";
$checksums256 .= " $sha256 $size $file\n";
$files .= " $md5 $size $section $priority $file\n";
}
print CHANGES $checksums;
print CHANGES $checksums256;
print CHANGES $files."\n";
close(CHANGES) or die "Unable to close $dir/$changes: $!\n";
if ($is_signed)
{
`gpg --output $dir/$changes --clearsign $dir/$changes.unsigned`;
unlink "$dir/$changes.unsigned";
}
else
{
rename "$dir/$changes.unsigned", "$dir/$changes"
}
}
# ===========================================================================
# readMakefile - Read a specific target from a makefile
# ---------------------------------------------------------------------------
sub readMakefile {
my ($content, $target) = @_;
$content =~ /^(\Q$target\E:\s*.*?)^\w/sm;
return "$1\n";
}
# ===========================================================================
# write - Write some content to a file, simply.
# ---------------------------------------------------------------------------
sub write {
my ($content, $file) = @_;
open(OUT, ">$file") or die "Unable to write to $file: $!\n";
print OUT $content;
close(OUT) or die "Unable to close $file: $!\n";
}
# ===========================================================================
# read - Slurp all of a file in for processing
# ---------------------------------------------------------------------------
sub read {
my ($file) = @_;
my $content = '';
open(IN, "<$file") or die "Unable to open $file: $!\n";
while (<IN>) {
$content .= $_;
}
return $content;
}