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