make-kpkg 31.4 KB
Newer Older
1
#! /usr/bin/perl -w
2 3 4 5 6 7
#                              -*- Mode: Perl -*-
# make-kpkg ---
# Author           : root ( root@melkor.pilgrim.umass.edu )
# Created On       : Mon Jun 17 01:10:11 1996
# Created On Node  : melkor.pilgrim.umass.edu
# Last Modified By : Manoj Srivastava
8
# Last Modified On : Mon Apr 13 01:18:41 2009
9
# Last Machine Used: anzu.internal.golden-gryphon.com
10
# Update Count     : 242
11 12 13 14 15
# Status           : Unknown, Use with caution!
# HISTORY          :
# Description      :
#
#
16
#
17
#    $Id: make-kpkg,v 1.94 2003/09/28 01:35:27 srivasta Exp $
18
#
19 20 21
require 5.002;
use strict;
use Getopt::Long;
22
use File::Path;
23 24 25 26 27 28 29

=head1 NAME

make-kpkg - build Debian kernel packages from Linux kernel sources.

=cut

30 31 32 33 34 35 36 37 38
( $main::MYNAME = $main::0 ) =~ s|.*/||;
$main::Author     = "Manoj Srivastava";
$main::AuthorMail = "srivasta\@debian.org";
$main::Version    = '=K=V';

my $added_modules     = '';
my $append_to_version = '';
my $arch              = '';
my $arch_in_name      = 0;
39
my $uimage;
40 41 42 43 44
my $concurrency   = 0;
my $config_target = 'oldconfig';
my $cross_compile = '';
my $key_id        = '';
my $help_opt      = 0;
45
my $noexec;
46
my $verbose;
47
my $initrd = 0;
Manoj Srivastava's avatar
Manoj Srivastava committed
48
my $revision;
49
my $root_cmd;
50 51 52 53 54 55
my $signature        = "";
my $subarch          = '';
my $stem             = '';
my $targ_opt         = 0;
my $unsign_changelog = '';
my $unsign_source    = '';
56 57
my $mkimage          = '';
my $overlay_dir      = '';
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87

my %option_ctl = (
  "help"                => \$help_opt,
  "noexec"              => \$noexec,
  "verbose"             => \$verbose,
  "initrd"              => \$initrd,
  "revision=s"          => \$revision,
  "added_modules=s"     => \$added_modules,
  "added-modules=s"     => \$added_modules,
  "append-to-version=s" => \$append_to_version,
  "append_to_version=s" => \$append_to_version,
  "arch=s"              => \$arch,
  "config=s"            => \$config_target,
  "cross_compile=s"     => \$cross_compile,
  "cross-compile=s"     => \$cross_compile,
  "subarch=s"           => \$subarch,
  "stem=s"              => \$stem,
  "arch_in_name"        => \$arch_in_name,
  "arch-in-name"        => \$arch_in_name,
  "overlay-dir=s"       => \$overlay_dir,
  "pgpsign=s"           => \$signature,
  "key_id=s"            => \$key_id,
  "targets"             => \$targ_opt,
  "rootcmd=s"           => \$root_cmd,
  "us"                  => \$unsign_source,
  "uc"                  => \$unsign_changelog,
  "uimage"              => \$uimage,
  "mkimage=s"           => \$mkimage,
  "jobs|j=i"            => \$concurrency
);
88 89 90

=head1 SYNOPSIS

91
 usage: make-kpkg [options] [target [target ...]]
92 93 94 95 96 97

=cut

=head1 DESCRIPTION

This manual page explains the  Debian  B<make-kpkg>  utility,
98
which  is  used  to create the kernel related Debian pack­
99
ages. This utility needs to be run from a top level  Linux
100
kernel source directory.
101 102 103 104 105 106 107 108 109 110 111 112 113

=cut

=head1 OPTIONS

=over 3

=item B<--help> Print out a usage message.

=item B<--revision> number

=over 2

114 115 116 117 118 119
Sets the Debian revision number for the packages produced to the argument
B<number>. This has certain constraints: It only has an effect during the
configure phase. I suggest you run make-kpkg clean unless you know what you are
doing. Secondly, it must start with a digit, it may contain only alphanumerics
and the characters + . (full stop, and plus) and must contain a digit. B<NOTE>:
No hyphens allowed. (Look at the Debian policy manual for details).
120 121

Optionally, you may prepend the revision with a digit followed by a colon (:)
122 123

This is because  B<dpkg> imposes an ordering on version numbers,
124
so that it can tell whether packages are being up- or downgraded and
125 126 127 128
so that dselect can tell whether a package it finds available is
newer than the one installed on the system.


129 130
=back

131 132
=item B<--append-to-version> foo

