diff options
Diffstat (limited to 'v4l/scripts/gentree.pl')
-rw-r--r-- | v4l/scripts/gentree.pl | 186 |
1 files changed, 186 insertions, 0 deletions
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); |