Makefile 38.6 KB
Newer Older
Linus Torvalds's avatar
Linus Torvalds committed
1
VERSION = 2
Linus Torvalds's avatar
Linus Torvalds committed
2
PATCHLEVEL = 6
Linus Torvalds's avatar
Linus Torvalds committed
3 4
SUBLEVEL = 9
EXTRAVERSION = -rc1
Linus Torvalds's avatar
Linus Torvalds committed
5
NAME=Zonked Quokka
Linus Torvalds's avatar
Linus Torvalds committed
6

7
# *DOCUMENTATION*
Kai Germaschewski's avatar
Kai Germaschewski committed
8
# To see a list of typical targets execute "make help"
9
# More info can be located in ./README
Kai Germaschewski's avatar
Kai Germaschewski committed
10
# Comments in this file are targeted only to the developer, do not
11 12
# expect to learn how to build the kernel reading this file.

13 14 15
# Do not print "Entering directory ..."
MAKEFLAGS += --no-print-directory

16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
# We are using a recursive build, so we need to do a little thinking
# to get the ordering right.
#
# Most importantly: sub-Makefiles should only ever modify files in
# their own directory. If in some directory we have a dependency on
# a file in another dir (which doesn't happen often, but it's of
# unavoidable when linking the built-in.o targets which finally
# turn into vmlinux), we will call a sub make in that other dir, and
# after that we are sure that everything which is in that other dir
# is now up to date.
#
# The only cases where we need to modify files which have global
# effects are thus separated out and done before the recursive
# descending is started. They are now explicitly listed as the
# prepare rule.

32 33 34 35 36 37 38 39 40
# To put more focus on warnings, be less verbose as default
# Use 'make V=1' to see the full commands

ifdef V
  ifeq ("$(origin V)", "command line")
    KBUILD_VERBOSE = $(V)
  endif
endif
ifndef KBUILD_VERBOSE
41
  KBUILD_VERBOSE = 0
42 43 44 45 46 47 48 49 50 51 52 53 54 55
endif

# Call sparse as part of compilation of C files
# Use 'make C=1' to enable sparse checking

ifdef C
  ifeq ("$(origin C)", "command line")
    KBUILD_CHECKSRC = $(C)
  endif
endif
ifndef KBUILD_CHECKSRC
  KBUILD_CHECKSRC = 0
endif

56
# Use make M=dir to specify directory of external module to build
57 58 59 60 61 62 63 64 65 66 67 68
# Old syntax make ... SUBDIRS=$PWD is still supported
# Setting the environment variable KBUILD_EXTMOD take precedence
ifdef SUBDIRS
  KBUILD_EXTMOD ?= $(SUBDIRS)
endif
ifdef M
  ifeq ("$(origin M)", "command line")
    KBUILD_EXTMOD := $(M)
  endif
endif


69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
# kbuild supports saving output files in a separate directory.
# To locate output files in a separate directory two syntax'es are supported.
# In both cases the working directory must be the root of the kernel src.
# 1) O=
# Use "make O=dir/to/store/output/files/"
# 
# 2) Set KBUILD_OUTPUT
# Set the environment variable KBUILD_OUTPUT to point to the directory
# where the output files shall be placed.
# export KBUILD_OUTPUT=dir/to/store/output/files/
# make
#
# The O= assigment takes precedence over the KBUILD_OUTPUT environment variable.


# KBUILD_SRC is set on invocation of make in OBJ directory
# KBUILD_SRC is not intended to be used by the regular user (for now)
ifeq ($(KBUILD_SRC),)

# OK, Make called in directory where kernel src resides
# Do we want to locate output files in a separate directory?
ifdef O
  ifeq ("$(origin O)", "command line")
    KBUILD_OUTPUT := $(O)
  endif
endif

96
# That's our default target when none is given on the command line
97 98 99
.PHONY: _all
_all:

100 101
ifneq ($(KBUILD_OUTPUT),)
# Invoke a second make in the output directory, passing relevant variables
102 103 104
# check that the output directory actually exists
saved-output := $(KBUILD_OUTPUT)
KBUILD_OUTPUT := $(shell cd $(KBUILD_OUTPUT) && /bin/pwd)
105
$(if $(KBUILD_OUTPUT),, \
106
     $(error output directory "$(saved-output)" does not exist))
107

108
.PHONY: $(MAKECMDGOALS)
109

110
$(filter-out _all,$(MAKECMDGOALS)) _all:
111
	$(if $(KBUILD_VERBOSE:1=),@)$(MAKE) -C $(KBUILD_OUTPUT)		\
112
	KBUILD_SRC=$(CURDIR)	     KBUILD_VERBOSE=$(KBUILD_VERBOSE)	\
113
	KBUILD_CHECK=$(KBUILD_CHECK) KBUILD_EXTMOD="$(KBUILD_EXTMOD)"	\
114
        -f $(CURDIR)/Makefile $@
115 116 117 118 119 120 121 122 123

# Leave processing to above invocation of make
skip-makefile := 1
endif # ifneq ($(KBUILD_OUTPUT),)
endif # ifeq ($(KBUILD_SRC),)

# We process the rest of the Makefile if this is the final invocation of make
ifeq ($(skip-makefile),)

124 125 126 127 128 129 130 131 132
# If building an external module we do not care about the all: rule
# but instead _all depend on modules
.PHONY: all
ifeq ($(KBUILD_EXTMOD),)
_all: all
else
_all: modules
endif

133
srctree		:= $(if $(KBUILD_SRC),$(KBUILD_SRC),$(CURDIR))
134 135 136 137 138 139 140 141 142 143
TOPDIR		:= $(srctree)
# FIXME - TOPDIR is obsolete, use srctree/objtree
objtree		:= $(CURDIR)
src		:= $(srctree)
obj		:= $(objtree)

VPATH		:= $(srctree)

export srctree objtree VPATH TOPDIR

Linus Torvalds's avatar
Linus Torvalds committed
144 145
KERNELRELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)

146 147 148 149 150 151
# SUBARCH tells the usermode build what the underlying arch is.  That is set
# first, and if a usermode build is happening, the "ARCH=um" on the command
# line overrides the setting of ARCH below.  If a native build is happening,
# then ARCH is assigned, getting whatever value it gets normally, and 
# SUBARCH is subsequently ignored.

152 153
SUBARCH := $(shell uname -m | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ \
				  -e s/arm.*/arm/ -e s/sa110/arm/ \
154
				  -e s/s390x/s390/ -e s/parisc64/parisc/ )
155

156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
# Cross compiling and selecting different set of gcc/bin-utils
# ---------------------------------------------------------------------------
#
# When performing cross compilation for other architectures ARCH shall be set
# to the target architecture. (See arch/* for the possibilities).
# ARCH can be set during invocation of make:
# make ARCH=ia64
# Another way is to have ARCH set in the environment.
# The default ARCH is the host where make is executed.

# CROSS_COMPILE specify the prefix used for all executables used
# during compilation. Only gcc and related bin-utils executables
# are prefixed with $(CROSS_COMPILE).
# CROSS_COMPILE can be set on the command line
# make CROSS_COMPILE=ia64-linux-
# Alternatively CROSS_COMPILE can be set in the environment.
# Default value for CROSS_COMPILE is not to prefix executables
# Note: Some architectures assign CROSS_COMPILE in their arch/*/Makefile