133 134 135
=item B<--append_to_version> foo

This argument (B<foo>) is appended to the value of the EXTRAVERSION
136 137
variable present in the kernel Makefile. Since EXTRAVERSION is a
component of the kernel version, it is also added to the Debian
138 139 140 141 142
package name, and, as such must obey the policy governing the package
name. That means it may contain only B<lowercase> alphanumerics and
the characters - + . (full stop, hyphen, and plus). Uppercase letters
are not permitted under the Policy for a new package.

143 144
Please note that you must run a B<make-kpkg clean> after configuring
the kernel using make (x|menu)?config, since that creates
145
include/linux/version.h without the appended version I<foo>.
146

147 148
=back

149 150
=item B<--added-modules> foo

151 152 153 154 155 156 157 158 159 160 161
=item B<--added_modules> foo

=over 2

The argument should be a comma or space separated list of additional
add-on modules (not in the main kernel tree) that you wish to
build when you invoke the modules_blah targets. You may give full path
names of the directory the modules reside in, or just the module name
if it can be found in C<MODULE_LOC>, which defaults to /usr/src/modules.
The default is that all modules in  C<MODULE_LOC> are compiled when
the modules_blah targets are invoked.
162 163 164

=back

165 166 167 168
=item B<--arch> foo

=over 2

169
Sets the architecture. This is mostly useful when cross compiling.
170 171 172

=back

173 174
=item B<--cross-compile> foo

175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
=item B<--cross_compile> foo

=over 2

Sets the target string. This is mostly useful when cross compiling.

=back

=item B<--subarch> foo

=over 2

Some architectures (the Alpha, and the m68k) require a different
kernel for each subarchitecture. This option provides a way of
specifying it as an argument to make-kpkg. Please note that additional
190
support for subarchitectures may be required in the kernel sources to
191 192 193
actually make this do anything.


194 195
=back

196
=item B<--arch-in-name> foo
197

198
=item B<--arch_in_name> foo
199 200 201 202 203 204

=over 2

This option uses an extended name for the kernel image package by
embedding the subarchitecture in the image name, so one could write a
script to create multiple subarchitectures one after the other. You
205
may also do this by setting the environment variable ARCH_IN_NAME.
206

207 208
=back

209 210 211 212 213 214 215 216
=item B<--stem> foo

=over 2

This option determines the stem of the name of the packages. This is
set to C<kernel> by default. You may also do this by setting the
environment variable KPKG_STEM.

217 218 219 220 221 222 223 224 225 226 227
=item B<--pgpsign> name

=over 2

Set the string used to sign the B<changes> file for any external modules
in I</usr/src/modules/> using PGP. This option will override the builtin
default and the site wide customizations stored in the file
I</etc/kernel-pkg.conf>.

=back

228

229 230 231 232 233 234
=item B<--config> I<target>

=over 2

Change the type of configure done from the default C<oldconfig>.
I<target> must be one of C<oldconfig>, C<config>, C<menuconfig>,
235
C<xconfig>, C<gconfig>, C<nconfig>, or C<old>, C<menu>, C<g> or C<x>.
236 237 238

=back

239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256
=item B<--targets>

=over 2

Prints out a list of known targets. See the Section B<Targets> below.

=back

=item B<--noexec>

=over 2

Pass  a  B<-n> option to the I<make> so that commands are merely
printed  to  the  screen  but  not actually  executed.  This is very
useful for debugging.

=back

257 258 259 260 261 262 263 264 265
=item B<--verbose>

=over 2

Pass  a  B<V=1> option to the I<make> so that commands are verbosely
printed  to  the  screen  while executed.  This is very useful for debugging.

=back

266 267 268 269
=item B<--initrd>

=over 2

270
If make-kpkg is generating a linux-image package, perform any actions
271
necessary for a kernel loaded using initrd
272

273
This may include extra dependencies, and modifications to maintainer
274
scripts.  It has no effect when make-kpkg is not making a linux-image
275
package.(The INITRD_OK variable is now obsolete).
276

277 278
=back

279 280
=item B<-j> -I<jobs>, B<--jobs> -I<jobs> Set CONCURRENCY_LEVEL=-I<jobs>

281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303
=item B<--overlay-dir> /path/to/directory

=over 2

The specified directory should contain files that will be placed in
C<./debian> directory of the kernel sources, in preparation to
building the debian packages. The files will replace anything in
C</usr/share/kernel-package> that would normally be placed there, and
it is up to the user to make sure that the files in the overlay
directory are compatible. f you break C<make-kpkg> with an overlay
file, you get to keep the pieces.

Please note that C<overlay-dir/Control> and C<overlay-dir/changelog>
are special, and variable substitution is done on these files.

