forked from tbsdtv/media_build
-
Notifications
You must be signed in to change notification settings - Fork 1
/
build
executable file
·717 lines (553 loc) · 17.2 KB
/
build
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
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
#!/usr/bin/perl
use strict;
use Getopt::Long;
use Pod::Usage;
#####################
# Parameters handling
#####################
my $level = 0;
my $help = 0;
my $man = 0;
my $check_only = 0;
my $main_git = 0;
my $depth;
my @git;
#my $main_git_url = "git://linuxtv.org/media_tree.git";
#my $main_branch = "master";
#my $firmware_url = "http://www.linuxtv.org/downloads/firmware/";
#my $firmware_tarball = "dvb-firmwares.tar.bz2";
my $main_git_url = "https://github.com/tbsdtv/linux_media.git";
my $main_branch = "latest";
my $firmware_url = "https://github.com/tbsdtv/media_build/releases/download/latest";
my $firmware_tarball = "dvb-firmwares.tar.bz2";
GetOptions('v|verbose' => \$level,
'help|?' => \$help,
man => \$man,
'check_only|check-only' => \$check_only,
'main_git|main-git' => \$main_git,
'depth=i' => \$depth,
'git=s{2}' => \@git,
) or pod2usage(2);
pod2usage(1) if $help;
pod2usage(-exitstatus => 0, -verbose => 2) if $man;
$depth="--depth $depth" if ($depth);
#############
# Static vars
#############
my @missing;
my $system_release;
##################################################
# Subroutines used at the check missing deps logic
##################################################
sub catcheck($)
{
my $res = "";
$res = qx(cat $_[0]) if (-r $_[0]);
return $res;
}
sub give_redhat_hints()
{
my $install;
my %map = (
"wget" => "wget",
"lsdiff" => "patchutils",
"Digest::SHA" => "perl-Digest-SHA",
"Proc::ProcessTable" => "perl-Proc-ProcessTable",
);
foreach my $prog (@missing) {
print "ERROR: please install \"$prog\", otherwise, build won't work.\n";
if (defined($map{$prog})) {
$install .= " " . $map{$prog};
} else {
$install .= " " . $prog;
}
}
printf("You should run:\n\tyum install -y $install\n");
}
sub give_ubuntu_hints()
{
my $install;
my %map = (
"lsdiff" => "patchutils",
"Digest::SHA" => "libdigest-sha1-perl",
"Proc::ProcessTable" => "libproc-processtable-perl",
);
foreach my $prog (@missing) {
print "ERROR: please install \"$prog\", otherwise, build won't work.\n";
if (defined($map{$prog})) {
$install .= " " . $map{$prog};
} else {
$install .= " " . $prog;
}
}
printf("You should run:\n\tsudo apt-get install $install\n");
}
sub give_opensuse_hints()
{
my $install;
my %map = (
"lsdiff" => "patchutils",
"Digest::SHA" => "perl-Digest-SHA1",
"Proc::ProcessTable" => "perl-Proc-ProcessTable",
);
my $need_perl_repo = 0;
foreach my $prog (@missing) {
print "ERROR: please install \"$prog\", otherwise, build won't work.\n";
if (defined($map{$prog})) {
$install .= " " . $map{$prog};
} else {
$install .= " " . $prog;
}
if ($prog eq "Proc::ProcessTable") {
$need_perl_repo = 1;
}
}
printf("You should run:\n\tsudo zypper install $install\n");
if ($need_perl_repo) {
printf("\nThe Proc::ProcessTable perl module can be found in the perl buildservice repository. ");
printf("Add with the command (replacing 12.1 with your openSUSE release version):\n");
printf("\tsudo zypper ar http://download.opensuse.org/repositories/devel:/languages:/perl/openSUSE_12.1/ perl\n");
}
}
sub give_arch_linux_hints()
{
my $install;
my %map = (
"lsdiff" => "community/patchutils",
"Digest::SHA" => "extra/perl-digest-sha1",
"Proc::ProcessTable" => "aur/perl-proc-processtable",
);
foreach my $prog (@missing) {
print "ERROR: please install \"$prog\", otherwise, build won't work.\n";
if (defined($map{$prog})) {
$install .= " " . $map{$prog};
} else {
$install .= " " . $prog;
}
}
printf("You should install those package(s) (repository/package): $install\n");
}
sub give_gentoo_hints()
{
my $install;
my %map = (
"lsdiff" => "dev-util/patchutils",
"Digest::SHA" => "dev-perl/Digest-SHA1",
"Proc::ProcessTable" => "dev-perl/Proc-ProcessTable",
);
foreach my $prog (@missing) {
print "ERROR: please install \"$prog\", otherwise, build won't work.\n";
if (defined($map{$prog})) {
$install .= " " . $map{$prog};
} else {
$install .= " " . $prog;
}
}
printf("You should emerge those package(s): $install\n");
}
sub give_hints()
{
# Distro-specific hints
if ($system_release =~ /Red Hat Enterprise Linux/) {
give_redhat_hints;
return;
}
if ($system_release =~ /Fedora/) {
give_redhat_hints;
return;
}
if ($system_release =~ /Ubuntu/) {
give_ubuntu_hints;
return;
}
if ($system_release =~ /openSUSE/) {
give_opensuse_hints;
return;
}
if ($system_release =~ /Arch Linux/) {
give_arch_linux_hints;
return;
}
if ($system_release =~ /Debian/) {
give_ubuntu_hints;
return;
}
if ($system_release =~ /Raspbian/) {
give_ubuntu_hints;
return;
}
if ($system_release =~ /Gentoo/) {
give_gentoo_hints;
return;
}
# Fall-back to generic hint code
foreach my $prog (@missing) {
print "ERROR: please install \"$prog\", otherwise, build won't work.\n";
}
print "I don't know distro $system_release. So, I can't provide you a hint with the package names.\n";
print "Be welcome to contribute with a patch for media-build, by submitting a distro-specific hint\n";
print "to linux-media\@vger.kernel.org\n";
}
my $need = 0;
sub findprog($)
{
foreach(split(/:/, $ENV{PATH})) {
return "$_/$_[0]" if(-x "$_/$_[0]");
}
}
sub need_program($)
{
my $prog = shift;
return if findprog($prog);
push @missing, $prog;
$need++;
}
sub need_perl_module($)
{
my $prog = shift;
my $err = system("perl -M$prog -e 1 2>/dev/null /dev/null");
return if ($err == 0);
push @missing, $prog;
$need++;
}
sub check_needs()
{
if ($system_release) {
print "Checking if the needed tools for $system_release are available\n";
} else {
print "Checking if the needed tools are present\n";
}
# Check for needed programs/tools
need_program "git";
need_program "make";
need_program "gcc";
need_program "patch";
need_program "lsdiff";
need_program "wget";
# Check for needed perl modules
need_perl_module "Digest::SHA";
need_perl_module "Proc::ProcessTable";
give_hints if ($need);
die "Build can't procceed as $need dependency is missing" if ($need == 1);
die "Build can't procceed as $need dependencies are missing" if ($need);
print "Needed package dependencies are met.\n";
}
######
# Git
######
sub get_remote_name()
{
if ($git[0] =~ m,^(http|https|git|git\+ssh|ssh):\/\/linuxtv.org\/(.*),) {
my $name = $2;
$name =~ s,^/git,,;
$name =~ s,\.git$,,g;
$name =~ s,/,_,g;
return ($name, 0);
}
if ($git[0] =~ m,^(http|https|git|git\+ssh|ssh):\/\/bitbucket.org\/(.*),) {
my $name = $2;
$name =~ s,^/git,,;
$name =~ s,\.git$,,g;
$name =~ s,/,_,g;
return ($name, 0);
}
if ($git[0] =~ m,^(http|https|git|git\+ssh|ssh):\/\/github.com\/(.*),) {
my $name = $2;
$name =~ s,^/git,,;
$name =~ s,\.git$,,g;
$name =~ s,/,_,g;
return ($name, 0);
}
if (!($git[0] =~ m,^(http|https|git|git\+ssh|ssh):\/\/,)) {
my $name = $git[0];
$name =~ s,\s*$,,;
$name =~ s,/$,,;
$name =~ s,/,_,g;
return ($name, 1);
}
die "Invalid URL. Need to use one from linuxtv.org site or a local one\n";
}
sub check_git($$)
{
my $cmd = shift;
my $remote = shift;
print "\$ git --git-dir media/.git $cmd (checking for '$remote')\n" if ($level);
open IN, "git --git-dir media/.git $cmd|" or die "can't run git --git-dir media/.git $cmd";
while (<IN>) {
return 1 if (m/^[\*]*\s*($remote)\n$/);
}
close IN;
print "check failed\n" if ($level);
return 0;
}
####################
# Other aux routines
####################
sub license ()
{
print "************************************************************\n";
print "* All drivers and build system are under GPLv2 License *\n";
print "* Firmware files are under the license terms found at: *\n";
printf "* %-56s *\n", $firmware_url;
print "* Please abort in the next 5 secs if you don't agree with *\n";
print "* the license *\n";
print "************************************************************\n";
print "\n";
sleep 5;
print "Not aborted. It means that the licence was agreed. Proceeding...\n\n";
}
sub which($)
{
my $file = shift;
my @path = split ":", $ENV{PATH};
foreach my $dir(@path) {
my $name = $dir.'/'.$file;
return $name if (-x $name );
}
return undef;
}
sub run($$)
{
my $cmd = shift;
my $err = shift;
$err = '' unless defined($err);
my ($pkg,$filename,$line) = caller;
print "\$ $cmd\n" if ($level);
system($cmd) == 0
or die($err . " at $filename line $line\n");
}
######
# Main
######
# Determine the system type. There's no standard unique way that would
# work with all distros with a minimal package install. So, several
# methods are used here.
#
# By default, it will use lsb_release function. If not available, it will
# fail back to reading the known different places where the distro name
# is stored
#
$system_release = qx(lsb_release -d) if which("lsb_release");
$system_release =~ s/Description:\s*// if ($system_release);
$system_release = catcheck("/etc/system-release") if !$system_release;
$system_release = catcheck("/etc/redhat-release") if !$system_release;
$system_release = catcheck("/etc/lsb-release") if !$system_release;
$system_release = catcheck("/etc/gentoo-release") if !$system_release;
$system_release = catcheck("/etc/issue") if !$system_release;
$system_release =~ s/\s+$//;
check_needs;
exit (0) if ($check_only);
if ($main_git) {
$git[0] = $main_git_url;
$git[1] = $main_branch;
}
if (@git == 2) {
my $name;
my $workdir;
my ($rname,$local) = get_remote_name();
if ($local) {
$name = "l_" . $rname;
} else {
$name = "r_" . $rname;
}
if ($git[0] ne $main_git_url) {
print "\n";
print "************************************************************\n";
print "* WARNING: This script will use a git tree as reference for*\n";
print "* the media drivers. This build system takes into accont *\n";
print "* only the main repository, and the latest staging branch. *\n";
print "* Trying to compile an old experimental tree will likely *\n";
print "* fail, as the backport patches may not fit on the needs *\n";
print "************************************************************\n";
print "\n";
$workdir = qx(which git-new-workdir);
} else {
print "************************************************************\n";
printf "* building %-38s git tree *\n", $git[0];
print "************************************************************\n";
}
license;
if (!stat "./media/.git/config") {
if (!$local) {
print "Getting the latest Kernel tree. This will take some time\n";
if ($depth) {
run("git clone --origin '$rname/$git[1]' git://linuxtv.org/media_tree.git media $depth",
"Can't clone from the upstream tree");
} else {
run("git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git media $depth",
"Can't clone from the upstream tree");
}
system('git --git-dir media/.git config format.cc "Linux Media Mailing List <[email protected]>"');
system('git --git-dir media/.git config format.signoff true');
system('git --git-dir media/.git config format.numbered auto');
system('git --git-dir media/.git config sendemail.chainreplyto false');
} else {
if ($workdir ne "") {
print "Creating a new workdir from $git[0] at media\n";
run("git new-workdir $git[0] media",
"Can't create a new workdir");
} else {
print "Creating a new clone\n";
run("git clone -l $git[0] media $depth",
"Can't create a new clone");
}
}
} elsif ($workdir eq "") {
if (check_git("remote", "$rname/$git[1]")) {
run("git --git-dir media/.git remote update '$rname/$git[1]'",
"Can't update from the upstream tree");
} else {
run("git --git-dir media/.git remote update origin",
"Can't update from the upstream tree");
}
}
if ($workdir eq "") {
if (!check_git("remote", "$name")) {
print "adding remote $name to track $git[0]\n";
run("git --git-dir media/.git remote add $name $git[0]",
"Can't create remote $name");
}
if (!$depth) {
print "updating remote $rname\n";
run("git --git-dir media/.git remote update $name",
"Can't update remote $name");
print "creating a local branch $rname\n";
if (!check_git("branch", "$rname/$git[1]")) {
run("(cd media; git checkout -b $rname/$git[1] remotes/$name/$git[1])",
"Can't create local branch $rname");
} else {
run("(cd media; git checkout $rname/$git[1])",
"Can't checkout to branch $rname");
run("(cd media; git pull . remotes/$name/$git[1])",
"Can't update local branch $name");
}
}
} else {
print "git checkout $git[1]\n";
run("(cd media; git checkout $git[1])",
"Can't checkout $git[1]");
}
run("make -C linux dir DIR=../media/",
"Can't link the building system to the media directory.");
} else {
print "\n";
print "************************************************************\n";
print "* This script will download the latest tarball and build it*\n";
print "* Assuming that your kernel is compatible with the latest *\n";
print "* drivers. If not, you'll need to add some extra backports,*\n";
print "* ./backports/<kernel> directory. *\n";
print "* It will also update this tree to be sure that all compat *\n";
print "* bits are there, to avoid compilation failures *\n";
print "************************************************************\n";
license;
print "****************************\n";
print "Updating the building system\n";
print "****************************\n";
system("git pull https://github.com/tbsdtv/media_build.git master");
run("make -C linux/ download", "Download failed");
run("make -C linux/ untar", "Untar failed");
}
print "**********************************************************\n";
print "* Downloading firmwares from linuxtv.org. *\n";
print "**********************************************************\n";
if (!stat $firmware_tarball) {
run("wget $firmware_url/$firmware_tarball -O $firmware_tarball",
"Can't download $firmware_tarball");
}
run("(cd v4l/firmware/; tar xvfj ../../$firmware_tarball)",
"Can't extract $firmware_tarball");
print "******************\n";
print "* Start building *\n";
print "******************\n";
run("make allyesconfig", "can't select all drivers");
run("make -j5", "build failed");
print "**********************************************************\n";
print "* Compilation finished. Use 'make install' to install them\n";
print "**********************************************************\n";
__END__
=head1 NAME
build - Builds the media drivers without needing to compile a new kernel
=head1 SYNOPSIS
build [--help] [--man] [--verbose] [--check-only] [<--git> [URL] [BRANCH]]
[--main-git] [--depth [DEPTH]]
=head1 OPTIONS
=over 8
=item B<--help>
Print a brief help message and exits.
=item B<--man>
Prints the manual page and exits.
=item B<--verbose>
Be more verbose.
=item B<--check-only>
Don't do anything, except for checking if the needed dependencies are there.
=item B<--git> [URL] [BRANCH]
Allows specifying a URL and a git branch, instead of the default ones.
Currently, only linuxtv.org git URL's are supported, as the build needs to
warrant an unique namespace for git remotes.
=item B<--main-git>
Use the main development git tree, as found at
L<http://git.linuxtv.org/media_tree.git>.
=item B<--depth> [DEPTH]
When doing a git clone (e. g. with --git or --main-git), pass the
depth parameter, in order to get a smaller tree.
That helps to reduce disk storage and download time.
=back
=head1 DESCRIPTION
B<build> will download and compile the latest drivers from linuxtv.org,
allowing testing them before reaching the upstream kernels.
This is an experimental build system for media drivers.
All files on this tree are covered by GPLv2, as stated at COPYING file.
Usage:
Just call the build utility:
=over 8
~/media_build $ B<./build>
=back
Then, install the drivers as root, with:
=over 8
~/media_build # B<make install>
=back
In order to test, unload old drivers with:
=over 8
~/media_build # B<make rmmod>
=back
Then modprobe the driver you want to test. For example, to load driver B<foo>:
=over 8
~/media_build # B<modprobe foo>
=back
If you're developing a new driver or patch, it is better to use:
=over 8
~/media_build $ B<./build --main-git> B<--depth 1>
=back
Then, install the drivers as root, with:
=over 8
~/media_build # B<make install>
=back
In order to test, unload old drivers with:
=over 8
~/media_build # B<make rmmod>
=back
Then modprobe the driver you want to test:
=over 8
~/media_build # B<modprobe foo>
=back
In this case, in order to modify something, you should edit the file at
the media/ subdir.
For example, a typical procedure to develop a new patch would be:
=over 8
~/media_build $ B<cd media>
~/media $ B<gedit drivers/media/video/foo.c>
~/media $ B<make -C ../v4l>
~/media $ B<make -C .. rmmod>
~/media $ B<modprobe foo>
(some procedure to test the "foo" driver)
~/media $ B<git diff >/tmp/my_changes.patch>
(email /tmp/my_changes.patch inlined to <[email protected]>)
=back
=head1 BUGS
Report bugs to <[email protected]>
=head1 COPYRIGHT
Copyright (c) 2011 by Mauro Carvalho Chehab.
License GPLv2: GNU GPL version 2 L<http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
=cut