ARCH		?= $(SUBARCH)
CROSS_COMPILE	?=

# Architecture as present in compile.h
179 180
UTS_MACHINE := $(ARCH)

181
# SHELL used by kbuild
Linus Torvalds's avatar
Linus Torvalds committed
182 183 184 185 186
CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
	  else if [ -x /bin/bash ]; then echo /bin/bash; \
	  else echo sh; fi ; fi)

HOSTCC  	= gcc
187
HOSTCXX  	= g++
Linus Torvalds's avatar
Linus Torvalds committed
188
HOSTCFLAGS	= -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer
189
HOSTCXXFLAGS	= -O2
Linus Torvalds's avatar
Linus Torvalds committed
190

191 192
# 	Decide whether to build built-in, modular, or both.
#	Normally, just do built-in.
193

194
KBUILD_MODULES :=
195 196
KBUILD_BUILTIN := 1

197
#	If we have only "make modules", don't compile built-in objects.
198 199 200
#	When we're building modules with modversions, we need to consider
#	the built-in objects during the descend as well, in order to
#	make sure the checksums are uptodate before we record them.
201 202

ifeq ($(MAKECMDGOALS),modules)
203
  KBUILD_BUILTIN := $(if $(CONFIG_MODVERSIONS),1)
204 205 206 207 208 209
endif

#	If we have "make <whatever> modules", compile modules
#	in addition to whatever we do anyway.
#	Just "make" or "make all" shall build modules as well

210
ifneq ($(filter all _all modules,$(MAKECMDGOALS)),)
211 212 213
  KBUILD_MODULES := 1
endif

214
ifeq ($(MAKECMDGOALS),)
215 216 217
  KBUILD_MODULES := 1
endif

218
export KBUILD_MODULES KBUILD_BUILTIN KBUILD_VERBOSE
219
export KBUILD_CHECKSRC KBUILD_SRC KBUILD_EXTMOD
220

221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242
# Beautify output
# ---------------------------------------------------------------------------
#
# Normally, we echo the whole command before executing it. By making
# that echo $($(quiet)$(cmd)), we now have the possibility to set
# $(quiet) to choose other forms of output instead, e.g.
#
#         quiet_cmd_cc_o_c = Compiling $(RELDIR)/$@
#         cmd_cc_o_c       = $(CC) $(c_flags) -c -o $@ $<
#
# If $(quiet) is empty, the whole command will be printed.
# If it is set to "quiet_", only the short version will be printed. 
# If it is set to "silent_", nothing wil be printed at all, since
# the variable $(silent_cmd_cc_o_c) doesn't exist.
#
# A simple variant is to prefix commands with $(Q) - that's usefull
# for commands that shall be hidden in non-verbose mode.
#
#	$(Q)ln $@ :<
#
# If KBUILD_VERBOSE equals 0 then the above command will be hidden.
# If KBUILD_VERBOSE equals 1 then the above command is displayed.
243

244 245 246 247
ifeq ($(KBUILD_VERBOSE),1)
  quiet =
  Q =
else
248
  quiet=quiet_
249
  Q = @
250 251
endif

252 253
# If the user is running make -s (silent mode), suppress echoing of
# commands
254 255 256 257 258

ifneq ($(findstring s,$(MAKEFLAGS)),)
  quiet=silent_
endif

259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281
export quiet Q KBUILD_VERBOSE

######
# cc support functions to be used (only) in arch/$(ARCH)/Makefile
# See documentation in Documentation/kbuild/makefiles.txt

# cc-option
# Usage: cflags-y += $(call gcc-option, -march=winchip-c6, -march=i586)

cc-option = $(shell if $(CC) $(CFLAGS) $(1) -S -o /dev/null -xc /dev/null \
             > /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi ;)

# For backward compatibility
check_gcc = $(warning check_gcc is deprecated - use cc-option) \
            $(call cc-option, $(1),$(2))

# cc-option-yn
# Usage: flag := $(call gcc-option-yn, -march=winchip-c6)
cc-option-yn = $(shell if $(CC) $(CFLAGS) $(1) -S -o /dev/null -xc /dev/null \
                > /dev/null 2>&1; then echo "y"; else echo "n"; fi;)

# cc-version
# Usage gcc-ver := $(call cc-version $(CC))
Sam Ravnborg's avatar
Sam Ravnborg committed
282 283
cc-version = $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-version.sh \
              $(if $(1), $(1), $(CC)))
284

285

286 287
# Look for make include files relative to root of kernel src
MAKEFLAGS += --include-dir=$(srctree)
288

289 290
# For maximum performance (+ possibly random breakage, uncomment
# the following)
291

292
#MAKEFLAGS += -rR
293

294
# Make variables (CC, etc...)
Linus Torvalds's avatar
Linus Torvalds committed
295 296 297 298 299 300 301 302 303 304

AS		= $(CROSS_COMPILE)as
LD		= $(CROSS_COMPILE)ld
CC		= $(CROSS_COMPILE)gcc
CPP		= $(CC) -E
AR		= $(CROSS_COMPILE)ar
NM		= $(CROSS_COMPILE)nm
STRIP		= $(CROSS_COMPILE)strip
OBJCOPY		= $(CROSS_COMPILE)objcopy
OBJDUMP		= $(CROSS_COMPILE)objdump
305
AWK		= awk
306
GENKSYMS	= scripts/genksyms/genksyms
307
DEPMOD		= /sbin/depmod
308
KALLSYMS	= scripts/kallsyms
Kai Germaschewski's avatar
Kai Germaschewski committed
309
PERL		= perl
310
CHECK		= sparse
311
CHECKFLAGS     :=
Linus Torvalds's avatar
Linus Torvalds committed
312
MODFLAGS	= -DMODULE
313
CFLAGS_MODULE   = $(MODFLAGS)
314
AFLAGS_MODULE   = $(MODFLAGS)
315
LDFLAGS_MODULE  = -r
Linus Torvalds's avatar
Linus Torvalds committed
316
CFLAGS_KERNEL	=
317
AFLAGS_KERNEL	=
318

319
NOSTDINC_FLAGS  = -nostdinc -iwithprefix include
Linus Torvalds's avatar
Linus Torvalds committed
320

321 322 323 324 325 326
# Use LINUXINCLUDE when you must reference the include/ directory.
# Needed to be compatible with the O= option
LINUXINCLUDE    := -Iinclude \
                   $(if $(KBUILD_SRC),-Iinclude2 -I$(srctree)/include)

CPPFLAGS        := -D__KERNEL__ $(LINUXINCLUDE)
327

328
CFLAGS 		:= -Wall -Wstrict-prototypes -Wno-trigraphs \
Dave Jones's avatar
Dave Jones committed
329
	  	   -fno-strict-aliasing -fno-common
330
AFLAGS		:= -D__ASSEMBLY__
331