If a C<overlay-dir/post-install> executable (or executable script)
exists, it shall be run immediately after C<./debian> is
populated. The script shall be executed in the C<./debian>
directory. This can be used, For instance, to delete files the user
does not want, or to take actions other than simple replacement.

=back

304 305 306 307 308 309 310 311
=item B<--uimage>

=over 2

Makes a uImage kernel. Useful for people who want a uImage kernel.

=back

312 313 314 315
=item B<--rootcmd>

=over 2

316 317
The command that provides a means of gaining superuser access (for
example, `sudo' or `fakeroot') as needed by dpkg-buildpackages' C<-r>
318
option.
319 320 321

=back

322 323 324 325 326 327
=item B<--us>

=over 2

This option is passed to dpkg-buildpackage, and directs that package
not to sign the source. This is only relevant to the buildpackage
328
target.
329 330 331 332 333 334 335 336 337

=back

=item B<--uc>

=over 2

This option is passed to dpkg-buildpackage, and directs that package
not to sign the changelog. This is only relevant to the buildpackage
338
target.
339 340 341

=back

342 343
=back

Manoj Srivastava's avatar
Manoj Srivastava committed
344
The options may be shortened to the smallest unique string, and may be
345 346 347
entered with either a - or a -- prefix, and you may use a space or an
= symbol between an option string and a value.  Please refer to man
Getopt::Long for details on how the options may be entered.
348 349 350 351 352

=cut

my $usage = <<"EOUSAGE";
This program should be run in a linux kernel source top level directory.
353
/usr/share/doc/kernel-package/Problems.gz contains a list of known problems.
354 355 356 357

usage: $main::MYNAME [options] target [target ...]
  where options are:
 --help                This message.
358 359
 --revision number     The debian revision number. ([0-9][a-zA-Z.~+0-9]) (Must
                       start with a digit)
360
 --append-to-version foo
361 362
 --append_to_version foo an additional kernel sub-version. ([-a-z.+0-9])
                         Does not require editing the kernel Makefile
363
                         over rides env var APPEND_TO_VERSION.
364
                         requires a make-kpkg clean
365
 --added-modules foo
366
 --added_modules foo   Comma/space separated list of add on modules
367
                       affected by the modules_<blah> targets
368
 --arch     foo        architecture
369
 --cross-compile
370
 --cross_compile       target string
371
 --subarch  bar        Set the subarch for the image being compiled
372
                        (have to be on a compatible machine).
373
 --arch-in-name
374
 --arch_in_name        Embed the subarch in the image package name
375
 --stem     foo        Call the packages foo-* instead of kernel-*
376
 --initrd              Create a image package suitable for initrd.
377 378
 -j         jobs       Sec CONCURRENCY_LEVEL to -I<jobs> for this action.
 --jobs     jobs       Set CONCURRENCY_LEVEL to -I<jobs> for this action.
379
 --pgpsign  name       An ID used to sign the changes file using pgp.
380 381
 --config target       Change the type of configure done from the  default
                       oldconfig.
382
 --targets             Lists the known targets.
383
 --noexec              Pass a -n option to the make process
384
 --overlay dir         An overlay directory to (re))place file in ./debian
385
 --verbose             Pass a V=1 option to the make process
386 387
 --uimage              Create a kernel using uImage rather than zImage
                       or bzImage
388
 --rootcmd method      A command that provides a means of gaining
