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

Revision 3527, 23.6 KB (checked in by mds, 12 years ago)

Copy sensors.c and sensors.h from the lm_sensors package and

name them i2c-proc.c and i2c-proc.h.
Add DEVICEID's from sensors.h to i2c-id.h.
Add #defines from i2c-isa.h in lm_sensors to i2c.h.
Update mkpatch for i2c-proc.[ch].

  • 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
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
476
477# This is needed for automatic patch generation: sensors code starts here
478# This is needed for automatic patch generation: sensors code ends here
479
480include $(TOPDIR)/Rules.make
481
482EOF
483  } else {
484    print OUTPUT <<'EOF';
485#
486# Makefile for the kernel i2c bus driver.
487#
488
489SUB_DIRS     :=
490MOD_SUB_DIRS := $(SUB_DIRS)
491ALL_SUB_DIRS := $(SUB_DIRS)
492MOD_LIST_NAME := I2C_MODULES
493
494L_TARGET := i2c.a
495MX_OBJS := 
496M_OBJS  :=
497LX_OBJS :=
498L_OBJS  :=
499
500# -----
501# i2c core components
502# -----
503
504ifeq ($(CONFIG_I2C),y)
505  LX_OBJS += i2c-core.o
506else
507  ifeq ($(CONFIG_I2C),m)
508    MX_OBJS += i2c-core.o
509  endif
510endif
511
512ifeq ($(CONFIG_I2C_CHARDEV),y)
513  L_OBJS += i2c-dev.o
514else
515  ifeq ($(CONFIG_I2C_CHARDEV),m)
516    M_OBJS += i2c-dev.o
517  endif
518endif
519
520ifeq ($(CONFIG_I2C_PROC),y)
521  L_OBJS += i2c-proc.o
522else
523  ifeq ($(CONFIG_I2C_PROC),m)
524    M_OBJS += i2c-proc.o
525  endif
526endif
527
528# -----
529# Bit banging adapters...
530# -----
531
532ifeq ($(CONFIG_I2C_ALGOBIT),y)
533  LX_OBJS += i2c-algo-bit.o
534else
535  ifeq ($(CONFIG_I2C_ALGOBIT),m)
536    MX_OBJS += i2c-algo-bit.o
537  endif
538endif
539
540ifeq ($(CONFIG_I2C_PHILIPSPAR),y)
541  L_OBJS += i2c-philips-par.o
542else
543  ifeq ($(CONFIG_I2C_PHILIPSPAR),m)
544    M_OBJS += i2c-philips-par.o
545  endif
546endif
547
548ifeq ($(CONFIG_I2C_ELV),y)
549  L_OBJS += i2c-elv.o
550else
551  ifeq ($(CONFIG_I2C_ELV),m)
552    M_OBJS += i2c-elv.o
553  endif
554endif
555
556ifeq ($(CONFIG_I2C_VELLEMAN),y)
557  L_OBJS += i2c-velleman.o
558else
559  ifeq ($(CONFIG_I2C_VELLEMAN),m)
560    M_OBJS += i2c-velleman.o
561  endif
562endif
563
564
565
566# -----
567# PCF components
568# -----
569
570ifeq ($(CONFIG_I2C_ALGOPCF),y)
571  LX_OBJS += i2c-algo-pcf.o
572else
573  ifeq ($(CONFIG_I2C_ALGOPCF),m)
574    MX_OBJS += i2c-algo-pcf.o
575  endif
576endif
577
578ifeq ($(CONFIG_I2C_ELEKTOR),y)
579  L_OBJS += i2c-elektor.o
580else
581  ifeq ($(CONFIG_I2C_ELEKTOR),m)
582    M_OBJS += i2c-elektor.o
583  endif
584endif
585
586# This is needed for automatic patch generation: sensors code starts here
587# This is needed for automatic patch generation: sensors code ends here
588
589include $(TOPDIR)/Rules.make
590
591EOF
592  }
593  close OUTPUT;
594  print_diff $package_root,$kernel_root,$kernel_file,$package_file;
595}
596
597# This generates diffs for drivers/char/Config.in
598# It adds a line just before CONFIG_APM or main_menu_option lines to include
599# the I2C Config.in.
600# Of course, care is taken old lines are removed.
601# $_[0]: i2c package root (like /tmp/i2c)
602# $_[1]: Linux kernel tree (like /usr/src/linux)
603sub gen_drivers_char_Config_in
604{
605  my ($package_root,$kernel_root) = @_;
606  my $kernel_file = "drivers/char/Config.in";
607  my $package_file = $temp;
608  my $ready = 0;
609  my $printed = 0;
610
611  open INPUT,"$kernel_root/$kernel_file"
612        or die "Can't open `$kernel_root/$kernel_file'";
613  open OUTPUT,">$package_root/$package_file"
614        or die "Can't open $package_root/$package_file";
615  MAIN: while(<INPUT>) {
616    if (m@i2c@) {
617      $_ = <INPUT>;
618      $_ = <INPUT> if (m@^$@);
619      redo MAIN;
620    }
621    if ($ready and not $printed and 
622        (m@^mainmenu_option@ or m@CONFIG_APM@ or m@CONFIG_ALPHA_BOOK1@ or
623         m@source drivers/sensors/Config.in@)) {
624      $printed = 1;
625      print OUTPUT <<'EOF';
626source drivers/i2c/Config.in
627
628EOF
629    }
630    $ready = 1 if (m@^mainmenu_option@);
631    print OUTPUT;
632  }
633  close INPUT;
634  close OUTPUT;
635  die "Automatic patch generation for `drivers/char/Config.in' failed.\n".
636      "Contact the authors please!" if $printed == 0;
637  print_diff $package_root,$kernel_root,$kernel_file,$package_file;
638}
639 
640
641# This generates diffs for drivers/char/mem.c They are a bit intricate.
642# Lines are generated at the beginning to declare i2c_init and i2c_init_all.
643# The first is the invocation for the old I2C driver, the second for the
644# new driver. At the bottom, a call to i2c_init_all is added when the
645# new I2C stuff is configured in.
646# Of course, care is taken old lines are removed.
647# $_[0]: i2c package root (like /tmp/i2c)
648# $_[1]: Linux kernel tree (like /usr/src/linux)
649sub gen_drivers_char_mem_c
650{
651  my ($package_root,$kernel_root) = @_;
652  my $kernel_file = "drivers/char/mem.c";
653  my $package_file = $temp;
654  my $right_place = 0;
655  my $done = 0;
656  my $atstart = 1;
657  my $pr1 = 0;
658  my $pr2 = 0;
659
660  open INPUT,"$kernel_root/$kernel_file"
661        or die "Can't open `$kernel_root/$kernel_file'";
662  open OUTPUT,">$package_root/$package_file"
663        or die "Can't open $package_root/$package_file";
664  MAIN: while(<INPUT>) {
665    if (m@#include <linux/i2c.h>@) {
666       $_=<INPUT>;
667       redo MAIN;
668    }
669    if ($atstart and m@#ifdef@) {
670      print OUTPUT << 'EOF';
671#ifdef CONFIG_I2C
672extern int i2c_init_all(void);
673#endif
674EOF
675      $atstart = 0;
676      $pr1 = 1;
677    }
678    while (not $right_place and (m@CONFIG_I2C@ or m@CONFIG_VIDEO_BT848@)) {
679      $_ = <INPUT> while not m@#endif@;
680      $_ = <INPUT>;
681      redo MAIN;
682    }
683    $right_place = 1 if (m@chr_dev_init@);
684    if ($right_place and m@CONFIG_I2C@) {
685      $_ = <INPUT> while not m@#endif@;
686      $_ = <INPUT>;
687      $_ = <INPUT> if m@^$@;
688      redo MAIN;
689    }
690    if ($right_place and not $done and
691        (m@CONFIG_VIDEO_BT848@ or m@return 0;@ or m@CONFIG_SENSORS@ or
692         m@CONFIG_FB@)) {
693      print OUTPUT <<'EOF';
694#ifdef CONFIG_I2C
695        i2c_init_all();
696#endif
697EOF
698      $done = 1;
699      $pr2 = 1;
700    }
701    print OUTPUT;
702  }
703  close INPUT;
704  close OUTPUT;
705  die "Automatic patch generation for `drivers/char/mem.c' failed.\n".
706      "Contact the authors please!" if $pr1 == 0 or $pr2 == 0;
707  print_diff $package_root,$kernel_root,$kernel_file,$package_file;
708}
709 
710# Generate the diffs for the list of MAINTAINERS
711# $_[0]: i2c package root (like /tmp/i2c)
712# $_[1]: Linux kernel tree (like /usr/src/linux)
713sub gen_MAINTAINERS
714{
715  my ($package_root,$kernel_root) = @_;
716  my $kernel_file = "MAINTAINERS";
717  my $package_file = $temp;
718  my $done = 0;
719
720  open INPUT,"$kernel_root/$kernel_file"
721        or die "Can't open `$kernel_root/$kernel_file'";
722  open OUTPUT,">$package_root/$package_file"
723        or die "Can't open $package_root/$package_file";
724  MAIN: while(<INPUT>) {
725    if (m@I2C DRIVERS@) {
726       $_=<INPUT> while not m@^$@;
727       $_=<INPUT>;
728       redo MAIN;
729    }
730    if (not $done and (m@i386 BOOT CODE@ or m@IBM MCA SCSI SUBSYSTEM DRIVER@)) {
731      print OUTPUT <<'EOF';
732I2C DRIVERS
733P:      Simon Vogl
734M:      simon@tk.uni-linz.ac.at
735P:      Frodo Looijaard
736M:      frodol@dds.nl
737L:      linux-i2c@pelican.tk.uni-linz.ac.at
738W:      http://www.tk.uni-linz.ac.at/~simon/private/i2c
739S:      Maintained
740
741EOF
742      $done = 1;
743    }
744    print OUTPUT;
745  }
746  close INPUT;
747  close OUTPUT;
748  die "Automatic patch generation for `MAINTAINERS' failed.\n".
749      "Contact the authors please!" if $done == 0;
750  print_diff $package_root,$kernel_root,$kernel_file,$package_file;
751}
752
753# Main function
754sub main
755{
756  my ($package_root,$kernel_root,%files,%includes,$package_file,$kernel_file);
757  my ($diff_command,$dummy,$data0,$data1,$sedscript,@sensors_subs);
758
759  # --> Read the command-line
760  $package_root = $ARGV[0];
761  die "Package root `$package_root' is not found\n" 
762        unless -d "$package_root/mkpatch";
763  $kernel_root = $ARGV[1];
764  die "Kernel root `$kernel_root' is not found\n" 
765        unless -f "$kernel_root/Rules.make";
766
767  patch_old_i2c $package_root, $kernel_root;
768         
769
770  # --> Read FILES
771  open INPUT, "$package_root/mkpatch/FILES" 
772        or die "Can't open `$package_root/mkpatch/FILES'";
773  while (<INPUT>) {
774    ($data0,$data1) = /(\S+)\s+(\S+)/;
775    $files{$data0} = $data1;
776  } 
777  close INPUT;
778
779  # --> Read INCLUDES
780  open INPUT, "$package_root/mkpatch/INCLUDES" 
781        or die "Can't open `$package_root/mkpatch/INCLUDES'";
782  while (<INPUT>) {
783    ($data0,$data1) = /(\S+)\s+(\S+)/;
784    $includes{$data0} = $data1;
785    $sedscript .= 's,(#\s*include\s*)'.$data0.'(\s*),\1'."$data1".'\2, ; ';
786  } 
787  close INPUT;
788
789  # --> Start generating
790  foreach $package_file (sort keys %files) {
791    $kernel_file = $files{$package_file};
792    @sensors_subs = find_sensors_code "$kernel_root","$kernel_file";
793    open INPUT, "$package_root/$package_file"
794         or die "Can't open `$package_root/$package_file'";
795    open OUTPUT, ">$package_root/$temp"
796         or die "Can't open `$package_root/$temp'";
797    while (<INPUT>) {
798      eval $sedscript;
799      if (m@sensors code starts here@) {
800        print OUTPUT;
801        while (<INPUT>) {
802           last if m@sensors code ends here@;
803        }
804        print OUTPUT $sensors_subs[0];
805        shift @sensors_subs
806      }
807      print OUTPUT;
808    }
809    close INPUT;
810    close OUTPUT;
811    print_diff "$package_root","$kernel_root","$kernel_file","$temp";
812  }
813
814  gen_Makefile $package_root, $kernel_root;
815  gen_drivers_Makefile $package_root, $kernel_root;
816  gen_drivers_i2c_Makefile $package_root, $kernel_root;
817  gen_drivers_char_Config_in $package_root, $kernel_root;
818  gen_drivers_char_mem_c $package_root, $kernel_root;
819  gen_Documentation_Configure_help $package_root, $kernel_root;
820  gen_MAINTAINERS $package_root, $kernel_root;
821}
822
823main;
824
Note: See TracBrowser for help on using the browser.