Linus Torvalds's avatar
Linus Torvalds committed
332
export	VERSION PATCHLEVEL SUBLEVEL EXTRAVERSION KERNELRELEASE ARCH \
333
	CONFIG_SHELL HOSTCC HOSTCFLAGS CROSS_COMPILE AS LD CC \
334
	CPP AR NM STRIP OBJCOPY OBJDUMP MAKE AWK GENKSYMS PERL UTS_MACHINE \
335
	HOSTCXX HOSTCXXFLAGS LDFLAGS_BLOB LDFLAGS_MODULE CHECK CHECKFLAGS
Linus Torvalds's avatar
Linus Torvalds committed
336

337
export CPPFLAGS NOSTDINC_FLAGS LINUXINCLUDE OBJCOPYFLAGS LDFLAGS
Kai Germaschewski's avatar
Kai Germaschewski committed
338 339 340
export CFLAGS CFLAGS_KERNEL CFLAGS_MODULE 
export AFLAGS AFLAGS_KERNEL AFLAGS_MODULE

341 342 343
# When compiling out-of-tree modules, put MODVERDIR in the module
# tree rather than in the kernel tree. The kernel tree might
# even be read-only.
344
export MODVERDIR := $(if $(KBUILD_EXTMOD),$(firstword $(KBUILD_EXTMOD))/).tmp_versions
345

346 347
# The temporary file to save gcc -MD generated dependencies must not
# contain a comma
348
comma := ,
349
depfile = $(subst $(comma),_,$(@D)/.$(@F).d)
350

351
# Files to ignore in find ... statements
Linus Torvalds's avatar
Linus Torvalds committed
352

353 354
RCS_FIND_IGNORE := \( -name SCCS -o -name BitKeeper -o -name .svn -o -name CVS -o -name .pc \) -prune -o
RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn --exclude CVS --exclude .pc
355

356 357 358
# ===========================================================================
# Rules shared between *config targets and build targets

359 360 361 362
# Basic helpers built in scripts/
.PHONY: scripts_basic
scripts_basic:
	$(Q)$(MAKE) $(build)=scripts/basic
363

364 365 366 367 368 369 370 371
# To make sure we do not include .config for any of the *config targets
# catch them early, and hand them over to scripts/kconfig/Makefile
# It is allowed to specify more targets when calling make, including
# mixing *config targets and build targets.
# For example 'make oldconfig all'. 
# Detect when mixed targets is specified, and make a second invocation
# of make so .config is not included in this case either (for *config).

372 373 374
no-dot-config-targets := clean mrproper distclean \
			 cscope TAGS tags help %docs check%

375 376
config-targets := 0
mixed-targets  := 0
377 378 379 380 381 382 383 384
dot-config     := 1

ifneq ($(filter $(no-dot-config-targets), $(MAKECMDGOALS)),)
	ifeq ($(filter-out $(no-dot-config-targets), $(MAKECMDGOALS)),)
		dot-config := 0
	endif
endif

385 386 387 388 389 390 391
ifeq ($(KBUILD_EXTMOD),)
        ifneq ($(filter config %config,$(MAKECMDGOALS)),)
                config-targets := 1
                ifneq ($(filter-out config %config,$(MAKECMDGOALS)),)
                        mixed-targets := 1
                endif
        endif
392 393 394 395 396 397 398 399
endif

ifeq ($(mixed-targets),1)
# ===========================================================================
# We're called with mixed targets (*config and build targets).
# Handle them one by one.

%:: FORCE
400
	$(Q)$(MAKE) -C $(srctree) KBUILD_SRC= $@
401 402 403 404 405 406 407

else
ifeq ($(config-targets),1)
# ===========================================================================
# *config targets only - make sure prerequisites are updated, and descend
# in scripts/kconfig to make the *config target

408
config: scripts_basic FORCE
409
	$(Q)$(MAKE) $(build)=scripts/kconfig $@
410
%config: scripts_basic FORCE
411 412 413 414 415 416 417
	$(Q)$(MAKE) $(build)=scripts/kconfig $@

else
# ===========================================================================
# Build targets only - this includes vmlinux, arch specific targets, clean
# targets and others. In general all targets except *config targets.

418
ifeq ($(KBUILD_EXTMOD),)
419 420 421 422 423 424 425 426 427
# Additional helpers built in scripts/
# Carefully list dependencies so we do not try to build scripts twice
# in parrallel
.PHONY: scripts
scripts: scripts_basic include/config/MARKER
	$(Q)$(MAKE) $(build)=$(@)

scripts_basic: include/linux/autoconf.h

428
# Objects we will link into vmlinux / subdirs we need to visit
429 430 431 432
init-y		:= init/
drivers-y	:= drivers/ sound/
net-y		:= net/
libs-y		:= lib/
433
core-y		:= usr/
434
endif # KBUILD_EXTMOD
435

436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451
ifeq ($(dot-config),1)
# In this section, we need .config

# Read in dependencies to all Kconfig* files, make sure to run
# oldconfig if changes are detected.
-include .config.cmd

include .config

# If .config needs to be updated, it will be done via the dependency
# that autoconf has on .config.
# To avoid any implicit rule to kick in, define an empty command
.config: ;

# If .config is newer than include/linux/autoconf.h, someone tinkered
# with it and forgot to run make oldconfig
452 453
include/linux/autoconf.h: .config
	$(Q)$(MAKE) -f $(srctree)/Makefile silentoldconfig
454 455 456
else
# Dummy target needed, because used as prerequisite
include/linux/autoconf.h: ;
457
endif
458

459
include $(srctree)/arch/$(ARCH)/Makefile
460

461 462 463 464 465 466 467 468 469 470 471 472 473
# Default kernel image to build when no specific target is given.
# KBUILD_IMAGE may be overruled on the commandline or
# set in the environment
# Also any assingments in arch/$(ARCH)/Makefiel take precedence over
# this default value
export KBUILD_IMAGE ?= vmlinux

# The all: target is the default when no target is given on the
# command line.
# This allow a user to issue only 'make' to build a kernel including modules
# Defaults vmlinux but it is usually overriden in the arch makefile
all: vmlinux

474 475 476 477 478 479
ifdef CONFIG_CC_OPTIMIZE_FOR_SIZE
CFLAGS		+= -Os
else
CFLAGS		+= -O2
endif

480 481 482 483
ifndef CONFIG_FRAME_POINTER
CFLAGS		+= -fomit-frame-pointer
endif

484 485 486 487
ifdef CONFIG_DEBUG_INFO
CFLAGS		+= -g
endif

488
# warn about C99 declaration after statement
489
CFLAGS += $(call cc-option,-Wdeclaration-after-statement,)
490

Linus Torvalds's avatar
Linus Torvalds committed
491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506
#
# INSTALL_PATH specifies where to place the updated kernel and system map
# images.  Uncomment if you want to place them anywhere other than root.
#

#export	INSTALL_PATH=/boot

#
# INSTALL_MOD_PATH specifies a prefix to MODLIB for module directory
# relocations required by build roots.  This is not defined in the
# makefile but the arguement can be passed to make if needed.
#

MODLIB	:= $(INSTALL_MOD_PATH)/lib/modules/$(KERNELRELEASE)
export MODLIB