389 390
                       superuser access (for example, `sudo' or
                       `fakeroot') as needed by dpkg-buildpackages'
391 392
                       -r option. Does not work for targets binary,
                        binary-indep,  and  binary-arch.
393 394 395
 --us                  This option is passed to dpkg-buildpackage, and
                       directs that package not to sign the
                       source. This is only relevant for the
396
                       buildpackage target.
397 398 399
 --uc                  This option is passed to dpkg-buildpackage, and
                       directs that package not to sign the
                       changelog. This is only relevant for the
400
                       buildpackage target.
401

402 403 404 405
Option Format: The options may be shortened to the smallest unique
string, and may be entered with either a - or a -- prefix, and you may
use a space between an option string and a value. Please refer to man
Getopt::Long for details on how the options may be entered.
406 407 408 409 410 411 412 413 414 415 416 417 418

Version: $main::Version
$main::Author <$main::AuthorMail>
EOUSAGE

=head1 TARGETS

=over 3

=item B<clean>

=over 3

419 420 421 422 423 424 425 426
Cleans the kernel source directory of all files created by target B<build>, and
runs a I<make distclean>. (Please look at a Linux kernel Makefile for details).
Please note that although we take care of the list of current kernel
configuration contained in the file I<.config>, the file
I<include/linux/autoconf.h> is not preserved. Please note that by default the
clean target is not run as root, whic works fine of the command I<fakeroot> was
used. However, if previously the build was done using I<sudo>, you need to run
I<make-kpkg clean> also under I<sudo>
427 428 429 430 431 432 433

=back

=item B<buildpackage>

=over 3

434 435
This target runs the targets B<clean>, B<build>, and B<binary>, and
produces the complete package using B<dpkg-buildpackage>.
436 437 438 439 440 441 442

=back

=item B<binary>

=over 3

443 444 445
This target produces all five Debian kernel packages by running the
targets B<kernel_source>, B<kernel_headers>, B<kernel_manual>,
B<kernel_doc> and B<kernel_image>.
446 447 448 449 450 451 452 453

=back

=item B<kernel_source>

=over 3

This target produces a debianised package of the Linux kernel
454
sources.
455 456 457 458 459 460 461 462

=back

=item B<kernel_headers>

=over 3

This target produces a Debian package containing the header files
463
included in the Linux kernel.
464 465 466 467 468 469 470 471

=back

=item B<kernel_doc>

=over 3

This target produces a Debian package containing the documentation
472
included in the Linux kernel.
473 474 475

=back

476 477 478 479 480 481 482 483 484
=item B<kernel_manual>

=over 3

This target produces a Debian package containing the section 9 manual
pages included in the Linux kernel.

=back

485 486 487 488 489 490
=item B<kernel_image>

=over 3

This target produces a Debian package of the Linux kernel source
image, and any modules configured in the kernel configuration file
491 492
I<.config>.  On deletion, the package checks the version of the kernel
running, and refuses to delete a running kernel.
493 494 495

=back

496 497 498 499 500 501 502 503 504
=item B<kernel_debug>

=over 3

This target produces a Debian package of just the debugging symbols
for a linux kernel, and is not meant to be bootable.

=back

505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535
=item B<build>

=over 3

This target, used by target B<kernel_image> above, compiles the Linux
kernel image.

=back

=item B<modules>

=over 3

This target allows you to build all add-on modules and packages that
are very dependent on the precise kernel version they are compiled for
at the same time you build your kernel image.  This target expects to
find the modules or packages under /usr/src/modules, and, for all such
directories, changes to I</usr/src/modules/x>, and runs the B<kdist> rule in
the local I<debian.rules> file.  This target should create the B<Debian>
module package(s), and may also produce a compressed tar file, and a
compressed diff file, with I<md5sums> recorded in a changes file using
B<dpkg-genchanges>.  The file is signed by the same identity that would
be used to sign the kernel packages.

=back

=item B<modules_config>

=over 3

This target allows you to  configure  all  packages under
536
I</usr/src/modules>.
537 538 539 540 541 542 543 544 545 546 547 548 549 550

=back

=item B<modules_image>

=over 3


This target allows you to build all packages under I</usr/src/modules>,
but does not create the source or diff files, and does not create and
sign a changes file.

=back

551 552 553 554 555
=item B<modules_clean>

=over 3


556
This target allows you to clean the modules directories.
557 558 559

=back

560 561 562 563 564
=item B<configure>

=over 3

This target allows people to create the debian directory and create a
565
configuration timestamp, so that any special edits to
566 567 568 569
configuration-generated files are not stomped over later.

=back

570 571 572 573
=back

=cut

574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615
my %Known_targets = (
  "clean"          => 1,
  "buildpackage"   => 1,
  "binary"         => 1,
  "binary-indep"   => 2,
  "debian"         => 1,
  "kernel_source"  => 3,
  "kernel-source"  => 3,
  "linux_source"   => 3,
  "linux-source"   => 3,
  "kernel_headers" => 3,
  "kernel-headers" => 3,
  "linux_headers"  => 3,
  "linux-headers"  => 3,
  "kernel_debug"   => 3,
  "kernel-debug"   => 3,
  "linux_debug"    => 3,
  "linux-debug"    => 3,
  "kernel-manual"  => 3,
  "kernel_manual"  => 3,
  "libc-kheaders"  => 3,
  "kernel_doc"     => 3,
  "kernel-doc"     => 3,
  "linux_doc"      => 3,
  "linux-doc"      => 3,
  "binary-arch"    => 2,
  "kernel_image"   => 3,
  "kernel-image"   => 3,
  "linux_image"    => 3,
  "linux-image"    => 3,
  "build"          => 4,
  "modules"        => 1,
  "modules_image"  => 1,
  "modules_config" => 1,
  "modules_clean"  => 1,
  "modules-image"  => 1,
  "modules-config" => 1,
  "modules-clean"  => 1,
  "configure"      => 1
);

my $targets_help = <<EOTRGT;
616 617 618 619
 Known Targets are:
===============================================================================
|     Targets                      |   Automatically builds                   |
===============================================================================
620 621 622 623
|  clean                           |                                          |
|  buildpackage                    | Builds the whole package                 |
|* binary                          | Builds kernel_{source,headers,image,doc} |
|*      binary-indep               |                                          |
624 625
|            kernel_source         |                                          |
|            kernel_doc            |                                          |
626
|            kernel_manual         |                                          |
627
|*      binary-arch                |                                          |
628
|            kernel_headers        |                                          |
629
|            kernel_debug          |                                          |
630 631 632 633 634
|            kernel_image          | Builds build                             |
|                           build  |                                          |
| modules                          |                                          |
| modules_image                    |                                          |
| modules_config                   |                                          |
635
| modules_clean                    |                                          |
636
| configure                        | If you wish to edit files                |
637
|                           debian | generated by make config                 |
638
| debian                           | Creates ./debian dir                     |
639
===============================================================================
640
 *: make-kpkg needs to be run as root (or fakeroot), --rootcmd will not work
641
See /usr/share/kernel-package/rules for details.
642 643
Also, please note that running clean requires using sudo if sudo had been
used to buikd the image (using sudo is deprecated)
644 645
EOTRGT

646
sub main () {
647 648
  my $ret;
  my $rules_file;
649
  my $alt_rules_file;
650
  my $target;
651
  my $errors  = "";
652
  my $Targets = "";
653

654
  $rules_file     = "debian/rules";
655
  $alt_rules_file = "/usr/share/kernel-package/ruleset/minimal.mk";
656

657
  Getopt::Long::Configure("bundling");
658
  $ret = GetOptions(%option_ctl);
659 660 661
  if ( !$ret ) {
    print "use --help to display command line syntax help.\n";
    exit 1;
662
  }
663 664
  if ( $help_opt || $targ_opt ) {
    print "$usage"        if $help_opt;
665 666 667
    print "$targets_help" if $targ_opt;
    exit 0;
  }
668

669 670 671 672 673 674
  if ( $config_target
    !~ /^(?:|silentold|old|menu|n|x|g|rand|def|all(mod|yes|no))(config)?$/ ) {
    print
      "Config type must be one of {config,silentoldconfig,oldconfig,menuconfig,xconfig,\n";
    print
      " nconfig,gconfig,randconfig,defconfig,allmodconfigallyesconfig,allnoconfig}.\n";
675 676
    print "use --help to display command line syntax help.\n";
    exit 1;
677
  } ## end if ( $config_target !~...)
678
  $config_target = 'config' unless $2;
679

680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701
  if ( $ENV{'MAKEFLAGS'}
    && ( $ENV{'MAKEFLAGS'} =~ /-j/ || $ENV{'MAKEFLAGS'} =~ /--jobs/ ) ) {
    $errors
      .= "The environment variable MAKEFLAGS contains the flag -j.\n"
      . "Unfortunately, this is not supported at this time. Instead, please\n"
      . "use the supported mechanism by setting CONCURRENCY_LEVEL, or the -j flag"
      . "of"
      . $main::MYNAME . "\n";
  } ## end if ( $ENV{'MAKEFLAGS'}...)

  if ( $ENV{'MFLAGS'}
    && ( $ENV{'MFLAGS'} =~ /-j/ || $ENV{'MFLAGS'} =~ /--jobs/ ) ) {
    $errors
      .= "The environment variable MFLAGS contains the flag -j.\n"
      . "Unfortunately, this is not supported at this time. Instead, please\n"
      . "use the supported mechanism by setting CONCURRENCY_LEVEL, or the -j flag"
      . "of"
      . $main::MYNAME . "\n";
  } ## end if ( $ENV{'MFLAGS'} &&...)

  if ( $concurrency > 0 ) {
    $ENV{'CONCURRENCY_LEVEL'} = $concurrency;
702 703
  }

704 705 706 707 708 709 710 711 712 713 714
  if ( $root_cmd || $unsign_source || $unsign_changelog ) {
    if ($root_cmd) {
      if ( $root_cmd =~ m/^-/o ) {
        $errors
          .= "The rootcmd option takes a simple command name\n"
          . "Like sudo or fakeroot. The leading - confuses me.\n"
          . "rejecting rootcmd $root_cmd";
      } ## end if ( $root_cmd =~ m/^-/o)
    } ## end if ($root_cmd)
    my $argstring = join( ' ', @ARGV );
  } ## end if ( $root_cmd || $unsign_source...)
715

716
  # Fine. Now we check targets.
717 718
  foreach $target (@ARGV) {
    if ( $Known_targets{$target} ) {
719 720 721
      $Targets .= "$target ";
    }
    else {
722
      $errors .= "Unknown target $target ";
723
    }
724 725
  } ## end foreach $target (@ARGV)
  if ($errors) {
726
    print STDERR "Error: $errors\n";
727
    print "use --targets to display help on valid targets.\n";
728
    exit 1;
729
  }
730

731
  # See if we are running in a linux kernel directory
732 733 734 735
  if ( ( !( -d "drivers" && -d "kernel" && -d "fs" && -d "include/linux" ) )
    && ( !( -d "dev" && -d "kern" && -d "fs" && -d "i386/include" ) ) ) {
    my @other_targets = grep ( !m/^modules/, @ARGV );
    if ( $#other_targets != -1 || !-d "include/linux" ) {
736
      print STDERR <<EOERR;
737 738
We do not seem to be in a top level linux kernel source directory
tree. Since we are trying to make a kernel package, that does not make
739 740 741 742
sense.  Please change directory to a top level linux kernel source
directory, and try again. (If I am wrong, and this is indeed a top
level linux kernel source directory, then I have gotten sadly out of
date with current kernels, and you should upgrade kernel-package)
743
EOERR
744
      exit 1;
745
    } ## end if ( $#other_targets !=...)
746 747 748 749 750 751 752
    else {
      print STDERR <<EOERR2;
We do not seem to be in a top level linux kernel source directory
tree. However, there are kernel headers that may be suitable to build
external kernel modules. Since you do not have non-module targets, let
us continue.
EOERR2
753 754
    } ## end else [ if ( $#other_targets !=...)]
  } ## end if ( ( !( -d "drivers"...)))
755

756
  if ( !-e "$alt_rules_file" ) {
757 758
    print STDERR <<EOERR1;
    Could not locate the rules file (Normally found at the location
759 760
 /usr/share/kernel-package/rules), which would seem an impossibility.
 I give up.
761
EOERR1
762
    die "Could not find rules file\n";
763
  } ## end if ( !-e "$alt_rules_file")
764

765 766
  if ( $Targets =~ m/^\bclean\b/ ) {
    if ( $Targets !~ m/^\s*clean\s*$/ ) {
767 768 769 770
      print STDERR <<EOERR3;
 The clean target must be called by itself, and not along with other
 targets on the same invocation, since that may cause unforeseen
 errors and complications.  The targets I have been called with are:
771
  $Targets
772 773 774
 I am replacing this list with just the clean target, please retry
 with the clean target on a separate invocation.
EOERR3
775 776 777
      $Targets = "clean";
    } ## end if ( $Targets !~ m/^\s*clean\s*$/)
  } ## end if ( $Targets =~ m/^\bclean\b/)
Manoj Srivastava's avatar
Manoj Srivastava committed
778

779
  # Fine. Just do it!
780
  my $alt_cmd = "make kpkg_version=$main::Version -f $alt_rules_file ";
781
  my $command = "$rules_file ";
782
  if ($signature) {
783
    $command .= "  PGP_SIGNATURE=$signature ";
784
  }
785 786
  if ( $Targets =~ m/^\s*clean\s*$/ ) {
    $alt_cmd .= "clean ";
787 788
  }
  else {
789
    $alt_cmd .= "debian";
790
  }
Manoj Srivastava's avatar
Manoj Srivastava committed
791

792
  if ($revision) {
793 794
    if ( $Targets !~ m/^\s*clean\s*$/ )
    {    # No need to do all this for just clean
795
      $command .= " DEBIAN_REVISION=$revision ";
796
      $alt_cmd .= " DEBIAN_REVISION=$revision ";
797
      if ( $revision !~ m/^(\d+:)?\d[a-zA-Z\d\~\.\+\-]*$/o ) {
798 799 800 801 802 803
        print STDERR " Error: The revision string may only contain\n";
        print STDERR " alphanumerics and  the  characters ~ +  .\n";
        print STDERR " If epochs are used, the colon : is also allowed\n";
        print STDERR " The current value is: $revision\n";
        print STDERR " Aborting.\n";
        exit 1;
804
      } ## end if ( $revision !~ m/^(\d+:)?\d[a-zA-Z\d\~\.\+\-]*$/o)
805 806 807 808 809 810 811

      if ( $revision =~ m/\-/o ) {
        print STDERR
          " I note you are using a hyphen in the revision number.\n";
        print STDERR " Please ensure that the upstream and debian revision\n";
        print STDERR " numbers are policy compliant enough that dpkg and\n";
        print STDERR " shall not choke on them at the end of the compile\n";
812
        if ( $revision !~ m/^(\d+:)?\d[a-zA-Z\d\~\.\+\-]+-\d+[^-]*$/o ) {
813 814 815 816 817 818 819
          die " The revision $revision fails policy compliance, aborting\n";
        }
        else {
          sleep 3;
        }
      } ## end if ( $revision =~ m/\-/o)

820 821
      if ( $revision !~ m/^(\d+:)?\d.*$/ ) {
        print STDERR " Error: The revision string must start with digits,\n";
822 823 824 825
        print STDERR " or else the package creation scripts complain\n";
        print STDERR " The current value is: $revision\n";
        print STDERR " Aborting.\n";
        exit 1;
826
      } ## end if ( $revision !~ m/^(\d+:)?\d.*$/)
827
    } ## end if ( $Targets !~ m/^\s*clean\s*$/)
828 829 830 831 832
    else {
      # No checking, since this is the clean target
      $command .= " DEBIAN_REVISION=$revision ";
      $alt_cmd .= " DEBIAN_REVISION=$revision ";
    }
833
  } ## end if ($revision)
834

835
  if ( $Targets !~ m/^\s*clean\s*$/ ) {
836
    if ($append_to_version) {
837
      if ( $append_to_version !~ m/^[a-z\d\.\-\+]+$/o ) {
838
        print STDERR " Error: The extended version may only contain\n";
839 840
        print STDERR
          " lowercase alphanumerics and  the  characters  - +  .\n";
841 842 843
        print STDERR " The current value is: $append_to_version\n";
        print STDERR " Aborting.\n";
        exit 1;
844 845
      } ## end if ( $append_to_version...)
      if ( $append_to_version =~ m/[A-Z]+/o ) {
846 847 848 849
        print STDERR "Error: Uppercase letters are not allowed in\n";
        print STDERR "the extended version, since the version becomes\n";
        print STDERR "part of the kernel-image name; and package names\n";
        print STDERR "may only contain lowercase alphanumerics.\n";
850 851
        print STDERR
          "I have $append_to_version, which shall be disallowed \n";
852 853
        print STDERR "by the packaging tools. Aborting.\n";
        exit 1;
854
      } ## end if ( $append_to_version...)
855

856
      $command .= " APPEND_TO_VERSION=$append_to_version ";
857
      $alt_cmd .= " APPEND_TO_VERSION=$append_to_version ";
858 859
    } ## end if ($append_to_version)
  } ## end if ( $Targets !~ m/^\s*clean\s*$/)
860

861
  if ($arch) {
862
    $command .= " KPKG_ARCH=$arch ";
863
    $alt_cmd .= " KPKG_ARCH=$arch  ";
864
  }
865
  if ( $config_target ne 'oldconfig' ) {
866
    $command .= " CONFIG_TARGET=$config_target ";
867
    $alt_cmd .= " CONFIG_TARGET=$config_target ";
868
  }
869
  if ($cross_compile) {
870
    $command .= " CROSS_COMPILE=$cross_compile ";
871
    $alt_cmd .= " CROSS_COMPILE=$cross_compile ";
872
  }
873
  if ($subarch) {
874
    $command .= " KPKG_SUBARCH=$subarch ";
875
    $alt_cmd .= " KPKG_SUBARCH=$subarch ";
876
  }
877 878 879 880
  if ($overlay_dir) {
    $command .= " KPKG_OVERLAY_DIR=\"$overlay_dir\" ";
    $alt_cmd .= " KPKG_OVERLAY_DIR=\"$overlay_dir\" ";
  }
881
  if ($added_modules) {
882
    $command .= " KPKG_SELECTED_MODULES=\"$added_modules\" ";
883
    $alt_cmd .= " KPKG_SELECTED_MODULES=\"$added_modules\" ";
884
  }
885
  if ($arch_in_name) {
886
    $command .= " ARCH_IN_NAME=YES ";
887
    $alt_cmd .= " ARCH_IN_NAME=YES ";
888
  }
889
  if ($stem) {
890 891 892 893 894 895 896 897 898
    if ( !$stem =~ m/[a-z0-9][a-z0-9\.\+\-]+/ ) {
      print STDERR
        "The stem, since it is the initial part of a package name\n";
      print STDERR
        "must consist only of lower case letters (`a-z'), digits\n";
      print STDERR
        "(`0-9'), plus (`+') and minus (`-') signs, and periods \n";
      print STDERR
        "(`.').  It must be at least two characters long and must\n";
899 900 901
      print STDERR "start with an alphanumeric character\n";
      print STDERR "$stem does not match the criteria.\n";
      die "Illegal stem option.\n";
902
    } ## end if ( !$stem =~ m/[a-z0-9][a-z0-9\.\+\-]+/)
903
    $command .= " KPKG_STEM=$stem ";
904
    $alt_cmd .= " KPKG_STEM=$stem ";
905 906
  } ## end if ($stem)
  if ($noexec) {
907
    $command .= " -n ";
908
    $alt_cmd .= " -n ";
909
  }
910
  if ($verbose) {
911
    $command .= " V=1 ";
912
    $alt_cmd .= " V=1 ";
913
  }
914
  if ($initrd) {
915
    $command .= " INITRD=YES ";
916
    $alt_cmd .= " INITRD=YES ";
917
  }
918 919 920
  if ($root_cmd) {
    $command .= " ROOT_CMD=$root_cmd ";
    $alt_cmd .= " ROOT_CMD=$root_cmd ";
921
  }
922
  if ($unsign_changelog) {
923 924
    $command .= " UNSIGN_CHANGELOG=YES ";
  }
925
  if ($unsign_source) {
926 927
    $command .= " UNSIGN_SOURCE=YES ";
  }
928
  if ($uimage) {
929 930
    $command .= " IMAGE_TYPE=uImage ";
  }
931

932 933 934
  my $hostcc = $ENV{'HOSTCC'} if $ENV{'HOSTCC'};
  $hostcc =~ s/^\s+//g if $hostcc;
  $hostcc =~ s/\s+$//g if $hostcc;
935
  $hostcc .= " ";
936
  if ( $hostcc eq " " ) { $hostcc = "gcc"; }
937

938 939 940
  my $cc = $ENV{'CC'} if $ENV{'CC'};
  $cc =~ s/^\s+//g if $cc;
  $cc =~ s/\s+$//g if $cc;
941
  $cc .= " ";
942
  if ( $cc eq ' ' ) { $cc = $cross_compile; $cc .= "gcc "; }
943

944 945 946
  #$cc .= " -D__KERNEL__ -I";
  #chomp($cc .= `pwd`);
  #$cc .= "/include";
947

948 949
  # For some reason, this causes all modules to fail
  #$command .= " CC=\"$cc\" HOSTCC=\"$hostcc\"";
950
  $command .= " $Targets";
951

952
  # print STDERR $command;
953

954
  # OK. Time to get rid of ./debian
955 956
  if ( -d "./debian" ) {
    rmtree( ['debian'], 0, 1 );
957 958 959
  }

  # Now, recreate ./debian
960
  if ( "$alt_cmd" !~ /^\s*$/ ) {
961
    print STDERR "exec $alt_cmd\n";
962 963
    if ( $Targets =~ m/^\s*clean\s*$/ || $Targets =~ m/^\s*debian\s*$/ ) {

964 965 966 967 968 969
      # There is no ./debian, and we do need to preserve .config, and so on
      exec $alt_cmd;
    }
    else {
      # We call system, and not exec, since we are just creating a
      # ./debian dir here, _then_ we go and do the real command.
970
      system($alt_cmd) == 0
971
        or die "Failed to create a ./debian directory: $!";
972 973 974
    } ## end else [ if ( $Targets =~ m/^\s*clean\s*$/...)]
  } ## end if ( "$alt_cmd" !~ /^\s*$/)

975
  # ./debian/rules had better be present now
976
  if ( !-x "$rules_file" ) {
977 978 979 980 981 982
    print STDERR <<EOERR19;
    Could not locate the rules file (Normally found at the location
 $rules_file), which would seem an
 impossibility. I give up.
EOERR19
    die "Could not find rules file\n";
983
  } ## end if ( !-x "$rules_file")
984
  print STDERR "exec $command\n";
985
  exec $command;
986
} ## end sub main
987 988 989 990 991 992 993 994 995 996 997 998 999 1000

## Now just call main
&main();

=head1 FILES

Apart from the runtime options, the debian.rules file run by B<make-kpkg>
also looks for site-wide defaults in the file I</etc/kernel-pkg.conf>.
The default configuration allows there to be a site wide override for
the full name and email address of the person responsible for
maintaining the kernel packages on the site, but the
I</etc/kernel-pkg.conf> file is actually a I<Makefile> snippet, and any
legal make directives may be included in there.  B<Note>: Caution is
urged with this file, since you can totally change the way that the
1001
make is run by suitably editing this file. Please look at
1002 1003
I</usr/share/doc/kernel-package/Problems.gz> for a list of known
problems while compiling kernel images.
1004 1005 1006 1007 1008 1009

=cut

=head1 B<SEE ALSO>

B<kernel-pkg.conf>(5), B<dpkg-deb>(1), B<dpkg-source>(1),  B<make>(1),
1010
B<The GNU Make manual>, and the extensive documentation in the
1011
directory I</usr/share/doc/kernel-package/>
1012 1013 1014 1015 1016

=cut

=head1 BUGS

1017
None known so far.
1018 1019 1020 1021 1022 1023

=cut

=head1 AUTHOR

This  was  written by Manoj Srivastava <srivasta@debian.org>, for the
1024
Debian GNU/Linux system.
1025 1026 1027 1028 1029

=cut

exit 0;
__END__