root/lm-sensors/trunk/mkpatch/mkpatch.pl @ 1099

Revision 1099, 35.3 KB (checked in by frodo, 14 years ago)

Fix to make mkpatch work with 2.4.5 kernels

The base Makefile changed again. Sigh.

  • 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# Generate a diff between the old kernel file and the new lm_sensors file. We
26# arrange the headers to tell us the old tree was under directory
27# `linux-old', and the new tree under `linux'.
28# $_[0]: sensors package root (like /tmp/sensors)
29# $_[1]: Linux kernel tree (like /usr/src/linux)
30# $_[2]: Name of the kernel file
31# $_[3]: Name of the patched file
32sub print_diff
33{
34  my ($package_root,$kernel_root,$kernel_file,$package_file) = @_;
35  my ($diff_command,$dummy);
36
37  $diff_command = "diff -u2";
38  if ( -e "$kernel_root/$kernel_file") {
39    $diff_command .= " $kernel_root/$kernel_file ";
40  } else {
41    $diff_command .= " /dev/null ";
42  }
43  if ( -e "$package_root/$package_file") {
44    $diff_command .= " $package_root/$package_file ";
45  } else {
46    $diff_command .= " /dev/null";
47  }
48  open INPUT, "$diff_command|" or die "Can't execute `$diff_command'";
49  $dummy = <INPUT>;
50  $dummy = <INPUT>;
51  print "--- linux-old/$kernel_file\t".`date`;
52  print "+++ linux/$kernel_file\t".`date`;
53   
54  while (<INPUT>) {
55    print;
56  }
57  close INPUT;
58}
59
60# This generates diffs for kernel file Documentation/Configure.help. This
61# file contains the help texts that can be displayed during `make *config'
62# for the kernel.
63# The new texts are put at the end of the file, or just before the
64# lm_sensors texts.
65# Of course, care is taken old lines are removed.
66# $_[0]: i2c package root (like /tmp/i2c)
67# $_[1]: Linux kernel tree (like /usr/src/linux)
68sub gen_Documentation_Configure_help
69{
70  my ($package_root,$kernel_root) = @_;
71  my $kernel_file = "Documentation/Configure.help";
72  my $package_file = $temp;
73
74  open INPUT,"$kernel_root/$kernel_file"
75        or die "Can't open `$kernel_root/$kernel_file'";
76  open OUTPUT,">$package_root/$package_file"
77        or die "Can't open $package_root/$package_file";
78  MAIN: while(<INPUT>) {
79    if (m@I2C mainboard interfaces@ or 
80           m@Acer Labs ALI 1533 and 1543C@ or
81           m@Apple Hydra Mac I/O@ or
82           m@Intel 82371AB PIIX4\(E\)@ or
83           m@VIA Technologies, Inc. VT82C586B@ or
84           m@Pseudo ISA adapter \(for hardware sensors modules\)@ or
85           m@Analog Devices ADM1021 and compatibles@ or
86           m@Analog Devices ADM9240 and compatibles@ or
87           m@Genesys Logic GL518SM@ or
88           m@National Semiconductors LM75@ or
89           m@National Semiconductors LM78@ or
90           m@National Semiconductors LM80@ or
91           m@Silicon Integrated Systems Corp. SiS5595@ or
92           m@Winbond W83781D, W83782D and W83783S@ or
93           m@EEprom \(DIMM\) reader@) {
94      $_ = <INPUT>;
95      $_ = <INPUT>;
96      $_ = <INPUT> while not m@^\S@ and not eof(INPUT);
97      redo MAIN;
98    }
99    if (eof(INPUT)) {
100      print OUTPUT <<'EOF'
101I2C mainboard interfaces
102CONFIG_I2C_MAINBOARD
103  Many modern mainboards have some kind of I2C interface integrated. This
104  is often in the form of a SMBus, or System Management Bus, which is
105  basically the same as I2C but which uses only a subset of the I2C
106  protocol.
107
108  You will also want the latest user-space utilties: you can find them
109  in the lm_sensors package, which you can download at
110  http://www.lm-sensors.nu
111
112Acer Labs ALI 1533 and 1543C
113CONFIG_I2C_ALI15X3
114  If you say yes to this option, support will be included for the Acer
115  Labs ALI 1533 and 1543C mainboard I2C interfaces. This can also be
116  built as a module which can be inserted and removed while the kernel
117  is running.
118
119AMD 756
120CONFIG_I2C_AMD756
121  If you say yes to this option, support will be included for the AMD
122  756 mainboard I2C interfaces. This can also be
123  built as a module which can be inserted and removed while the kernel
124  is running.
125
126Apple Hydra Mac I/O
127CONFIG_I2C_HYDRA
128  If you say yes to this option, support will be included for the
129  Hydra mainboard I2C interface. This can also be built as a module
130  which can be inserted and removed while the kernel is running.
131
132Intel I801
133CONFIG_I2C_I801
134  If you say yes to this option, support will be included for the
135  Intel I801 mainboard I2C interfaces. "I810" mainboard sensor chips are
136  generally located on the I801's I2C bus. This can also be
137  built as a module which can be inserted and removed while the kernel
138  is running.
139
140Intel I810
141CONFIG_I2C_I810
142  If you say yes to this option, support will be included for the
143  Intel I810 mainboard I2C interfaces. The I2C busses on the I810
144  are generally used only for video devices. For "810" mainboard sensor
145  chips, use the I801 I2C driver instead. This can also be
146  built as a module which can be inserted and removed while the kernel
147  is running.
148
149Intel 82371AB PIIX4(E) / ServerWorks OSB4
150CONFIG_I2C_PIIX4
151  If you say yes to this option, support will be included for the
152  Intel PIIX4 and PIIX4E and Serverworks OSB4 mainboard
153  I2C interfaces. This can also be
154  built as a module which can be inserted and removed while the kernel
155  is running.
156
157Silicon Integrated Systems Corp. SiS5595
158CONFIG_I2C_SIS5595
159  If you say yes to this option, support will be included for the
160  SiS5595 mainboard I2C interfaces. For integrated sensors on the
161  Sis5595, use CONFIG_SENSORS_SIS5595. This can also be
162  built as a module which can be inserted and removed while the kernel
163  is running.
164
165VIA Technologies, Inc. VT82C586B
166CONFIG_I2C_VIA
167  If you say yes to this option, support will be included for the VIA
168  Technologies I2C adapter found on some motherboards. This can also
169  be built as a module which can be inserted and removed while the
170  kernel is running.
171
172VIA Technologies, Inc. VT82C596, 596B, 686A/B
173CONFIG_I2C_VIAPRO
174  If you say yes to this option, support will be included for the VIA
175  Technologies I2C adapter on these chips. For integrated sensors on the
176  Via 686A/B, use CONFIG_SENSORS_VIA686A. This can also be
177  be built as a module which can be inserted and removed while the
178  kernel is running.
179
1803DFX Banshee / Voodoo3
181CONFIG_I2C_VOODOO3
182  If you say yes to this option, support will be included for the
183  3DFX Banshee and Voodoo3 I2C interfaces. The I2C busses on the these
184  chips are generally used only for video devices.
185  This can also be
186  built as a module which can be inserted and removed while the kernel
187  is running.
188
189Pseudo ISA adapter (for hardware sensors modules)
190CONFIG_I2C_ISA
191  This provides support for accessing some hardware sensor chips over
192  the ISA bus rather than the I2C or SMBus. If you want to do this,
193  say yes here. This feature can also be built as a module which can
194  be inserted and removed while the kernel is running.
195
196  You will also need the latest user-space utilties: you can find them
197  in the lm_sensors package, which you can download at
198  http://www.lm-sensors.nu
199
200Analog Devices ADM1021 and compatibles
201CONFIG_SENSORS_ADM1021
202  If you say yes here you get support for Analog Devices ADM1021
203  and ADM1023 sensor chips and clones: Maxim MAX1617 and MAX1617A,
204  Genesys Logic GL523SM, National Semi LM84, TI THMC10,
205  and the XEON processor built-in sensor. This can also
206  be built as a module which can be inserted and removed while the
207  kernel is running.
208
209  You will also need the latest user-space utilties: you can find them
210  in the lm_sensors package, which you can download at
211  http://www.lm-sensors.nu
212
213Analog Devices ADM1025
214CONFIG_SENSORS_ADM1025
215  If you say yes here you get support for Analog Devices ADM1025 sensor
216  chips.  This can also be built as a module which can be inserted and
217  removed while the kernel is running.
218
219  You will also need the latest user-space utilties: you can find them
220  in the lm_sensors package, which you can download at
221  http://www.lm-sensors.nu
222
223Analog Devices ADM9240 and compatibles
224CONFIG_SENSORS_ADM9240
225  If you say yes here you get support for Analog Devices ADM9240
226  sensor chips and clones: the Dallas Semiconductor DS1780 and
227  the National Semiconductor LM81. This can also be built as a
228  module which can be inserted and removed while the kernel is
229  running.
230
231  You will also need the latest user-space utilties: you can find them
232  in the lm_sensors package, which you can download at
233  http://www.lm-sensors.nu
234
235Genesys Logic GL518SM
236CONFIG_SENSORS_GL518SM
237  If you say yes here you get support for Genesys Logic GL518SM sensor
238  chips.  This can also be built as a module which can be inserted and
239  removed while the kernel is running.
240
241  You will also need the latest user-space utilties: you can find them
242  in the lm_sensors package, which you can download at
243  http://www.lm-sensors.nu
244
245Genesys Logic GL520SM
246CONFIG_SENSORS_GL520SM
247  If you say yes here you get support for Genesys Logic GL518SM sensor
248  chips.  This can also be built as a module which can be inserted and
249  removed while the kernel is running.
250
251  You will also need the latest user-space utilties: you can find them
252  in the lm_sensors package, which you can download at
253  http://www.lm-sensors.nu
254
255National Semiconductor LM75 and compatibles
256CONFIG_SENSORS_LM75
257  If you say yes here you get support for National Semiconductor LM75
258  sensor chips and clones: Dallas Semi DS75 and DS1775, TelCon
259  TCN75, and National Semi LM77. This can also be built as a module which
260  can be inserted and removed while the kernel is running.
261
262  You will also need the latest user-space utilties: you can find them
263  in the lm_sensors package, which you can download at
264  http://www.lm-sensors.nu
265
266National Semiconductor LM78
267CONFIG_SENSORS_LM78
268  If you say yes here you get support for National Semiconductor LM78
269  sensor chips family: the LM78-J and LM79. Many clone chips will
270  also work at least somewhat with this driver. This can also be built
271  as a module which can be inserted and removed while the kernel is
272  running.
273
274  You will also need the latest user-space utilties: you can find them
275  in the lm_sensors package, which you can download at
276  http://www.lm-sensors.nu
277
278National Semiconductor LM80
279CONFIG_SENSORS_LM80
280  If you say yes here you get support for National Semiconductor LM80
281  sensor chips. This can also be built as a module which can be
282  inserted and removed while the kernel is running.
283
284  You will also need the latest user-space utilties: you can find them
285  in the lm_sensors package, which you can download at
286  http://www.lm-sensors.nu
287
288National Semiconductor LM87
289CONFIG_SENSORS_LM87
290  If you say yes here you get support for National Semiconductor LM87
291  sensor chips. This can also be built as a module which can be
292  inserted and removed while the kernel is running.
293
294  You will also need the latest user-space utilties: you can find them
295  in the lm_sensors package, which you can download at
296  http://www.lm-sensors.nu
297
298Silicon Integrated Systems Corp. SiS5595
299CONFIG_SENSORS_SIS5595
300  If you say yes here you get support for the integrated sensors in
301  SiS5595 South Bridges. This can also be built as a module
302  which can be inserted and removed while the kernel is running.
303
304  You will also need the latest user-space utilties: you can find them
305  in the lm_sensors package, which you can download at
306  http://www.lm-sensors.nu
307
308Texas Instruments THMC50 / Analog Devices ADM1022
309CONFIG_SENSORS_THMC50
310  If you say yes here you get support for Texas Instruments THMC50
311  sensor chips and clones: the Analog Devices ADM1022.
312  This can also be built as a module which
313  can be inserted and removed while the kernel is running.
314
315  You will also need the latest user-space utilties: you can find them
316  in the lm_sensors package, which you can download at
317  http://www.lm-sensors.nu
318
319Via VT82C686A/B
320CONFIG_SENSORS_VIA686A
321  If you say yes here you get support for the integrated sensors in
322  Via 686A/B South Bridges. This can also be built as a module
323  which can be inserted and removed while the kernel is running.
324
325  You will also need the latest user-space utilties: you can find them
326  in the lm_sensors package, which you can download at
327  http://www.lm-sensors.nu
328
329Winbond W83781D, W83782D, W83783S, W83627HF, AS99127F
330CONFIG_SENSORS_W83781D
331  If you say yes here you get support for the Winbond W8378x series
332  of sensor chips: the W83781D, W83782D, W83783S and W83682HF,
333  and the similar Asus AS99127F. This
334  can also be built as a module which can be inserted and removed
335  while the kernel is running.
336
337  You will also need the latest user-space utilties: you can find them
338  in the lm_sensors package, which you can download at
339  http://www.lm-sensors.nu
340
341EEprom (DIMM) reader
342CONFIG_SENSORS_EEPROM
343  If you say yes here you get read-only access to the EEPROM data
344  available on modern memory DIMMs, and which could theoretically
345  also be available on other devices. This can also be built as a
346  module which can be inserted and removed while the kernel is
347  running.
348
349  You will also need the latest user-space utilties: you can find them
350  in the lm_sensors package, which you can download at
351  http://www.lm-sensors.nu
352
353EOF
354    }
355    print OUTPUT;
356  }
357  close INPUT;
358  close OUTPUT;
359  print_diff $package_root,$kernel_root,$kernel_file,$package_file;
360}
361
362
363# This generates diffs for the main Linux Makefile.
364# Three lines which add drivers/sensors/sensors.a to the DRIVERS list are
365# put just before the place where the architecture Makefile is included.
366# Of course, care is taken old lines are removed.
367# $_[0]: sensors package root (like /tmp/sensors)
368# $_[1]: Linux kernel tree (like /usr/src/linux)
369sub gen_Makefile
370{
371  my ($package_root,$kernel_root) = @_;
372  my $kernel_file = "Makefile";
373  my $package_file = $temp;
374  my $type = 0;
375  my $pr1 = 0;
376
377  open INPUT,"$kernel_root/$kernel_file"
378        or die "Can't open `$kernel_root/$kernel_file'";
379  open OUTPUT,">$package_root/$package_file"
380        or die "Can't open $package_root/$package_file";
381  `grep -q -s 'i2c\.o' "$kernel_root/$kernel_file"`;
382  $type = 2 if ! $?;
383  MAIN: while(<INPUT>) {
384    $type = 1 if !$type and (m@^DRIVERS-\$@);
385    if (m@DRIVERS-\$\(CONFIG_SENSORS\)@) {
386      $_ = <INPUT>;
387      redo MAIN;
388    } elsif (m@CONFIG_SENSORS@) {
389      $_ = <INPUT> while not m@endif@;
390      $_ = <INPUT>;
391      $_ = <INPUT> if m@^$@;
392      redo MAIN;
393    }
394    if ($type == 1 and m@^DRIVERS \+= \$\(DRIVERS-y\)@) {
395      print OUTPUT <<'EOF';
396DRIVERS-$(CONFIG_SENSORS) += drivers/sensors/sensors.a
397EOF
398      $pr1 = 1;
399    }
400    if ($type == 2 and m@^DRIVERS .*= \$\(DRIVERS-y\)@) {
401      print OUTPUT <<'EOF';
402DRIVERS-$(CONFIG_SENSORS) += drivers/sensors/sensor.o
403EOF
404      $pr1 = 1;
405    }
406    if ($type == 0 and m@include arch/\$\(ARCH\)/Makefile@) {
407      print OUTPUT <<'EOF';
408ifeq ($(CONFIG_SENSORS),y)
409DRIVERS := $(DRIVERS) drivers/sensors/sensors.a
410endif
411
412EOF
413      $pr1 = 1;
414    }
415    print OUTPUT;
416  }
417  close INPUT;
418  close OUTPUT;
419  die "Automatic patch generation for `Makefile' failed.\n".
420      "Contact the authors please!" if $pr1 == 0;
421  print_diff $package_root,$kernel_root,$kernel_file,$package_file;
422}
423
424# This generates diffs for drivers/Makefile
425# First, `sensors' is added to the ALL_SUB_DIRS list. Next, a couple of lines
426# to add sensors to the SUB_DIRS and/or MOD_SUB_DIRS lists is put right before
427# Rules.make is included.
428# Of course, care is taken old lines are removed.
429# $_[0]: sensors package root (like /tmp/sensors)
430# $_[1]: Linux kernel tree (like /usr/src/linux)
431sub gen_drivers_Makefile
432{
433  my ($package_root,$kernel_root) = @_;
434  my $kernel_file = "drivers/Makefile";
435  my $package_file = $temp;
436  my $sensors_present;
437  my $pr1 = 0;
438  my $pr2 = 0;
439  my $new_style = 0;
440
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  MAIN: while(<INPUT>) {
446    if (m@^mod-subdirs\s*:=@) {
447      $new_style = 1;
448    }
449    if ((! $new_style and m@^ALL_SUB_DIRS\s*:=@) or m@^mod-subdirs\s*:=@) {
450      $pr1 = 1;
451      $sensors_present = 0;
452      while (m@\\$@) {
453        $sensors_present = 1 if m@sensors@;
454        print OUTPUT;
455        $_ = <INPUT>;
456      }
457      $sensors_present = 1 if m@sensors@;
458      s@$@ sensors@ if (not $sensors_present);
459      print OUTPUT;
460      $_ = <INPUT>;
461      redo MAIN;
462    } 
463    if (m@^ifeq.*CONFIG_SENSORS@) {
464      $_ = <INPUT> while not m@^endif@;
465      $_ = <INPUT>;
466      $_ = <INPUT> if m@^$@;
467      redo MAIN;
468    } 
469    if (m@^subdir.*CONFIG_SENSORS@) {
470      $_ = <INPUT>;
471      redo MAIN;
472    }
473    if (!$pr2 and (m@^include \$\(TOPDIR\)/Rules.make$@ or m@^subdir-\$\(CONFIG_ACPI@)) {
474      $pr2 = 1;
475      if ($new_style) {
476      print OUTPUT <<'EOF';
477subdir-$(CONFIG_SENSORS)        += sensors
478EOF
479      } else {
480      print OUTPUT <<'EOF';
481ifeq ($(CONFIG_SENSORS),y)
482SUB_DIRS += sensors
483MOD_SUB_DIRS += sensors
484else
485  ifeq ($(CONFIG_SENSORS),m)
486  MOD_SUB_DIRS += sensors
487  endif
488endif
489
490EOF
491      }
492    }
493    print OUTPUT;
494  }
495  close INPUT;
496  close OUTPUT;
497  die "Automatic patch generation for `drivers/Makefile' failed.\n".
498      "Contact the authors please!" if $pr1 == 0 or $pr2 == 0;
499  print_diff $package_root,$kernel_root,$kernel_file,$package_file;
500}
501
502# This generates diffs for drivers/char/Config.in
503# It adds a line just before CONFIG_APM or main_menu_option lines to include
504# the sensors Config.in.
505# Of course, care is taken old lines are removed.
506# $_[0]: sensors package root (like /tmp/sensors)
507# $_[1]: Linux kernel tree (like /usr/src/linux)
508sub gen_drivers_char_Config_in
509{
510  my ($package_root,$kernel_root) = @_;
511  my $kernel_file = "drivers/char/Config.in";
512  my $package_file = $temp;
513  my $pr1 = 0;
514
515  open INPUT,"$kernel_root/$kernel_file"
516        or die "Can't open `$kernel_root/$kernel_file'";
517  open OUTPUT,">$package_root/$package_file"
518        or die "Can't open $package_root/$package_file";
519  MAIN: while(<INPUT>) {
520    if (m@source drivers/i2c/Config.in@) {
521      $pr1 = 1;
522      print OUTPUT;
523      print OUTPUT "\nsource drivers/sensors/Config.in\n";
524      $_ = <INPUT>;
525      redo MAIN;
526    }
527    if (m@sensors@) {
528      $_ = <INPUT>;
529      $_ = <INPUT> if m@^$@;
530      redo MAIN;
531    }
532    print OUTPUT;
533  }
534  close INPUT;
535  close OUTPUT;
536  die "Automatic patch generation for `drivers/Makefile' failed.\n".
537      "Contact the authors please!" if $pr1 == 0;
538  print_diff $package_root,$kernel_root,$kernel_file,$package_file;
539}
540 
541
542# This generates diffs for drivers/char/mem.c They are a bit intricate.
543# Lines are generated at the beginning to declare sensors_init_all
544# At the bottom, a call to sensors_init_all is added when the
545# new lm_sensors stuff is configured in.
546# Of course, care is taken old lines are removed.
547# $_[0]: sensors package root (like /tmp/sensors)
548# $_[1]: Linux kernel tree (like /usr/src/linux)
549sub gen_drivers_char_mem_c
550{
551  my ($package_root,$kernel_root) = @_;
552  my $kernel_file = "drivers/char/mem.c";
553  my $package_file = $temp;
554  my $right_place = 0;
555  my $done = 0;
556  my $atstart = 1;
557  my $pr1 = 0;
558  my $pr2 = 0;
559
560  open INPUT,"$kernel_root/$kernel_file"
561        or die "Can't open `$kernel_root/$kernel_file'";
562  open OUTPUT,">$package_root/$package_file"
563        or die "Can't open $package_root/$package_file";
564  MAIN: while(<INPUT>) {
565    if ($atstart and m@#ifdef@) {
566      $pr1 = 1;
567      print OUTPUT << 'EOF';
568#ifdef CONFIG_SENSORS
569extern void sensors_init_all(void);
570#endif
571EOF
572      $atstart = 0;
573    }
574    if (not $right_place and m@CONFIG_SENSORS@) {
575      $_ = <INPUT> while not m@#endif@;
576      $_ = <INPUT>;
577      redo MAIN;
578    }
579    $right_place = 1 if (m@lp_init\(\);@);
580    if ($right_place and not $done and
581        m@CONFIG_SENSORS@) {
582      $_ = <INPUT> while not m@#endif@;
583      $_ = <INPUT>;
584      $_ = <INPUT> if m@^$@;
585      redo MAIN;
586    }
587    if ($right_place and not $done and m@return 0;@) {
588      $pr2 = 1;
589      print OUTPUT <<'EOF';
590#ifdef CONFIG_SENSORS
591        sensors_init_all();
592#endif
593
594EOF
595      $done = 1;
596    }
597    print OUTPUT;
598  }
599  close INPUT;
600  close OUTPUT;
601  die "Automatic patch generation for `drivers/char/mem.c' failed.\n".
602      "Contact the authors please!" if $pr1 == 0 or $pr2 == 0;
603  print_diff $package_root,$kernel_root,$kernel_file,$package_file;
604}
605
606
607# This generates diffs for drivers/i2c/Config.in
608# Several adapter drivers that are included in the lm_sensors package are
609# added at the first and onlu sensors marker.
610# Of course, care is taken old lines are removed.
611# $_[0]: sensors package root (like /tmp/sensors)
612# $_[1]: Linux kernel tree (like /usr/src/linux)
613sub gen_drivers_i2c_Config_in
614{
615  my ($package_root,$kernel_root) = @_;
616  my $kernel_file = "drivers/i2c/Config.in";
617  my $package_file = "$temp";
618  my $pr1 = 0;
619
620  open INPUT,"$kernel_root/$kernel_file"
621        or die "Can't open `$kernel_root/$kernel_file'";
622  open OUTPUT,">$package_root/$package_file"
623        or die "Can't open $package_root/$package_file";
624  while(<INPUT>) {
625    if (m@sensors code starts here@) {
626      $pr1++;
627      print OUTPUT;
628      while (<INPUT>) {
629        last if m@sensors code ends here@;
630      }
631      print OUTPUT << 'EOF';
632  bool 'I2C mainboard interfaces' CONFIG_I2C_MAINBOARD
633  if [ "$CONFIG_I2C_MAINBOARD" = "y" ]; then
634    tristate '  Acer Labs ALI 1533 and 1543C' CONFIG_I2C_ALI15X3
635    dep_tristate '  Apple Hydra Mac I/O' CONFIG_I2C_HYDRA $CONFIG_I2C_ALGOBIT
636    tristate '  AMD 756' CONFIG_I2C_AMD756
637    tristate '  Intel 82801AA, 82801AB and 82801BA' CONFIG_I2C_I801
638    tristate '  Intel i810AA, i810AB and i815' CONFIG_I2C_I810
639    tristate '  Intel 82371AB PIIX4(E)' CONFIG_I2C_PIIX4
640    tristate '  SiS 5595' CONFIG_I2C_SIS5595
641    dep_tristate '  VIA Technologies, Inc. VT82C586B' CONFIG_I2C_VIA $CONFIG_I2C_ALGOBIT
642    tristate '  VIA Technologies, Inc. VT596A/B' CONFIG_I2C_VIAPRO
643    dep_tristate '  Voodoo3 I2C interface' CONFIG_I2C_VOODOO $CONFIG_I2C_ALGOBIT
644    tristate '  Pseudo ISA adapter (for hardware sensors modules)' CONFIG_I2C_ISA
645  fi
646
647EOF
648    }
649    print OUTPUT;
650  }
651  close INPUT;
652  close OUTPUT;
653  die "Automatic patch generation for `drivers/i2c/Config.in' failed.\n".
654      "Contact the authors please!" if $pr1 != 1;
655  print_diff $package_root,$kernel_root,$kernel_file,$package_file;
656}
657
658sub gen_drivers_sensors_Makefile
659{
660  my ($package_root,$kernel_root) = @_;
661  my $kernel_file = "drivers/sensors/Makefile";
662  my $package_file = $temp;
663  my $use_new_format;
664  `grep -q -s 'i2c\.o' "$kernel_root/drivers/i2c/Makefile"`;
665  $use_new_format = ! $?;
666
667  open OUTPUT,">$package_root/$package_file"
668        or die "Can't open $package_root/$package_file";
669  if ($use_new_format) {
670    print OUTPUT <<'EOF';
671#
672# Makefile for the kernel hardware sensors drivers.
673#
674
675MOD_LIST_NAME := SENSORS_MODULES
676O_TARGET := sensor.o
677
678export-objs     := sensors.o
679
680obj-$(CONFIG_SENSORS)           += sensors.o
681obj-$(CONFIG_SENSORS_ADM1021)   += adm1021.o
682obj-$(CONFIG_SENSORS_ADM1025)   += adm1025.o
683obj-$(CONFIG_SENSORS_ADM9240)   += adm9240.o
684obj-$(CONFIG_SENSORS_BT869)     += bt869.o
685obj-$(CONFIG_SENSORS_DDCMON)    += ddcmon.o
686obj-$(CONFIG_SENSORS_EEPROM)    += eeprom.o
687obj-$(CONFIG_SENSORS_GL518SM)   += gl518sm.o
688obj-$(CONFIG_SENSORS_GL520SM)   += gl520sm.o
689obj-$(CONFIG_SENSORS_LM75)      += lm75.o
690obj-$(CONFIG_SENSORS_LM78)      += lm78.o
691obj-$(CONFIG_SENSORS_LM80)      += lm80.o
692obj-$(CONFIG_SENSORS_LM87)      += lm87.o
693obj-$(CONFIG_SENSORS_SIS5595)   += sis5595.o
694obj-$(CONFIG_SENSORS_THMC50)    += thmc50.o
695obj-$(CONFIG_SENSORS_VIA686A)   += via686a.o
696obj-$(CONFIG_SENSORS_W83781D)   += w83781d.o
697
698include $(TOPDIR)/Rules.make
699
700EOF
701  } else {
702    print OUTPUT <<'EOF';
703#
704# Makefile for the kernel hardware sensors drivers.
705#
706
707SUB_DIRS     :=
708MOD_SUB_DIRS := $(SUB_DIRS)
709ALL_SUB_DIRS := $(SUB_DIRS)
710MOD_LIST_NAME := SENSORS_MODULES
711
712L_TARGET := sensors.a
713MX_OBJS := 
714M_OBJS  :=
715LX_OBJS :=
716L_OBJS  :=
717
718# -----
719# i2c core components
720# -----
721
722ifeq ($(CONFIG_SENSORS),y)
723  LX_OBJS += sensors.o
724else
725  ifeq ($(CONFIG_SENSORS),m)
726    MX_OBJS += sensors.o
727  endif
728endif
729
730ifeq ($(CONFIG_SENSORS_ADM1021),y)
731  L_OBJS += adm1021.o
732else
733  ifeq ($(CONFIG_SENSORS_ADM1021),m)
734    M_OBJS += adm1021.o
735  endif
736endif
737
738ifeq ($(CONFIG_SENSORS_ADM1025),y)
739  L_OBJS += adm1025.o
740else
741  ifeq ($(CONFIG_SENSORS_ADM1025),m)
742    M_OBJS += adm1025.o
743  endif
744endif
745
746ifeq ($(CONFIG_SENSORS_ADM9240),y)
747  L_OBJS += adm9240.o
748else
749  ifeq ($(CONFIG_SENSORS_ADM9240),m)
750    M_OBJS += adm9240.o
751  endif
752endif
753
754ifeq ($(CONFIG_SENSORS_DDCMON),y)
755  L_OBJS += ddcmon.o
756else
757  ifeq ($(CONFIG_SENSORS_DDCMON),m)
758    M_OBJS += ddcmon.o
759  endif
760endif
761
762ifeq ($(CONFIG_SENSORS_EEPROM),y)
763  L_OBJS += eeprom.o
764else
765  ifeq ($(CONFIG_SENSORS_EEPROM),m)
766    M_OBJS += eeprom.o
767  endif
768endif
769
770ifeq ($(CONFIG_SENSORS_GL518SM),y)
771  L_OBJS += gl518sm.o
772else
773  ifeq ($(CONFIG_SENSORS_GL518SM),m)
774    M_OBJS += gl518sm.o
775  endif
776endif
777
778ifeq ($(CONFIG_SENSORS_GL520SM),y)
779  L_OBJS += gl520sm.o
780else
781  ifeq ($(CONFIG_SENSORS_GL520SM),m)
782    M_OBJS += gl520sm.o
783  endif
784endif
785
786ifeq ($(CONFIG_SENSORS_LM75),y)
787  L_OBJS += lm75.o
788else
789  ifeq ($(CONFIG_SENSORS_LM75),m)
790    M_OBJS += lm75.o
791  endif
792endif
793
794ifeq ($(CONFIG_SENSORS_LM78),y)
795  L_OBJS += lm78.o
796else
797  ifeq ($(CONFIG_SENSORS_LM78),m)
798    M_OBJS += lm78.o
799  endif
800endif
801
802ifeq ($(CONFIG_SENSORS_LM80),y)
803  L_OBJS += lm80.o
804else
805  ifeq ($(CONFIG_SENSORS_LM80),m)
806    M_OBJS += lm80.o
807  endif
808endif
809
810ifeq ($(CONFIG_SENSORS_LM87),y)
811  L_OBJS += lm87.o
812else
813  ifeq ($(CONFIG_SENSORS_LM87),m)
814    M_OBJS += lm87.o
815  endif
816endif
817
818ifeq ($(CONFIG_SENSORS_MATORB),y)
819  L_OBJS += matorb.o
820else
821  ifeq ($(CONFIG_SENSORS_MATORB),m)
822    M_OBJS += matorb.o
823  endif
824endif
825
826ifeq ($(CONFIG_SENSORS_SIS5595),y)
827  L_OBJS += sis5595.o
828else
829  ifeq ($(CONFIG_SENSORS_SIS5595),m)
830    M_OBJS += sis5595.o
831  endif
832endif
833
834ifeq ($(CONFIG_SENSORS_THMC50),y)
835  L_OBJS += thmc50.o
836else
837  ifeq ($(CONFIG_SENSORS_THMC50),m)
838    M_OBJS += thmc50.o
839  endif
840endif
841
842ifeq ($(CONFIG_SENSORS_VIA686A),y)
843  L_OBJS += via686a.o
844else
845  ifeq ($(CONFIG_SENSORS_VIA686A),m)
846    M_OBJS += via686a.o
847  endif
848endif
849
850ifeq ($(CONFIG_SENSORS_W83781D),y)
851  L_OBJS += w83781d.o
852else
853  ifeq ($(CONFIG_SENSORS_W83781D),m)
854    M_OBJS += w83781d.o
855  endif
856endif
857
858include $(TOPDIR)/Rules.make
859EOF
860  } 
861  close OUTPUT;
862  print_diff $package_root,$kernel_root,$kernel_file,$package_file;
863}
864
865# This generates diffs for drivers/i2c/Makefile.
866# Lines to add correct files to M_OBJS and/or L_OBJS are added just before
867# Rules.make is included
868# Of course, care is taken old lines are removed.
869# $_[0]: sensors package root (like /tmp/sensors)
870# $_[1]: Linux kernel tree (like /usr/src/linux)
871sub gen_drivers_i2c_Makefile
872{
873  my ($package_root,$kernel_root) = @_;
874  my $kernel_file = "drivers/i2c/Makefile";
875  my $package_file = $temp;
876  my $pr1 = 0;
877  my $new_format = 0;
878
879  open INPUT,"$kernel_root/$kernel_file"
880        or die "Can't open `$kernel_root/$kernel_file'";
881  open OUTPUT,">$package_root/$package_file"
882        or die "Can't open $package_root/$package_file";
883  while(<INPUT>) {
884    $new_format = 1 if m@i2c\.o@;
885    if (m@sensors code starts here@) {
886      $pr1 ++;
887      print OUTPUT;
888      while (<INPUT>) {
889        last if m@sensors code ends here@;
890      }
891      if ($new_format) {
892        print OUTPUT << 'EOF';
893obj-$(CONFIG_I2C_ALI15X3)               += i2c-ali15x3.o
894obj-$(CONFIG_I2C_AMD756)                += i2c-amd756.o
895obj-$(CONFIG_I2C_HYDRA)                 += i2c-hydra.o
896obj-$(CONFIG_I2C_I801)                  += i2c-i801.o
897obj-$(CONFIG_I2C_I810)                  += i2c-i810.o
898obj-$(CONFIG_I2C_ISA)                   += i2c-isa.o
899obj-$(CONFIG_I2C_PIIX4)                 += i2c-piix4.o
900obj-$(CONFIG_I2C_SIS5595)               += i2c-sis5595.o
901obj-$(CONFIG_I2C_VIA)                   += i2c-via.o
902obj-$(CONFIG_I2C_VIAPRO)                += i2c-viapro.o
903obj-$(CONFIG_I2C_VOODOO3)               += i2c-voodoo3.o
904EOF
905      } else {
906        print OUTPUT << 'EOF';
907ifeq ($(CONFIG_I2C_ALI15X3),y)
908  L_OBJS += i2c-ali15x3.o
909else 
910  ifeq ($(CONFIG_I2C_ALI15X3),m)
911    M_OBJS += i2c-ali15x3.o
912  endif
913endif
914
915ifeq ($(CONFIG_I2C_AMD756),y)
916  L_OBJS += i2c-amd756.o
917else 
918  ifeq ($(CONFIG_I2C_AMD756),m)
919    M_OBJS += i2c-amd756.o
920  endif
921endif
922
923ifeq ($(CONFIG_I2C_HYDRA),y)
924  L_OBJS += i2c-hydra.o
925else 
926  ifeq ($(CONFIG_I2C_HYDRA),m)
927    M_OBJS += i2c-hydra.o
928  endif
929endif
930
931ifeq ($(CONFIG_I2C_I801),y)
932  L_OBJS += i2c-i801.o
933else 
934  ifeq ($(CONFIG_I2C_I801),m)
935    M_OBJS += i2c-i801.o
936  endif
937endif
938
939ifeq ($(CONFIG_I2C_I810),y)
940  L_OBJS += i2c-i810.o
941else 
942  ifeq ($(CONFIG_I2C_I810),m)
943    M_OBJS += i2c-i810.o
944  endif
945endif
946
947ifeq ($(CONFIG_I2C_ISA),y)
948  L_OBJS += i2c-isa.o
949else 
950  ifeq ($(CONFIG_I2C_ISA),m)
951    M_OBJS += i2c-isa.o
952  endif
953endif
954
955ifeq ($(CONFIG_I2C_PIIX4),y)
956  L_OBJS += i2c-piix4.o
957else 
958  ifeq ($(CONFIG_I2C_PIIX4),m)
959    M_OBJS += i2c-piix4.o
960  endif
961endif
962
963ifeq ($(CONFIG_I2C_SIS5595),y)
964  L_OBJS += i2c-sis5595.o
965else 
966  ifeq ($(CONFIG_I2C_SIS5595),m)
967    M_OBJS += i2c-sis5595.o
968  endif
969endif
970
971ifeq ($(CONFIG_I2C_VIA),y)
972  L_OBJS += i2c-via.o
973else 
974  ifeq ($(CONFIG_I2C_VIA),m)
975    M_OBJS += i2c-via.o
976  endif
977endif
978
979ifeq ($(CONFIG_I2C_VIAPRO),y)
980  L_OBJS += i2c-viapro.o
981else 
982  ifeq ($(CONFIG_I2C_VIAPRO),m)
983    M_OBJS += i2c-viapro.o
984  endif
985endif
986
987ifeq ($(CONFIG_I2C_VOODOO3),y)
988  L_OBJS += i2c-voodoo3.o
989else 
990  ifeq ($(CONFIG_I2C_VOODOO3),m)
991    M_OBJS += i2c-voodoo3.o
992  endif
993endif
994
995EOF
996      }
997    }
998    print OUTPUT;
999  }
1000  close INPUT;
1001  close OUTPUT;
1002  die "Automatic patch generation for `drivers/i2c/Makefile' failed.\n".
1003      "Contact the authors please!" if $pr1 != 1;
1004  print_diff $package_root,$kernel_root,$kernel_file,$package_file;
1005}
1006
1007# This generates diffs for drivers/i2c/i2c-core.c
1008# Lines are generated at the beginning to declare several *_init functions.
1009# At the bottom, calls to them are added when the sensors stuff is configured
1010# in.
1011# $_[0]: sensors package root (like /tmp/sensors)
1012# $_[1]: Linux kernel tree (like /usr/src/linux)
1013sub gen_drivers_i2c_i2c_core_c
1014{
1015  my ($package_root,$kernel_root) = @_;
1016  my $kernel_file = "drivers/i2c/i2c-core.c";
1017  my $package_file = $temp;
1018  my $patch_nr = 1;
1019
1020  open INPUT,"$kernel_root/$kernel_file"
1021        or die "Can't open `$kernel_root/$kernel_file'";
1022  open OUTPUT,">$package_root/$package_file"
1023        or die "Can't open $package_root/$package_file";
1024  while(<INPUT>) {
1025    if (m@sensors code starts here@) {
1026      print OUTPUT;
1027      while (<INPUT>) {
1028        last if m@sensors code ends here@;
1029      }
1030      if ($patch_nr == 1) {
1031        print OUTPUT << 'EOF';
1032#ifdef CONFIG_I2C_ALI15X3
1033        extern int i2c_ali15x3_init(void);
1034#endif
1035#ifdef CONFIG_I2C_AMD756
1036        extern int i2c_amd756_init(void);
1037#endif
1038#ifdef CONFIG_I2C_HYDRA
1039        extern int i2c_hydra_init(void);
1040#endif
1041#ifdef CONFIG_I2C_I801
1042        extern int i2c_i801_init(void);
1043#endif
1044#ifdef CONFIG_I2C_I810
1045        extern int i2c_i810_init(void);
1046#endif
1047#ifdef CONFIG_I2C_ISA
1048        extern int i2c_isa_init(void);
1049#endif
1050#ifdef CONFIG_I2C_PIIX4
1051        extern int i2c_piix4_init(void);
1052#endif
1053#ifdef CONFIG_I2C_SIS5595
1054        extern int i2c_sis5595_init(void);
1055#endif
1056#ifdef CONFIG_I2C_VIA
1057        extern int i2c_via_init(void);
1058#endif
1059#ifdef CONFIG_I2C_VIAPRO
1060        extern int i2c_vt596_init(void);
1061#endif
1062#ifdef CONFIG_I2C_VOODOO3
1063        extern int i2c_voodoo3_init(void);
1064#endif
1065EOF
1066      } elsif ($patch_nr == 2) {
1067      print OUTPUT << 'EOF';
1068#ifdef CONFIG_I2C_ALI15X3
1069        i2c_ali15x3_init();
1070#endif
1071#ifdef CONFIG_I2C_AMD756
1072        i2c_amd756_init();
1073#endif
1074#ifdef CONFIG_I2C_HYDRA
1075        i2c_hydra_init();
1076#endif
1077#ifdef CONFIG_I2C_I801
1078        i2c_i801_init();
1079#endif
1080#ifdef CONFIG_I2C_I810
1081        i2c_i810_init();
1082#endif
1083#ifdef CONFIG_I2C_PIIX4
1084        i2c_piix4_init();
1085#endif
1086#ifdef CONFIG_I2C_SIS5595
1087        i2c_sis5595_init();
1088#endif
1089#ifdef CONFIG_I2C_VIA
1090        i2c_via_init();
1091#endif
1092#ifdef CONFIG_I2C_VIAPRO
1093        i2c_vt596_init();
1094#endif
1095#ifdef CONFIG_I2C_VOODOO3
1096        i2c_voodoo3_init();
1097#endif
1098#ifdef CONFIG_I2C_ISA
1099        i2c_isa_init();
1100#endif
1101EOF
1102      }
1103      $patch_nr ++;
1104    }
1105    print OUTPUT;
1106  }
1107  close INPUT;
1108  close OUTPUT;
1109  die "Automatic patch generation for `drivers/i2c/i2c-core.c' failed.\n".
1110      "Contact the authors please!" if $patch_nr != 3;
1111  print_diff $package_root,$kernel_root,$kernel_file,$package_file;
1112}
1113
1114# Generate the diffs for the list of MAINTAINERS
1115# $_[0]: i2c package root (like /tmp/i2c)
1116# $_[1]: Linux kernel tree (like /usr/src/linux)
1117sub gen_MAINTAINERS
1118{
1119  my ($package_root,$kernel_root) = @_;
1120  my $kernel_file = "MAINTAINERS";
1121  my $package_file = $temp;
1122  my $done = 0;
1123
1124  open INPUT,"$kernel_root/$kernel_file"
1125        or die "Can't open `$kernel_root/$kernel_file'";
1126  open OUTPUT,">$package_root/$package_file"
1127        or die "Can't open $package_root/$package_file";
1128  MAIN: while(<INPUT>) {
1129    if (m@SENSORS DRIVERS@) {
1130       $_=<INPUT> while not m@^$@;
1131       $_=<INPUT>;
1132       redo MAIN;
1133    }
1134    if (not $done and (m@SGI VISUAL WORKSTATION 320 AND 540@)) {
1135      print OUTPUT <<'EOF';
1136SENSORS DRIVERS
1137P:      Frodo Looijaard
1138M:      frodol@dds.nl
1139P:      Philip Edelbrock
1140M:      phil@netroedge.com
1141L:      sensors@stimpy.netroedge.com
1142W:      http://www.lm-sensors.nu/
1143S:      Maintained
1144
1145EOF
1146      $done = 1;
1147    }
1148    print OUTPUT;
1149  }
1150  close INPUT;
1151  close OUTPUT;
1152  die "Automatic patch generation for `MAINTAINERS' failed.\n".
1153      "Contact the authors please!" if $done == 0;
1154  print_diff $package_root,$kernel_root,$kernel_file,$package_file;
1155}
1156
1157
1158# Main function
1159sub main
1160{
1161  my ($package_root,$kernel_root,%files,%includes,$package_file,$kernel_file);
1162  my ($diff_command,$dummy,$data0,$data1,$sedscript,$version_string);
1163
1164  # --> Read the command-lineo
1165  $package_root = $ARGV[0];
1166  die "Package root `$package_root' is not found\n" 
1167        unless -d "$package_root/mkpatch";
1168  $kernel_root = $ARGV[1];
1169  die "Kernel root `$kernel_root' is not found\n" 
1170        unless -f "$kernel_root/Rules.make";
1171
1172  # --> Read FILES
1173  open INPUT, "$package_root/mkpatch/FILES" 
1174        or die "Can't open `$package_root/mkpatch/FILES'";
1175  while (<INPUT>) {
1176    ($data0,$data1) = /(\S+)\s+(\S+)/;
1177    $files{$data0} = $data1;
1178  } 
1179  close INPUT;
1180
1181  # --> Read INCLUDES
1182  open INPUT, "$package_root/mkpatch/INCLUDES" 
1183        or die "Can't open `$package_root/mkpatch/INCLUDES'";
1184  while (<INPUT>) {
1185    ($data0,$data1) = /(\S+)\s+(\S+)/;
1186    $includes{$data0} = $data1;
1187    $sedscript .= 's,(#\s*include\s*)'.$data0.'(\s*),\1'."$data1".'\2, ; ';
1188  } 
1189  close INPUT;
1190
1191  die "First apply the i2c patches to `$kernel_root'!" 
1192       if ! -d "$kernel_root/drivers/i2c";
1193
1194  # --> Read "version.h"
1195  open INPUT, "$package_root/version.h"
1196        or die "Can't open `$package_root/version.h'";
1197  $version_string .= $_ while <INPUT>;
1198  close INPUT;
1199 
1200  # --> Start generating
1201  foreach $package_file (sort keys %files) {
1202    open INPUT,"$package_root/$package_file" 
1203          or die "Can't open `$package_root/$package_file'";
1204    open OUTPUT,">$package_root/$temp"
1205          or die "Can't open `$package_root/$temp'";
1206    while (<INPUT>) {
1207      eval $sedscript;
1208      if (m@#\s*include\s*"version.h"@) {
1209        print OUTPUT $version_string;
1210      } else {
1211        print OUTPUT;
1212      }
1213    }
1214    close INPUT;
1215    close OUTPUT;
1216
1217    $kernel_file = $files{$package_file};
1218    print_diff $package_root,$kernel_root,$kernel_file,$temp;
1219  }
1220
1221  gen_Makefile $package_root, $kernel_root;
1222  gen_drivers_Makefile $package_root, $kernel_root;
1223  gen_drivers_sensors_Makefile $package_root, $kernel_root;
1224  gen_drivers_char_Config_in $package_root, $kernel_root;
1225  gen_drivers_char_mem_c $package_root, $kernel_root;
1226  gen_drivers_i2c_Config_in $package_root, $kernel_root;
1227  gen_drivers_i2c_Makefile $package_root, $kernel_root;
1228  gen_drivers_i2c_i2c_core_c $package_root, $kernel_root;
1229  gen_Documentation_Configure_help $package_root, $kernel_root;
1230  gen_MAINTAINERS $package_root, $kernel_root;
1231}
1232
1233main;
1234
Note: See TracBrowser for help on using the browser.