507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527

ifeq ($(KBUILD_EXTMOD),)
core-y		+= kernel/ mm/ fs/ ipc/ security/ crypto/

vmlinux-dirs	:= $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
		     $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
		     $(net-y) $(net-m) $(libs-y) $(libs-m)))

vmlinux-alldirs	:= $(sort $(vmlinux-dirs) $(patsubst %/,%,$(filter %/, \
		     $(init-n) $(init-) \
		     $(core-n) $(core-) $(drivers-n) $(drivers-) \
		     $(net-n)  $(net-)  $(libs-n)    $(libs-))))

init-y		:= $(patsubst %/, %/built-in.o, $(init-y))
core-y		:= $(patsubst %/, %/built-in.o, $(core-y))
drivers-y	:= $(patsubst %/, %/built-in.o, $(drivers-y))
net-y		:= $(patsubst %/, %/built-in.o, $(net-y))
libs-y1		:= $(patsubst %/, %/lib.a, $(libs-y))
libs-y2		:= $(patsubst %/, %/built-in.o, $(libs-y))
libs-y		:= $(libs-y1) $(libs-y2)

528 529 530 531 532 533 534 535 536
# Build vmlinux
# ---------------------------------------------------------------------------

#	This is a bit tricky: If we need to relink vmlinux, we want
#	the version number incremented, which means recompile init/version.o
#	and relink init/init.o. However, we cannot do this during the
#       normal descending-into-subdirs phase, since at that time
#       we cannot yet know if we will need to relink vmlinux.
#	So we descend into init/ inside the rule for vmlinux again.
537
vmlinux-objs := $(head-y) $(init-y) $(core-y) $(libs-y) $(drivers-y) $(net-y)
538

539 540
quiet_cmd_vmlinux__ = LD      $@
define cmd_vmlinux__
541
	$(LD) $(LDFLAGS) $(LDFLAGS_vmlinux) $(head-y) $(init-y) \
Ingo Molnar's avatar
Ingo Molnar committed
542
	--start-group \
543 544 545 546
	$(core-y) \
	$(libs-y) \
	$(drivers-y) \
	$(net-y) \
Ingo Molnar's avatar
Ingo Molnar committed
547
	--end-group \
548
	$(filter .tmp_kallsyms%,$^) \
Ingo Molnar's avatar
Ingo Molnar committed
549 550
	-o $@
endef
551 552 553

#	set -e makes the rule exit immediately on error

554
define rule_vmlinux__
555
	+set -e;							\
556 557
	$(if $(filter .tmp_kallsyms%,$^),,				\
	  echo '  GEN     .version';					\
558
	  . $(srctree)/scripts/mkversion > .tmp_version;		\
559 560
	  mv -f .tmp_version .version;					\
	  $(MAKE) $(build)=init;					\
561 562 563 564
	)								\
	$(if $($(quiet)cmd_vmlinux__),					\
	  echo '  $($(quiet)cmd_vmlinux__)' &&) 			\
	$(cmd_vmlinux__);						\
565 566 567
	echo 'cmd_$@ := $(cmd_vmlinux__)' > $(@D)/.$(@F).cmd
endef

568 569 570
quiet_cmd_sysmap = SYSMAP 
      cmd_sysmap = $(CONFIG_SHELL) $(srctree)/scripts/mksysmap
		   
571
LDFLAGS_vmlinux += -T arch/$(ARCH)/kernel/vmlinux.lds
572

Ingo Molnar's avatar
Ingo Molnar committed
573
#	Generate section listing all symbols and add it into vmlinux
574
#	It's a three stage process:
575
#	o .tmp_vmlinux1 has all symbols and sections, but __kallsyms is
576
#	  empty
Kai Germaschewski's avatar
Kai Germaschewski committed
577
#	  Running kallsyms on that gives us .tmp_kallsyms1.o with
578
#	  the right size
579
#	o .tmp_vmlinux2 now has a __kallsyms section of the right size,
580
#	  but due to the added section, some addresses have shifted
581 582
#	  From here, we generate a correct .tmp_kallsyms2.o
#	o The correct .tmp_kallsyms2.o is linked into the final vmlinux.
583 584 585 586 587 588
#	o Verify that the System.map from vmlinux matches the map from
#	  .tmp_vmlinux2, just in case we did not generate kallsyms correctly.
#	o If CONFIG_KALLSYMS_EXTRA_PASS is set, do an extra pass using
#	  .tmp_vmlinux3 and .tmp_kallsyms3.o.  This is only meant as a
#	  temporary bypass to allow the kernel to be built while the
#	  maintainers work out what went wrong with kallsyms.
Ingo Molnar's avatar
Ingo Molnar committed
589 590 591

ifdef CONFIG_KALLSYMS

592 593 594 595 596 597 598 599 600
ifdef CONFIG_KALLSYMS_EXTRA_PASS
last_kallsyms := 3
else
last_kallsyms := 2
endif

kallsyms.o := .tmp_kallsyms$(last_kallsyms).o

define rule_verify_kallsyms
601 602 603 604
	$(Q)$(if $($(quiet)cmd_sysmap),                       \
	  echo '  $($(quiet)cmd_sysmap) .tmp_System.map' &&)  \
	  $(cmd_sysmap) .tmp_vmlinux$(last_kallsyms) .tmp_System.map
	$(Q)cmp -s System.map .tmp_System.map || \
605 606
		(echo Inconsistent kallsyms data, try setting CONFIG_KALLSYMS_EXTRA_PASS ; rm .tmp_kallsyms* ; false)
endef
Ingo Molnar's avatar
Ingo Molnar committed
607 608

quiet_cmd_kallsyms = KSYM    $@
609
cmd_kallsyms = $(NM) -n $< | $(KALLSYMS) $(foreach x,$(CONFIG_KALLSYMS_ALL),--all-symbols) > $@
610

611
.tmp_kallsyms1.o .tmp_kallsyms2.o .tmp_kallsyms3.o: %.o: %.S scripts FORCE
612
	$(call if_changed_dep,as_o_S)
Ingo Molnar's avatar
Ingo Molnar committed
613

614
.tmp_kallsyms%.S: .tmp_vmlinux% $(KALLSYMS)
615
	$(call cmd,kallsyms)
Ingo Molnar's avatar
Ingo Molnar committed
616

617
.tmp_vmlinux1: $(vmlinux-objs) arch/$(ARCH)/kernel/vmlinux.lds FORCE
618
	$(call if_changed_rule,vmlinux__)
Ingo Molnar's avatar
Ingo Molnar committed
619

620
.tmp_vmlinux2: $(vmlinux-objs) .tmp_kallsyms1.o arch/$(ARCH)/kernel/vmlinux.lds FORCE
621
	$(call if_changed_rule,vmlinux__)
622

623
.tmp_vmlinux3: $(vmlinux-objs) .tmp_kallsyms2.o arch/$(ARCH)/kernel/vmlinux.lds FORCE
624 625
	$(call if_changed_rule,vmlinux__)

626 627 628
# Needs to visit scripts/ before $(KALLSYMS) can be used.
$(KALLSYMS): scripts ;

