summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGerd Knorr <devnull@localhost>2005-05-03 12:21:23 +0000
committerGerd Knorr <devnull@localhost>2005-05-03 12:21:23 +0000
commit5523ba7a276b770ab17bc6b26250715fc0cf5a09 (patch)
tree597f28cf4dccda2ce18d8c0265aea16324dcd9dc
parent1a9dbd64138cd193f7a4bc3210983469b8e3976b (diff)
downloadmediapointer-dvb-s2-5523ba7a276b770ab17bc6b26250715fc0cf5a09.tar.gz
mediapointer-dvb-s2-5523ba7a276b770ab17bc6b26250715fc0cf5a09.tar.bz2
- added the buildpatch script I've used to generate kernel patches
to the new repository @ linuxtv.org @ linuxtv.org
-rw-r--r--v4l/scripts/buildpatch182
1 files changed, 182 insertions, 0 deletions
diff --git a/v4l/scripts/buildpatch b/v4l/scripts/buildpatch
new file mode 100644
index 000000000..e308d7ec2
--- /dev/null
+++ b/v4l/scripts/buildpatch
@@ -0,0 +1,182 @@
+#!/usr/bin/perl
+use strict;
+
+my $SRC = shift;
+my $LINUX = shift;
+my $CONF = shift;
+
+$SRC = "." if !defined($SRC);
+$LINUX = "/usr/src/linux" if !defined($LINUX);
+$CONF = "$SRC/.buildpatch" if !defined($CONF);
+
+my ($VERSION,$CODE) = &kernel_version;
+my $DEBUG = 0;
+
+
+#################################################################
+# helpers
+
+sub readfile ($) {
+ my ($filename) = @_;
+ my $file;
+
+ open FILE, "<$filename" or
+ die "can't open file $filename: $!";
+ { local $/; undef $/; $file = <FILE> }
+ close FILE;
+ return $file;
+}
+
+sub kernel_version() {
+ my $makefile = readfile("$LINUX/Makefile");
+ my (@ver,$ver,$code);
+
+ @ver = (); $code = 0;
+ foreach my $name ("VERSION", "PATCHLEVEL", "SUBLEVEL") {
+ $makefile =~ /$name = (\d+)/ or die;
+ $code = $code * 256 + $1;
+ push @ver,$1;
+ }
+ $ver = join(".",@ver);
+ $makefile =~ /EXTRAVERSION = (\S+)/ and $ver .= "$1";
+ return ($ver,$code);
+}
+
+
+#################################################################
+# filter out version-specific code
+
+sub filter_source ($$) {
+ my ($in,$out) = @_;
+ my ($line,$if,$state);
+
+ open IN, "<$in";
+ open OUT, ">$out";
+
+ while ($line = <IN>) {
+ die "nested" if defined($state) && $line =~ /^#if/;
+ if ($line =~ m/^#include <linux\/version.h>/ &&
+ $in =~ m/.*\.c/) {
+ next;
+ }
+ if ($line =~ m/^#include \"compat.h\"/) {
+ next;
+ }
+ if ($line =~ /^#if.*LINUX_VERSION_CODE/) {
+ chomp($line);
+ $line =~ s@^#if\s*@@;
+ $line =~ s@LINUX_VERSION_CODE@\$CODE@;
+ $line =~ s@KERNEL_VERSION\((\d+),\s*(\d+),\s*(\d+)\)@
+ sprintf("%d",$1*65536 + $2*256 + $3) @e;
+ $if = eval $line;
+ $state = "if";
+ print OUT "/* BP #if $if ($line) */\n" if $DEBUG;
+ next;
+ }
+ if (defined($state) && $line =~ /^#else/) {
+ $state = "else";
+ print OUT "/* BP #else */\n" if $DEBUG;
+ next;
+ }
+ if (defined($state) && $line =~ /^#endif/) {
+ undef $state;
+ print OUT "/* BP #endif */\n" if $DEBUG;
+ next;
+ }
+ if (!defined($state) ||
+ $state eq "if" && $if ||
+ $state eq "else" && !$if) {
+ print OUT $line;
+ } else {
+ chomp($line);
+ print OUT "/* BP DEL $line */\n" if $DEBUG;
+ }
+ }
+ close IN;
+ close OUT;
+}
+
+
+#################################################################
+# build diffs
+
+sub makediff ($$) {
+ my ($here,$kernel) = @_;
+ my ($line1,$line2,$file1,$file2);
+ my $tmp = "/tmp/src.$$";
+
+ filter_source($here,"$tmp");
+ if (-f "$LINUX/$kernel") {
+ open DIFF, "diff -u $LINUX/$kernel $tmp|";
+ } else {
+ # new file
+ open DIFF, "diff -u /dev/null $tmp|";
+ }
+
+ # header
+ $line1 = <DIFF>;
+ $line1 =~ s@$LINUX@linux-$VERSION@;
+ $line1 =~ s@/dev/null@linux-$VERSION/$kernel@;
+ $file1 = $1 if $line1 =~ m/^\-\-\- (\S+)/;
+ $line2 = <DIFF>;
+ $line2 =~ s@$tmp@linux/$kernel@;
+ $file2 = $1 if $line2 =~ m/^\+\+\+ (\S+)/;
+ print "diff -u $file1 $file2\n"
+ if defined($file1) && defined($file2);
+ print $line1;
+ print $line2;
+
+ # body
+ { local $/; undef $/; my $diff = <DIFF>; print $diff; }
+ close DIFF;
+
+ unlink $tmp;
+}
+
+sub delfile ($) {
+ my ($kernel) = @_;
+ my ($line);
+
+ return unless -f "$LINUX/$kernel";
+ open DIFF, "diff -u $LINUX/$kernel /dev/null|";
+
+ # header
+ $line = <DIFF>;
+ $line =~ s@$LINUX@linux-$VERSION@;
+ print $line;
+ $line = <DIFF>;
+ $line =~ s@/dev/null@linux/$kernel@;
+ print $line;
+
+ # body
+ { local $/; undef $/; $line = <DIFF>; print $line; }
+ close DIFF;
+}
+
+
+#################################################################
+# main
+
+printf STDERR <<EOF,$CODE;
+kernel in $LINUX is $VERSION (0x%x)
+EOF
+
+open CONFIG,"$CONF" or
+ die "can't open file $CONF: $!";
+while (my $line = <CONFIG>) {
+ $line =~ s/#.*//; # kill comments
+ next if $line =~ /^\s*$/; # empty line
+
+ if ($line =~ /srcdiff\s+(\S+)\s+(\S+)/) {
+ print STDERR "srcdiff $2\n";
+ makediff($1,$2);
+
+ } elsif ($line =~ /delete\s+(\S+)/) {
+ print STDERR "delete $1\n";
+ delfile($1);
+
+ } else {
+ die "Huh?: $line";
+
+ }
+}