root/i2c/trunk/mkpatch/mkpatch.pl @ 3535

Revision 3535, 23.7 KB (checked in by mds, 12 years ago)

(mds) fix mkpatch for drivers/i2c/Makefile for i2c-proc.c.

2.2 kernel wouldn't compile (i2c-proc is a symbol exporter - tkt #526);
2.4 kernel didn't compile i2c-proc.c at all.

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
Line 
1#!/usr/bin/perl
2
3#    mkpatch - Create patches against the Linux kernel
4#    Copyright (c) 1999  Frodo Looijaard <frodol@dds.nl>
5#
6#    This program is free software; you can redistribute it and/or modify
7#    it under the terms of the GNU General Public License as published by
8#    the Free Software Foundation; either version 2 of the License, or
9#    (at your option) any later version.
10#
11#    This program is distributed in the hope that it will be useful,
12#    but WITHOUT ANY WARRANTY; without even the implied warranty of
13#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14#    GNU General Public License for more details.
15#
16#    You should have received a copy of the GNU General Public License
17#    along with this program; if not, write to the Free Software
18#    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19
20use strict;
21
22use vars qw($temp);
23$temp = "mkpatch/.temp";
24
25# Forward declaration
26sub gen_drivers_char_Makefile;
27
28# Generate a diff between the old kernel file and the new I2C file. We
29# arrange the headers to tell us the old tree was under directory
30# `linux-old', and the new tree under `linux'.
31# $_[0]: i2c package root (like /tmp/i2c)
32# $_[1]: Linux kernel tree (like /usr/src/linux)
33# $_[2]: Name of the kernel file
34# $_[3]: Name of the patched file
35sub print_diff
36{
37  my ($package_root,$kernel_root,$kernel_file,$package_file) = @_;
38  my ($diff_command,$dummy);
39
40  $diff_command = "diff -u2";
41  if ( -e "$kernel_root/$kernel_file") {
42    $diff_command .= " $kernel_root/$kernel_file ";
43  } else {
44    $diff_command .= " /dev/null ";
45  }
46  if ( -e "$package_root/$package_file") {
47    $diff_command .= " $package_root/$package_file ";
48  } else {
49    $diff_command .= " /dev/null";
50  }
51  open INPUT, "$diff_command|" or die "Can't call `$diff_command'";
52  $dummy = <INPUT>;
53  $dummy = <INPUT>;
54  print "--- linux-old/$kernel_file\t".`date`;
55  print "+++ linux/$kernel_file\t".`date`;
56   
57  while (<INPUT>) {
58    print;
59  }
60  close INPUT;
61}
62
63# Find all the lm_sensors code in a file
64# $_[0]: Linux kernel tree (like /usr/src/linux)
65# $_[1]: Name of the kernel file
66# Returns a list of strings with the sensors codes
67sub find_sensors_code
68{
69  my ($kernel_root,$kernel_file) = @_;
70  my @res;
71  open INPUT, "$kernel_root/$kernel_file" 
72       or return @res;
73  while (<INPUT>) {
74    if (m@sensors code starts here@) {
75      push @res,"";
76      while (<INPUT>) {
77        last if m@sensors code ends here@;
78        $res[$#res] .= $_;
79      }
80    }
81  }
82  return @res;   
83} 
84
85# Here we generate diffs for all kernel files mentioned in OLDI2C
86# which change the invocation # `#include <linux/i2c.h>' to
87# `#include <linux/i2c-old.h>'. But first, we generate diffs to copy
88# file <linux/i2c.h> to <linux/i2c-old.h>, if the kernel does not have
89# this file yet.
90# $_[0]: sensors package root (like /tmp/sensors)
91# $_[1]: Linux kernel tree (like /usr/src/linux)
92sub patch_old_i2c
93{
94  my ($package_root,$kernel_root) = @_;
95  my (@files,$file,$f);
96  # If i2c.c does not exist, either we renamed it earlier, or there is no
97  # i2c support in this kernel at all.
98  return if not -e "$kernel_root/drivers/char/i2c.c";
99
100  print_diff $kernel_root,$kernel_root,"include/linux/i2c-old.h", 
101             "include/linux/i2c.h";
102
103
104  open INPUT, "$package_root/mkpatch/OLDI2C" 
105        or die "Can't open `$package_root/mkpatch/OLDI2C'";
106  @files = <INPUT>;
107  close INPUT;
108
109  foreach $f (@files,"drivers/char/i2c-old.c") {
110    $file = $f; # Ugly, but seemingly needed to run on Perl 5.6.
111    chomp $file;
112    if ($file eq "drivers/char/i2c-old.c") {
113      open INPUT, "$kernel_root/drivers/char/i2c.c"
114            or next;
115    } else { 
116      open INPUT, "$kernel_root/$file"
117           or next;
118    }
119    open OUTPUT, ">$package_root/$temp"
120           or die "Can't open `$package_root/$temp'";
121    while (<INPUT>) {
122      s@(\s*#\s*include\s*)<linux/i2c.h>@\1<linux/i2c-old.h>@;
123      print OUTPUT;
124    }
125    close INPUT;
126    close OUTPUT;
127    print_diff $package_root,$kernel_root,$file,$temp;
128  }
129  print_diff "/dev",$kernel_root,"drivers/char/i2c.c","null";
130  gen_drivers_char_Makefile $package_root, $kernel_root;
131}
132
133# This generates diffs for kernel file Documentation/Configure.help. This
134# file contains the help texts that can be displayed during `make *config'
135# for the kernel.
136# The new texts are put at the end of the file, or just before the
137# lm_sensors texts.
138# Of course, care is taken old lines are removed.
139# $_[0]: i2c package root (like /tmp/i2c)
140# $_[1]: Linux kernel tree (like /usr/src/linux)
141sub gen_Documentation_Configure_help
142{
143  my ($package_root,$kernel_root) = @_;
144  my $kernel_file = "Documentation/Configure.help";
145  my $package_file = $temp;
146  my $printed = 0;
147
148  open INPUT,"$kernel_root/$kernel_file"
149        or die "Can't open `$kernel_root/$kernel_file'";
150  open OUTPUT,">$package_root/$package_file"
151        or die "Can't open $package_root/$package_file";
152  MAIN: while(<INPUT>) {
153    if (m@^I2C support$@ or m@^I2C bit-banging interfaces@ or
154           m@^Philips style parallel port adapter@ or
155           m@^ELV adapter@ or m@^Velleman K9000 adapter@ or
156           m@^I2C PCF 8584 interfaces@ or m@^Elektor ISA card@ or
157           m@^I2C device interface@ ) {
158      $_ = <INPUT>;
159      $_ = <INPUT>;
160      $_ = <INPUT> while not m@^\S@ and not eof(INPUT);
161      redo MAIN;
162    }
163    if (not $printed and (eof(INPUT) or m@I2C mainboard interfaces@ or
164                          m@A couple of things I keep forgetting@ or
165                          m@Bus Mouse Support@)) {
166      print OUTPUT <<'EOF';
167I2C support
168CONFIG_I2C
169  I2C (pronounce: I-square-C) is a slow serial bus protocol used in
170  many micro controller applications and developed by Philips. SMBus,
171  or System Management Bus is a subset of the I2C protocol. More
172  information is contained in the directory Documentation/i2c/,
173  especially in the file called "summary" there.
174
175  Both I2C and SMBus are supported here. You will need this for
176  hardware sensors support, and also for Video for Linux support.
177  Specifically, if you want to use a BT848 based frame grabber/overlay
178  boards under Linux, say Y here and also to "I2C bit-banging
179  interfaces", below.
180
181  If you want I2C support, you should say Y here and also to the
182  specific driver for your bus adapter(s) below. If you say Y to
183  "/proc file system" below, you will then get a /proc interface which
184  is documented in Documentation/i2c/proc-interface.
185
186  This I2C support is also available as a module. If you want to
187  compile it as a module, say M here and read
188  Documentation/modules.txt. The module will be called i2c-core.o.
189
190I2C bit-banging interfaces
191CONFIG_I2C_ALGOBIT
192  This allows you to use a range of I2C adapters called bit-banging
193  adapters. Say Y if you own an I2C adapter belonging to this class
194  and then say Y to the specific driver for you adapter below.
195
196  This support is also available as a module. If you want to compile
197  it as a module, say M here and read Documentation/modules.txt. The
198  module will be called i2c-algo-bit.o.
199
200Philips style parallel port adapter
201CONFIG_I2C_PHILIPSPAR
202  This supports parallel-port I2C adapters made by Philips. Say Y if
203  you own such an adapter.
204
205  This driver is also available as a module. If you want to compile
206  it as a module, say M here and read Documentation/modules.txt. The
207  module will be called i2c-philips-par.o.
208
209  Note that if you want support for different parallel port devices,
210  life will be much easier if you compile them all as modules.
211
212ELV adapter
213CONFIG_I2C_ELV
214  This supports parallel-port I2C adapters called ELV. Say Y if you
215  own such an adapter.
216
217  This driver is also available as a module. If you want to compile
218  it as a module, say M here and read Documentation/modules.txt. The
219  module will be called i2c-elv.o.
220
221Velleman K9000 adapter
222CONFIG_I2C_VELLEMAN
223  This supports the Velleman K9000 parallel-port I2C adapter. Say Y if
224  you own such an adapter.
225
226  This driver is also available as a module. If you want to compile
227  it as a module, say M here and read Documentation/modules.txt. The
228  module will be called i2c-velleman.o.
229
230I2C PCF 8584 interfaces
231CONFIG_I2C_ALGOPCF
232  This allows you to use a range of I2C adapters called PCF adapters.
233  Say Y if you own an I2C adapter belonging to this class and then say
234  Y to the specific driver for you adapter below.
235
236  This support is also available as a module. If you want to compile
237  it as a module, say M here and read Documentation/modules.txt. The
238  module will be called i2c-algo-pcf.o.
239
240Elektor ISA card
241CONFIG_I2C_ELEKTOR
242  This supports the PCF8584 ISA bus I2C adapter. Say Y if you own such
243  an adapter.
244
245  This driver is also available as a module. If you want to compile
246  it as a module, say M here and read Documentation/modules.txt. The
247  module will be called i2c-elektor.o.
248
249I2C device interface
250CONFIG_I2C_CHARDEV
251  Say Y here to use i2c-* device files, usually found in the /dev
252  directory on your system. They make it possible to have user-space
253  programs use the I2C bus. Information on how to do this is contained
254  in the file Documentation/i2c/dev-interface.
255
256  This code is also available as a module. If you want to compile
257  it as a module, say M here and read Documentation/modules.txt. The
258  module will be called i2c-dev.o.
259
260I2C /proc support
261CONFIG_I2C_PROC
262  This provides support for i2c device entries in the /proc filesystem.
263  The entries will be found in /proc/sys/dev/sensors.
264
265  This code is also available as a module. If you want to compile
266  it as a module, say M here and read Documentation/modules.txt. The
267  module will be called i2c-dev.o.
268
269EOF
270      $printed = 1;
271    }
272    print OUTPUT;
273  }
274  close INPUT;
275  close OUTPUT;
276  print_diff $package_root,$kernel_root,$kernel_file,$package_file;
277}
278
279# This generates diffs for the main Linux Makefile.
280# Three lines which add drivers/i2c/i2.a to the DRIVERS list are put just
281# before the place where the architecture Makefile is included.
282# Of course, care is taken old lines are removed.
283# $_[0]: i2c package root (like /tmp/i2c)
284# $_[1]: Linux kernel tree (like /usr/src/linux)
285sub gen_Makefile
286{
287  my ($package_root,$kernel_root) = @_;
288  my $kernel_file = "Makefile";
289  my $package_file = $temp;
290  my $printed = 0;
291  my $new_style = 0;
292
293  open INPUT,"$kernel_root/$kernel_file"
294        or die "Can't open `$kernel_root/$kernel_file'";
295  open OUTPUT,">$package_root/$package_file"
296        or die "Can't open $package_root/$package_file";
297  MAIN: while(<INPUT>) {
298    if (m@^DRIVERS :=@) {
299       $new_style = 1;
300    }
301    if (m@DRIVERS-\$\(CONFIG_I2C\)@) {
302      $_ = <INPUT>;
303      redo MAIN;
304    } elsif (m@CONFIG_I2C@) {
305      $_ = <INPUT> while not m@endif@;
306      $_ = <INPUT>;
307      $_ = <INPUT> if m@^$@;
308      redo MAIN;
309    }
310    if (not $printed and m@DRIVERS-\$\(CONFIG_PHONE\)@) {
311      if ($new_style) {
312        print OUTPUT << 'EOF';
313DRIVERS-$(CONFIG_I2C) += drivers/i2c/i2c.a
314EOF
315      } else {
316        print OUTPUT << 'EOF';
317DRIVERS-$(CONFIG_I2C) += drivers/i2c/i2c.o
318EOF
319      }
320      $printed = 1;
321    } elsif (not $printed and 
322        (m@include arch/\$\(ARCH\)/Makefile@ or m@CONFIG_SENSORS@ or
323         m@CONFIG_PHONE@ )) {
324      print OUTPUT <<'EOF';
325ifeq ($(CONFIG_I2C),y)
326DRIVERS := $(DRIVERS) drivers/i2c/i2c.a
327endif
328
329EOF
330      $printed = 1;
331    }
332    print OUTPUT;
333  }
334  close INPUT;
335  close OUTPUT;
336  die "Automatic patch generation for `Makefile' failed.\n".
337      "Contact the authors please!" if $printed == 0;
338  print_diff $package_root,$kernel_root,$kernel_file,$package_file;
339}
340
341# This generates diffs for drivers/Makefile
342# First, `i2c' is added to the ALL_SUB_DIRS list. Next, a couple of lines
343# to add i2c to the SUB_DIRS and/or MOD_SUB_DIRS lists is put right before
344# Rules.make is included.
345# Of course, care is taken old lines are removed.
346# $_[0]: i2c package root (like /tmp/i2c)
347# $_[1]: Linux kernel tree (like /usr/src/linux)
348sub gen_drivers_Makefile
349{
350  my ($package_root,$kernel_root) = @_;
351  my $kernel_file = "drivers/Makefile";
352  my $package_file = $temp;
353  my $i2c_present;
354  my $printed = 0;
355  my $added = 0;
356  my $new_style = 0;
357
358  open INPUT,"$kernel_root/$kernel_file"
359        or die "Can't open `$kernel_root/$kernel_file'";
360  open OUTPUT,">$package_root/$package_file"
361        or die "Can't open $package_root/$package_file";
362  MAIN: while(<INPUT>) {
363    if (m@^mod-subdirs\s*:=@) {
364       $new_style = 1;
365    }
366    if ((! $new_style and m@^ALL_SUB_DIRS\s*:=@) or m@^mod-subdirs\s*:=@ ) {
367      $added = 1;
368      $i2c_present = 0;
369      while (m@\\$@) {
370        $i2c_present = 1 if m@i2c@;
371        print OUTPUT;
372        $_ = <INPUT>;
373      }
374      $i2c_present = 1 if m@i2c@;
375      s@$@ i2c@ if (not $i2c_present);
376      print OUTPUT;
377      $_ = <INPUT>;
378      redo MAIN;
379    } 
380    if (m@^ifeq.*CONFIG_I2C@) {
381      $_ = <INPUT> while not m@^endif@;
382      $_ = <INPUT>;
383      $_ = <INPUT> if m@^$@;
384      redo MAIN;
385    } 
386    if (m@^subdir.*CONFIG_I2C@) {
387      $_ = <INPUT>;
388      redo MAIN;
389    }
390    if (not $printed and
391        (m@^include \$\(TOPDIR\)/Rules.make$@ or
392         m@^ifeq \(\$\(CONFIG_ACPI\),y\)$@ or
393         m@^ifeq \(\$\(CONFIG_SENSORS\),y\)@) or
394         m@^subdir-\$\(CONFIG_ACPI\)@) {
395      if ($new_style) {
396        print OUTPUT <<'EOF';
397subdir-$(CONFIG_I2C)            += i2c
398EOF
399      } else {
400        print OUTPUT <<'EOF';
401ifeq ($(CONFIG_I2C),y)
402SUB_DIRS += i2c
403MOD_SUB_DIRS += i2c
404else
405  ifeq ($(CONFIG_I2C),m)
406  MOD_SUB_DIRS += i2c
407  endif
408endif
409
410EOF
411      }
412      $printed = 1;
413    }
414    print OUTPUT;
415  }
416  close INPUT;
417  close OUTPUT;
418  die "Automatic patch generation for `Makefile' failed.\n".
419      "Contact the authors please!" if $printed == 0 or $added == 0;
420  print_diff $package_root,$kernel_root,$kernel_file,$package_file;
421}
422
423# This generates diffs for drivers/char/Makefile
424# It changes all occurences of `i2c.o' to `i2c-old.o'.
425# $_[0]: i2c package root (like /tmp/i2c)
426# $_[1]: Linux kernel tree (like /usr/src/linux)
427sub gen_drivers_char_Makefile
428{
429  my ($package_root,$kernel_root) = @_;
430  my $kernel_file = "drivers/char/Makefile";
431  my $package_file = $temp;
432  open INPUT,"$kernel_root/$kernel_file"
433        or die "Can't open `$kernel_root/$kernel_file'";
434  open OUTPUT,">$package_root/$package_file"
435        or die "Can't open $package_root/$package_file";
436  while(<INPUT>) {
437    s@i2c\.o@i2c-old\.o@;
438    print OUTPUT;
439  }
440  close INPUT;
441  close OUTPUT;
442  print_diff $package_root,$kernel_root,$kernel_file,$package_file;
443}
444
445sub gen_drivers_i2c_Makefile
446{
447  my ($package_root,$kernel_root) = @_;
448  my $kernel_file = "drivers/i2c/Makefile";
449  my $package_file = $temp;
450  my $use_new_format = 0;
451  if (-e "$kernel_root/$kernel_file") {
452    `grep -q -s 'i2c\.o' "$kernel_root/$kernel_file"`;
453     $use_new_format = ! $?;
454  }
455
456  open OUTPUT,">$package_root/$package_file"
457        or die "Can't open $package_root/$package_file";
458  if ($use_new_format) {
459    print OUTPUT <<'EOF';
460#
461# Makefile for the kernel i2c bus driver.
462#
463
464O_TARGET := i2c.o
465
466export-objs     := i2c-core.o i2c-algo-bit.o i2c-algo-pcf.o i2c-proc.o
467
468obj-$(CONFIG_I2C)               += i2c-core.o
469obj-$(CONFIG_I2C_CHARDEV)       += i2c-dev.o
470obj-$(CONFIG_I2C_ALGOBIT)       += i2c-algo-bit.o
471obj-$(CONFIG_I2C_PHILIPSPAR)    += i2c-philips-par.o
472obj-$(CONFIG_I2C_ELV)           += i2c-elv.o
473obj-$(CONFIG_I2C_VELLEMAN)      += i2c-velleman.o
474obj-$(CONFIG_I2C_ALGOPCF)       += i2c-algo-pcf.o
475obj-$(CONFIG_I2C_ELEKTOR)       += i2c-elektor.o
476obj-$(CONFIG_I2C_PROC)          += i2c-proc.o
477
478# This is needed for automatic patch generation: sensors code starts here
479# This is needed for automatic patch generation: sensors code ends here
480
481include $(TOPDIR)/Rules.make
482
483EOF
484  } else {
485    print OUTPUT <<'EOF';
486#
487# Makefile for the kernel i2c bus driver.
488#
489
490SUB_DIRS     :=
491MOD_SUB_DIRS := $(SUB_DIRS)
492ALL_SUB_DIRS := $(SUB_DIRS)
493MOD_LIST_NAME := I2C_MODULES
494
495L_TARGET := i2c.a
496MX_OBJS := 
497M_OBJS  :=
498LX_OBJS :=
499L_OBJS  :=
500
501# -----
502# i2c core components
503# -----
504
505ifeq ($(CONFIG_I2C),y)
506  LX_OBJS += i2c-core.o
507else
508  ifeq ($(CONFIG_I2C),m)
509    MX_OBJS += i2c-core.o
510  endif
511endif
512
513ifeq ($(CONFIG_I2C_CHARDEV),y)
514  L_OBJS += i2c-dev.o
515else
516  ifeq ($(CONFIG_I2C_CHARDEV),m)
517    M_OBJS += i2c-dev.o
518  endif
519endif
520
521ifeq ($(CONFIG_I2C_PROC),y)
522  LX_OBJS += i2c-proc.o
523else
524  ifeq ($(CONFIG_I2C_PROC),m)
525    MX_OBJS += i2c-proc.o
526  endif
527endif
528
529# -----
530# Bit banging adapters...
531# -----
532
533ifeq ($(CONFIG_I2C_ALGOBIT),y)
534  LX_OBJS += i2c-algo-bit.o
535else
536  ifeq ($(CONFIG_I2C_ALGOBIT),m)
537    MX_OBJS += i2c-algo-bit.o
538  endif
539endif
540
541ifeq ($(CONFIG_I2C_PHILIPSPAR),y)
542  L_OBJS += i2c-philips-par.o
543else
544  ifeq ($(CONFIG_I2C_PHILIPSPAR),m)
545    M_OBJS += i2c-philips-par.o
546  endif
547endif
548
549ifeq ($(CONFIG_I2C_ELV),y)
550  L_OBJS += i2c-elv.o
551else
552  ifeq ($(CONFIG_I2C_ELV),m)
553    M_OBJS += i2c-elv.o
554  endif
555endif
556
557ifeq ($(CONFIG_I2C_VELLEMAN),y)
558  L_OBJS += i2c-velleman.o
559else
560  ifeq ($(CONFIG_I2C_VELLEMAN),m)
561    M_OBJS += i2c-velleman.o
562  endif
563endif
564
565
566
567# -----
568# PCF components
569# -----
570
571ifeq ($(CONFIG_I2C_ALGOPCF),y)
572  LX_OBJS += i2c-algo-pcf.o
573else
574  ifeq ($(CONFIG_I2C_ALGOPCF),m)
575    MX_OBJS += i2c-algo-pcf.o
576  endif
577endif
578
579ifeq ($(CONFIG_I2C_ELEKTOR),y)
580  L_OBJS += i2c-elektor.o
581else
582  ifeq ($(CONFIG_I2C_ELEKTOR),m)
583    M_OBJS += i2c-elektor.o
584  endif
585endif
586
587# This is needed for automatic patch generation: sensors code starts here
588# This is needed for automatic patch generation: sensors code ends here
589
590include $(TOPDIR)/Rules.make
591
592EOF
593  }
594  close OUTPUT;
595  print_diff $package_root,$kernel_root,$kernel_file,$package_file;
596}
597
598# This generates diffs for drivers/char/Config.in
599# It adds a line just before CONFIG_APM or main_menu_option lines to include
600# the I2C Config.in.
601# Of course, care is taken old lines are removed.
602# $_[0]: i2c package root (like /tmp/i2c)
603# $_[1]: Linux kernel tree (like /usr/src/linux)
604sub gen_drivers_char_Config_in
605{
606  my ($package_root,$kernel_root) = @_;
607  my $kernel_file = "drivers/char/Config.in";
608  my $package_file = $temp;
609  my $ready = 0;
610  my $printed = 0;
611
612  open INPUT,"$kernel_root/$kernel_file"
613        or die "Can't open `$kernel_root/$kernel_file'";
614  open OUTPUT,">$package_root/$package_file"
615        or die "Can't open $package_root/$package_file";
616  MAIN: while(<INPUT>) {
617    if (m@i2c@) {
618      $_ = <INPUT>;
619      $_ = <INPUT> if (m@^$@);
620      redo MAIN;
621    }
622    if ($ready and not $printed and 
623        (m@^mainmenu_option@ or m@CONFIG_APM@ or m@CONFIG_ALPHA_BOOK1@ or
624         m@source drivers/sensors/Config.in@)) {
625      $printed = 1;
626      print OUTPUT <<'EOF';
627source drivers/i2c/Config.in
628
629EOF
630    }
631    $ready = 1 if (m@^mainmenu_option@);
632    print OUTPUT;
633  }
634  close INPUT;
635  close OUTPUT;
636  die "Automatic patch generation for `drivers/char/Config.in' failed.\n".
637      "Contact the authors please!" if $printed == 0;
638  print_diff $package_root,$kernel_root,$kernel_file,$package_file;
639}
640 
641
642# This generates diffs for drivers/char/mem.c They are a bit intricate.
643# Lines are generated at the beginning to declare i2c_init and i2c_init_all.
644# The first is the invocation for the old I2C driver, the second for the
645# new driver. At the bottom, a call to i2c_init_all is added when the
646# new I2C stuff is configured in.
647# Of course, care is taken old lines are removed.
648# $_[0]: i2c package root (like /tmp/i2c)
649# $_[1]: Linux kernel tree (like /usr/src/linux)
650sub gen_drivers_char_mem_c
651{
652  my ($package_root,$kernel_root) = @_;
653  my $kernel_file = "drivers/char/mem.c";
654  my $package_file = $temp;
655  my $right_place = 0;
656  my $done = 0;
657  my $atstart = 1;
658  my $pr1 = 0;
659  my $pr2 = 0;
660
661  open INPUT,"$kernel_root/$kernel_file"
662        or die "Can't open `$kernel_root/$kernel_file'";
663  open OUTPUT,">$package_root/$package_file"
664        or die "Can't open $package_root/$package_file";
665  MAIN: while(<INPUT>) {
666    if (m@#include <linux/i2c.h>@) {
667       $_=<INPUT>;
668       redo MAIN;
669    }
670    if ($atstart and m@#ifdef@) {
671      print OUTPUT << 'EOF';
672#ifdef CONFIG_I2C
673extern int i2c_init_all(void);
674#endif
675EOF
676      $atstart = 0;
677      $pr1 = 1;
678    }
679    while (not $right_place and (m@CONFIG_I2C@ or m@CONFIG_VIDEO_BT848@)) {
680      $_ = <INPUT> while not m@#endif@;
681      $_ = <INPUT>;
682      redo MAIN;
683    }
684    $right_place = 1 if (m@chr_dev_init@);
685    if ($right_place and m@CONFIG_I2C@) {
686      $_ = <INPUT> while not m@#endif@;
687      $_ = <INPUT>;
688      $_ = <INPUT> if m@^$@;
689      redo MAIN;
690    }
691    if ($right_place and not $done and
692        (m@CONFIG_VIDEO_BT848@ or m@return 0;@ or m@CONFIG_SENSORS@ or
693         m@CONFIG_FB@)) {
694      print OUTPUT <<'EOF';
695#ifdef CONFIG_I2C
696        i2c_init_all();
697#endif
698EOF
699      $done = 1;
700      $pr2 = 1;
701    }
702    print OUTPUT;
703  }
704  close INPUT;
705  close OUTPUT;
706  die "Automatic patch generation for `drivers/char/mem.c' failed.\n".
707      "Contact the authors please!" if $pr1 == 0 or $pr2 == 0;
708  print_diff $package_root,$kernel_root,$kernel_file,$package_file;
709}
710 
711# Generate the diffs for the list of MAINTAINERS
712# $_[0]: i2c package root (like /tmp/i2c)
713# $_[1]: Linux kernel tree (like /usr/src/linux)
714sub gen_MAINTAINERS
715{
716  my ($package_root,$kernel_root) = @_;
717  my $kernel_file = "MAINTAINERS";
718  my $package_file = $temp;
719  my $done = 0;
720
721  open INPUT,"$kernel_root/$kernel_file"
722        or die "Can't open `$kernel_root/$kernel_file'";
723  open OUTPUT,">$package_root/$package_file"
724        or die "Can't open $package_root/$package_file";
725  MAIN: while(<INPUT>) {
726    if (m@I2C DRIVERS@) {
727       $_=<INPUT> while not m@^$@;
728       $_=<INPUT>;
729       redo MAIN;
730    }
731    if (not $done and (m@i386 BOOT CODE@ or m@IBM MCA SCSI SUBSYSTEM DRIVER@)) {
732      print OUTPUT <<'EOF';
733I2C DRIVERS
734P:      Simon Vogl
735M:      simon@tk.uni-linz.ac.at
736P:      Frodo Looijaard
737M:      frodol@dds.nl
738L:      linux-i2c@pelican.tk.uni-linz.ac.at
739W:      http://www.tk.uni-linz.ac.at/~simon/private/i2c
740S:      Maintained
741
742EOF
743      $done = 1;
744    }
745    print OUTPUT;
746  }
747  close INPUT;
748  close OUTPUT;
749  die "Automatic patch generation for `MAINTAINERS' failed.\n".
750      "Contact the authors please!" if $done == 0;
751  print_diff $package_root,$kernel_root,$kernel_file,$package_file;
752}
753
754# Main function
755sub main
756{
757  my ($package_root,$kernel_root,%files,%includes,$package_file,$kernel_file);
758  my ($diff_command,$dummy,$data0,$data1,$sedscript,@sensors_subs);
759
760  # --> Read the command-line
761  $package_root = $ARGV[0];
762  die "Package root `$package_root' is not found\n" 
763        unless -d "$package_root/mkpatch";
764  $kernel_root = $ARGV[1];
765  die "Kernel root `$kernel_root' is not found\n" 
766        unless -f "$kernel_root/Rules.make";
767
768  patch_old_i2c $package_root, $kernel_root;
769         
770
771  # --> Read FILES
772  open INPUT, "$package_root/mkpatch/FILES" 
773        or die "Can't open `$package_root/mkpatch/FILES'";
774  while (<INPUT>) {
775    ($data0,$data1) = /(\S+)\s+(\S+)/;
776    $files{$data0} = $data1;
777  } 
778  close INPUT;
779
780  # --> Read INCLUDES
781  open INPUT, "$package_root/mkpatch/INCLUDES" 
782        or die "Can't open `$package_root/mkpatch/INCLUDES'";
783  while (<INPUT>) {
784    ($data0,$data1) = /(\S+)\s+(\S+)/;
785    $includes{$data0} = $data1;
786    $sedscript .= 's,(#\s*include\s*)'.$data0.'(\s*),\1'."$data1".'\2, ; ';
787  } 
788  close INPUT;
789
790  # --> Start generating
791  foreach $package_file (sort keys %files) {
792    $kernel_file = $files{$package_file};
793    @sensors_subs = find_sensors_code "$kernel_root","$kernel_file";
794    open INPUT, "$package_root/$package_file"
795         or die "Can't open `$package_root/$package_file'";
796    open OUTPUT, ">$package_root/$temp"
797         or die "Can't open `$package_root/$temp'";
798    while (<INPUT>) {
799      eval $sedscript;
800      if (m@sensors code starts here@) {
801        print OUTPUT;
802        while (<INPUT>) {
803           last if m@sensors code ends here@;
804        }
805        print OUTPUT $sensors_subs[0];
806        shift @sensors_subs
807      }
808      print OUTPUT;
809    }
810    close INPUT;
811    close OUTPUT;
812    print_diff "$package_root","$kernel_root","$kernel_file","$temp";
813  }
814
815  gen_Makefile $package_root, $kernel_root;
816  gen_drivers_Makefile $package_root, $kernel_root;
817  gen_drivers_i2c_Makefile $package_root, $kernel_root;
818  gen_drivers_char_Config_in $package_root, $kernel_root;
819  gen_drivers_char_mem_c $package_root, $kernel_root;
820  gen_Documentation_Configure_help $package_root, $kernel_root;
821  gen_MAINTAINERS $package_root, $kernel_root;
822}
823
824main;
825
Note: See TracBrowser for help on using the browser.