629
endif
630

631 632 633
# Finally the vmlinux rule
# This rule is also used to generate System.map
# and to verify that the content of kallsyms are consistent
634

635
define rule_vmlinux
636
	$(rule_vmlinux__);
637 638 639 640 641 642
	$(Q)$(if $($(quiet)cmd_sysmap),                  \
	  echo '  $($(quiet)cmd_sysmap) System.map' &&)  \
	$(cmd_sysmap) $@ System.map;                     \
	if [ $$? -ne 0 ]; then                           \
		rm -f $@;                                \
		/bin/false;                              \
643
	fi;
644 645 646
	$(rule_verify_kallsyms)
endef

647
vmlinux: $(vmlinux-objs) $(kallsyms.o) arch/$(ARCH)/kernel/vmlinux.lds FORCE
648
	$(call if_changed_rule,vmlinux)
649

650 651
#	The actual objects are generated when descending, 
#	make sure no implicit rule kicks in
652

653
$(sort $(vmlinux-objs)) arch/$(ARCH)/kernel/vmlinux.lds: $(vmlinux-dirs) ;
Linus Torvalds's avatar
Linus Torvalds committed
654

655 656 657 658 659
# Handle descending into subdirectories listed in $(vmlinux-dirs)
# Preset locale variables to speed up the build process. Limit locale
# tweaks to this spot to avoid wrong language settings when running
# make menuconfig etc.
# Error messages still appears in the original language
660

661 662
.PHONY: $(vmlinux-dirs)
$(vmlinux-dirs): prepare-all scripts
663
	$(Q)$(MAKE) $(build)=$@
664

665 666 667 668 669
# Things we need to do before we recursively start building the kernel
# or the modules are listed in "prepare-all".
# A multi level approach is used. prepare1 is updated first, then prepare0.
# prepare-all is the collection point for the prepare targets.

670 671 672 673 674 675 676 677 678 679 680
.PHONY: prepare-all prepare prepare0 prepare1 prepare2

# prepare 2 generate Makefile to be placed in output directory, if
# using a seperate output directory. This allows convinient use
# of make in output directory
prepare2:
	$(Q)if [ ! $(srctree) -ef $(objtree) ]; then       \
	$(CONFIG_SHELL) $(srctree)/scripts/mkmakefile      \
	    $(srctree) $(objtree) $(VERSION) $(PATCHLEVEL) \
	    > $(objtree)/Makefile;                         \
	fi
681 682 683 684 685 686

# prepare1 is used to check if we are building in a separate output directory,
# and if so do:
# 1) Check that make has not been executed in the kernel src $(srctree)
# 2) Create the include2 directory, used for the second asm symlink

687
prepare1: prepare2
688 689 690 691 692 693 694 695 696 697
ifneq ($(KBUILD_SRC),)
	@echo '  Using $(srctree) as source for kernel'
	$(Q)if [ -h $(srctree)/include/asm -o -f $(srctree)/.config ]; then \
		echo "  $(srctree) is not clean, please run 'make mrproper'";\
		echo "  in the '$(srctree)' directory.";\
		/bin/false; \
	fi;
	$(Q)if [ ! -d include2 ]; then mkdir -p include2; fi;
	$(Q)ln -fsn $(srctree)/include/asm-$(ARCH) include2/asm
endif
698

699
prepare0: prepare1 include/linux/version.h include/asm include/config/MARKER
700
ifneq ($(KBUILD_MODULES),)
701
	$(Q)rm -rf $(MODVERDIR)
702 703
	$(Q)mkdir -p $(MODVERDIR)
endif
704

705 706 707
# All the preparing..
prepare-all: prepare0 prepare

708 709
#	Leave this as default for preprocessing vmlinux.lds.S, which is now
#	done in arch/$(ARCH)/kernel/Makefile
710

711
export CPPFLAGS_vmlinux.lds += -P -C -U$(ARCH)
712

713 714 715
# Single targets
# ---------------------------------------------------------------------------

716
%.s: %.c scripts FORCE
717
	$(Q)$(MAKE) $(build)=$(@D) $@
718
%.i: %.c scripts FORCE
719
	$(Q)$(MAKE) $(build)=$(@D) $@
720
%.o: %.c scripts FORCE
721
	$(Q)$(MAKE) $(build)=$(@D) $@
722
%/:      scripts prepare FORCE
723
	$(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) $(build)=$(@D)
724
%.lst: %.c scripts FORCE
725
	$(Q)$(MAKE) $(build)=$(@D) $@
726
%.s: %.S scripts FORCE
727
	$(Q)$(MAKE) $(build)=$(@D) $@
728
%.o: %.S scripts FORCE
729
	$(Q)$(MAKE) $(build)=$(@D) $@
730

731 732 733
# 	FIXME: The asm symlink changes when $(ARCH) changes. That's
#	hard to detect, but I suppose "make mrproper" is a good idea
#	before switching between archs anyway.
734

735
include/asm:
736 737 738
	@echo '  SYMLINK $@ -> include/asm-$(ARCH)'
	$(Q)if [ ! -d include ]; then mkdir -p include; fi;
	@ln -fsn asm-$(ARCH) $@
739

740
# 	Split autoconf.h into include/linux/config/*
741

742
include/config/MARKER: include/linux/autoconf.h
743
	@echo '  SPLIT   include/linux/autoconf.h -> include/config/*'
744
	@scripts/basic/split-include include/linux/autoconf.h include/config
745
	@touch $@
Linus Torvalds's avatar
Linus Torvalds committed
746

747
# Generate some files
748
# ---------------------------------------------------------------------------
Linus Torvalds's avatar
Linus Torvalds committed
749

750 751
#	version.h changes when $(KERNELRELEASE) etc change, as defined in
#	this Makefile
Linus Torvalds's avatar
Linus Torvalds committed
752

753 754
uts_len := 64

755
define filechk_version.h
756
	if [ `echo -n "$(KERNELRELEASE)" | wc -c ` -gt $(uts_len) ]; then \
757 758
	  echo '"$(KERNELRELEASE)" exceeds $(uts_len) characters' >&2; \
	  exit 1; \
759
	fi; \
760
	(echo \#define UTS_RELEASE \"$(KERNELRELEASE)\"; \
761 762
	  echo \#define LINUX_VERSION_CODE `expr $(VERSION) \\* 65536 + $(PATCHLEVEL) \\* 256 + $(SUBLEVEL)`; \
	 echo '#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))'; \
763 764 765 766 767
	)
endef

include/linux/version.h: Makefile
	$(call filechk,version.h)
Linus Torvalds's avatar
Linus Torvalds committed
768

769 770
# ---------------------------------------------------------------------------

771 772
.PHONY: depend dep
depend dep:
773
	@echo '*** Warning: make $@ is unnecessary now.'
774

775 776
# ---------------------------------------------------------------------------
# Modules
Linus Torvalds's avatar
Linus Torvalds committed
777 778

ifdef CONFIG_MODULES
779

780 781 782 783
# 	By default, build modules as well

all: modules

784 785
#	Build modules

786
.PHONY: modules
787
modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux)
788
	@echo '  Building modules, stage 2.';
