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

Revision 3648, 24.1 KB (checked in by mds, 11 years ago)

(mds)
Here's the last bit of the patch to make 8xx i2c work again. This is
safe to do since if the code for the specified object doesn't exist, we
only run into a problem if we try and compile the code (which would be a
large problem, if it doesn't exist :))

--
Tom Rini (TR1265)
 http://gate.crashing.org/~trini/

  • 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@ or
158           m@^I2C /proc interface \(required for hardware sensors\)@) {
159      $_ = <INPUT>;
160      $_ = <INPUT>;
161      $_ = <INPUT> while not m@^\S@ and not eof(INPUT);
162      redo MAIN;
163    }
164    if (not $printed and (eof(INPUT) or m@I2C mainboard interfaces@ or
165                          m@A couple of things I keep forgetting@ or
166                          m@Bus Mouse Support@)) {
167      print OUTPUT <<'EOF';
168I2C support
169CONFIG_I2C
170  I2C (pronounce: I-square-C) is a slow serial bus protocol used in
171  many micro controller applications and developed by Philips.  SMBus,
172  or System Management Bus is a subset of the I2C protocol.  More
173  information is contained in the directory <file:Documentation/i2c/>,
174  especially in the file called "summary" there.
175
176  Both I2C and SMBus are supported here. You will need this for
177  hardware sensors support, and also for Video For Linux support.
178  Specifically, if you want to use a BT848 based frame grabber/overlay
179  boards under Linux, say Y here and also to "I2C bit-banging
180  interfaces", below.
181
182  If you want I2C support, you should say Y here and also to the
183  specific driver for your bus adapter(s) below.  If you say Y to
184  "/proc file system" below, you will then get a /proc interface which
185  is documented in <file:Documentation/i2c/proc-interface>.
186
187  This I2C support is also available as a module.  If you want to
188  compile it as a module, say M here and read
189  <file:Documentation/modules.txt>.
190  The module will be called i2c-core.o.
191
192I2C bit-banging interfaces
193CONFIG_I2C_ALGOBIT
194  This allows you to use a range of I2C adapters called bit-banging
195  adapters.  Say Y if you own an I2C adapter belonging to this class
196  and then say Y to the specific driver for you adapter below.
197
198  This support is also available as a module.  If you want to compile
199  it as a module, say M here and read
200  <file:Documentation/modules.txt>.
201  The module will be called i2c-algo-bit.o.
202
203Philips style parallel port adapter
204CONFIG_I2C_PHILIPSPAR
205  This supports parallel-port I2C adapters made by Philips.  Say Y if
206  you own such an adapter.
207
208  This driver is also available as a module.  If you want to compile
209  it as a module, say M here and read
210  <file:Documentation/modules.txt>.
211  The module will be called i2c-philips-par.o.
212
213  Note that if you want support for different parallel port devices,
214  life will be much easier if you compile them all as modules.
215
216ELV adapter
217CONFIG_I2C_ELV
218  This supports parallel-port I2C adapters called ELV.  Say Y if you
219  own such an adapter.
220
221  This driver is also available as a module.  If you want to compile
222  it as a module, say M here and read
223  <file:Documentation/modules.txt>.
224  The module will be called i2c-elv.o.
225
226Velleman K9000 adapter
227CONFIG_I2C_VELLEMAN
228  This supports the Velleman K9000 parallel-port I2C adapter.  Say Y
229  if you own such an adapter.
230
231  This driver is also available as a module.  If you want to compile
232  it as a module, say M here and read
233  <file:Documentation/modules.txt>.
234  The module will be called i2c-velleman.o.
235
236I2C PCF 8584 interfaces
237CONFIG_I2C_ALGOPCF
238  This allows you to use a range of I2C adapters called PCF adapters.
239  Say Y if you own an I2C adapter belonging to this class and then say
240  Y to the specific driver for you adapter below.
241
242  This support is also available as a module.  If you want to compile
243  it as a module, say M here and read
244  <file:Documentation/modules.txt>.
245  The module will be called i2c-algo-pcf.o.
246
247Elektor ISA card
248CONFIG_I2C_ELEKTOR
249  This supports the PCF8584 ISA bus I2C adapter.  Say Y if you own
250  such an adapter.
251
252  This driver is also available as a module.  If you want to compile
253  it as a module, say M here and read
254  <file:Documentation/modules.txt>.
255  The module will be called i2c-elektor.o.
256
257I2C device interface
258CONFIG_I2C_CHARDEV
259  Say Y here to use i2c-* device files, usually found in the /dev
260  directory on your system.  They make it possible to have user-space
261  programs use the I2C bus.  Information on how to do this is
262  contained in the file <file:Documentation/i2c/dev-interface>.
263
264  This code is also available as a module.  If you want to compile
265  it as a module, say M here and read
266  <file:Documentation/modules.txt>.
267  The module will be called i2c-dev.o.
268
269I2C /proc interface (required for hardware sensors)
270CONFIG_I2C_PROC
271  This provides support for i2c device entries in the /proc filesystem.
272  The entries will be found in /proc/sys/dev/sensors.
273
274  This code is also available as a module. If you want to compile
275  it as a module, say M here and read <file:Documentation/modules.txt>.
276  The module will be called i2c-proc.o.
277
278EOF
279      $printed = 1;
280    }
281    print OUTPUT;
282  }
283  close INPUT;
284  close OUTPUT;
285  print_diff $package_root,$kernel_root,$kernel_file,$package_file;
286}
287
288# This generates diffs for the main Linux Makefile.
289# Three lines which add drivers/i2c/i2.a to the DRIVERS list are put just
290# before the place where the architecture Makefile is included.
291# Of course, care is taken old lines are removed.
292# $_[0]: i2c package root (like /tmp/i2c)
293# $_[1]: Linux kernel tree (like /usr/src/linux)
294sub gen_Makefile
295{
296  my ($package_root,$kernel_root) = @_;
297  my $kernel_file = "Makefile";
298  my $package_file = $temp;
299  my $printed = 0;
300  my $new_style = 0;
301
302  open INPUT,"$kernel_root/$kernel_file"
303        or die "Can't open `$kernel_root/$kernel_file'";
304  open OUTPUT,">$package_root/$package_file"
305        or die "Can't open $package_root/$package_file";
306  MAIN: while(<INPUT>) {
307    if (m@^DRIVERS :=@) {
308       $new_style = 1;
309    }
310    if (m@DRIVERS-\$\(CONFIG_I2C\)@) {
311      $_ = <INPUT>;
312      redo MAIN;
313    } elsif (m@CONFIG_I2C@) {
314      $_ = <INPUT> while not m@endif@;
315      $_ = <INPUT>;
316      $_ = <INPUT> if m@^$@;
317      redo MAIN;
318    }
319    if (not $printed and m@DRIVERS-\$\(CONFIG_PHONE\)@) {
320      if ($new_style) {
321        print OUTPUT << 'EOF';
322DRIVERS-$(CONFIG_I2C) += drivers/i2c/i2c.a
323EOF
324      } else {
325        print OUTPUT << 'EOF';
326DRIVERS-$(CONFIG_I2C) += drivers/i2c/i2c.o
327EOF
328      }
329      $printed = 1;
330    } elsif (not $printed and 
331        (m@include arch/\$\(ARCH\)/Makefile@ or m@CONFIG_SENSORS@ or
332         m@CONFIG_PHONE@ )) {
333      print OUTPUT <<'EOF';
334ifeq ($(CONFIG_I2C),y)
335DRIVERS := $(DRIVERS) drivers/i2c/i2c.a
336endif
337
338EOF
339      $printed = 1;
340    }
341    print OUTPUT;
342  }
343  close INPUT;
344  close OUTPUT;
345  die "Automatic patch generation for `Makefile' failed.\n".
346      "See our home page http://www.lm-sensors.nu for assistance!" if $printed == 0;
347  print_diff $package_root,$kernel_root,$kernel_file,$package_file;
348}
349
350# This generates diffs for drivers/Makefile
351# First, `i2c' is added to the ALL_SUB_DIRS list. Next, a couple of lines
352# to add i2c to the SUB_DIRS and/or MOD_SUB_DIRS lists is put right before
353# Rules.make is included.
354# Of course, care is taken old lines are removed.
355# $_[0]: i2c package root (like /tmp/i2c)
356# $_[1]: Linux kernel tree (like /usr/src/linux)
357sub gen_drivers_Makefile
358{
359  my ($package_root,$kernel_root) = @_;
360  my $kernel_file = "drivers/Makefile";
361  my $package_file = $temp;
362  my $i2c_present;
363  my $printed = 0;
364  my $added = 0;
365  my $new_style = 0;
366
367  open INPUT,"$kernel_root/$kernel_file"
368        or die "Can't open `$kernel_root/$kernel_file'";
369  open OUTPUT,">$package_root/$package_file"
370        or die "Can't open $package_root/$package_file";
371  MAIN: while(<INPUT>) {
372    if (m@^mod-subdirs\s*:=@) {
373       $new_style = 1;
374    }
375    if ((! $new_style and m@^ALL_SUB_DIRS\s*:=@) or m@^mod-subdirs\s*:=@ ) {
376      $added = 1;
377      $i2c_present = 0;
378      while (m@\\$@) {
379        $i2c_present = 1 if m@i2c@;
380        print OUTPUT;
381        $_ = <INPUT>;
382      }
383      $i2c_present = 1 if m@i2c@;
384      s@$@ i2c@ if (not $i2c_present);
385      print OUTPUT;
386      $_ = <INPUT>;
387      redo MAIN;
388    } 
389    if (m@^ifeq.*CONFIG_I2C@) {
390      $_ = <INPUT> while not m@^endif@;
391      $_ = <INPUT>;
392      $_ = <INPUT> if m@^$@;
393      redo MAIN;
394    } 
395    if (m@^subdir.*CONFIG_I2C@) {
396      $_ = <INPUT>;
397      redo MAIN;
398    }
399    if (not $printed and
400        (m@^include \$\(TOPDIR\)/Rules.make$@ or
401         m@^ifeq \(\$\(CONFIG_ACPI\),y\)$@ or
402         m@^ifeq \(\$\(CONFIG_SENSORS\),y\)@) or
403         m@^subdir-\$\(CONFIG_ACPI\)@) {
404      if ($new_style) {
405        print OUTPUT <<'EOF';
406subdir-$(CONFIG_I2C)            += i2c
407EOF
408      } else {
409        print OUTPUT <<'EOF';
410ifeq ($(CONFIG_I2C),y)
411SUB_DIRS += i2c
412MOD_SUB_DIRS += i2c
413else
414  ifeq ($(CONFIG_I2C),m)
415  MOD_SUB_DIRS += i2c
416  endif
417endif
418
419EOF
420      }
421      $printed = 1;
422    }
423    print OUTPUT;
424  }
425  close INPUT;
426  close OUTPUT;
427  die "Automatic patch generation for `Makefile' failed.\n".
428      "See our home page http://www.lm-sensors.nu for assistance!" if $printed == 0 or $added == 0;
429  print_diff $package_root,$kernel_root,$kernel_file,$package_file;
430}
431
432# This generates diffs for drivers/char/Makefile
433# It changes all occurences of `i2c.o' to `i2c-old.o'.
434# $_[0]: i2c package root (like /tmp/i2c)
435# $_[1]: Linux kernel tree (like /usr/src/linux)
436sub gen_drivers_char_Makefile
437{
438  my ($package_root,$kernel_root) = @_;
439  my $kernel_file = "drivers/char/Makefile";
440  my $package_file = $temp;
441  open INPUT,"$kernel_root/$kernel_file"
442        or die "Can't open `$kernel_root/$kernel_file'";
443  open OUTPUT,">$package_root/$package_file"
444        or die "Can't open $package_root/$package_file";
445  while(<INPUT>) {
446    s@i2c\.o@i2c-old\.o@;
447    print OUTPUT;
448  }
449  close INPUT;
450  close OUTPUT;
451  print_diff $package_root,$kernel_root,$kernel_file,$package_file;
452}
453
454sub gen_drivers_i2c_Makefile
455{
456  my ($package_root,$kernel_root) = @_;
457  my $kernel_file = "drivers/i2c/Makefile";
458  my $package_file = $temp;
459  my $use_new_format = 0;
460  if (-e "$kernel_root/$kernel_file") {
461    `grep -q -s 'i2c\.o' "$kernel_root/$kernel_file"`;
462     $use_new_format = ! $?;
463  }
464
465  open OUTPUT,">$package_root/$package_file"
466        or die "Can't open $package_root/$package_file";
467  if ($use_new_format) {
468    print OUTPUT <<'EOF';
469#
470# Makefile for the kernel i2c bus driver.
471#
472
473O_TARGET := i2c.o
474
475export-objs     := i2c-core.o i2c-algo-bit.o i2c-algo-pcf.o i2c-proc.o \
476                        i2c-algo-8xx.o
477
478obj-$(CONFIG_I2C)               += i2c-core.o
479obj-$(CONFIG_I2C_CHARDEV)       += i2c-dev.o
480obj-$(CONFIG_I2C_ALGOBIT)       += i2c-algo-bit.o
481obj-$(CONFIG_I2C_PHILIPSPAR)    += i2c-philips-par.o
482obj-$(CONFIG_I2C_ELV)           += i2c-elv.o
483obj-$(CONFIG_I2C_VELLEMAN)      += i2c-velleman.o
484obj-$(CONFIG_I2C_ALGOPCF)       += i2c-algo-pcf.o
485obj-$(CONFIG_I2C_ELEKTOR)       += i2c-elektor.o
486obj-$(CONFIG_I2C_PROC)          += i2c-proc.o
487
488# This is needed for automatic patch generation: sensors code starts here
489# This is needed for automatic patch generation: sensors code ends here
490
491include $(TOPDIR)/Rules.make
492
493EOF
494  } else {
495    print OUTPUT <<'EOF';
496#
497# Makefile for the kernel i2c bus driver.
498#
499
500SUB_DIRS     :=
501MOD_SUB_DIRS := $(SUB_DIRS)
502ALL_SUB_DIRS := $(SUB_DIRS)
503MOD_LIST_NAME := I2C_MODULES
504
505L_TARGET := i2c.a
506MX_OBJS := 
507M_OBJS  :=
508LX_OBJS :=
509L_OBJS  :=
510
511# -----
512# i2c core components
513# -----
514
515ifeq ($(CONFIG_I2C),y)
516  LX_OBJS += i2c-core.o
517else
518  ifeq ($(CONFIG_I2C),m)
519    MX_OBJS += i2c-core.o
520  endif
521endif
522
523ifeq ($(CONFIG_I2C_CHARDEV),y)
524  L_OBJS += i2c-dev.o
525else
526  ifeq ($(CONFIG_I2C_CHARDEV),m)
527    M_OBJS += i2c-dev.o
528  endif
529endif
530
531ifeq ($(CONFIG_I2C_PROC),y)
532  LX_OBJS += i2c-proc.o
533else
534  ifeq ($(CONFIG_I2C_PROC),m)
535    MX_OBJS += i2c-proc.o
536  endif
537endif
538
539# -----
540# Bit banging adapters...
541# -----
542
543ifeq ($(CONFIG_I2C_ALGOBIT),y)
544  LX_OBJS += i2c-algo-bit.o
545else
546  ifeq ($(CONFIG_I2C_ALGOBIT),m)
547    MX_OBJS += i2c-algo-bit.o
548  endif
549endif
550
551ifeq ($(CONFIG_I2C_PHILIPSPAR),y)
552  L_OBJS += i2c-philips-par.o
553else
554  ifeq ($(CONFIG_I2C_PHILIPSPAR),m)
555    M_OBJS += i2c-philips-par.o
556  endif
557endif
558
559ifeq ($(CONFIG_I2C_ELV),y)
560  L_OBJS += i2c-elv.o
561else
562  ifeq ($(CONFIG_I2C_ELV),m)
563    M_OBJS += i2c-elv.o
564  endif
565endif
566
567ifeq ($(CONFIG_I2C_VELLEMAN),y)
568  L_OBJS += i2c-velleman.o
569else
570  ifeq ($(CONFIG_I2C_VELLEMAN),m)
571    M_OBJS += i2c-velleman.o
572  endif
573endif
574
575
576
577# -----
578# PCF components
579# -----
580
581ifeq ($(CONFIG_I2C_ALGOPCF),y)
582  LX_OBJS += i2c-algo-pcf.o
583else
584  ifeq ($(CONFIG_I2C_ALGOPCF),m)
585    MX_OBJS += i2c-algo-pcf.o
586  endif
587endif
588
589ifeq ($(CONFIG_I2C_ELEKTOR),y)
590  L_OBJS += i2c-elektor.o
591else
592  ifeq ($(CONFIG_I2C_ELEKTOR),m)
593    M_OBJS += i2c-elektor.o
594  endif
595endif
596
597# This is needed for automatic patch generation: sensors code starts here
598# This is needed for automatic patch generation: sensors code ends here
599
600include $(TOPDIR)/Rules.make
601
602EOF
603  }
604  close OUTPUT;
605  print_diff $package_root,$kernel_root,$kernel_file,$package_file;
606}
607
608# This generates diffs for drivers/char/Config.in
609# It adds a line just before CONFIG_APM or main_menu_option lines to include
610# the I2C Config.in.
611# Of course, care is taken old lines are removed.
612# $_[0]: i2c package root (like /tmp/i2c)
613# $_[1]: Linux kernel tree (like /usr/src/linux)
614sub gen_drivers_char_Config_in
615{
616  my ($package_root,$kernel_root) = @_;
617  my $kernel_file = "drivers/char/Config.in";
618  my $package_file = $temp;
619  my $ready = 0;
620  my $printed = 0;
621
622  open INPUT,"$kernel_root/$kernel_file"
623        or die "Can't open `$kernel_root/$kernel_file'";
624  open OUTPUT,">$package_root/$package_file"
625        or die "Can't open $package_root/$package_file";
626  MAIN: while(<INPUT>) {
627    if (m@i2c@) {
628      $_ = <INPUT>;
629      $_ = <INPUT> if (m@^$@);
630      redo MAIN;
631    }
632    if ($ready and not $printed and 
633        (m@^mainmenu_option@ or m@CONFIG_APM@ or m@CONFIG_ALPHA_BOOK1@ or
634         m@source drivers/sensors/Config.in@)) {
635      $printed = 1;
636      print OUTPUT <<'EOF';
637source drivers/i2c/Config.in
638
639EOF
640    }
641    $ready = 1 if (m@^mainmenu_option@);
642    print OUTPUT;
643  }
644  close INPUT;
645  close OUTPUT;
646  die "Automatic patch generation for `drivers/char/Config.in' failed.\n".
647      "See our home page http://www.lm-sensors.nu for assistance!" if $printed == 0;
648  print_diff $package_root,$kernel_root,$kernel_file,$package_file;
649}
650 
651
652# This generates diffs for drivers/char/mem.c They are a bit intricate.
653# Lines are generated at the beginning to declare i2c_init and i2c_init_all.
654# The first is the invocation for the old I2C driver, the second for the
655# new driver. At the bottom, a call to i2c_init_all is added when the
656# new I2C stuff is configured in.
657# Of course, care is taken old lines are removed.
658# $_[0]: i2c package root (like /tmp/i2c)
659# $_[1]: Linux kernel tree (like /usr/src/linux)
660sub gen_drivers_char_mem_c
661{
662  my ($package_root,$kernel_root) = @_;
663  my $kernel_file = "drivers/char/mem.c";
664  my $package_file = $temp;
665  my $right_place = 0;
666  my $done = 0;
667  my $atstart = 1;
668  my $pr1 = 0;
669  my $pr2 = 0;
670
671  open INPUT,"$kernel_root/$kernel_file"
672        or die "Can't open `$kernel_root/$kernel_file'";
673  open OUTPUT,">$package_root/$package_file"
674        or die "Can't open $package_root/$package_file";
675  MAIN: while(<INPUT>) {
676    if (m@#include <linux/i2c.h>@) {
677       $_=<INPUT>;
678       redo MAIN;
679    }
680    if ($atstart and m@#ifdef@) {
681      print OUTPUT << 'EOF';
682#ifdef CONFIG_I2C
683extern int i2c_init_all(void);
684#endif
685EOF
686      $atstart = 0;
687      $pr1 = 1;
688    }
689    while (not $right_place and (m@CONFIG_I2C@ or m@CONFIG_VIDEO_BT848@)) {
690      $_ = <INPUT> while not m@#endif@;
691      $_ = <INPUT>;
692      redo MAIN;
693    }
694    $right_place = 1 if (m@chr_dev_init@);
695    if ($right_place and m@CONFIG_I2C@) {
696      $_ = <INPUT> while not m@#endif@;
697      $_ = <INPUT>;
698      $_ = <INPUT> if m@^$@;
699      redo MAIN;
700    }
701    if ($right_place and not $done and
702        (m@CONFIG_VIDEO_BT848@ or m@return 0;@ or m@CONFIG_SENSORS@ or
703         m@CONFIG_FB@)) {
704      print OUTPUT <<'EOF';
705#ifdef CONFIG_I2C
706        i2c_init_all();
707#endif
708EOF
709      $done = 1;
710      $pr2 = 1;
711    }
712    print OUTPUT;
713  }
714  close INPUT;
715  close OUTPUT;
716  die "Automatic patch generation for `drivers/char/mem.c' failed.\n".
717      "See our home page http://www.lm-sensors.nu for assistance!" if $pr1 == 0 or $pr2 == 0;
718  print_diff $package_root,$kernel_root,$kernel_file,$package_file;
719}
720 
721# Generate the diffs for the list of MAINTAINERS
722# $_[0]: i2c package root (like /tmp/i2c)
723# $_[1]: Linux kernel tree (like /usr/src/linux)
724sub gen_MAINTAINERS
725{
726  my ($package_root,$kernel_root) = @_;
727  my $kernel_file = "MAINTAINERS";
728  my $package_file = $temp;
729  my $done = 0;
730
731  open INPUT,"$kernel_root/$kernel_file"
732        or die "Can't open `$kernel_root/$kernel_file'";
733  open OUTPUT,">$package_root/$package_file"
734        or die "Can't open $package_root/$package_file";
735  MAIN: while(<INPUT>) {
736    if (m@I2C DRIVERS@) {
737       $_=<INPUT> while not m@^$@;
738       $_=<INPUT>;
739       redo MAIN;
740    }
741    if (not $done and (m@i386 BOOT CODE@ or m@IBM MCA SCSI SUBSYSTEM DRIVER@)) {
742      print OUTPUT <<'EOF';
743I2C DRIVERS
744P:      Simon Vogl
745M:      simon@tk.uni-linz.ac.at
746P:      Frodo Looijaard
747M:      frodol@dds.nl
748L:      linux-i2c@pelican.tk.uni-linz.ac.at
749W:      http://www.tk.uni-linz.ac.at/~simon/private/i2c
750S:      Maintained
751
752EOF
753      $done = 1;
754    }
755    print OUTPUT;
756  }
757  close INPUT;
758  close OUTPUT;
759  die "Automatic patch generation for `MAINTAINERS' failed.\n".
760      "See our home page http://www.lm-sensors.nu for assistance!" if $done == 0;
761  print_diff $package_root,$kernel_root,$kernel_file,$package_file;
762}
763
764# Main function
765sub main
766{
767  my ($package_root,$kernel_root,%files,%includes,$package_file,$kernel_file);
768  my ($diff_command,$dummy,$data0,$data1,$sedscript,@sensors_subs);
769
770  # --> Read the command-line
771  $package_root = $ARGV[0];
772  die "Package root `$package_root' is not found\n" 
773        unless -d "$package_root/mkpatch";
774  $kernel_root = $ARGV[1];
775  die "Kernel root `$kernel_root' is not found\n" 
776        unless -f "$kernel_root/Rules.make";
777
778  patch_old_i2c $package_root, $kernel_root;
779         
780
781  # --> Read FILES
782  open INPUT, "$package_root/mkpatch/FILES" 
783        or die "Can't open `$package_root/mkpatch/FILES'";
784  while (<INPUT>) {
785    ($data0,$data1) = /(\S+)\s+(\S+)/;
786    $files{$data0} = $data1;
787  } 
788  close INPUT;
789
790  # --> Read INCLUDES
791  open INPUT, "$package_root/mkpatch/INCLUDES" 
792        or die "Can't open `$package_root/mkpatch/INCLUDES'";
793  while (<INPUT>) {
794    ($data0,$data1) = /(\S+)\s+(\S+)/;
795    $includes{$data0} = $data1;
796    $sedscript .= 's,(#\s*include\s*)'.$data0.'(\s*),\1'."$data1".'\2, ; ';
797  } 
798  close INPUT;
799
800  # --> Start generating
801  foreach $package_file (sort keys %files) {
802    $kernel_file = $files{$package_file};
803    @sensors_subs = find_sensors_code "$kernel_root","$kernel_file";
804    open INPUT, "$package_root/$package_file"
805         or die "Can't open `$package_root/$package_file'";
806    open OUTPUT, ">$package_root/$temp"
807         or die "Can't open `$package_root/$temp'";
808    while (<INPUT>) {
809      eval $sedscript;
810      if (m@sensors code starts here@) {
811        print OUTPUT;
812        while (<INPUT>) {
813           last if m@sensors code ends here@;
814        }
815        print OUTPUT $sensors_subs[0];
816        shift @sensors_subs
817      }
818      print OUTPUT;
819    }
820    close INPUT;
821    close OUTPUT;
822    print_diff "$package_root","$kernel_root","$kernel_file","$temp";
823  }
824
825  gen_Makefile $package_root, $kernel_root;
826  gen_drivers_Makefile $package_root, $kernel_root;
827  gen_drivers_i2c_Makefile $package_root, $kernel_root;
828  gen_drivers_char_Config_in $package_root, $kernel_root;
829  gen_drivers_char_mem_c $package_root, $kernel_root;
830  gen_Documentation_Configure_help $package_root, $kernel_root;
831  gen_MAINTAINERS $package_root, $kernel_root;
832}
833
834main;
835
Note: See TracBrowser for help on using the browser.