| 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 | |
|---|
| 20 | use strict; |
|---|
| 21 | |
|---|
| 22 | use vars qw($temp); |
|---|
| 23 | $temp = "mkpatch/.temp"; |
|---|
| 24 | |
|---|
| 25 | # $_[0]: sensors package root (like /tmp/sensors) |
|---|
| 26 | # $_[1]: Linux kernel tree (like /usr/src/linux) |
|---|
| 27 | # $_[2]: Name of the kernel file |
|---|
| 28 | # $_[3]: Name of the patched file |
|---|
| 29 | sub print_diff |
|---|
| 30 | { |
|---|
| 31 | my ($package_root,$kernel_root,$kernel_file,$package_file) = @_; |
|---|
| 32 | my ($diff_command,$dummy); |
|---|
| 33 | |
|---|
| 34 | $diff_command = "diff -u2"; |
|---|
| 35 | if ( -e "$kernel_root/$kernel_file") { |
|---|
| 36 | $diff_command .= " $kernel_root/$kernel_file "; |
|---|
| 37 | } else { |
|---|
| 38 | $diff_command .= " /dev/null "; |
|---|
| 39 | } |
|---|
| 40 | if ( -e "$package_root/$package_file") { |
|---|
| 41 | $diff_command .= " $package_root/$package_file "; |
|---|
| 42 | } else { |
|---|
| 43 | $diff_command .= " /dev/null"; |
|---|
| 44 | } |
|---|
| 45 | open INPUT, "$diff_command|" or die "Can't execute `$diff_command'"; |
|---|
| 46 | $dummy = <INPUT>; |
|---|
| 47 | $dummy = <INPUT>; |
|---|
| 48 | print "--- linux-old/$kernel_file\t".`date`; |
|---|
| 49 | print "+++ linux/$kernel_file\t".`date`; |
|---|
| 50 | |
|---|
| 51 | while (<INPUT>) { |
|---|
| 52 | print; |
|---|
| 53 | } |
|---|
| 54 | close INPUT; |
|---|
| 55 | } |
|---|
| 56 | |
|---|
| 57 | |
|---|
| 58 | # $_[0]: sensors package root (like /tmp/sensors) |
|---|
| 59 | # $_[1]: Linux kernel tree (like /usr/src/linux) |
|---|
| 60 | sub gen_Makefile |
|---|
| 61 | { |
|---|
| 62 | my ($package_root,$kernel_root) = @_; |
|---|
| 63 | my $kernel_file = "Makefile"; |
|---|
| 64 | my $package_file = $temp; |
|---|
| 65 | |
|---|
| 66 | open INPUT,"$kernel_root/$kernel_file" |
|---|
| 67 | or die "Can't open `$kernel_root/$kernel_file'"; |
|---|
| 68 | open OUTPUT,">$package_root/$package_file" |
|---|
| 69 | or die "Can't open $package_root/$package_file"; |
|---|
| 70 | while(<INPUT>) { |
|---|
| 71 | if (m@CONFIG_SENSORS@) { |
|---|
| 72 | $_ = <INPUT> while not m@endif@; |
|---|
| 73 | $_ = <INPUT>; |
|---|
| 74 | $_ = <INPUT> if m@^$@; |
|---|
| 75 | } |
|---|
| 76 | if (m@include arch/\$\(ARCH\)/Makefile@) { |
|---|
| 77 | print OUTPUT <<'EOF'; |
|---|
| 78 | ifeq ($(CONFIG_SENSORS),y) |
|---|
| 79 | DRIVERS := $(DRIVERS) drivers/sensors/sensors.a |
|---|
| 80 | endif |
|---|
| 81 | |
|---|
| 82 | EOF |
|---|
| 83 | } |
|---|
| 84 | print OUTPUT; |
|---|
| 85 | } |
|---|
| 86 | close INPUT; |
|---|
| 87 | close OUTPUT; |
|---|
| 88 | print_diff $package_root,$kernel_root,$kernel_file,$package_file; |
|---|
| 89 | } |
|---|
| 90 | |
|---|
| 91 | # $_[0]: sensors package root (like /tmp/sensors) |
|---|
| 92 | # $_[1]: Linux kernel tree (like /usr/src/linux) |
|---|
| 93 | sub gen_drivers_Makefile |
|---|
| 94 | { |
|---|
| 95 | my ($package_root,$kernel_root) = @_; |
|---|
| 96 | my $kernel_file = "drivers/Makefile"; |
|---|
| 97 | my $package_file = $temp; |
|---|
| 98 | my $sensors_present; |
|---|
| 99 | |
|---|
| 100 | open INPUT,"$kernel_root/$kernel_file" |
|---|
| 101 | or die "Can't open `$kernel_root/$kernel_file'"; |
|---|
| 102 | open OUTPUT,">$package_root/$package_file" |
|---|
| 103 | or die "Can't open $package_root/$package_file"; |
|---|
| 104 | while(<INPUT>) { |
|---|
| 105 | if (m@^ALL_SUB_DIRS\s*:=@) { |
|---|
| 106 | $sensors_present = 0; |
|---|
| 107 | while (m@\\$@) { |
|---|
| 108 | $sensors_present = 1 if m@sensors@; |
|---|
| 109 | print OUTPUT; |
|---|
| 110 | $_ = <INPUT>; |
|---|
| 111 | } |
|---|
| 112 | $sensors_present = 1 if m@sensors@; |
|---|
| 113 | s@$@ sensors@ if (not $sensors_present); |
|---|
| 114 | } |
|---|
| 115 | if (m@CONFIG_SENSORS@) { |
|---|
| 116 | $_ = <INPUT> while not m@^endif@; |
|---|
| 117 | $_ = <INPUT>; |
|---|
| 118 | $_ = <INPUT> if m@^$@; |
|---|
| 119 | } |
|---|
| 120 | if (m@^include \$\(TOPDIR\)/Rules.make$@) { |
|---|
| 121 | print OUTPUT <<'EOF'; |
|---|
| 122 | ifeq ($(CONFIG_SENSORS),y) |
|---|
| 123 | SUB_DIRS += sensors |
|---|
| 124 | MOD_SUB_DIRS += sensors |
|---|
| 125 | else |
|---|
| 126 | ifeq ($(CONFIG_SENSORS),m) |
|---|
| 127 | MOD_SUB_DIRS += sensors |
|---|
| 128 | endif |
|---|
| 129 | endif |
|---|
| 130 | |
|---|
| 131 | EOF |
|---|
| 132 | } |
|---|
| 133 | print OUTPUT; |
|---|
| 134 | } |
|---|
| 135 | close INPUT; |
|---|
| 136 | close OUTPUT; |
|---|
| 137 | print_diff $package_root,$kernel_root,$kernel_file,$package_file; |
|---|
| 138 | } |
|---|
| 139 | |
|---|
| 140 | # $_[0]: sensors package root (like /tmp/sensors) |
|---|
| 141 | # $_[1]: Linux kernel tree (like /usr/src/linux) |
|---|
| 142 | sub gen_drivers_char_Config_in |
|---|
| 143 | { |
|---|
| 144 | my ($package_root,$kernel_root) = @_; |
|---|
| 145 | my $kernel_file = "drivers/char/Config.in"; |
|---|
| 146 | my $package_file = $temp; |
|---|
| 147 | my $ready = 0; |
|---|
| 148 | my $done = 0; |
|---|
| 149 | |
|---|
| 150 | open INPUT,"$kernel_root/$kernel_file" |
|---|
| 151 | or die "Can't open `$kernel_root/$kernel_file'"; |
|---|
| 152 | open OUTPUT,">$package_root/$package_file" |
|---|
| 153 | or die "Can't open $package_root/$package_file"; |
|---|
| 154 | while(<INPUT>) { |
|---|
| 155 | if (m@source drivers/i2c/Config.in@) { |
|---|
| 156 | print OUTPUT; |
|---|
| 157 | print OUTPUT "source drivers/sensors/Config.in\n"; |
|---|
| 158 | $_ = <INPUT>; |
|---|
| 159 | } |
|---|
| 160 | if (m@sensors@) { |
|---|
| 161 | $_ = <INPUT>; |
|---|
| 162 | $_ = <INPUT> if (m@^$@); |
|---|
| 163 | } |
|---|
| 164 | print OUTPUT; |
|---|
| 165 | } |
|---|
| 166 | close INPUT; |
|---|
| 167 | close OUTPUT; |
|---|
| 168 | print_diff $package_root,$kernel_root,$kernel_file,$package_file; |
|---|
| 169 | } |
|---|
| 170 | |
|---|
| 171 | |
|---|
| 172 | # $_[0]: sensors package root (like /tmp/sensors) |
|---|
| 173 | # $_[1]: Linux kernel tree (like /usr/src/linux) |
|---|
| 174 | sub gen_drivers_char_mem_c |
|---|
| 175 | { |
|---|
| 176 | my ($package_root,$kernel_root) = @_; |
|---|
| 177 | my $kernel_file = "drivers/char/mem.c"; |
|---|
| 178 | my $package_file = $temp; |
|---|
| 179 | my $right_place = 0; |
|---|
| 180 | my $done = 0; |
|---|
| 181 | my $atstart = 1; |
|---|
| 182 | |
|---|
| 183 | open INPUT,"$kernel_root/$kernel_file" |
|---|
| 184 | or die "Can't open `$kernel_root/$kernel_file'"; |
|---|
| 185 | open OUTPUT,">$package_root/$package_file" |
|---|
| 186 | or die "Can't open $package_root/$package_file"; |
|---|
| 187 | while(<INPUT>) { |
|---|
| 188 | if ($atstart and m@#ifdef@) { |
|---|
| 189 | print OUTPUT << 'EOF'; |
|---|
| 190 | #ifdef CONFIG_SENSORS |
|---|
| 191 | extern void sensors_init_all(void); |
|---|
| 192 | #endif |
|---|
| 193 | EOF |
|---|
| 194 | $atstart = 0; |
|---|
| 195 | } |
|---|
| 196 | if (not $right_place and m@CONFIG_SENSORS@) { |
|---|
| 197 | $_ = <INPUT> while not m@#endif@; |
|---|
| 198 | $_ = <INPUT>; |
|---|
| 199 | } |
|---|
| 200 | $right_place = 1 if (m@lp_init\(\);@); |
|---|
| 201 | if ($right_place and not $done and |
|---|
| 202 | (m@CONFIG_SENSORS@ or m@return 0;@)) { |
|---|
| 203 | if (not m@return 0;@) { |
|---|
| 204 | $_ = <INPUT> while not m@#endif@; |
|---|
| 205 | $_ = <INPUT>; |
|---|
| 206 | $_ = <INPUT> if m@^$@; |
|---|
| 207 | } |
|---|
| 208 | print OUTPUT <<'EOF'; |
|---|
| 209 | #ifdef CONFIG_SENSORS |
|---|
| 210 | sensors_init_all(); |
|---|
| 211 | #endif |
|---|
| 212 | |
|---|
| 213 | EOF |
|---|
| 214 | $done = 1; |
|---|
| 215 | } |
|---|
| 216 | print OUTPUT; |
|---|
| 217 | } |
|---|
| 218 | close INPUT; |
|---|
| 219 | close OUTPUT; |
|---|
| 220 | print_diff $package_root,$kernel_root,$kernel_file,$package_file; |
|---|
| 221 | } |
|---|
| 222 | |
|---|
| 223 | |
|---|
| 224 | # $_[0]: sensors package root (like /tmp/sensors) |
|---|
| 225 | # $_[1]: Linux kernel tree (like /usr/src/linux) |
|---|
| 226 | sub gen_drivers_i2c_Config_in |
|---|
| 227 | { |
|---|
| 228 | my ($package_root,$kernel_root) = @_; |
|---|
| 229 | my $kernel_file = "drivers/i2c/Config.in"; |
|---|
| 230 | my $package_file = "$temp"; |
|---|
| 231 | |
|---|
| 232 | open INPUT,"$kernel_root/$kernel_file" |
|---|
| 233 | or die "Can't open `$kernel_root/$kernel_file'"; |
|---|
| 234 | open OUTPUT,">$package_root/$package_file" |
|---|
| 235 | or die "Can't open $package_root/$package_file"; |
|---|
| 236 | while(<INPUT>) { |
|---|
| 237 | if (m@CONFIG_I2C_MAINBOARD@) { |
|---|
| 238 | $_ = <INPUT> while not m@^ fi$@; |
|---|
| 239 | $_ = <INPUT>; |
|---|
| 240 | $_ = <INPUT> if m@^$@; |
|---|
| 241 | } |
|---|
| 242 | if (m@^fi@) { |
|---|
| 243 | print OUTPUT << 'EOF' |
|---|
| 244 | bool 'I2C mainboard interfaces' CONFIG_I2C_MAINBOARD |
|---|
| 245 | if [ "$CONFIG_I2C_MAINBOARD" = "y" ]; then |
|---|
| 246 | dep_tristate ' Acer Labs ALI 1533 and 1543C' CONFIG_I2C_ALI5X3 $CONFIG_I2C_MAINBOARD |
|---|
| 247 | dep_tristate ' Apple Hydra Mac I/O' CONFIG_I2C_HYDRA $CONFIG_I2C_MAINBOARD |
|---|
| 248 | dep_tristate ' Intel 82371AB PIIX4(E)' CONFIG_I2C_PIIX4 $CONFIG_I2C_MAINBOARD |
|---|
| 249 | dep_tristate ' VIA Technologies, Inc. VT82C586B' CONFIG_I2C_VIA $CONFIG_I2C_MAINBOARD |
|---|
| 250 | dep_tristate ' Pseudo ISA adapter (for hardware sensors modules)' CONFIG_I2C_ISA $CONFIG_I2C_MAINBOARD |
|---|
| 251 | fi |
|---|
| 252 | |
|---|
| 253 | EOF |
|---|
| 254 | } |
|---|
| 255 | print OUTPUT; |
|---|
| 256 | } |
|---|
| 257 | close INPUT; |
|---|
| 258 | close OUTPUT; |
|---|
| 259 | print_diff $package_root,$kernel_root,$kernel_file,$package_file; |
|---|
| 260 | } |
|---|
| 261 | |
|---|
| 262 | # $_[0]: sensors package root (like /tmp/sensors) |
|---|
| 263 | # $_[1]: Linux kernel tree (like /usr/src/linux) |
|---|
| 264 | sub gen_drivers_i2c_Makefile |
|---|
| 265 | { |
|---|
| 266 | my ($package_root,$kernel_root) = @_; |
|---|
| 267 | my $kernel_file = "drivers/i2c/Makefile"; |
|---|
| 268 | my $package_file = $temp; |
|---|
| 269 | |
|---|
| 270 | open INPUT,"$kernel_root/$kernel_file" |
|---|
| 271 | or die "Can't open `$kernel_root/$kernel_file'"; |
|---|
| 272 | open OUTPUT,">$package_root/$package_file" |
|---|
| 273 | or die "Can't open $package_root/$package_file"; |
|---|
| 274 | while(<INPUT>) { |
|---|
| 275 | while (m@CONFIG_I2C_ALI5X3@ or m@CONFIG_I2C_HYDRA@ or m@CONFIG_I2C_PIIX4@ or |
|---|
| 276 | m@CONFIG_I2C_VIA@ or m@CONFIG_I2C_ISA@) { |
|---|
| 277 | $_ = <INPUT> while not m@^endif@; |
|---|
| 278 | $_ = <INPUT>; |
|---|
| 279 | $_ = <INPUT> if m@^$@; |
|---|
| 280 | } |
|---|
| 281 | if (m@Rules.make@) { |
|---|
| 282 | print OUTPUT << 'EOF' |
|---|
| 283 | ifeq ($(CONFIG_I2C_ALI5X3),y) |
|---|
| 284 | L_OBJS += i2c-ali5x3.o |
|---|
| 285 | else |
|---|
| 286 | ifeq ($(CONFIG_I2C_ALI5X3),m) |
|---|
| 287 | M_OBJS += i2c-ali5x3.o |
|---|
| 288 | endif |
|---|
| 289 | endif |
|---|
| 290 | |
|---|
| 291 | ifeq ($(CONFIG_I2C_HYDRA),y) |
|---|
| 292 | L_OBJS += i2c-hydra.o |
|---|
| 293 | else |
|---|
| 294 | ifeq ($(CONFIG_I2C_HYDRA),m) |
|---|
| 295 | M_OBJS += i2c-hydra.o |
|---|
| 296 | endif |
|---|
| 297 | endif |
|---|
| 298 | |
|---|
| 299 | ifeq ($(CONFIG_I2C_PIIX4),y) |
|---|
| 300 | L_OBJS += i2c-piix4.o |
|---|
| 301 | else |
|---|
| 302 | ifeq ($(CONFIG_I2C_PIIX4),m) |
|---|
| 303 | M_OBJS += i2c-piix4.o |
|---|
| 304 | endif |
|---|
| 305 | endif |
|---|
| 306 | |
|---|
| 307 | ifeq ($(CONFIG_I2C_VIA),y) |
|---|
| 308 | L_OBJS += i2c-via.o |
|---|
| 309 | else |
|---|
| 310 | ifeq ($(CONFIG_I2C_VIA),m) |
|---|
| 311 | M_OBJS += i2c-via.o |
|---|
| 312 | endif |
|---|
| 313 | endif |
|---|
| 314 | |
|---|
| 315 | ifeq ($(CONFIG_I2C_ISA),y) |
|---|
| 316 | L_OBJS += i2c-isa.o |
|---|
| 317 | else |
|---|
| 318 | ifeq ($(CONFIG_I2C_ISA),m) |
|---|
| 319 | M_OBJS += i2c-isa.o |
|---|
| 320 | endif |
|---|
| 321 | endif |
|---|
| 322 | |
|---|
| 323 | EOF |
|---|
| 324 | } |
|---|
| 325 | print OUTPUT; |
|---|
| 326 | } |
|---|
| 327 | close INPUT; |
|---|
| 328 | close OUTPUT; |
|---|
| 329 | print_diff $package_root,$kernel_root,$kernel_file,$package_file; |
|---|
| 330 | } |
|---|
| 331 | |
|---|
| 332 | sub gen_drivers_i2c_i2c_core_c |
|---|
| 333 | { |
|---|
| 334 | my ($package_root,$kernel_root) = @_; |
|---|
| 335 | my $kernel_file = "drivers/i2c/i2c-core.c"; |
|---|
| 336 | my $package_file = $temp; |
|---|
| 337 | my $right_place = 0; |
|---|
| 338 | |
|---|
| 339 | open INPUT,"$kernel_root/$kernel_file" |
|---|
| 340 | or die "Can't open `$kernel_root/$kernel_file'"; |
|---|
| 341 | open OUTPUT,">$package_root/$package_file" |
|---|
| 342 | or die "Can't open $package_root/$package_file"; |
|---|
| 343 | while(<INPUT>) { |
|---|
| 344 | while (m@CONFIG_I2C_ALI5X3@ or m@CONFIG_I2C_HYDRA@ or m@CONFIG_I2C_PIIX4@ or |
|---|
| 345 | m@CONFIG_I2C_VIA@ or m@CONFIG_I2C_ISA@) { |
|---|
| 346 | $_ = <INPUT> while not m@#endif@; |
|---|
| 347 | $_ = <INPUT>; |
|---|
| 348 | } |
|---|
| 349 | if (m@^int __init i2c_init_all@) { |
|---|
| 350 | $right_place = 1; |
|---|
| 351 | print OUTPUT << 'EOF'; |
|---|
| 352 | #ifdef CONFIG_I2C_ALI5X3 |
|---|
| 353 | extern int i2c_ali5x3_init(void); |
|---|
| 354 | #endif |
|---|
| 355 | #ifdef CONFIG_I2C_HYDRA |
|---|
| 356 | extern int i2c_hydra_init(void); |
|---|
| 357 | #endif |
|---|
| 358 | #ifdef CONFIG_I2C_PIIX4 |
|---|
| 359 | extern int i2c_piix4_init(void); |
|---|
| 360 | #endif |
|---|
| 361 | #ifdef CONFIG_I2C_VIA |
|---|
| 362 | extern int i2c_via_init(void); |
|---|
| 363 | #endif |
|---|
| 364 | #ifdef CONFIG_I2C_ISA |
|---|
| 365 | extern int i2c_isa_init(void); |
|---|
| 366 | #endif |
|---|
| 367 | EOF |
|---|
| 368 | } |
|---|
| 369 | if ($right_place and m@return 0;@) { |
|---|
| 370 | print OUTPUT << 'EOF'; |
|---|
| 371 | #ifdef CONFIG_I2C_ALI5X3 |
|---|
| 372 | i2c_ali5x3_init(); |
|---|
| 373 | #endif |
|---|
| 374 | #ifdef CONFIG_I2C_HYDRA |
|---|
| 375 | i2c_hydra_init(); |
|---|
| 376 | #endif |
|---|
| 377 | #ifdef CONFIG_I2C_PIIX4 |
|---|
| 378 | i2c_piix4_init(); |
|---|
| 379 | #endif |
|---|
| 380 | #ifdef CONFIG_I2C_VIA |
|---|
| 381 | i2c_via_init(); |
|---|
| 382 | #endif |
|---|
| 383 | #ifdef CONFIG_I2C_ISA |
|---|
| 384 | i2c_isa_init(); |
|---|
| 385 | #endif |
|---|
| 386 | EOF |
|---|
| 387 | } |
|---|
| 388 | print OUTPUT; |
|---|
| 389 | } |
|---|
| 390 | close INPUT; |
|---|
| 391 | close OUTPUT; |
|---|
| 392 | print_diff $package_root,$kernel_root,$kernel_file,$package_file; |
|---|
| 393 | } |
|---|
| 394 | |
|---|
| 395 | |
|---|
| 396 | sub main |
|---|
| 397 | { |
|---|
| 398 | my ($package_root,$kernel_root,%files,%includes,$package_file,$kernel_file); |
|---|
| 399 | my ($diff_command,$dummy,$data0,$data1,$sedscript,$version_string); |
|---|
| 400 | |
|---|
| 401 | # --> Read the command-lineo |
|---|
| 402 | $package_root = $ARGV[0]; |
|---|
| 403 | die "Package root `$package_root' is not found\n" |
|---|
| 404 | unless -d "$package_root/mkpatch"; |
|---|
| 405 | $kernel_root = $ARGV[1]; |
|---|
| 406 | die "Kernel root `$kernel_root' is not found\n" |
|---|
| 407 | unless -f "$kernel_root/Rules.make"; |
|---|
| 408 | |
|---|
| 409 | # --> Read FILES |
|---|
| 410 | open INPUT, "$package_root/mkpatch/FILES" |
|---|
| 411 | or die "Can't open `$package_root/mkpatch/FILES'"; |
|---|
| 412 | while (<INPUT>) { |
|---|
| 413 | ($data0,$data1) = /(\S+)\s+(\S+)/; |
|---|
| 414 | $files{$data0} = $data1; |
|---|
| 415 | } |
|---|
| 416 | close INPUT; |
|---|
| 417 | |
|---|
| 418 | # --> Read INCLUDES |
|---|
| 419 | open INPUT, "$package_root/mkpatch/INCLUDES" |
|---|
| 420 | or die "Can't open `$package_root/mkpatch/INCLUDES'"; |
|---|
| 421 | while (<INPUT>) { |
|---|
| 422 | ($data0,$data1) = /(\S+)\s+(\S+)/; |
|---|
| 423 | $includes{$data0} = $data1; |
|---|
| 424 | $sedscript .= 's,(#\s*include\s*)'.$data0.'(\s*),\1'."$data1".'\2, ; '; |
|---|
| 425 | } |
|---|
| 426 | close INPUT; |
|---|
| 427 | |
|---|
| 428 | # --> Read "version.h" |
|---|
| 429 | open INPUT, "$package_root/version.h" |
|---|
| 430 | or die "Can't open `$package_root/version.h'"; |
|---|
| 431 | $version_string .= $_ while <INPUT>; |
|---|
| 432 | close INPUT; |
|---|
| 433 | |
|---|
| 434 | # --> Start generating |
|---|
| 435 | foreach $package_file (sort keys %files) { |
|---|
| 436 | open INPUT,"$package_root/$package_file" |
|---|
| 437 | or die "Can't open `$package_root/$package_file'"; |
|---|
| 438 | open OUTPUT,">$package_root/$temp" |
|---|
| 439 | or die "Can't open `$package_root/$temp'"; |
|---|
| 440 | while (<INPUT>) { |
|---|
| 441 | eval $sedscript; |
|---|
| 442 | if (m@#\s*include\s*"version.h"@) { |
|---|
| 443 | print OUTPUT $version_string; |
|---|
| 444 | } elsif (m@#\s*include\s*"compat.h"@) { |
|---|
| 445 | print OUTPUT << 'EOF'; |
|---|
| 446 | |
|---|
| 447 | /* --> COMPATIBILITY SECTION FOR OLD (2.0, 2.1) KERNELS */ |
|---|
| 448 | |
|---|
| 449 | #ifdef MODULE |
|---|
| 450 | #include <linux/module.h> |
|---|
| 451 | #ifndef MODULE_AUTHOR |
|---|
| 452 | #define MODULE_AUTHOR(whatever) |
|---|
| 453 | #endif |
|---|
| 454 | #ifndef MODULE_DESCRIPTION |
|---|
| 455 | #define MODULE_DESCRIPTION(whatever) |
|---|
| 456 | #endif |
|---|
| 457 | #endif /* def MODULE */ |
|---|
| 458 | |
|---|
| 459 | EOF |
|---|
| 460 | if (`grep KERNEL_VERSION "$package_root/$package_file"`) { |
|---|
| 461 | print OUTPUT << 'EOF'; |
|---|
| 462 | #include <linux/version.h> |
|---|
| 463 | #ifndef KERNEL_VERSION |
|---|
| 464 | #define KERNEL_VERSION(a,b,c) (((a) << 16) | ((b) << 8) | (c)) |
|---|
| 465 | #endif |
|---|
| 466 | |
|---|
| 467 | EOF |
|---|
| 468 | } |
|---|
| 469 | if (`grep 'copy_from_user\\|copy_to_user\\|get_user_data' "$package_root/$package_file"`) { |
|---|
| 470 | print OUTPUT << 'EOF'; |
|---|
| 471 | /* copy_from/to_usr is called memcpy_from/to_fs in 2.0 kernels |
|---|
| 472 | get_user was redefined in 2.1 kernels to use two arguments, and returns |
|---|
| 473 | an error code */ |
|---|
| 474 | #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,1,4)) |
|---|
| 475 | #define copy_from_user memcpy_fromfs |
|---|
| 476 | #define copy_to_user memcpy_tofs |
|---|
| 477 | #define get_user_data(to,from) ((to) = get_user(from),0) |
|---|
| 478 | #else |
|---|
| 479 | #include <asm/uaccess.h> |
|---|
| 480 | #define get_user_data(to,from) get_user(to,from) |
|---|
| 481 | #endif |
|---|
| 482 | |
|---|
| 483 | EOF |
|---|
| 484 | } |
|---|
| 485 | if (`grep 'schedule_timeout' "$package_root/$package_file"`) { |
|---|
| 486 | print OUTPUT << 'EOF'; |
|---|
| 487 | /* Add a scheduling fix for the new code in kernel 2.1.127 */ |
|---|
| 488 | #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,1,127)) |
|---|
| 489 | #define schedule_timeout(x) ( current->timeout = jiffies + (x), schedule() ) |
|---|
| 490 | #endif |
|---|
| 491 | |
|---|
| 492 | EOF |
|---|
| 493 | } |
|---|
| 494 | if (`grep 'pci_' "$package_root/$package_file"`) { |
|---|
| 495 | print OUTPUT << 'EOF'; |
|---|
| 496 | /* If the new PCI interface is not present, fall back on the old PCI BIOS |
|---|
| 497 | interface. We also define some things to unite both interfaces. Not |
|---|
| 498 | very nice, but it works like a charm. |
|---|
| 499 | device is the 2.1 struct pci_dev, bus is the 2.0 bus number, dev is the |
|---|
| 500 | 2.0 device/function code, com is the PCI command, and res is the result. */ |
|---|
| 501 | #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,1,54)) |
|---|
| 502 | #define pci_present pcibios_present |
|---|
| 503 | #define pci_read_config_byte_united(device,bus,dev,com,res) \ |
|---|
| 504 | pcibios_read_config_byte(bus,dev,com,res) |
|---|
| 505 | #define pci_read_config_word_united(device,bus,dev,com,res) \ |
|---|
| 506 | pcibios_read_config_word(bus,dev,com,res) |
|---|
| 507 | #define pci_write_config_byte_united(device,bus,dev,com,res) \ |
|---|
| 508 | pcibios_write_config_byte(bus,dev,com,res) |
|---|
| 509 | #define pci_write_config_word_united(device,bus,dev,com,res) \ |
|---|
| 510 | pcibios_write_config_word(bus,dev,com,res) |
|---|
| 511 | #else |
|---|
| 512 | #define pci_read_config_byte_united(device,bus,dev,com,res) \ |
|---|
| 513 | pci_read_config_byte(device,com,res) |
|---|
| 514 | #define pci_read_config_word_united(device,bus,dev,com,res) \ |
|---|
| 515 | pci_read_config_word(device,com,res) |
|---|
| 516 | #define pci_write_config_byte_united(device,bus,dev,com,res) \ |
|---|
| 517 | pci_write_config_byte(device,com,res) |
|---|
| 518 | #define pci_write_config_word_united(device,bus,dev,com,res) \ |
|---|
| 519 | pci_write_config_word(device,com,res) |
|---|
| 520 | #endif |
|---|
| 521 | |
|---|
| 522 | EOF |
|---|
| 523 | } |
|---|
| 524 | if (`grep 'ioremap\|iounmap' "$package_root/$package_file"`) { |
|---|
| 525 | print OUTPUT << 'EOF'; |
|---|
| 526 | /* I hope this is always correct, even for the PPC, but I really think so. |
|---|
| 527 | And yes, the kernel version is exactly correct */ |
|---|
| 528 | #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,1,0)) |
|---|
| 529 | #include <linux/mm.h> |
|---|
| 530 | #define ioremap vremap |
|---|
| 531 | #define iounmap vfree |
|---|
| 532 | #endif |
|---|
| 533 | |
|---|
| 534 | EOF |
|---|
| 535 | } |
|---|
| 536 | if (`grep 'init_MUTEX' "$package_root/$package_file"`) { |
|---|
| 537 | print OUTPUT << 'EOF'; |
|---|
| 538 | #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,3,1)) |
|---|
| 539 | #define init_MUTEX(s) do { *(s) = MUTEX; } while(0) |
|---|
| 540 | #endif |
|---|
| 541 | EOF |
|---|
| 542 | } |
|---|
| 543 | if (`grep '__init' "$package_root/$package_file"`) { |
|---|
| 544 | print OUTPUT << 'EOF'; |
|---|
| 545 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,53) |
|---|
| 546 | #include <linux/init.h> |
|---|
| 547 | #else |
|---|
| 548 | #define __init |
|---|
| 549 | #define __initdata |
|---|
| 550 | #endif |
|---|
| 551 | EOF |
|---|
| 552 | } |
|---|
| 553 | if (`grep 'PCI_DEVICE_ID_VIA_82C586_3' "$package_root/$package_file"`) { |
|---|
| 554 | print OUTPUT << 'EOF'; |
|---|
| 555 | #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,0,34)) |
|---|
| 556 | #define PCI_DEVICE_ID_VIA_82C586_3 0x3040 |
|---|
| 557 | #endif |
|---|
| 558 | EOF |
|---|
| 559 | |
|---|
| 560 | } |
|---|
| 561 | if (`grep 'PCI_DEVICE_ID_AL_M7101' "$package_root/$package_file"`) { |
|---|
| 562 | print OUTPUT << 'EOF'; |
|---|
| 563 | #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,0,34)) |
|---|
| 564 | #define PCI_DEVICE_ID_AL_M7101 0x7101 |
|---|
| 565 | #endif |
|---|
| 566 | EOF |
|---|
| 567 | } |
|---|
| 568 | if (`grep 'PCI_DEVICE_ID_INTEL_82371AB_3' "$package_root/$package_file"`) { |
|---|
| 569 | print OUTPUT << 'EOF'; |
|---|
| 570 | #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,0,31)) |
|---|
| 571 | #define PCI_DEVICE_ID_INTEL_82371AB_3 0x7113 |
|---|
| 572 | #endif |
|---|
| 573 | EOF |
|---|
| 574 | } |
|---|
| 575 | if (`grep 'PCI_VENDOR_ID_APPLE' "$package_root/$package_file"`) { |
|---|
| 576 | print OUTPUT << 'EOF'; |
|---|
| 577 | #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,0,31)) |
|---|
| 578 | #define PCI_VENDOR_ID_APPLE 0x106b |
|---|
| 579 | #endif |
|---|
| 580 | EOF |
|---|
| 581 | } |
|---|
| 582 | if (`grep 'PCI_DEVICE_ID_APPLE_HYDRA' "$package_root/$package_file"`) { |
|---|
| 583 | print OUTPUT << 'EOF'; |
|---|
| 584 | #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,0,31)) |
|---|
| 585 | #define PCI_DEVICE_ID_APPLE_HYDRA 0x000e |
|---|
| 586 | #endif |
|---|
| 587 | EOF |
|---|
| 588 | } |
|---|
| 589 | if (`grep 'PCI_DEVICE_ID_INTEL_82801AA_3\|PCI_DEVICE_ID_INTEL_82801AB_3' "$package_root/$package_file"`) { |
|---|
| 590 | print OUTPUT << 'EOF'; |
|---|
| 591 | #ifndef PCI_DEVICE_ID_INTEL_82801AA_3 |
|---|
| 592 | #define PCI_DEVICE_ID_INTEL_82801AA_3 0x2413 |
|---|
| 593 | #endif |
|---|
| 594 | #ifndef PCI_DEVICE_ID_INTEL_82801AB_3 |
|---|
| 595 | #define PCI_DEVICE_ID_INTEL_82801AB_3 0x2423 |
|---|
| 596 | #endif |
|---|
| 597 | EOF |
|---|
| 598 | } |
|---|
| 599 | print OUTPUT << 'EOF'; |
|---|
| 600 | |
|---|
| 601 | /* --> END OF COMPATIBILITY SECTION */ |
|---|
| 602 | |
|---|
| 603 | EOF |
|---|
| 604 | } else { |
|---|
| 605 | print OUTPUT; |
|---|
| 606 | } |
|---|
| 607 | } |
|---|
| 608 | close INPUT; |
|---|
| 609 | close OUTPUT; |
|---|
| 610 | |
|---|
| 611 | $kernel_file = $files{$package_file}; |
|---|
| 612 | print_diff $package_root,$kernel_root,$kernel_file,$temp; |
|---|
| 613 | } |
|---|
| 614 | |
|---|
| 615 | gen_Makefile $package_root, $kernel_root; |
|---|
| 616 | gen_drivers_Makefile $package_root, $kernel_root; |
|---|
| 617 | gen_drivers_char_Config_in $package_root, $kernel_root; |
|---|
| 618 | gen_drivers_char_mem_c $package_root, $kernel_root; |
|---|
| 619 | gen_drivers_i2c_Config_in $package_root, $kernel_root; |
|---|
| 620 | gen_drivers_i2c_Makefile $package_root, $kernel_root; |
|---|
| 621 | gen_drivers_i2c_i2c_core_c $package_root, $kernel_root; |
|---|
| 622 | } |
|---|
| 623 | |
|---|
| 624 | main; |
|---|
| 625 | |
|---|