789
	$(Q)$(MAKE) -rR -f $(srctree)/scripts/Makefile.modpost
790

791

792 793 794 795 796
# Target to prepare building external modules
.PHONY: modules_prepare
modules_prepare: prepare-all scripts

# Target to install modules
Linus Torvalds's avatar
Linus Torvalds committed
797
.PHONY: modules_install
798
modules_install: _modinst_ _modinst_post
Linus Torvalds's avatar
Linus Torvalds committed
799 800 801

.PHONY: _modinst_
_modinst_:
802 803
	@if [ -z "`$(DEPMOD) -V | grep module-init-tools`" ]; then \
		echo "Warning: you may need to install module-init-tools"; \
804
		echo "See http://www.codemonkey.org.uk/docs/post-halloween-2.6.txt";\
805 806
		sleep 1; \
	fi
Linus Torvalds's avatar
Linus Torvalds committed
807
	@rm -rf $(MODLIB)/kernel
808
	@rm -f $(MODLIB)/source
Linus Torvalds's avatar
Linus Torvalds committed
809
	@mkdir -p $(MODLIB)/kernel
810 811 812 813 814
	@ln -s $(srctree) $(MODLIB)/source
	@if [ ! $(objtree) -ef  $(MODLIB)/build ]; then \
		rm -f $(MODLIB)/build ; \
		ln -s $(objtree) $(MODLIB)/build ; \
	fi
815
	$(Q)$(MAKE) -rR -f $(srctree)/scripts/Makefile.modinst
Linus Torvalds's avatar
Linus Torvalds committed
816

817 818 819 820 821 822 823 824 825 826 827
# If System.map exists, run depmod.  This deliberately does not have a
# dependency on System.map since that would run the dependency tree on
# vmlinux.  This depmod is only for convenience to give the initial
# boot a modules.dep even before / is mounted read-write.  However the
# boot script depmod is the master version.
ifeq "$(strip $(INSTALL_MOD_PATH))" ""
depmod_opts	:=
else
depmod_opts	:= -b $(INSTALL_MOD_PATH) -r
endif
.PHONY: _modinst_post
828
_modinst_post: _modinst_
829 830
	if [ -r System.map ]; then $(DEPMOD) -ae -F System.map $(depmod_opts) $(KERNELRELEASE); fi

831 832 833
else # CONFIG_MODULES

# Modules not configured
834
# ---------------------------------------------------------------------------
Linus Torvalds's avatar
Linus Torvalds committed
835

836
modules modules_install: FORCE
Linus Torvalds's avatar
Linus Torvalds committed
837 838 839 840 841 842 843
	@echo
	@echo "The present kernel configuration has modules disabled."
	@echo "Type 'make config' and enable loadable module support."
	@echo "Then build a kernel with module support enabled."
	@echo
	@exit 1

844
endif # CONFIG_MODULES
Linus Torvalds's avatar
Linus Torvalds committed
845

846 847 848
# Generate asm-offsets.h 
# ---------------------------------------------------------------------------

849
define filechk_gen-asm-offsets
850 851 852 853 854 855 856 857 858 859
	(set -e; \
	 echo "#ifndef __ASM_OFFSETS_H__"; \
	 echo "#define __ASM_OFFSETS_H__"; \
	 echo "/*"; \
	 echo " * DO NOT MODIFY."; \
	 echo " *"; \
	 echo " * This file was generated by arch/$(ARCH)/Makefile"; \
	 echo " *"; \
	 echo " */"; \
	 echo ""; \
860
	 sed -ne "/^->/{s:^->\([^ ]*\) [\$$#]*\([^ ]*\) \(.*\):#define \1 \2 /* \3 */:; s:->::; p;}"; \
861 862 863 864
	 echo ""; \
	 echo "#endif" )
endef

865

866 867
###
# Cleaning is done on three levels.
868 869 870
# make clean     Delete most generated files
#                Leave enough to build external modules
# make mrproper  Delete the current configuration, and all generated files
871
# make distclean Remove editor backup files, patch leftover files and the like
872

873 874
# Directories & files removed with 'make clean'
CLEAN_DIRS  += $(MODVERDIR)
875
CLEAN_FILES +=	vmlinux System.map \
876
                .tmp_kallsyms* .tmp_version .tmp_vmlinux* .tmp_System.map
877 878 879 880 881

# Directories & files removed with 'make mrproper'
MRPROPER_DIRS  += include/config include2
MRPROPER_FILES += .config .config.old include/asm .version \
                  include/linux/autoconf.h include/linux/version.h \
882
                  Module.symvers tags TAGS cscope*
883 884

# clean - Delete most, but leave enough to build external modules
885
#
886 887
clean: rm-dirs  := $(CLEAN_DIRS)
clean: rm-files := $(CLEAN_FILES)
888
clean-dirs      := $(addprefix _clean_,$(vmlinux-alldirs))
889 890

.PHONY: $(clean-dirs) clean archclean
891
$(clean-dirs):
892
	$(Q)$(MAKE) $(clean)=$(patsubst _clean_%,%,$@)
893

894
clean: archclean $(clean-dirs)
895 896
	$(call cmd,rmdirs)
	$(call cmd,rmfiles)
897
	@find . $(RCS_FIND_IGNORE) \
898
	 	\( -name '*.[oas]' -o -name '*.ko' -o -name '.*.cmd' \
899 900
		-o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \) \
		-type f -print | xargs rm -f
Linus Torvalds's avatar
Linus Torvalds committed
901

902
# mrproper - Delete all generated files, including .config
903
#
904 905 906 907 908 909 910 911 912
mrproper: rm-dirs  := $(wildcard $(MRPROPER_DIRS))
mrproper: rm-files := $(wildcard $(MRPROPER_FILES))
mrproper-dirs      := $(addprefix _mrproper_,Documentation/DocBook scripts)

.PHONY: $(mrproper-dirs) mrproper archmrproper
$(mrproper-dirs):
	$(Q)$(MAKE) $(clean)=$(patsubst _mrproper_%,%,$@)

mrproper: clean archmrproper $(mrproper-dirs)
913 914
	$(call cmd,rmdirs)
	$(call cmd,rmfiles)
915 916 917 918 919 920

# distclean
#
.PHONY: distclean

distclean: mrproper
921
	@find $(srctree) $(RCS_FIND_IGNORE) \
