diff options
author | Mauro Carvalho Chehab <devnull@localhost> | 2005-10-19 14:43:56 +0000 |
---|---|---|
committer | Mauro Carvalho Chehab <devnull@localhost> | 2005-10-19 14:43:56 +0000 |
commit | 5c29d617cbe473dc90f773b0af712db7605002c1 (patch) | |
tree | 2e9882caffe0e13b75ab712bd3de758866a8d112 | |
parent | 70ce3008a2aaf2ba66b48107241c913010e9d4dd (diff) | |
download | mediapointer-dvb-s2-5c29d617cbe473dc90f773b0af712db7605002c1.tar.gz mediapointer-dvb-s2-5c29d617cbe473dc90f773b0af712db7605002c1.tar.bz2 |
* ../v4l/scripts/gentree.pl:
- Add new script to create a clean tree (without uneeded #if).
Signed-off-by: Mauro Carvalho Chehab <mchehab@brturbo.com.br>
-rw-r--r-- | v4l/ChangeLog | 7 | ||||
-rw-r--r-- | v4l/scripts/gentree.pl | 186 |
2 files changed, 193 insertions, 0 deletions
diff --git a/v4l/ChangeLog b/v4l/ChangeLog index 1aa91a040..fbf185bbd 100644 --- a/v4l/ChangeLog +++ b/v4l/ChangeLog @@ -1,3 +1,10 @@ +2005-10-19 14:39 mchehab + + * ../v4l/scripts/gentree.pl: + - Add new script to create a clean tree (without uneeded #if). + + Signed-off-by: Mauro Carvalho Chehab <mchehab@brturbo.com.br> + 2005-10-19 14:19 mchehab * ../linux/drivers/media/video/tuner-core.c: (tuner_attach): diff --git a/v4l/scripts/gentree.pl b/v4l/scripts/gentree.pl new file mode 100644 index 000000000..21076092e --- /dev/null +++ b/v4l/scripts/gentree.pl @@ -0,0 +1,186 @@ +#!/usr/bin/perl +use strict; +use File::Find; +use Fcntl ':mode'; +use Cwd; + +my $VER = shift; +my $SRC = shift; +my $DESTDIR = shift; +my $cwd; + +$SRC = "../linux" if !defined($SRC); +$VER = "2.6.14" if !defined($VER); +$DESTDIR = "/tmp/linux" if !defined($DESTDIR); + +my ($VERSION,$CODE) = &kernel_version; +my $DEBUG = 0; + + +################################################################# +# helpers + +sub kernel_version() { + my ($ver,$code); + + $code = 0; + $ver = $VER; + + $ver =~ m/^(\d)\.(\d)\.(\d)/; + my $v1 = $1; + my $v2 = $2; + my $v3 = $3; + foreach my $name ($v1, $v2, $v3) { + $code = $code * 256 + $1; + } + + return ($ver,$code); +} + + +################################################################# +# filter out version-specific code + +sub filter_source ($$) { + my ($in,$out) = @_; + my ($line,$if,$state,$mmkernel); + + 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 =~ m/\$Id: gentree.pl,v 1.1 2005/10/19 14:43:56 mchehab Exp $/) { + next; + } + if ($line =~ /^#ifdef MM_KERNEL/) { + chomp($line); + $state = "if"; + $if = $mmkernel; + print OUT "/* BP #if $if ($line) */\n" if $DEBUG; + next; + } + if ($line =~ /^#if 0/) { + chomp($line); + $state = "if"; + $if = 0; + print OUT "/* BP #if $if ($line) */\n" if $DEBUG; + next; + } + if ($line =~ /^#if 1 .*KEEP.*/) { + print OUT "#if 1\n"; + next; + } + if ($line =~ /^#if 1/) { + chomp($line); + $state = "if"; + $if = 1; + print OUT "/* BP #if $if ($line) */\n" if $DEBUG; + 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; + 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; +} + +################################################################# + +sub parse_dir { + my $file = $File::Find::name; + my $srcdir=$SRC; + + if ($file =~ /CVS/) { + return; + } + + if ($file =~ /\~$/) { + return; + } + + my $mode = (lstat("$cwd/$file"))[2]; + +# printf "Permissions of %s/%s are %04o (dir=%s\n", $cwd,$file, $mode, cwd; + + if ($mode & S_IFDIR) { + return; + } + + $srcdir =~ s/(.)/[\]($1)/g; + my $f2 = $file; + + $f2 =~ s,^$srcdir,$DESTDIR,; + print STDERR "from $file to $f2\n"; + + my $tmp = "/tmp/src.$$"; + filter_source("$cwd/$file","$tmp"); + + my $dir = $f2; + $dir =~ s,(.*)[/][^/]*$,$1,; + + print("mkdir -p $dir\n"); + system("mkdir -p $dir\n"); + system("cp $tmp $f2"); + unlink $tmp; +} + + +# main + +my $patchtmploc = "/tmp/temp.patch"; + +printf STDERR <<EOF,$VER,$CODE; +kernel is %s (0x%x) +EOF + +print STDERR "finding files at $SRC\n"; + +$cwd=cwd; + +find(\&parse_dir, $SRC); |