linux-bk/Makefile
<<
>>
Prefs
   1VERSION = 2
   2PATCHLEVEL = 6
   3SUBLEVEL = 1
   4EXTRAVERSION =
   5
   6# *DOCUMENTATION*
   7# To see a list of typical targets execute "make help"
   8# More info can be located in ./README
   9# Comments in this file are targeted only to the developer, do not
  10# expect to learn how to build the kernel reading this file.
  11
  12# Do not print "Entering directory ..."
  13MAKEFLAGS += --no-print-directory
  14
  15# We are using a recursive build, so we need to do a little thinking
  16# to get the ordering right.
  17#
  18# Most importantly: sub-Makefiles should only ever modify files in
  19# their own directory. If in some directory we have a dependency on
  20# a file in another dir (which doesn't happen often, but it's of
  21# unavoidable when linking the built-in.o targets which finally
  22# turn into vmlinux), we will call a sub make in that other dir, and
  23# after that we are sure that everything which is in that other dir
  24# is now up to date.
  25#
  26# The only cases where we need to modify files which have global
  27# effects are thus separated out and done before the recursive
  28# descending is started. They are now explicitly listed as the
  29# prepare rule.
  30
  31# To put more focus on warnings, be less verbose as default
  32# Use 'make V=1' to see the full commands
  33
  34ifdef V
  35  ifeq ("$(origin V)", "command line")
  36    KBUILD_VERBOSE = $(V)
  37  endif
  38endif
  39ifndef KBUILD_VERBOSE
  40  KBUILD_VERBOSE = 0
  41endif
  42
  43# Call sparse as part of compilation of C files
  44# Use 'make C=1' to enable sparse checking
  45
  46ifdef C
  47  ifeq ("$(origin C)", "command line")
  48    KBUILD_CHECKSRC = $(C)
  49  endif
  50endif
  51ifndef KBUILD_CHECKSRC
  52  KBUILD_CHECKSRC = 0
  53endif
  54
  55# kbuild supports saving output files in a separate directory.
  56# To locate output files in a separate directory two syntax'es are supported.
  57# In both cases the working directory must be the root of the kernel src.
  58# 1) O=
  59# Use "make O=dir/to/store/output/files/"
  60# 
  61# 2) Set KBUILD_OUTPUT
  62# Set the environment variable KBUILD_OUTPUT to point to the directory
  63# where the output files shall be placed.
  64# export KBUILD_OUTPUT=dir/to/store/output/files/
  65# make
  66#
  67# The O= assigment takes precedence over the KBUILD_OUTPUT environment variable.
  68
  69
  70# KBUILD_SRC is set on invocation of make in OBJ directory
  71# KBUILD_SRC is not intended to be used by the regular user (for now)
  72ifeq ($(KBUILD_SRC),)
  73
  74# OK, Make called in directory where kernel src resides
  75# Do we want to locate output files in a separate directory?
  76ifdef O
  77  ifeq ("$(origin O)", "command line")
  78    KBUILD_OUTPUT := $(O)
  79  endif
  80endif
  81
  82# That's our default target when none is given on the command line
  83.PHONY: all
  84all:
  85  
  86ifneq ($(KBUILD_OUTPUT),)
  87# Invoke a second make in the output directory, passing relevant variables
  88# check that the output directory actually exists
  89saved-output := $(KBUILD_OUTPUT)
  90KBUILD_OUTPUT := $(shell cd $(KBUILD_OUTPUT) && /bin/pwd)
  91$(if $(wildcard $(KBUILD_OUTPUT)),, \
  92     $(error output directory "$(saved-output)" does not exist))
  93
  94.PHONY: $(MAKECMDGOALS)
  95
  96$(filter-out all,$(MAKECMDGOALS)) all:
  97        $(if $(KBUILD_VERBOSE:1=),@)$(MAKE) -C $(KBUILD_OUTPUT)         \
  98        KBUILD_SRC=$(CURDIR)    KBUILD_VERBOSE=$(KBUILD_VERBOSE)        \
  99        KBUILD_CHECK=$(KBUILD_CHECK) -f $(CURDIR)/Makefile $@
 100
 101# Leave processing to above invocation of make
 102skip-makefile := 1
 103endif # ifneq ($(KBUILD_OUTPUT),)
 104endif # ifeq ($(KBUILD_SRC),)
 105
 106# We process the rest of the Makefile if this is the final invocation of make
 107ifeq ($(skip-makefile),)
 108
 109srctree         := $(if $(KBUILD_SRC),$(KBUILD_SRC),$(CURDIR))
 110TOPDIR          := $(srctree)
 111# FIXME - TOPDIR is obsolete, use srctree/objtree
 112objtree         := $(CURDIR)
 113src             := $(srctree)
 114obj             := $(objtree)
 115
 116VPATH           := $(srctree)
 117
 118export srctree objtree VPATH TOPDIR
 119
 120KERNELRELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
 121
 122# SUBARCH tells the usermode build what the underlying arch is.  That is set
 123# first, and if a usermode build is happening, the "ARCH=um" on the command
 124# line overrides the setting of ARCH below.  If a native build is happening,
 125# then ARCH is assigned, getting whatever value it gets normally, and 
 126# SUBARCH is subsequently ignored.
 127
 128SUBARCH := $(shell uname -m | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ \
 129                                  -e s/arm.*/arm/ -e s/sa110/arm/ \
 130                                  -e s/s390x/s390/ -e s/parisc64/parisc/ )
 131
 132# Cross compiling and selecting different set of gcc/bin-utils
 133# ---------------------------------------------------------------------------
 134#
 135# When performing cross compilation for other architectures ARCH shall be set
 136# to the target architecture. (See arch/* for the possibilities).
 137# ARCH can be set during invocation of make:
 138# make ARCH=ia64
 139# Another way is to have ARCH set in the environment.
 140# The default ARCH is the host where make is executed.
 141
 142# CROSS_COMPILE specify the prefix used for all executables used
 143# during compilation. Only gcc and related bin-utils executables
 144# are prefixed with $(CROSS_COMPILE).
 145# CROSS_COMPILE can be set on the command line
 146# make CROSS_COMPILE=ia64-linux-
 147# Alternatively CROSS_COMPILE can be set in the environment.
 148# Default value for CROSS_COMPILE is not to prefix executables
 149# Note: Some architectures assign CROSS_COMPILE in their arch/*/Makefile
 150
 151ARCH            ?= $(SUBARCH)
 152CROSS_COMPILE   ?=
 153
 154# Architecture as present in compile.h
 155UTS_MACHINE := $(ARCH)
 156
 157# SHELL used by kbuild
 158CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
 159          else if [ -x /bin/bash ]; then echo /bin/bash; \
 160          else echo sh; fi ; fi)
 161
 162HOSTCC          = gcc
 163HOSTCXX         = g++
 164HOSTCFLAGS      = -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer
 165HOSTCXXFLAGS    = -O2
 166
 167#       Decide whether to build built-in, modular, or both.
 168#       Normally, just do built-in.
 169
 170KBUILD_MODULES :=
 171KBUILD_BUILTIN := 1
 172
 173#       If we have only "make modules", don't compile built-in objects.
 174#       When we're building modules with modversions, we need to consider
 175#       the built-in objects during the descend as well, in order to
 176#       make sure the checksums are uptodate before we record them.
 177
 178ifeq ($(MAKECMDGOALS),modules)
 179  KBUILD_BUILTIN := $(if $(CONFIG_MODVERSIONS),1)
 180endif
 181
 182#       If we have "make <whatever> modules", compile modules
 183#       in addition to whatever we do anyway.
 184#       Just "make" or "make all" shall build modules as well
 185
 186ifneq ($(filter all modules,$(MAKECMDGOALS)),)
 187  KBUILD_MODULES := 1
 188endif
 189
 190ifeq ($(MAKECMDGOALS),)
 191  KBUILD_MODULES := 1
 192endif
 193
 194export KBUILD_MODULES KBUILD_BUILTIN KBUILD_VERBOSE
 195export KBUILD_CHECKSRC KBUILD_SRC
 196
 197# Beautify output
 198# ---------------------------------------------------------------------------
 199#
 200# Normally, we echo the whole command before executing it. By making
 201# that echo $($(quiet)$(cmd)), we now have the possibility to set
 202# $(quiet) to choose other forms of output instead, e.g.
 203#
 204#         quiet_cmd_cc_o_c = Compiling $(RELDIR)/$@
 205#         cmd_cc_o_c       = $(CC) $(c_flags) -c -o $@ $<
 206#
 207# If $(quiet) is empty, the whole command will be printed.
 208# If it is set to "quiet_", only the short version will be printed. 
 209# If it is set to "silent_", nothing wil be printed at all, since
 210# the variable $(silent_cmd_cc_o_c) doesn't exist.
 211#
 212# A simple variant is to prefix commands with $(Q) - that's usefull
 213# for commands that shall be hidden in non-verbose mode.
 214#
 215#       $(Q)ln $@ :<
 216#
 217# If KBUILD_VERBOSE equals 0 then the above command will be hidden.
 218# If KBUILD_VERBOSE equals 1 then the above command is displayed.
 219
 220ifeq ($(KBUILD_VERBOSE),1)
 221  quiet =
 222  Q =
 223else
 224  quiet=quiet_
 225  Q = @
 226endif
 227
 228# If the user is running make -s (silent mode), suppress echoing of
 229# commands
 230
 231ifneq ($(findstring s,$(MAKEFLAGS)),)
 232  quiet=silent_
 233endif
 234
 235check_gcc = $(shell if $(CC) $(CFLAGS) $(1) -S -o /dev/null -xc /dev/null > /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi ;)
 236
 237export quiet Q KBUILD_VERBOSE check_gcc
 238
 239# Look for make include files relative to root of kernel src
 240MAKEFLAGS += --include-dir=$(srctree)
 241
 242# For maximum performance (+ possibly random breakage, uncomment
 243# the following)
 244
 245#MAKEFLAGS += -rR
 246
 247# Make variables (CC, etc...)
 248
 249AS              = $(CROSS_COMPILE)as
 250LD              = $(CROSS_COMPILE)ld
 251CC              = $(CROSS_COMPILE)gcc
 252CPP             = $(CC) -E
 253AR              = $(CROSS_COMPILE)ar
 254NM              = $(CROSS_COMPILE)nm
 255STRIP           = $(CROSS_COMPILE)strip
 256OBJCOPY         = $(CROSS_COMPILE)objcopy
 257OBJDUMP         = $(CROSS_COMPILE)objdump
 258AWK             = awk
 259RPM             := $(shell if [ -x "/usr/bin/rpmbuild" ]; then echo rpmbuild; \
 260                        else echo rpm; fi)
 261GENKSYMS        = scripts/genksyms/genksyms
 262DEPMOD          = /sbin/depmod
 263KALLSYMS        = scripts/kallsyms
 264PERL            = perl
 265CHECK           = sparse
 266MODFLAGS        = -DMODULE
 267CFLAGS_MODULE   = $(MODFLAGS)
 268AFLAGS_MODULE   = $(MODFLAGS)
 269LDFLAGS_MODULE  = -r
 270CFLAGS_KERNEL   =
 271AFLAGS_KERNEL   =
 272
 273NOSTDINC_FLAGS  = -nostdinc -iwithprefix include
 274
 275CPPFLAGS        := -D__KERNEL__ -Iinclude \
 276                   $(if $(KBUILD_SRC),-Iinclude2 -I$(srctree)/include)
 277
 278CFLAGS          := -Wall -Wstrict-prototypes -Wno-trigraphs \
 279                   -fno-strict-aliasing -fno-common
 280AFLAGS          := -D__ASSEMBLY__
 281
 282export  VERSION PATCHLEVEL SUBLEVEL EXTRAVERSION KERNELRELEASE ARCH \
 283        CONFIG_SHELL HOSTCC HOSTCFLAGS CROSS_COMPILE AS LD CC \
 284        CPP AR NM STRIP OBJCOPY OBJDUMP MAKE AWK GENKSYMS PERL UTS_MACHINE \
 285        HOSTCXX HOSTCXXFLAGS LDFLAGS_BLOB LDFLAGS_MODULE CHECK
 286
 287export CPPFLAGS NOSTDINC_FLAGS OBJCOPYFLAGS LDFLAGS
 288export CFLAGS CFLAGS_KERNEL CFLAGS_MODULE 
 289export AFLAGS AFLAGS_KERNEL AFLAGS_MODULE
 290
 291export MODVERDIR := .tmp_versions
 292
 293# The temporary file to save gcc -MD generated dependencies must not
 294# contain a comma
 295comma := ,
 296depfile = $(subst $(comma),_,$(@D)/.$(@F).d)
 297
 298# Files to ignore in find ... statements
 299
 300RCS_FIND_IGNORE := \( -name SCCS -o -name BitKeeper -o -name .svn -o -name CVS \) -prune -o
 301RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn --exclude CVS
 302
 303# ===========================================================================
 304# Rules shared between *config targets and build targets
 305
 306# Helpers built in scripts/
 307
 308scripts/docproc scripts/split-include : scripts ;
 309
 310.PHONY: scripts scripts/fixdep
 311scripts:
 312        $(Q)$(MAKE) $(build)=scripts
 313
 314scripts/fixdep:
 315        $(Q)$(MAKE) $(build)=scripts $@
 316
 317
 318# To make sure we do not include .config for any of the *config targets
 319# catch them early, and hand them over to scripts/kconfig/Makefile
 320# It is allowed to specify more targets when calling make, including
 321# mixing *config targets and build targets.
 322# For example 'make oldconfig all'. 
 323# Detect when mixed targets is specified, and make a second invocation
 324# of make so .config is not included in this case either (for *config).
 325
 326no-dot-config-targets := clean mrproper distclean \
 327                         cscope TAGS tags help %docs check%
 328
 329config-targets := 0
 330mixed-targets  := 0
 331dot-config     := 1
 332
 333ifneq ($(filter $(no-dot-config-targets), $(MAKECMDGOALS)),)
 334        ifeq ($(filter-out $(no-dot-config-targets), $(MAKECMDGOALS)),)
 335                dot-config := 0
 336        endif
 337endif
 338
 339ifneq ($(filter config %config,$(MAKECMDGOALS)),)
 340        config-targets := 1
 341        ifneq ($(filter-out config %config,$(MAKECMDGOALS)),)
 342                mixed-targets := 1
 343        endif
 344endif
 345
 346ifeq ($(mixed-targets),1)
 347# ===========================================================================
 348# We're called with mixed targets (*config and build targets).
 349# Handle them one by one.
 350
 351%:: FORCE
 352        $(Q)$(MAKE) -C $(srctree) KBUILD_SRC= $@
 353
 354else
 355ifeq ($(config-targets),1)
 356# ===========================================================================
 357# *config targets only - make sure prerequisites are updated, and descend
 358# in scripts/kconfig to make the *config target
 359
 360%config: scripts/fixdep FORCE
 361        $(Q)$(MAKE) $(build)=scripts/kconfig $@
 362config : scripts/fixdep FORCE
 363        $(Q)$(MAKE) $(build)=scripts/kconfig $@
 364
 365else
 366# ===========================================================================
 367# Build targets only - this includes vmlinux, arch specific targets, clean
 368# targets and others. In general all targets except *config targets.
 369
 370# That's our default target when none is given on the command line
 371# Note that 'modules' will be added as a prerequisite as well, 
 372# in the CONFIG_MODULES part below
 373
 374all:    vmlinux
 375
 376# Objects we will link into vmlinux / subdirs we need to visit
 377init-y          := init/
 378drivers-y       := drivers/ sound/
 379net-y           := net/
 380libs-y          := lib/
 381core-y          := usr/
 382SUBDIRS         :=
 383
 384ifeq ($(dot-config),1)
 385# In this section, we need .config
 386
 387# Read in dependencies to all Kconfig* files, make sure to run
 388# oldconfig if changes are detected.
 389-include .config.cmd
 390
 391include .config
 392
 393# If .config needs to be updated, it will be done via the dependency
 394# that autoconf has on .config.
 395# To avoid any implicit rule to kick in, define an empty command
 396.config: ;
 397
 398# If .config is newer than include/linux/autoconf.h, someone tinkered
 399# with it and forgot to run make oldconfig
 400include/linux/autoconf.h: .config
 401        $(Q)$(MAKE) -f $(srctree)/Makefile silentoldconfig
 402
 403endif
 404
 405include $(srctree)/arch/$(ARCH)/Makefile
 406
 407# Let architecture Makefiles change CPPFLAGS if needed
 408CFLAGS := $(CPPFLAGS) $(CFLAGS)
 409AFLAGS := $(CPPFLAGS) $(AFLAGS)
 410
 411core-y          += kernel/ mm/ fs/ ipc/ security/ crypto/
 412
 413SUBDIRS         += $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
 414                     $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
 415                     $(net-y) $(net-m) $(libs-y) $(libs-m)))
 416
 417ALL_SUBDIRS     := $(sort $(SUBDIRS) $(patsubst %/,%,$(filter %/, \
 418                     $(init-n) $(init-) \
 419                     $(core-n) $(core-) $(drivers-n) $(drivers-) \
 420                     $(net-n)  $(net-)  $(libs-n)    $(libs-))))
 421
 422init-y          := $(patsubst %/, %/built-in.o, $(init-y))
 423core-y          := $(patsubst %/, %/built-in.o, $(core-y))
 424drivers-y       := $(patsubst %/, %/built-in.o, $(drivers-y))
 425net-y           := $(patsubst %/, %/built-in.o, $(net-y))
 426libs-y1         := $(patsubst %/, %/lib.a, $(libs-y))
 427libs-y2         := $(patsubst %/, %/built-in.o, $(libs-y))
 428libs-y          := $(libs-y1) $(libs-y2)
 429
 430# Here goes the main Makefile
 431# ---------------------------------------------------------------------------
 432
 433
 434ifdef CONFIG_CC_OPTIMIZE_FOR_SIZE
 435CFLAGS          += -Os
 436else
 437CFLAGS          += -O2
 438endif
 439
 440ifndef CONFIG_FRAME_POINTER
 441CFLAGS          += -fomit-frame-pointer
 442endif
 443
 444ifdef CONFIG_DEBUG_INFO
 445CFLAGS          += -g
 446endif
 447
 448# warn about C99 declaration after statement
 449CFLAGS += $(call check_gcc,-Wdeclaration-after-statement,)
 450
 451#
 452# INSTALL_PATH specifies where to place the updated kernel and system map
 453# images.  Uncomment if you want to place them anywhere other than root.
 454#
 455
 456#export INSTALL_PATH=/boot
 457
 458#
 459# INSTALL_MOD_PATH specifies a prefix to MODLIB for module directory
 460# relocations required by build roots.  This is not defined in the
 461# makefile but the arguement can be passed to make if needed.
 462#
 463
 464MODLIB  := $(INSTALL_MOD_PATH)/lib/modules/$(KERNELRELEASE)
 465export MODLIB
 466
 467# Build vmlinux
 468# ---------------------------------------------------------------------------
 469
 470#       This is a bit tricky: If we need to relink vmlinux, we want
 471#       the version number incremented, which means recompile init/version.o
 472#       and relink init/init.o. However, we cannot do this during the
 473#       normal descending-into-subdirs phase, since at that time
 474#       we cannot yet know if we will need to relink vmlinux.
 475#       So we descend into init/ inside the rule for vmlinux again.
 476head-y += $(HEAD)
 477vmlinux-objs := $(head-y) $(init-y) $(core-y) $(libs-y) $(drivers-y) $(net-y)
 478
 479quiet_cmd_vmlinux__ = LD      $@
 480define cmd_vmlinux__
 481        $(LD) $(LDFLAGS) $(LDFLAGS_vmlinux) $(head-y) $(init-y) \
 482        --start-group \
 483        $(core-y) \
 484        $(libs-y) \
 485        $(drivers-y) \
 486        $(net-y) \
 487        --end-group \
 488        $(filter .tmp_kallsyms%,$^) \
 489        -o $@
 490endef
 491
 492#       set -e makes the rule exit immediately on error
 493
 494define rule_vmlinux__
 495        +set -e;                                                        \
 496        $(if $(filter .tmp_kallsyms%,$^),,                              \
 497          echo '  GEN     .version';                                    \
 498          . $(srctree)/scripts/mkversion > .tmp_version;                \
 499          mv -f .tmp_version .version;                                  \
 500          $(MAKE) $(build)=init;                                        \
 501        )                                                               \
 502        $(if $($(quiet)cmd_vmlinux__),                                  \
 503          echo '  $($(quiet)cmd_vmlinux__)' &&)                         \
 504        $(cmd_vmlinux__);                                               \
 505        echo 'cmd_$@ := $(cmd_vmlinux__)' > $(@D)/.$(@F).cmd
 506endef
 507
 508define rule_vmlinux
 509        $(rule_vmlinux__); \
 510        $(NM) $@ | grep -v '\(compiled\)\|\(\.o$$\)\|\( [aUw] \)\|\(\.\.ng$$\)\|\(LASH[RL]DI\)' | sort > System.map
 511endef
 512
 513LDFLAGS_vmlinux += -T arch/$(ARCH)/kernel/vmlinux.lds.s
 514
 515#       Generate section listing all symbols and add it into vmlinux
 516#       It's a three stage process:
 517#       o .tmp_vmlinux1 has all symbols and sections, but __kallsyms is
 518#         empty
 519#         Running kallsyms on that gives us .tmp_kallsyms1.o with
 520#         the right size
 521#       o .tmp_vmlinux2 now has a __kallsyms section of the right size,
 522#         but due to the added section, some addresses have shifted
 523#         From here, we generate a correct .tmp_kallsyms2.o
 524#       o The correct .tmp_kallsyms2.o is linked into the final vmlinux.
 525
 526ifdef CONFIG_KALLSYMS
 527
 528kallsyms.o := .tmp_kallsyms2.o
 529
 530quiet_cmd_kallsyms = KSYM    $@
 531cmd_kallsyms = $(NM) -n $< | $(KALLSYMS) > $@
 532
 533.tmp_kallsyms1.o .tmp_kallsyms2.o: %.o: %.S scripts FORCE
 534        $(call if_changed_dep,as_o_S)
 535
 536.tmp_kallsyms%.S: .tmp_vmlinux%
 537        $(call cmd,kallsyms)
 538
 539.tmp_vmlinux1: $(vmlinux-objs) arch/$(ARCH)/kernel/vmlinux.lds.s FORCE
 540        +$(call if_changed_rule,vmlinux__)
 541
 542.tmp_vmlinux2: $(vmlinux-objs) .tmp_kallsyms1.o arch/$(ARCH)/kernel/vmlinux.lds.s FORCE
 543        $(call if_changed_rule,vmlinux__)
 544
 545endif
 546
 547#       Finally the vmlinux rule
 548
 549vmlinux: $(vmlinux-objs) $(kallsyms.o) arch/$(ARCH)/kernel/vmlinux.lds.s FORCE
 550        $(call if_changed_rule,vmlinux)
 551
 552#       The actual objects are generated when descending, 
 553#       make sure no implicit rule kicks in
 554
 555$(sort $(vmlinux-objs)) arch/$(ARCH)/kernel/vmlinux.lds.s: $(SUBDIRS) ;
 556
 557#       Handle descending into subdirectories listed in $(SUBDIRS)
 558
 559.PHONY: $(SUBDIRS)
 560$(SUBDIRS): prepare-all
 561        $(Q)$(MAKE) $(build)=$@
 562
 563# Things we need to do before we recursively start building the kernel
 564# or the modules are listed in "prepare-all".
 565# A multi level approach is used. prepare1 is updated first, then prepare0.
 566# prepare-all is the collection point for the prepare targets.
 567
 568.PHONY: prepare-all prepare prepare0 prepare1
 569
 570# prepare1 is used to check if we are building in a separate output directory,
 571# and if so do:
 572# 1) Check that make has not been executed in the kernel src $(srctree)
 573# 2) Create the include2 directory, used for the second asm symlink
 574
 575prepare1:
 576ifneq ($(KBUILD_SRC),)
 577        @echo '  Using $(srctree) as source for kernel'
 578        $(Q)if [ -h $(srctree)/include/asm -o -f $(srctree)/.config ]; then \
 579                echo "  $(srctree) is not clean, please run 'make mrproper'";\
 580                echo "  in the '$(srctree)' directory.";\
 581                /bin/false; \
 582        fi;
 583        $(Q)if [ ! -d include2 ]; then mkdir -p include2; fi;
 584        $(Q)ln -fsn $(srctree)/include/asm-$(ARCH) include2/asm
 585endif
 586
 587prepare0: prepare1 include/linux/version.h include/asm include/config/MARKER
 588ifdef KBUILD_MODULES
 589ifeq ($(origin SUBDIRS),file)
 590        $(Q)rm -rf $(MODVERDIR)
 591else
 592        @echo '*** Warning: Overriding SUBDIRS on the command line can cause'
 593        @echo '***          inconsistencies'
 594endif
 595endif
 596        $(if $(CONFIG_MODULES),$(Q)mkdir -p $(MODVERDIR))
 597
 598# All the preparing..
 599prepare-all: prepare0 prepare
 600
 601#       Leave this as default for preprocessing vmlinux.lds.S, which is now
 602#       done in arch/$(ARCH)/kernel/Makefile
 603
 604export AFLAGS_vmlinux.lds.o += -P -C -U$(ARCH)
 605
 606# Single targets
 607# ---------------------------------------------------------------------------
 608
 609%.s: %.c scripts FORCE
 610        $(Q)$(MAKE) $(build)=$(@D) $@
 611%.i: %.c scripts FORCE
 612        $(Q)$(MAKE) $(build)=$(@D) $@
 613%.o: %.c scripts FORCE
 614        $(Q)$(MAKE) $(build)=$(@D) $@
 615%/:      scripts prepare FORCE
 616        $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) $(build)=$(@D)
 617%.lst: %.c scripts FORCE
 618        $(Q)$(MAKE) $(build)=$(@D) $@
 619%.s: %.S scripts FORCE
 620        $(Q)$(MAKE) $(build)=$(@D) $@
 621%.o: %.S scripts FORCE
 622        $(Q)$(MAKE) $(build)=$(@D) $@
 623
 624#       FIXME: The asm symlink changes when $(ARCH) changes. That's
 625#       hard to detect, but I suppose "make mrproper" is a good idea
 626#       before switching between archs anyway.
 627
 628include/asm:
 629        @echo '  SYMLINK $@ -> include/asm-$(ARCH)'
 630        $(Q)if [ ! -d include ]; then mkdir -p include; fi;
 631        @ln -fsn asm-$(ARCH) $@
 632
 633#       Split autoconf.h into include/linux/config/*
 634
 635include/config/MARKER: scripts/split-include include/linux/autoconf.h
 636        @echo '  SPLIT   include/linux/autoconf.h -> include/config/*'
 637        @scripts/split-include include/linux/autoconf.h include/config
 638        @touch $@
 639
 640# Generate some files
 641# ---------------------------------------------------------------------------
 642
 643#       version.h changes when $(KERNELRELEASE) etc change, as defined in
 644#       this Makefile
 645
 646uts_len := 64
 647
 648define filechk_version.h
 649        if expr length "$(KERNELRELEASE)" \> $(uts_len) >/dev/null ; then \
 650          echo '"$(KERNELRELEASE)" exceeds $(uts_len) characters' >&2; \
 651          exit 1; \
 652        fi; \
 653        (echo \#define UTS_RELEASE \"$(KERNELRELEASE)\"; \
 654          echo \#define LINUX_VERSION_CODE `expr $(VERSION) \\* 65536 + $(PATCHLEVEL) \\* 256 + $(SUBLEVEL)`; \
 655         echo '#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))'; \
 656        )
 657endef
 658
 659include/linux/version.h: Makefile
 660        $(call filechk,version.h)
 661
 662# ---------------------------------------------------------------------------
 663
 664.PHONY: depend dep
 665depend dep:
 666        @echo '*** Warning: make $@ is unnecessary now.'
 667
 668# ---------------------------------------------------------------------------
 669# Modules
 670
 671ifdef CONFIG_MODULES
 672
 673#       By default, build modules as well
 674
 675all: modules
 676
 677#       Build modules
 678
 679.PHONY: modules
 680modules: $(SUBDIRS) $(if $(KBUILD_BUILTIN),vmlinux)
 681        @echo '  Building modules, stage 2.';
 682        $(Q)$(MAKE) -rR -f $(srctree)/scripts/Makefile.modpost
 683
 684#       Install modules
 685
 686.PHONY: modules_install
 687modules_install: _modinst_ _modinst_post
 688
 689.PHONY: _modinst_
 690_modinst_:
 691        @if [ -z "`$(DEPMOD) -V | grep module-init-tools`" ]; then \
 692                echo "Warning: you may need to install module-init-tools"; \
 693                echo "See http://www.codemonkey.org.uk/post-halloween-2.5.txt";\
 694                sleep 1; \
 695        fi
 696        @rm -rf $(MODLIB)/kernel
 697        @rm -f $(MODLIB)/build
 698        @mkdir -p $(MODLIB)/kernel
 699        @ln -s $(TOPDIR) $(MODLIB)/build
 700        $(Q)$(MAKE) -rR -f $(srctree)/scripts/Makefile.modinst
 701
 702# If System.map exists, run depmod.  This deliberately does not have a
 703# dependency on System.map since that would run the dependency tree on
 704# vmlinux.  This depmod is only for convenience to give the initial
 705# boot a modules.dep even before / is mounted read-write.  However the
 706# boot script depmod is the master version.
 707ifeq "$(strip $(INSTALL_MOD_PATH))" ""
 708depmod_opts     :=
 709else
 710depmod_opts     := -b $(INSTALL_MOD_PATH) -r
 711endif
 712.PHONY: _modinst_post
 713_modinst_post: _modinst_
 714        if [ -r System.map ]; then $(DEPMOD) -ae -F System.map $(depmod_opts) $(KERNELRELEASE); fi
 715
 716else # CONFIG_MODULES
 717
 718# Modules not configured
 719# ---------------------------------------------------------------------------
 720
 721modules modules_install: FORCE
 722        @echo
 723        @echo "The present kernel configuration has modules disabled."
 724        @echo "Type 'make config' and enable loadable module support."
 725        @echo "Then build a kernel with module support enabled."
 726        @echo
 727        @exit 1
 728
 729endif # CONFIG_MODULES
 730
 731# Generate asm-offsets.h 
 732# ---------------------------------------------------------------------------
 733
 734define filechk_gen-asm-offsets
 735        (set -e; \
 736         echo "#ifndef __ASM_OFFSETS_H__"; \
 737         echo "#define __ASM_OFFSETS_H__"; \
 738         echo "/*"; \
 739         echo " * DO NOT MODIFY."; \
 740         echo " *"; \
 741         echo " * This file was generated by arch/$(ARCH)/Makefile"; \
 742         echo " *"; \
 743         echo " */"; \
 744         echo ""; \
 745         sed -ne "/^->/{s:^->\([^ ]*\) [\$$#]*\([^ ]*\) \(.*\):#define \1 \2 /* \3 */:; s:->::; p;}"; \
 746         echo ""; \
 747         echo "#endif" )
 748endef
 749
 750
 751###
 752# Cleaning is done on three levels.
 753# make clean     Delete all automatically generated files, including
 754#                tools and firmware.
 755# make mrproper  Delete the current configuration, and related files
 756#                Any core files spread around are deleted as well
 757# make distclean Remove editor backup files, patch leftover files and the like
 758
 759# Files removed with 'make clean'
 760CLEAN_FILES += vmlinux System.map MC*
 761
 762# Files removed with 'make mrproper'
 763MRPROPER_FILES += \
 764        include/linux/autoconf.h include/linux/version.h \
 765        .version .config .config.old config.in config.old \
 766        .menuconfig.log \
 767        include/asm \
 768        .hdepend include/linux/modversions.h \
 769        tags TAGS cscope* kernel.spec \
 770        .tmp*
 771
 772# Directories removed with 'make mrproper'
 773MRPROPER_DIRS += \
 774        $(MODVERDIR) \
 775        .tmp_export-objs \
 776        include/config \
 777        include/linux/modules \
 778        include2
 779
 780# clean - Delete all intermediate files
 781#
 782clean-dirs += $(addprefix _clean_,$(ALL_SUBDIRS) Documentation/DocBook scripts)
 783.PHONY: $(clean-dirs) clean archclean mrproper archmrproper distclean
 784$(clean-dirs):
 785        $(Q)$(MAKE) $(clean)=$(patsubst _clean_%,%,$@)
 786
 787quiet_cmd_rmclean = RM  $$(CLEAN_FILES)
 788cmd_rmclean       = rm -f $(CLEAN_FILES)
 789clean: archclean $(clean-dirs)
 790        $(call cmd,rmclean)
 791        @find . $(RCS_FIND_IGNORE) \
 792                \( -name '*.[oas]' -o -name '*.ko' -o -name '.*.cmd' \
 793                -o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \) \
 794                -type f -print | xargs rm -f
 795
 796# mrproper - delete configuration + modules + core files
 797#
 798quiet_cmd_mrproper = RM  $$(MRPROPER_DIRS) + $$(MRPROPER_FILES)
 799cmd_mrproper = rm -rf $(MRPROPER_DIRS) && rm -f $(MRPROPER_FILES)
 800mrproper distclean: clean archmrproper
 801        @echo '  Making $@ in the srctree'
 802        @find . $(RCS_FIND_IGNORE) \
 803                \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
 804                -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
 805                -o -name '.*.rej' -o -size 0 \
 806                -o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \
 807                -type f -print | xargs rm -f
 808        $(call cmd,mrproper)
 809
 810# Generate tags for editors
 811# ---------------------------------------------------------------------------
 812
 813define all-sources
 814        ( find . $(RCS_FIND_IGNORE) \
 815               \( -name include -o -name arch \) -prune -o \
 816               -name '*.[chS]' -print; \
 817          find arch/$(ARCH) $(RCS_FIND_IGNORE) \
 818               -name '*.[chS]' -print; \
 819          find include $(RCS_FIND_IGNORE) \
 820               \( -name config -o -name 'asm-*' \) -prune \
 821               -o -name '*.[chS]' -print; \
 822          find include/asm-$(ARCH) $(RCS_FIND_IGNORE) \
 823               -name '*.[chS]' -print; \
 824          find include/asm-generic $(RCS_FIND_IGNORE) \
 825               -name '*.[chS]' -print )
 826endef
 827
 828quiet_cmd_cscope = MAKE   $@
 829cmd_cscope = $(all-sources) | cscope -k -b -i -
 830
 831quiet_cmd_TAGS = MAKE   $@
 832cmd_TAGS = $(all-sources) | etags -
 833
 834#       Exuberant ctags works better with -I
 835
 836quiet_cmd_tags = MAKE   $@
 837define cmd_tags
 838        rm -f $@; \
 839        CTAGSF=`ctags --version | grep -i exuberant >/dev/null && echo "-I __initdata,__exitdata,EXPORT_SYMBOL,EXPORT_SYMBOL_NOVERS"`; \
 840        $(all-sources) | xargs ctags $$CTAGSF -a
 841endef
 842
 843cscope: FORCE
 844        $(call cmd,cscope)
 845
 846TAGS: FORCE
 847        $(call cmd,TAGS)
 848
 849tags: FORCE
 850        $(call cmd,tags)
 851
 852# RPM target
 853# ---------------------------------------------------------------------------
 854
 855.PHONY: rpm
 856
 857# Remove hyphens since they have special meaning in RPM filenames
 858KERNELPATH=kernel-$(subst -,,$(KERNELRELEASE))
 859
 860#       If you do a make spec before packing the tarball you can rpm -ta it
 861
 862spec:
 863        $(CONFIG_SHELL) $(srctree)/scripts/mkspec > $(objtree)/kernel.spec
 864
 865#       a) Build a tar ball
 866#       b) generate an rpm from it
 867#       c) and pack the result
 868#       - Use /. to avoid tar packing just the symlink
 869
 870rpm:    clean spec
 871        set -e; \
 872        cd .. ; \
 873        ln -sf $(srctree) $(KERNELPATH) ; \
 874        tar -cvz $(RCS_TAR_IGNORE) -f $(KERNELPATH).tar.gz $(KERNELPATH)/. ; \
 875        rm $(KERNELPATH)
 876
 877        set -e; \
 878        $(CONFIG_SHELL) $(srctree)/scripts/mkversion > $(objtree)/.tmp_version;\
 879        mv -f $(objtree)/.tmp_version $(objtree)/.version;
 880
 881        $(RPM) --target $(UTS_MACHINE) -ta ../$(KERNELPATH).tar.gz
 882        rm ../$(KERNELPATH).tar.gz
 883
 884# Brief documentation of the typical targets used
 885# ---------------------------------------------------------------------------
 886
 887help:
 888        @echo  'Cleaning targets:'
 889        @echo  '  clean           - remove most generated files but keep the config'
 890        @echo  '  mrproper        - remove all generated files + config + various backup files'
 891        @echo  ''
 892        @echo  'Configuration targets:'
 893        @$(MAKE) -f $(srctree)/scripts/kconfig/Makefile help
 894        @echo  ''
 895        @echo  'Other generic targets:'
 896        @echo  '  all             - Build all targets marked with [*]'
 897        @echo  '* vmlinux         - Build the bare kernel'
 898        @echo  '* modules         - Build all modules'
 899        @echo  '  modules_install - Install all modules'
 900        @echo  '  dir/            - Build all files in dir and below'
 901        @echo  '  dir/file.[ois]  - Build specified target only'
 902        @echo  '  rpm             - Build a kernel as an RPM package'
 903        @echo  '  tags/TAGS       - Generate tags file for editors'
 904        @echo  ''
 905        @echo  'Documentation targets:'
 906        @$(MAKE) -f $(srctree)/Documentation/DocBook/Makefile dochelp
 907        @echo  ''
 908        @echo  'Architecture specific targets ($(ARCH)):'
 909        @$(if $(archhelp),$(archhelp),\
 910                echo '  No architecture specific help defined for $(ARCH)')
 911        @echo  ''
 912        @echo  '  make V=0|1 [targets] 0 => quiet build (default), 1 => verbose build'
 913        @echo  '  make O=dir [targets] Locate all output files in "dir", including .config'
 914        @echo  '  make C=1   [targets] Check all c source with checker tool'
 915        @echo  ''
 916        @echo  'Execute "make" or "make all" to build all targets marked with [*] '
 917        @echo  'For further info see the ./README file'
 918
 919
 920# Documentation targets
 921# ---------------------------------------------------------------------------
 922%docs: scripts/docproc FORCE
 923        $(Q)$(MAKE) $(build)=Documentation/DocBook $@
 924
 925# Scripts to check various things for consistency
 926# ---------------------------------------------------------------------------
 927
 928configcheck:
 929        find * $(RCS_FIND_IGNORE) \
 930                -name '*.[hcS]' -type f -print | sort \
 931                | xargs $(PERL) -w scripts/checkconfig.pl
 932
 933includecheck:
 934        find * $(RCS_FIND_IGNORE) \
 935                -name '*.[hcS]' -type f -print | sort \
 936                | xargs $(PERL) -w scripts/checkincludes.pl
 937
 938versioncheck:
 939        find * $(RCS_FIND_IGNORE) \
 940                -name '*.[hcS]' -type f -print | sort \
 941                | xargs $(PERL) -w scripts/checkversion.pl
 942
 943endif #ifeq ($(config-targets),1)
 944endif #ifeq ($(mixed-targets),1)
 945
 946# FIXME Should go into a make.lib or something 
 947# ===========================================================================
 948
 949a_flags = -Wp,-MD,$(depfile) $(AFLAGS) $(AFLAGS_KERNEL) \
 950          $(NOSTDINC_FLAGS) $(CPPFLAGS) \
 951          $(modkern_aflags) $(EXTRA_AFLAGS) $(AFLAGS_$(*F).o)
 952
 953quiet_cmd_as_o_S = AS      $@
 954cmd_as_o_S       = $(CC) $(a_flags) -c -o $@ $<
 955
 956# read all saved command lines
 957
 958targets := $(wildcard $(sort $(targets)))
 959cmd_files := $(wildcard .*.cmd $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd))
 960
 961ifneq ($(cmd_files),)
 962  $(cmd_files): ;       # Do not try to update included dependency files
 963  include $(cmd_files)
 964endif
 965
 966# execute the command and also postprocess generated .d dependencies
 967# file
 968
 969if_changed_dep = $(if $(strip $? $(filter-out FORCE $(wildcard $^),$^)\
 970                          $(filter-out $(cmd_$(1)),$(cmd_$@))\
 971                          $(filter-out $(cmd_$@),$(cmd_$(1)))),\
 972        @set -e; \
 973        $(if $($(quiet)cmd_$(1)),echo '  $(subst ','\'',$($(quiet)cmd_$(1)))';) \
 974        $(cmd_$(1)); \
 975        scripts/fixdep $(depfile) $@ '$(subst $$,$$$$,$(subst ','\'',$(cmd_$(1))))' > $(@D)/.$(@F).tmp; \
 976        rm -f $(depfile); \
 977        mv -f $(@D)/.$(@F).tmp $(@D)/.$(@F).cmd)
 978
 979# Usage: $(call if_changed_rule,foo)
 980# will check if $(cmd_foo) changed, or any of the prequisites changed,
 981# and if so will execute $(rule_foo)
 982
 983if_changed_rule = $(if $(strip $? \
 984                               $(filter-out $(cmd_$(1)),$(cmd_$(@F)))\
 985                               $(filter-out $(cmd_$(@F)),$(cmd_$(1)))),\
 986                       @$(rule_$(1)))
 987
 988# If quiet is set, only print short version of command
 989
 990cmd = @$(if $($(quiet)cmd_$(1)),echo '  $($(quiet)cmd_$(1))' &&) $(cmd_$(1))
 991
 992# filechk is used to check if the content of a generated file is updated.
 993# Sample usage:
 994# define filechk_sample
 995#       echo $KERNELRELEASE
 996# endef
 997# version.h : Makefile
 998#       $(call filechk,sample)
 999# The rule defined shall write to stdout the content of the new file.
1000# The existing file will be compared with the new one.
1001# - If no file exist it is created
1002# - If the content differ the new file is used
1003# - If they are equal no change, and no timestamp update
1004
1005define filechk
1006        @set -e;                                \
1007        echo '  CHK     $@';                    \
1008        mkdir -p $(dir $@);                     \
1009        $(filechk_$(1)) < $< > $@.tmp;          \
1010        if [ -r $@ ] && cmp -s $@ $@.tmp; then  \
1011                rm -f $@.tmp;                   \
1012        else                                    \
1013                echo '  UPD     $@';            \
1014                mv -f $@.tmp $@;                \
1015        fi
1016endef
1017
1018# Shorthand for $(Q)$(MAKE) -f scripts/Makefile.build obj=dir
1019# Usage:
1020# $(Q)$(MAKE) $(build)=dir
1021build := -f $(if $(KBUILD_SRC),$(srctree)/)scripts/Makefile.build obj
1022
1023# Shorthand for $(Q)$(MAKE) -f scripts/Makefile.clean obj=dir
1024# Usage:
1025# $(Q)$(MAKE) $(clean)=dir
1026clean := -f $(if $(KBUILD_SRC),$(srctree)/)scripts/Makefile.clean obj
1027
1028#       $(call descend,<dir>,<target>)
1029#       Recursively call a sub-make in <dir> with target <target>
1030# Usage is deprecated, because make does not see this as an invocation of make.
1031descend =$(Q)$(MAKE) -f $(if $(KBUILD_SRC),$(srctree)/)scripts/Makefile.build obj=$(1) $(2)
1032
1033endif   # skip-makefile
1034
1035FORCE:
1036
lxr.linux.no kindly hosted by Redpill Linpro AS, provider of Linux consulting and operations services since 1995.