922
	 	\( -name '*.orig' -o -name '*.rej' -o -name '*~' \
Linus Torvalds's avatar
Linus Torvalds committed
923
		-o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
924 925 926
	 	-o -name '.*.rej' -o -size 0 \
		-o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \
		-type f -print | xargs rm -f
Linus Torvalds's avatar
Linus Torvalds committed
927

928

929 930 931 932
# Packaging of the kernel to various formats
# ---------------------------------------------------------------------------
# rpm target kept for backward compatibility
package-dir	:= $(srctree)/scripts/package
Sam Ravnborg's avatar
Sam Ravnborg committed
933

934
.PHONY: %-pkg rpm
935

936 937 938 939
%pkg: FORCE
	$(Q)$(MAKE) -f $(package-dir)/Makefile $@
rpm: FORCE
	$(Q)$(MAKE) -f $(package-dir)/Makefile $@
940

Sam Ravnborg's avatar
Sam Ravnborg committed
941

942 943 944
# Brief documentation of the typical targets used
# ---------------------------------------------------------------------------

945 946 947
boards := $(wildcard $(srctree)/arch/$(ARCH)/configs/*_defconfig)
boards := $(notdir $(boards))

948 949
help:
	@echo  'Cleaning targets:'
Sam Ravnborg's avatar
Sam Ravnborg committed
950 951
	@echo  '  clean		  - remove most generated files but keep the config'
	@echo  '  mrproper	  - remove all generated files + config + various backup files'
952 953
	@echo  ''
	@echo  'Configuration targets:'
954
	@$(MAKE) -f $(srctree)/scripts/kconfig/Makefile help
955 956
	@echo  ''
	@echo  'Other generic targets:'
Sam Ravnborg's avatar
Sam Ravnborg committed
957 958 959 960
	@echo  '  all		  - Build all targets marked with [*]'
	@echo  '* vmlinux	  - Build the bare kernel'
	@echo  '* modules	  - Build all modules'
	@echo  '  modules_install - Install all modules'
961
	@echo  '  dir/            - Build all files in dir and below'
Sam Ravnborg's avatar
Sam Ravnborg committed
962 963 964
	@echo  '  dir/file.[ois]  - Build specified target only'
	@echo  '  rpm		  - Build a kernel as an RPM package'
	@echo  '  tags/TAGS	  - Generate tags file for editors'
965
	@echo  '  cscope	  - Generate cscope index'
Andrew Morton's avatar
Andrew Morton committed
966
	@echo  '  checkstack      - Generate a list of stack hogs'
967 968
	@echo  'Kernel packaging:'
	@$(MAKE) -f $(package-dir)/Makefile help
969 970
	@echo  ''
	@echo  'Documentation targets:'
971
	@$(MAKE) -f $(srctree)/Documentation/DocBook/Makefile dochelp
972 973
	@echo  ''
	@echo  'Architecture specific targets ($(ARCH)):'
974 975
	@$(if $(archhelp),$(archhelp),\
		echo '  No architecture specific help defined for $(ARCH)')
976
	@echo  ''
977 978 979 980 981
	@$(if $(boards), \
		$(foreach b, $(boards), \
		printf "  %-24s - Build for %s\\n" $(b) $(subst _defconfig,,$(b));) \
		echo '')

Sam Ravnborg's avatar
Sam Ravnborg committed
982
	@echo  '  make V=0|1 [targets] 0 => quiet build (default), 1 => verbose build'
983
	@echo  '  make O=dir [targets] Locate all output files in "dir", including .config'
984 985
	@echo  '  make C=1   [targets] Check all c source with $$CHECK (sparse)'
	@echo  '  make C=2   [targets] Force check of all c source with $$CHECK (sparse)'
Sam Ravnborg's avatar
Sam Ravnborg committed
986
	@echo  ''
987
	@echo  'Execute "make" or "make all" to build all targets marked with [*] '
988
	@echo  'For further info see the ./README file'
989

990

991 992
# Documentation targets
# ---------------------------------------------------------------------------
993
%docs: scripts_basic FORCE
994
	$(Q)$(MAKE) $(build)=Documentation/DocBook $@
995

996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016
else # KBUILD_EXTMOD

###
# External module support.
# When building external modules the kernel used as basis is considered
# read-only, and no consistency checks are made and the make
# system is not used on the basis kernel. If updates are required
# in the basis kernel ordinary make commands (without M=...) must
# be used.
#
# The following are the only valid targets when building external
# modules.
# make M=dir clean     Delete all automatically generated files
# make M=dir modules   Make all modules in specified dir
# make M=dir	       Same as 'make M=dir modules'
# make M=dir modules_install
#                      Install the modules build in the module directory
#                      Assumes install directory is already created

# We are always building modules
KBUILD_MODULES := 1
1017
.PHONY: crmodverdir
1018
crmodverdir:
1019
	$(Q)mkdir -p $(MODVERDIR)
1020

1021 1022 1023 1024
module-dirs := $(addprefix _module_,$(KBUILD_EXTMOD))
.PHONY: $(module-dirs) modules
$(module-dirs): crmodverdir
	$(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
1025

1026
modules: $(module-dirs)
1027 1028 1029 1030 1031 1032 1033
	@echo '  Building modules, stage 2.';
	$(Q)$(MAKE) -rR -f $(srctree)/scripts/Makefile.modpost

.PHONY: modules_install
modules_install:
	$(Q)$(MAKE) -rR -f $(srctree)/scripts/Makefile.modinst

1034
clean-dirs := $(addprefix _clean_,$(KBUILD_EXTMOD))
1035 1036 1037 1038 1039

.PHONY: $(clean-dirs) clean
$(clean-dirs):
	$(Q)$(MAKE) $(clean)=$(patsubst _clean_%,%,$@)

1040
clean:	rm-dirs := $(MODVERDIR)
1041
clean: $(clean-dirs)
1042
	$(call cmd,rmdirs)
1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061
	@find $(KBUILD_EXTMOD) $(RCS_FIND_IGNORE) \
	 	\( -name '*.[oas]' -o -name '*.ko' -o -name '.*.cmd' \
		-o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \) \
		-type f -print | xargs rm -f

help:
	@echo  '  Building external modules.'
	@echo  '  Syntax: make -C path/to/kernel/src M=$$PWD target'
	@echo  ''
	@echo  '  modules         - default target, build the module(s)'
	@echo  '  modules_install - install the module'
	@echo  '  clean           - remove generated files in module directory only'
	@echo  ''
endif # KBUILD_EXTMOD

# Generate tags for editors
# ---------------------------------------------------------------------------

define all-sources
1062
	( find $(srctree) $(RCS_FIND_IGNORE) \
1063 1064
	       \( -name include -o -name arch \) -prune -o \
	       -name '*.[chS]' -print; \
1065
	  find $(srctree)/arch/$(ARCH) $(RCS_FIND_IGNORE) \
1066
	       -name '*.[chS]' -print; \
1067
	  find $(srctree)/security/selinux/include $(RCS_FIND_IGNORE) \
1068
	       -name '*.[chS]' -print; \
1069
	  find $(srctree)/include $(RCS_FIND_IGNORE) \
1070 1071
	       \( -name config -o -name 'asm-*' \) -prune \
	       -o -name '*.[chS]' -print; \
1072
	  find $(srctree)/include/asm-$(ARCH) $(RCS_FIND_IGNORE) \
1073
	       -name '*.[chS]' -print; \
1074
	  find $(srctree)/include/asm-generic $(RCS_FIND_IGNORE) \
1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106
	       -name '*.[chS]' -print )
endef

quiet_cmd_cscope-file = FILELST cscope.files
      cmd_cscope-file = $(all-sources) > cscope.files

quiet_cmd_cscope = MAKE    cscope.out
      cmd_cscope = cscope -k -b -q

cscope: FORCE
	$(call cmd,cscope-file)
	$(call cmd,cscope)

quiet_cmd_TAGS = MAKE   $@
cmd_TAGS = $(all-sources) | etags -

# 	Exuberant ctags works better with -I

quiet_cmd_tags = MAKE   $@
define cmd_tags
	rm -f $@; \
	CTAGSF=`ctags --version | grep -i exuberant >/dev/null && echo "-I __initdata,__exitdata,EXPORT_SYMBOL,EXPORT_SYMBOL_NOVERS"`; \
	$(all-sources) | xargs ctags $$CTAGSF -a
endef

TAGS: FORCE
	$(call cmd,TAGS)

tags: FORCE
	$(call cmd,tags)


1107 1108 1109
# Scripts to check various things for consistency
# ---------------------------------------------------------------------------

1110
configcheck:
1111
	find * $(RCS_FIND_IGNORE) \
1112 1113
		-name '*.[hcS]' -type f -print | sort \
		| xargs $(PERL) -w scripts/checkconfig.pl
1114

1115
includecheck:
1116
	find * $(RCS_FIND_IGNORE) \
1117 1118
		-name '*.[hcS]' -type f -print | sort \
		| xargs $(PERL) -w scripts/checkincludes.pl
1119

1120 1121 1122 1123 1124
versioncheck:
	find * $(RCS_FIND_IGNORE) \
		-name '*.[hcS]' -type f -print | sort \
		| xargs $(PERL) -w scripts/checkversion.pl

Andrew Morton's avatar
Andrew Morton committed
1125 1126
buildcheck:
	$(PERL) scripts/reference_discarded.pl
1127
	$(PERL) scripts/reference_init.pl
Andrew Morton's avatar
Andrew Morton committed
1128

1129 1130
endif #ifeq ($(config-targets),1)
endif #ifeq ($(mixed-targets),1)
1131

1132 1133 1134
.PHONY: checkstack
checkstack:
	$(OBJDUMP) -d vmlinux $$(find . -name '*.ko') | \
1135
	$(PERL) $(src)/scripts/checkstack.pl $(ARCH)
1136

1137
# FIXME Should go into a make.lib or something 
1138
# ===========================================================================
1139

1140 1141 1142 1143 1144 1145 1146
quiet_cmd_rmdirs = $(if $(wildcard $(rm-dirs)),CLEAN   $(wildcard $(rm-dirs)))
      cmd_rmdirs = rm -rf $(rm-dirs)

quiet_cmd_rmfiles = $(if $(wildcard $(rm-files)),CLEAN   $(wildcard $(rm-files)))
      cmd_rmfiles = rm -f $(rm-files)


1147 1148
a_flags = -Wp,-MD,$(depfile) $(AFLAGS) $(AFLAGS_KERNEL) \
	  $(NOSTDINC_FLAGS) $(CPPFLAGS) \
1149 1150
	  $(modkern_aflags) $(EXTRA_AFLAGS) $(AFLAGS_$(*F).o)

1151 1152 1153
quiet_cmd_as_o_S = AS      $@
cmd_as_o_S       = $(CC) $(a_flags) -c -o $@ $<

1154 1155
# read all saved command lines

1156 1157 1158
targets := $(wildcard $(sort $(targets)))
cmd_files := $(wildcard .*.cmd $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd))

1159
ifneq ($(cmd_files),)
1160
  $(cmd_files): ;	# Do not try to update included dependency files
1161 1162 1163
  include $(cmd_files)
endif

1164 1165 1166 1167 1168 1169 1170
# execute the command and also postprocess generated .d dependencies
# file

if_changed_dep = $(if $(strip $? $(filter-out FORCE $(wildcard $^),$^)\
		          $(filter-out $(cmd_$(1)),$(cmd_$@))\
			  $(filter-out $(cmd_$@),$(cmd_$(1)))),\
	@set -e; \
1171
	$(if $($(quiet)cmd_$(1)),echo '  $(subst ','\'',$($(quiet)cmd_$(1)))';) \
1172
	$(cmd_$(1)); \
1173
	scripts/basic/fixdep $(depfile) $@ '$(subst $$,$$$$,$(subst ','\'',$(cmd_$(1))))' > $(@D)/.$(@F).tmp; \
1174 1175 1176
	rm -f $(depfile); \
	mv -f $(@D)/.$(@F).tmp $(@D)/.$(@F).cmd)

1177 1178 1179 1180
# Usage: $(call if_changed_rule,foo)
# will check if $(cmd_foo) changed, or any of the prequisites changed,
# and if so will execute $(rule_foo)

1181 1182 1183 1184 1185
if_changed_rule = $(if $(strip $? \
		               $(filter-out $(cmd_$(1)),$(cmd_$(@F)))\
			       $(filter-out $(cmd_$(@F)),$(cmd_$(1)))),\
	               @$(rule_$(1)))

1186
# If quiet is set, only print short version of command
1187

1188
cmd = @$(if $($(quiet)cmd_$(1)),echo '  $($(quiet)cmd_$(1))' &&) $(cmd_$(1))
1189

1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203
# filechk is used to check if the content of a generated file is updated.
# Sample usage:
# define filechk_sample
#	echo $KERNELRELEASE
# endef
# version.h : Makefile
#	$(call filechk,sample)
# The rule defined shall write to stdout the content of the new file.
# The existing file will be compared with the new one.
# - If no file exist it is created
# - If the content differ the new file is used
# - If they are equal no change, and no timestamp update

define filechk
1204 1205
	@set -e;				\
	echo '  CHK     $@';			\
1206
	mkdir -p $(dir $@);			\
1207
	$(filechk_$(1)) < $< > $@.tmp;		\
1208 1209 1210 1211 1212
	if [ -r $@ ] && cmp -s $@ $@.tmp; then	\
		rm -f $@.tmp;			\
	else					\
		echo '  UPD     $@';		\
		mv -f $@.tmp $@;		\
1213 1214
	fi
endef
1215

Kai Germaschewski's avatar
Kai Germaschewski committed
1216
# Shorthand for $(Q)$(MAKE) -f scripts/Makefile.build obj=dir
1217 1218
# Usage:
# $(Q)$(MAKE) $(build)=dir
1219
build := -f $(if $(KBUILD_SRC),$(srctree)/)scripts/Makefile.build obj
1220

Kai Germaschewski's avatar
Kai Germaschewski committed
1221
# Shorthand for $(Q)$(MAKE) -f scripts/Makefile.clean obj=dir
1222 1223
# Usage:
# $(Q)$(MAKE) $(clean)=dir
1224
clean := -f $(if $(KBUILD_SRC),$(srctree)/)scripts/Makefile.clean obj
1225

1226 1227
#	$(call descend,<dir>,<target>)
#	Recursively call a sub-make in <dir> with target <target>
Kai Germaschewski's avatar
Kai Germaschewski committed
1228
# Usage is deprecated, because make does not see this as an invocation of make.
1229 1230 1231
descend =$(Q)$(MAKE) -f $(if $(KBUILD_SRC),$(srctree)/)scripts/Makefile.build obj=$(1) $(2)

endif	# skip-makefile
1232

1233
FORCE: