From 6414245c8fb95b7664678c441f8d84ef047d6489 Mon Sep 17 00:00:00 2001 From: Trent Piepho Date: Mon, 19 Feb 2007 15:57:38 -0800 Subject: compat: Add code to compat.h for try_to_sleep() From: Trent Piepho Compat.h used to have an argument, now it doesn't. There was also some code: if (current->flags & PF_FREEZE) { refrigerator(PF_FREEZE); } which is the same as try_to_freeze(), and so can be replaced by it. Signed-off-by: Trent Piepho --- v4l/compat.h | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'v4l') diff --git a/v4l/compat.h b/v4l/compat.h index 6ba49e825..ffe4e97a5 100644 --- a/v4l/compat.h +++ b/v4l/compat.h @@ -236,6 +236,15 @@ static inline unsigned long vmalloc_to_pfn(void * vmalloc_addr) #endif #endif +/* try_to_freeze() lost its argument. Must appear after linux/sched.h */ +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,13) && defined(_LINUX_SCHED_H) +# if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0) +# define try_to_freeze() try_to_freeze(PF_FREEZE) +# else +# define try_to_freeze() (0) +# endif +#endif + #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,14) #ifndef kzalloc #define kzalloc(size, flags) \ -- cgit v1.2.3 From fda56953d09325bd00e7edc0292d5034e494218e Mon Sep 17 00:00:00 2001 From: Trent Piepho Date: Mon, 19 Feb 2007 16:50:52 -0800 Subject: compat: Add -include linux/version.h to cflags From: Trent Piepho Add -include linux/version.h to the cflags. Now code can have backward compatibility test without including compat.h first. Linux headers included from compat.h are removed, so that code will get the same headers when compiling in v4l-dvb as it does in the kernel. Many drivers have compat.h moved to the end of their include list, as this lets compat.h do things it can't do at the beginning. Such as test of something is defined to include compat code, or to put a wrapper around a function without changing the function's name. Signed-off-by: Trent Piepho --- v4l/Makefile | 4 ++++ v4l/compat.h | 24 ++++++++++-------------- 2 files changed, 14 insertions(+), 14 deletions(-) (limited to 'v4l') diff --git a/v4l/Makefile b/v4l/Makefile index b07b592b1..f08143def 100644 --- a/v4l/Makefile +++ b/v4l/Makefile @@ -102,8 +102,12 @@ EXTRA_CFLAGS += -g EXTRA_CFLAGS += $(if $(wildcard $(srctree)/.mm), -DMM_KERNEL) +# Make sure kernel's options are overridden by v4l-dvb options EXTRA_CFLAGS += -include $(obj)/config-compat.h +# Allow kernel version compat tests without adding #include's +EXTRA_CFLAGS += -include linux/version.h + ################################################# # Kernel 2.4/2.6 specific rules diff --git a/v4l/compat.h b/v4l/compat.h index ffe4e97a5..bdad519e9 100644 --- a/v4l/compat.h +++ b/v4l/compat.h @@ -5,23 +5,14 @@ #ifndef _COMPAT_H #define _COMPAT_H -#include -#include -#include -#include -#include - #if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,18) # define minor(x) MINOR(x) #endif #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) -#include +# include # define need_resched() (current->need_resched) - -#define work_struct tq_struct -#else -#include +# define work_struct tq_struct #endif #if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,19) @@ -58,6 +49,10 @@ # define PCI_D0 (0) # define assert_spin_locked(foobar) #endif + +/* Since v4l-dvb now includes it's own copy of linux/i2c-id.h these + are no longer necessary */ +/* #if !defined(I2C_ALGO_SAA7134) #define I2C_ALGO_SAA7134 I2C_HW_B_BT848 #endif @@ -70,10 +65,10 @@ #if !defined(I2C_HW_SAA7146) # define I2C_HW_SAA7146 I2C_ALGO_SAA7146 #endif - #if !defined(I2C_HW_B_EM2820) #define I2C_HW_B_EM2820 0x99 #endif +*/ #ifndef I2C_M_IGNORE_NAK # define I2C_M_IGNORE_NAK 0x1000 @@ -291,7 +286,7 @@ static inline unsigned long vmalloc_to_pfn(void * vmalloc_addr) #define mutex_trylock(a) down_trylock(a) #endif -#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,14) +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,14) && defined(_LINUX_SCHED_H) static inline signed long __sched schedule_timeout_interruptible(signed long timeout) { @@ -327,7 +322,8 @@ static inline void setup_timer(struct timer_list * timer, turned on. We can not just include usb.h here, because there is a lot of code which will not compile if it has usb.h included, due to conflicts with symbol names. */ -#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,13) && defined(__LINUX_USB_H) +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,13) && \ + defined(__LINUX_USB_H) && defined(_INPUT_H) #include /* Found in linux/usb_input.h in 2.6.13 */ /* Moved to linux/usb/input.h in 2.6.18 */ -- cgit v1.2.3 From 13aac084f52613baf79f047bdac0b0decc2b37d2 Mon Sep 17 00:00:00 2001 From: Trent Piepho Date: Mon, 19 Feb 2007 19:01:09 -0800 Subject: compat: Fix compat stuff for usbvision and zr364xx From: Trent Piepho compat.h was missing from usbvideo-i2c.c and zr364xx.c zr364xx.c needed the struct semaphore -> struct mutex compat check. Added an old i2c id to compat.h. These could be added to the Hg copy of linux/i2c-id.h instead? There's just this one so far. zr364xx needs 2.6.15 because of vm_insert_page(), so add to versions.txt Signed-off-by: Trent Piepho --- v4l/compat.h | 6 ++++++ v4l/versions.txt | 1 + 2 files changed, 7 insertions(+) (limited to 'v4l') diff --git a/v4l/compat.h b/v4l/compat.h index bdad519e9..25c11f460 100644 --- a/v4l/compat.h +++ b/v4l/compat.h @@ -74,6 +74,12 @@ # define I2C_M_IGNORE_NAK 0x1000 #endif +/* v4l-dvb uses an out of kernel copy of i2c-id.h, which does not have + some stuff that previous versions of i2c-id.h defined. */ +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,14) && defined(LINUX_I2C_ID_H) +# define I2C_ALGO_BIT 0x010000 +#endif + #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,9) #define __le32 __u32 #endif diff --git a/v4l/versions.txt b/v4l/versions.txt index e30a74e85..07f8cdc38 100644 --- a/v4l/versions.txt +++ b/v4l/versions.txt @@ -43,6 +43,7 @@ USB_QUICKCAM_MESSENGER [2.6.15] USB_ZC0301 USB_ET61X251 +USB_ZR364XX [2.6.12] VIDEO_VIVI -- cgit v1.2.3 From df6112a72da3840ed73c44ba5bdc8f69228d4393 Mon Sep 17 00:00:00 2001 From: Trent Piepho Date: Mon, 19 Feb 2007 19:27:58 -0800 Subject: compat: input_dev compat code for konicawc and quickcam_messenger From: Trent Piepho Adjust konicawc and quickcam_messenger to use backward compat code relating to changes in the input layer in 2.6.15. They should now work in 2.6.12. Signed-off-by: Trent Piepho --- v4l/versions.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'v4l') diff --git a/v4l/versions.txt b/v4l/versions.txt index 07f8cdc38..d00fc9a67 100644 --- a/v4l/versions.txt +++ b/v4l/versions.txt @@ -36,8 +36,6 @@ TUNER_3036 # Changes to usb_input.h, struct input_dev [2.6.15] -USB_KONICAWC -USB_QUICKCAM_MESSENGER # Uses vm_insert_page() [2.6.15] @@ -216,3 +214,5 @@ RADIO_ZOLTRIX USB_SN9C102 VIDEO_SAA7110 SOUND_ACI_MIXER +USB_KONICAWC +USB_QUICKCAM_MESSENGER -- cgit v1.2.3 From 98901e271eeb3ffc496d67ebe1f30c744d7e63cd Mon Sep 17 00:00:00 2001 From: Trent Piepho Date: Mon, 19 Feb 2007 19:57:36 -0800 Subject: compat: Add compat code for vm_insert_page() From: Trent Piepho Add an inline versin of vm_insert_page() that uses remap_pfn_range() to compat.h. Remove compat code from em28xx-video.c, sn9c102_core.c, and usbvision-video.c since compat.h is now doing the same thing. USB_ZC0301, USB_ET61X251, and USB_ZR364XX will now compile under 2.6.12. Signed-off-by: Trent Piepho --- v4l/compat.h | 10 ++++++++++ v4l/versions.txt | 6 +++--- 2 files changed, 13 insertions(+), 3 deletions(-) (limited to 'v4l') diff --git a/v4l/compat.h b/v4l/compat.h index 25c11f460..2b2de93a7 100644 --- a/v4l/compat.h +++ b/v4l/compat.h @@ -224,6 +224,16 @@ static inline unsigned long vmalloc_to_pfn(void * vmalloc_addr) #endif +/* vm_insert_page() was added in 2.6.15 */ +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,15) && defined(_LINUX_MM_H) +static inline int vm_insert_page(struct vm_area_struct *vma, + unsigned long addr, struct page *page) +{ + return remap_pfn_range(vma, addr, page_to_pfn(page), PAGE_SIZE, + vma->vm_page_prot); +} +#endif + #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,9) #ifndef kcalloc #define kcalloc(n,size,flags) \ diff --git a/v4l/versions.txt b/v4l/versions.txt index d00fc9a67..f29387417 100644 --- a/v4l/versions.txt +++ b/v4l/versions.txt @@ -39,9 +39,6 @@ TUNER_3036 # Uses vm_insert_page() [2.6.15] -USB_ZC0301 -USB_ET61X251 -USB_ZR364XX [2.6.12] VIDEO_VIVI @@ -216,3 +213,6 @@ VIDEO_SAA7110 SOUND_ACI_MIXER USB_KONICAWC USB_QUICKCAM_MESSENGER +USB_ZC0301 +USB_ET61X251 +USB_ZR364XX -- cgit v1.2.3 From 3a5f8501c311744e929d5ad1ba989e2a5b42fe42 Mon Sep 17 00:00:00 2001 From: Mauro Carvalho Chehab Date: Wed, 21 Feb 2007 18:40:16 -0200 Subject: Updated gentree.pl From: Mauro Carvalho Chehab Relaxed some regular expressions to better handle whitespaces at the middle of cpp macros; Added #elif processing capability to the script. Signed-off-by: Mauro Carvalho Chehab --- v4l/scripts/gentree.pl | 40 ++++++++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 6 deletions(-) (limited to 'v4l') diff --git a/v4l/scripts/gentree.pl b/v4l/scripts/gentree.pl index bd1ee94e2..1b4e44f26 100755 --- a/v4l/scripts/gentree.pl +++ b/v4l/scripts/gentree.pl @@ -87,7 +87,7 @@ sub filter_source ($$) { $level++; next; } - if ($line =~ m|^\s*\#if\s+0\s*\/[\*]\s*[Kk][Ee].[Pp]\s*[\*]\/(.*)|) { + if ($line =~ m|^\s*\#\s*if\s+0\s*\/[\*]\s*[Kk][Ee].[Pp]\s*[\*]\/(.*)|) { if ($1 eq ";") { print OUT "#if 0\n"; } else { @@ -132,7 +132,7 @@ sub filter_source ($$) { $level++; next; } - if ($line =~ m|^\s*\#if\s+1\s*\/[\*]\s*[Kk][Ee].[Pp]\s*[\*]\/(.*)|) { + if ($line =~ m|^\s*\#\s*if\s+1\s*\/[\*]\s*[Kk][Ee].[Pp]\s*[\*]\/(.*)|) { print OUT "#if 1$1\n"; $state{$level} = "ifother"; $if{$level} = 1; @@ -180,7 +180,7 @@ sub filter_source ($$) { $level++; next; } - if ($line =~ /^\s*#\s*ifndef.\s*I2C_PEC/) { + if ($line =~ /^\s*#\s*ifndef\s+I2C_PEC/) { chomp($line); $state{$level} = "if"; $if{$level} = 0; @@ -188,7 +188,7 @@ sub filter_source ($$) { $level++; next; } - if ($line =~ /^\s*#\s*ifdef.\s*I2C_PEC/) { + if ($line =~ /^\s*#\s*ifdef\s+I2C_PEC/) { chomp($line); $state{$level} = "if"; $if{$level} = 1; @@ -219,8 +219,36 @@ sub filter_source ($$) { if ($line =~ /^\s*#\s*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@LINUX_VERSION_CODE@\$CODE@g; + print STDERR "/* BP orig: ($line) */\n" if $DEBUG; + + $line =~ s@KERNEL_VERSION\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)@ + sprintf("%d",$1*65536 + $2*256 + $3) @eg; + $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 ($line =~ /^\s*#\s*elif.*LINUX_VERSION_CODE/) { + chomp($line); + if ( !$level ) { + die "elif without if"; + } + $level--; + if ( $if{$level} ) { + # Else is 0 + $if{$level} = 0; + $state{$level} = "elif"; + print STDERR "/* BP #if LINUX_VERSION_CODE state=$state{$level} if=$if{$level} level=$level ($line) */\n" if $DEBUG; + + $level++; + next; + } + + $line =~ s@^#if\s*@@; + $line =~ s@LINUX_VERSION_CODE@\$CODE@g; + print STDERR "/* BP orig: ($line) */\n" if $DEBUG; $line =~ s@KERNEL_VERSION\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)@ sprintf("%d",$1*65536 + $2*256 + $3) @eg; -- cgit v1.2.3 From c34c53638fecfe18f59fb63819ac79bb8090bc34 Mon Sep 17 00:00:00 2001 From: Trent Piepho Date: Fri, 23 Feb 2007 02:09:33 -0800 Subject: Largely re-write gentree.pl From: Trent Piepho Mostly re-write gentree.pl to make a few improvements: About three times faster Correctly processes BTTV_VERSION_CODE checks Properly handles #elif Doesn't need absolute path names specified in command line arguments Improved debug output, which now shows input line number Can handle almost any general expression for a conditional compilation directive. Can understand all these: #if 0 #ifdef BROKEN_XAWTV #ifndef MM_KERNEL #if defined(STV0297_CS2) #if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,20) #elif defined(MM_KERNEL) || !BROKEN_XAWTV #if BTTV_VERSION_CODE > KERNEL_VERSION(0,8,0) || defined(BROKEN_XAWTV) #if (1 > 2) || (I2C_PEC && defined(I2C_CLASS_TV_ANALOG)) #ifndef CONFIG_XC3028 /* Keep */ <- knows to keep this one in the code Signed-off-by: Trent Piepho --- v4l/scripts/gentree.pl | 482 +++++++++++++++++-------------------------------- 1 file changed, 165 insertions(+), 317 deletions(-) (limited to 'v4l') diff --git a/v4l/scripts/gentree.pl b/v4l/scripts/gentree.pl index 1b4e44f26..2f918468e 100755 --- a/v4l/scripts/gentree.pl +++ b/v4l/scripts/gentree.pl @@ -1,45 +1,93 @@ #!/usr/bin/perl +# +# Original version by Mauro Carvalho Chehab +# Largely re-written (C) 2007 Trent Piepho +# +# Theory of Operation +# +# This acts as a sort of mini version of cpp, which will process +# #if/#elif/#ifdef/etc directives to strip out code used to support +# multiple kernel versions or otherwise not wanted to be sent upstream to +# git. +# +# Conditional compilation directives fall into two catagories, +# "processed" and "other". The "other" directives are ignored and simply +# output as they come in without changes (see 'keep' exception). The +# "processed" variaty are evaluated and only the lines in the 'true' part +# are kept, like cpp would do. +# +# If gentree knows the result of an expression, that directive will be +# "processed", otherwise it will be an "other". gentree knows the value +# of LINUX_VERSION_CODE, BTTV_VERSION_CODE, the KERNEL_VERSION(x,y,z) +# macro, numeric constants like 0 and 1, and a few defines like MM_KERNEL +# and STV0297_CS2. +# +# An exception is if the comment "/*KEEP*/" appears after the expression, +# in which case that directive will be considered an "other" and not +# processed, other than to remove the keep comment. +# +# Known bugs: +# don't specify the root directory e.g. '/' or even '////' +# directives continued with a back-slash will always be ignored +# you can't modify a source tree in-place, i.e. source dir == dest dir + use strict; use File::Find; use Fcntl ':mode'; -my $VER = shift; +my $VERSION = shift; my $SRC = shift; my $DESTDIR = shift; -my $extra; - - -#$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 \n\n"; exit; } -my ($VERSION,$CODE) = &kernel_version; +my $BTTVCODE = KERNEL_VERSION(0,9,17); +my ($LINUXCODE, $extra) = kernel_version($VERSION); my $DEBUG = 0; +my %defs = ( + 'LINUX_VERSION_CODE' => $LINUXCODE, + 'BTTV_VERSION_CODE' => $BTTVCODE, + '_COMPAT_H' => 0, + 'MM_KERNEL' => ($extra =~ /-mm/)?1:0, + 'BROKEN_XAWTV' => 0, + 'STV0297_CS2' => 0, + 'HAVE_VIDEO_BUF_DVB' => 1, + 'I2C_PEC' => 1, + 'I2C_DF_DUMMY' => 0, + 'CONFIG_XC3028' => 0, + 'I2C_CLASS_TV_ANALOG' => 1, + 'I2C_CLASS_TV_DIGITAL' => 1); ################################################################# # helpers -sub kernel_version() { - my ($ver,$code); - - $code = 0; - $ver = $VER; - - $ver =~ m/(\d)\.(\d)\.([0-9]*(.*))/; - my $v1 = $1; - my $v2 = $2; - my $v3 = $3; - $extra = $4; - - $code = $v1*65536 + $v2*256 + $v3; +sub kernel_version($) { + $_[0] =~ m/(\d+)\.(\d+)\.(\d+)(.*)/; + return ($1*65536 + $2*256 + $3, $4); +} - return ($ver,$code); +# used in eval() +sub KERNEL_VERSION($$$) { return $_[0]*65536 + $_[1]*256 + $_[2]; } + +sub evalexp($) { + local $_ = shift; + s|/\*.*?\*/||go; # delete /* */ comments + s|//.*$||o; # delete // comments + s/\bdefined\s*\(/(/go; # defined(foo) to (foo) + while (/\b([_A-Za-z]\w*)\b/go) { + if (exists $defs{$1}) { + my $id = $1; my $pos = $-[0]; + s/$id/$defs{$id}/; + pos = $-[0]; + } elsif ($1 ne 'KERNEL_VERSION') { + return(undef); + } + } + return(eval($_) ? 1 : 0); } ################################################################# @@ -47,298 +95,116 @@ sub kernel_version() { sub filter_source ($$) { my ($in,$out) = @_; - my ($line,$mmkernel); + my $line; my $level=0; my %if = (); - my %state =(); - my $print=0; + my %state = (); - if ($extra =~ m/\-mm/) { - $mmkernel = 1; - } else { - $mmkernel = 0; + my @dbgargs = \($level, %state, %if, $line); + sub dbgline($\@) { + my $level = ${$_[1][0]}; + printf STDERR ("/* BP %4d $_[0] state=$_[1][1]->{$level} if=$_[1][2]->{$level} level=$level (${$_[1][3]}) */\n", $.) if $DEBUG; } - open IN, "<$in"; - open OUT, ">$out"; + open IN, '<', $in or die "Error opening $in: $!\n"; + open OUT, '>', $out or die "Error opening $out: $!\n"; - print STDERR "File: $in, for kernel $VERSION($CODE)/\n" if $DEBUG; + print STDERR "File: $in, for kernel $VERSION($LINUXCODE)/\n" if $DEBUG; while ($line = ) { - if ($line =~ m/^#include \"compat.h\"/) { - next; - } -# if ($line =~ m/[\$]Id:/) { -# next; -# } - if ($line =~ /^\s*#\s*ifdef\s+MM_KERNEL/) { - chomp($line); - $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 =~ /^\s*#\s*ifdef\s+_COMPAT_H/) { - chomp($line); - $state{$level} = "if"; - $if{$level} = 0; - print STDERR "/* BP #if MM_KERNEL state=$state{$level} if=$if{$level} level=$level ($line) */\n" if $DEBUG; - $level++; - next; - } - if ($line =~ m|^\s*\#\s*if\s+0\s*\/[\*]\s*[Kk][Ee].[Pp]\s*[\*]\/(.*)|) { - if ($1 eq ";") { - print OUT "#if 0\n"; - } else { - print OUT "#if 0$1\n"; - } - chomp($line); + chomp $line; + next if ($line =~ m/^#include \"compat.h\"/o); +# next if ($line =~ m/[\$]Id:/); + + # For "#if 0 /*KEEP*/;" the ; should be dropped too + if ($line =~ m@^\s*#\s*if(n?def)?\s.*?(\s*/\*\s*(?i)keep\s*\*/;?)@) { $state{$level} = "ifother"; - $if{$level} = 0; - print STDERR "/* BP #if 0 (keep) state=$state{$level} if=$if{$level} level=$level ($line) */\n" if $DEBUG; - $level++; - next; - } - if ($line =~ /^\s*#\s*ifdef\s+STV0297_CS2/) { - chomp($line); - $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 =~ /^\s*#\s*ifndef\s+BROKEN_XAWTV/) { - chomp($line); - $state{$level} = "if"; $if{$level} = 1; - print STDERR "/* BP #if 0 state=$state{$level} if=$if{$level} level=$level ($line) */\n" if $DEBUG; + dbgline "#if$1 (keep)", @dbgargs; + $line =~ s/\Q$2\E//; $level++; - next; } - if ($line =~ /^\s*#\s*ifndef\s+STV0297_CS2/) { - chomp($line); - $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 =~ /^\s*#\s*if\s+0/) { - chomp($line); - $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 =~ m|^\s*\#\s*if\s+1\s*\/[\*]\s*[Kk][Ee].[Pp]\s*[\*]\/(.*)|) { - print OUT "#if 1$1\n"; + # handle all ifdef/ifndef lines + elsif ($line =~ /^\s*#\s*if(n?)def\s*(\w+)/o) { + if (exists $defs{$2}) { + $state{$level} = 'if'; + $if{$level} = ($1 eq 'n') ? !$defs{$2} : $defs{$2}; + dbgline "#if$1def $2", @dbgargs; + $level++; + next; + } $state{$level} = "ifother"; $if{$level} = 1; - print STDERR "/* BP #if 1 (keep) state=$state{$level} if=$if{$level} level=$level ($line) */\n" if $DEBUG; + dbgline "#if$1def (other)", @dbgargs; $level++; - next; } - if ($line =~ /^\s*#\s*if\s+1/) { - chomp($line); - $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 =~ /^\s*#\s*if.*HAVE_VIDEO_BUF_DVB/) { - chomp($line); - $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 =~ /^\s*#\s*if.*CONFIG_XC3028/) { - chomp($line); - $state{$level} = "if"; - $if{$level} = 0; - print STDERR "/* BP #if 1 state=$state{$level} if=$if{$level} level=$level ($line) */\n" if $DEBUG; - $level++; - next; - } - if ($line =~ /^\s*#\s*if.*I2C_CLASS_TV_ANALOG/) { - chomp($line); - $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 =~ /^\s*#\s*ifndef.\s*I2C_DF_DUMMY/) { - chomp($line); - $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 =~ /^\s*#\s*ifndef\s+I2C_PEC/) { - chomp($line); - $state{$level} = "if"; - $if{$level} = 0; - print STDERR "/* BP #if 1 state=$state{$level} if=$if{$level} level=$level ($line) */\n" if $DEBUG; - $level++; - next; - } - if ($line =~ /^\s*#\s*ifdef\s+I2C_PEC/) { - chomp($line); - $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 =~ /^\s*#\s*if.*I2C_CLASS_TV_DIGITAL/) { - chomp($line); - $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 =~ /^\s*#\s*if.*BTTV_VERSION_CODE/) { - chomp($line); - $line =~ s@^#if\s*@@; - $line =~ s@BTTV_VERSION_CODE@\$CODE@; - $line =~ s@KERNEL_VERSION\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)@ - sprintf("%d",$1*65536 + $2*256 + $3) @eg; - $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 =~ /^\s*#\s*if.*LINUX_VERSION_CODE/) { - chomp($line); - $line =~ s@^#if\s*@@; - $line =~ s@LINUX_VERSION_CODE@\$CODE@g; - print STDERR "/* BP orig: ($line) */\n" if $DEBUG; - - $line =~ s@KERNEL_VERSION\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)@ - sprintf("%d",$1*65536 + $2*256 + $3) @eg; - $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 ($line =~ /^\s*#\s*elif.*LINUX_VERSION_CODE/) { - chomp($line); - if ( !$level ) { - die "elif without if"; + # handle all ifs + elsif ($line =~ /^\s*#\s*if\s+(.*)$/o) { + my $res = evalexp($1); + if (defined $res) { + $state{$level} = 'if'; + $if{$level} = $res; + dbgline '#if '.($res?'(yes)':'(no)'), @dbgargs; + $level++; + next; + } else { + $state{$level} = 'ifother'; + $if{$level} = 1; + dbgline '#if (other)', @dbgargs; + $level++; } + } + # handle all elifs + elsif ($line =~ /^\s*#\s*elif\s+(.*)$/o) { + my $exp = $1; $level--; - if ( $if{$level} ) { - # Else is 0 + $level < 0 and die "more elifs than ifs"; + $state{$level} =~ /if/ or die "unmatched elif"; + + if ($state{$level} eq 'if' && !$if{$level}) { + my $res = evalexp($exp); + defined $res or die 'moving from if to ifother'; + $state{$level} = 'if'; + $if{$level} = $res; + dbgline '#elif1 '.($res?'(yes)':'(no)'), @dbgargs; + $level++; + next; + } elsif ($state{$level} ne 'ifother') { $if{$level} = 0; - $state{$level} = "elif"; - print STDERR "/* BP #if LINUX_VERSION_CODE state=$state{$level} if=$if{$level} level=$level ($line) */\n" if $DEBUG; - + $state{$level} = 'elif'; + dbgline '#elif0', @dbgargs; $level++; next; } - - $line =~ s@^#if\s*@@; - $line =~ s@LINUX_VERSION_CODE@\$CODE@g; - print STDERR "/* BP orig: ($line) */\n" if $DEBUG; - - $line =~ s@KERNEL_VERSION\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)@ - sprintf("%d",$1*65536 + $2*256 + $3) @eg; - $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 ($line =~ /^\s*#\s*if\s/) { - $state{$level} = "ifother"; - $if{$level} = 1; - print STDERR "/* BP $line state=$state{$level} if=$if{$level} level=$level ($line) */\n" if $DEBUG; - $level++; - } - - if ($line =~ /^\s*#\s*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 ($line =~ /^\s*#\s*ifndef/) { - $state{$level} = "ifother"; - $if{$level} = 1; - print STDERR "/* BP $line state=$state{$level} if=$if{$level} level=$level ($line) */\n" if $DEBUG; + elsif ($line =~ /^\s*#\s*else/o) { + $level--; + $level < 0 and die "more elses than ifs"; + $state{$level} =~ /if/ or die "unmatched else"; + $if{$level} = !$if{$level} if ($state{$level} eq 'if'); + $state{$level} =~ s/^if/else/o; # if -> else, ifother -> elseother, elif -> elif + dbgline '#else', @dbgargs; $level++; + next if $state{$level-1} !~ /other$/o; } - - if ($level) { - if ($state{$level-1} eq "if" && $line =~ /^\s*#\s*else/) { - $state{$level-1} = "else"; - print STDERR "/* BP #else state=$state{$level} if=$if{$level} level=$level ($line) */\n" if $DEBUG; - next; - } - } - if ($line =~ /^\s*#\s*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 { - 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; + elsif ($line =~ /^\s*#\s*endif/o) { + $level--; + $level < 0 and die "more endifs than ifs"; + dbgline '#endif', @dbgargs; + next if $state{$level} !~ /other$/o; + } + + my $print = 1; + for (my $i=0;$i<$level;$i++) { + next if $state{$i} =~ /other$/o; # keep code in ifother/elseother blocks + if (!$if{$i}) { + $print = 0; + dbgline 'DEL', @{[\$i, \%state, \%if, \$line]}; + last; } } - } - 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 = ) { - if ($line =~ m/[\$]Id:.*/) { - next; - } - print OUT $line; + print OUT "$line\n" if $print; } close IN; close OUT; @@ -348,54 +214,36 @@ sub filter_dest ($$) { sub parse_dir { my $file = $File::Find::name; - my $srcdir=$SRC; - if ($file =~ /CVS/) { - return; - } - - if ($file =~ /\~$/) { - return; - } + return if ($file =~ /CVS/); + return if ($file =~ /~$/); - my $mode = (lstat("$file"))[2]; + my $f2 = $file; + $f2 =~ s/^\Q$SRC\E/$DESTDIR/; + my $mode = (stat($file))[2]; if ($mode & S_IFDIR) { + print("mkdir -p '$f2'\n"); + system("mkdir -p '$f2'"); # should check for error return; } - - $srcdir =~ s/(.)/\[$1\]/g; - my $f2 = $file; - - $f2 =~ s,^$srcdir,$DESTDIR/,; print "from $file to $f2\n"; - my $tmp = "/tmp/src.$$"; if ($file =~ m/.*\.[ch]$/) { - filter_source("$file","$tmp"); + filter_source($file, $f2); } else { - system("cp $file $tmp"); + system("cp $file $f2"); } - - 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 "kernel is %s (0x%x)\n",$VERSION,$LINUXCODE; -printf < \&parse_dir, no_chdir => 1}, $SRC); -- cgit v1.2.3 From cc88074b4da7cb25b8c2bc93f41434cfc1763924 Mon Sep 17 00:00:00 2001 From: Mauro Carvalho Chehab Date: Fri, 23 Feb 2007 10:34:37 -0200 Subject: Fixed credits at gentree.pl From: Mauro Carvalho Chehab gentree.pl were part of Gerd Knorr scripts, used to generate patches from his tree against kernel. Several newer capabilities were added to the original script, including the ability to handle with multiple levels of #if/#else/#endif and support for #elif. This patch corrects the credits for this valuable piece of code. Signed-off-by: Mauro Carvalho Chehab --- v4l/scripts/gentree.pl | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'v4l') diff --git a/v4l/scripts/gentree.pl b/v4l/scripts/gentree.pl index 2f918468e..4d27fd789 100755 --- a/v4l/scripts/gentree.pl +++ b/v4l/scripts/gentree.pl @@ -1,6 +1,9 @@ #!/usr/bin/perl # -# Original version by Mauro Carvalho Chehab +# Original version were part of Gerd Knorr's v4l scripts. +# +# Several improvements by (c) 2005-2007 Mauro Carvalho Chehab +# # Largely re-written (C) 2007 Trent Piepho # # Theory of Operation -- cgit v1.2.3