Add the tar.bz2 archive
[dvb-osmc.git] / linux / patches_for_kernel.pl
blob91b79fd42fcb6105d5166627a74f0bf3b1713720
1 #!/usr/bin/perl
3 # This script allows checking what patches are needed for a given
4 # kernel version.
5 # Use it as ./patches_for_kernel.pl <version>
6 # The backport files are specified at: ../backports/backports.txt
8 use strict;
10 my $version = shift or die "Need a version to apply patches";
12 my $file = "../backports/backports.txt";
13 open IN, $file or die "can't find $file\n";
15 sub kernel_version($) {
16 my ($version, $patchlevel, $sublevel) = $_[0] =~ m/^(\d+)\.(\d+)\.?(\d*)/;
18 # fix kernel version for distros that 'translated' 3.0 to 2.6.40
19 if ($version == 2 && $patchlevel == 6 && $sublevel >= 40) {
20 $version = 3;
21 $patchlevel = $sublevel - 40;
22 $sublevel = 0;
24 $sublevel = 0 if ($sublevel == "");
25 return ($version * 65536 + $patchlevel * 256 + $sublevel);
28 my $kernel = kernel_version($version);
30 die "Invalid kernel version" if (!$kernel);
32 my $cur;
33 my @patches;
34 my $ln;
35 while (<IN>) {
36 $ln++;
37 s/\#.*//;
38 next if (m/^\n*$/);
39 if (m/\[(.*)\]/) {
40 $cur = kernel_version($1);
41 next;
43 if (m/add\s+(.*)/) {
44 next if ($cur < $kernel);
45 push @patches, $1;
46 next;
48 if (m/delete\s+(.*)/) {
49 next if ($cur < $kernel);
50 for (my $i = 0; $i < @patches; $i++) {
51 delete $patches[$i] if ($patches[$i] eq $1);
53 next;
55 die "Can't process line $ln\n";
57 close IN;
58 die ("Unsupported Kernel version $version") if ($cur > $kernel);
60 foreach my $patch (@patches) {
61 printf "%s ", $patch;
63 print "\n";