#!/usr/bin/perl use strict; use File::Find; use Fcntl ':mode'; use Cwd; my $VER = shift; my $SRC = shift; my $DESTDIR = shift; my $cwd; $VER = "2.6.14" if !defined($VER); $SRC = "../linux" if !defined($SRC); $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 = ) { die "nested" if defined($state) && $line =~ /^#if/; if ($line =~ m/^#include / && $in =~ m/.*\.c/) { next; } if ($line =~ m/^#include \"compat.h\"/) { next; } if ($line =~ m/[\$]Id:/) { 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,$cwd/$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 <