summaryrefslogtreecommitdiff
path: root/v4l/scripts
diff options
context:
space:
mode:
authorMauro Carvalho Chehab <devnull@localhost>2005-10-20 20:07:30 +0000
committerMauro Carvalho Chehab <devnull@localhost>2005-10-20 20:07:30 +0000
commit4e8c37e2c7d33a82afae943dc1d8d83a3374ab8d (patch)
treec90a9b27b9e3ff6b24168b9ea4d27e7c2aee1065 /v4l/scripts
parentd1669206c04cdc1237a24e87f2fec6a34ef0571f (diff)
downloadmediapointer-dvb-s2-4e8c37e2c7d33a82afae943dc1d8d83a3374ab8d.tar.gz
mediapointer-dvb-s2-4e8c37e2c7d33a82afae943dc1d8d83a3374ab8d.tar.bz2
- This script does create a version-specific V4L tree on
another dir, removing compat references. It allows nested #if or #ifdef. - It needs more testing. Signed-off-by: Mauro Carvalho Chehab <mchehab@brturbo.com.br>
Diffstat (limited to 'v4l/scripts')
-rw-r--r--v4l/scripts/gentree.pl170
1 files changed, 129 insertions, 41 deletions
diff --git a/v4l/scripts/gentree.pl b/v4l/scripts/gentree.pl
index 2e7c47950..49d0dd3ac 100644
--- a/v4l/scripts/gentree.pl
+++ b/v4l/scripts/gentree.pl
@@ -8,13 +8,20 @@ my $VER = shift;
my $SRC = shift;
my $DESTDIR = shift;
my $cwd;
+my $extra;
-$VER = "2.6.14" if !defined($VER);
-$SRC = "../linux" if !defined($SRC);
-$DESTDIR = "/tmp/linux" if !defined($DESTDIR);
+
+#$VER = "2.6.14" if !defined($VER);
+#$SRC = "../linux" if !defined($SRC);
+#$DESTDIR = "/tmp/linux" if !defined($DESTDIR);
+
+if (!defined($DESTDIR)) {
+ print "Usage:\ngentree.pl\t<version> <source dir> <dest dir>\n\n";
+ exit;
+}
my ($VERSION,$CODE) = &kernel_version;
-my $DEBUG = 0;
+my $DEBUG = 1;
#################################################################
@@ -26,30 +33,40 @@ sub kernel_version() {
$code = 0;
$ver = $VER;
- $ver =~ m/^(\d)\.(\d)\.(\d)/;
+ $ver =~ m/(\d)\.(\d)\.([0-9]*(.*))/;
my $v1 = $1;
my $v2 = $2;
my $v3 = $3;
- foreach my $name ($v1, $v2, $v3) {
- $code = $code * 256 + $1;
- }
+ $extra = $4;
+
+ $code = $v1*65536 + $v2*256 + $v3;
return ($ver,$code);
}
-
#################################################################
# filter out version-specific code
sub filter_source ($$) {
my ($in,$out) = @_;
- my ($line,$if,$state,$mmkernel);
+ my ($line,$mmkernel);
+ my $level=0;
+ my %if = ();
+ my %state =();
+ my $print=0;
+
+ if ($extra =~ m/\-mm/) {
+ $mmkernel = 1;
+ } else {
+ $mmkernel = 0;
+ }
open IN, "<$in";
open OUT, ">$out";
+ print STDERR "File: $in, for kernel $VERSION($CODE)/\n" if $DEBUG;
+
while ($line = <IN>) {
- die "nested" if defined($state) && $line =~ /^#if/;
if ($line =~ m/^#include <linux\/version.h>/ &&
$in =~ m/.*\.c/) {
next;
@@ -62,74 +79,141 @@ sub filter_source ($$) {
}
if ($line =~ /^#ifdef MM_KERNEL/) {
chomp($line);
- $state = "if";
- $if = $mmkernel;
- print OUT "/* BP #if $if ($line) */\n" if $DEBUG;
+ $state{$level} = "if";
+ $if{$level} = $mmkernel;
+ print STDERR "/* BP #if MM_KERNEL state=$state{$level} if=$if{$level} level=$level ($line) */\n" if $DEBUG;
+ $level++;
next;
}
if ($line =~ /^#if 0/) {
chomp($line);
- $state = "if";
- $if = 0;
- print OUT "/* BP #if $if ($line) */\n" if $DEBUG;
+ $state{$level} = "if";
+ $if{$level} = 0;
+ print STDERR "/* BP #if 0 state=$state{$level} if=$if{$level} level=$level ($line) */\n" if $DEBUG;
+ $level++;
next;
}
if ($line =~ /^#if 1 .*KEEP.*/) {
print OUT "#if 1\n";
+ $state{$level} = "ifother";
+ $if{$level} = 1;
+ print STDERR "/* BP #if 1 (keep) state=$state{$level} if=$if{$level} level=$level ($line) */\n" if $DEBUG;
+ $level++;
next;
}
if ($line =~ /^#if 1/) {
chomp($line);
- $state = "if";
- $if = 1;
- print OUT "/* BP #if $if ($line) */\n" if $DEBUG;
+ $state{$level} = "if";
+ $if{$level} = 1;
+ print STDERR "/* BP #if 1 state=$state{$level} if=$if{$level} level=$level ($line) */\n" if $DEBUG;
+ $level++;
next;
}
if ($line =~ /^#if.*BTTV_VERSION_CODE/) {
chomp($line);
- $state = "if";
$line =~ s@^#if\s*@@;
$line =~ s@BTTV_VERSION_CODE@\$CODE@;
$line =~ s@KERNEL_VERSION\((\d+),\s*(\d+),\s*(\d+)\)@
sprintf("%d",$1*65536 + $2*256 + $3) @e;
- $if = eval $line;
- print OUT "/* BP #if $if ($line) */\n" if $DEBUG;
+ $if{$level} = eval $line;
+ $state{$level} = "if";
+ print STDERR "/* BP #if BTTV_VERSION_CODE state=$state{$level} if=$if{$level} level=$level ($line) */\n" if $DEBUG;
+ $level++;
next;
}
if ($line =~ /^#if.*LINUX_VERSION_CODE/) {
chomp($line);
$line =~ s@^#if\s*@@;
$line =~ s@LINUX_VERSION_CODE@\$CODE@;
+print STDERR "/* BP orig: ($line) */\n" if $DEBUG;
+
$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;
+ $if{$level} = eval $line;
+ $state{$level} = "if";
+ print STDERR "/* BP #if LINUX_VERSION_CODE state=$state{$level} if=$if{$level} level=$level ($line) */\n" if $DEBUG;
+ $level++;
next;
}
- if (defined($state) && $line =~ /^#else/) {
- $state = "else";
- print OUT "/* BP #else */\n" if $DEBUG;
- next;
+ if ($line =~ /^#if/) {
+ $state{$level} = "ifother";
+ $if{$level} = 1;
+ print STDERR "/* BP $line state=$state{$level} if=$if{$level} level=$level ($line) */\n" if $DEBUG;
+ $level++;
}
- if (defined($state) && $line =~ /^#endif/) {
- undef $state;
- print OUT "/* BP #endif */\n" if $DEBUG;
- next;
+
+ if ($line =~ /^#ifdef/) {
+ $state{$level} = "ifother";
+ $if{$level} = 1;
+ print STDERR "/* BP $line state=$state{$level} if=$if{$level} level=$level ($line) */\n" if $DEBUG;
+ $level++;
}
- if (!defined($state) ||
- $state eq "if" && $if ||
- $state eq "else" && !$if) {
+
+ if ($level) {
+ if ($state{$level-1} eq "if" && $line =~ /^#else/) {
+ $state{$level-1} = "else";
+ print STDERR "/* BP #else state=$state{$level} if=$if{$level} level=$level ($line) */\n" if $DEBUG;
+ next;
+ }
+ }
+ if ($line =~ /^#endif/) {
+ if ($level) {
+ $level--;
+
+ print STDERR "/* BP #endif state=$state{$level} if=$if{$level} level=$level ($line) */\n" if $DEBUG;
+ } else {
+ die "more endifs than ifs";
+ }
+ if ($state{$level} ne "ifother") {
+ next;
+ }
+ }
+ if ($level == 0) {
print OUT $line;
} else {
- chomp($line);
- print OUT "/* BP DEL $line */\n" if $DEBUG;
+ my $i=0,$print=1;
+ for ($i=0;$i<$level;$i++) {
+ if (!($state{$i} eq "if" && $if{$i} ||
+ $state{$i} eq "else" && !$if{$i}) &&
+ $state{$i} ne "ifother" ) {
+ $print=0;
+ chomp($line);
+ print STDERR "/* BP DEL $line state=$state{$i} if=$if{$i} level=$i */\n" if $DEBUG;
+ }
+ }
+
+ if ($print) {
+ print OUT $line;
+ }
}
}
close IN;
close OUT;
}
+sub filter_dest ($$) {
+ my ($in,$out) = @_;
+ my ($line,$if,$state,$mmkernel);
+
+ if ($extra =~ "/\-mm/") {
+ $mmkernel = 1;
+ } else {
+ $mmkernel = 0;
+ }
+
+ open IN, "<$in";
+ open OUT, ">$out";
+
+ while ($line = <IN>) {
+ if ($line =~ m/[\$]Id:.*/) {
+ next;
+ }
+ print OUT $line;
+ }
+ close IN;
+ close OUT;
+}
+
#################################################################
sub parse_dir {
@@ -156,10 +240,14 @@ sub parse_dir {
my $f2 = $file;
$f2 =~ s,^$srcdir,$cwd/$DESTDIR/,;
- print STDERR "from $file to $f2\n";
+ print "from $file to $f2\n";
my $tmp = "/tmp/src.$$";
- filter_source("$cwd/$file","$tmp");
+ if ($file =~ m/.*\.[ch]$/) {
+ filter_source("$cwd/$file","$tmp");
+ } else {
+ system("cp $cwd/$file $tmp");
+ }
my $dir = $f2;
$dir =~ s,(.*)[/][^/]*$,$1,;