Makefile 31.9 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
SUBLEVEL = 3
Linus Torvalds's avatar
Linus Torvalds committed
4
EXTRAVERSION =
5
NAME=Feisty Dunnart
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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
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

# 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

83 84 85 86
# That's our default target when none is given on the command line
.PHONY: all
all:
  
87 88
ifneq ($(KBUILD_OUTPUT),)
# Invoke a second make in the output directory, passing relevant variables
89 90 91 92 93
# check that the output directory actually exists
saved-output := $(KBUILD_OUTPUT)
KBUILD_OUTPUT := $(shell cd $(KBUILD_OUTPUT) && /bin/pwd)
$(if $(wildcard $(KBUILD_OUTPUT)),, \
     $(error output directory "$(saved-output)" does not exist))
94

95
.PHONY: $(MAKECMDGOALS)
96

97
$(filter-out all,$(MAKECMDGOALS)) all:
98 99
	$(if $(KBUILD_VERBOSE:1=),@)$(MAKE) -C $(KBUILD_OUTPUT)		\
	KBUILD_SRC=$(CURDIR)	KBUILD_VERBOSE=$(KBUILD_VERBOSE)	\
100
	KBUILD_CHECK=$(KBUILD_CHECK) -f $(CURDIR)/Makefile $@
101 102 103 104 105 106 107 108 109

# 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),)

110
srctree		:= $(if $(KBUILD_SRC),$(KBUILD_SRC),$(CURDIR))
111 112 113 114 115 116 117 118 119 120
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
121 122
KERNELRELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)

123 124 125 126 127 128
# 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.

129 130
SUBARCH := $(shell uname -m | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ \
				  -e s/arm.*/arm/ -e s/sa110/arm/ \
131
				  -e s/s390x/s390/ -e s/parisc64/parisc/ )
132

133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
# 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
156 157
UTS_MACHINE := $(ARCH)

158
# SHELL used by kbuild
Linus Torvalds's avatar
Linus Torvalds committed
159 160 161 162 163
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
164
HOSTCXX  	= g++
Linus Torvalds's avatar
Linus Torvalds committed
165
HOSTCFLAGS	= -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer
166
HOSTCXXFLAGS	= -O2
Linus Torvalds's avatar
Linus Torvalds committed
167

168 169
# 	Decide whether to build built-in, modular, or both.
#	Normally, just do built-in.
170

171
KBUILD_MODULES :=
172 173
KBUILD_BUILTIN := 1

174
#	If we have only "make modules", don't compile built-in objects.
175 176 177
#	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.
178 179

ifeq ($(MAKECMDGOALS),modules)
180
  KBUILD_BUILTIN := $(if $(CONFIG_MODVERSIONS),1)
181 182 183 184 185 186
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

187
ifneq ($(filter all modules,$(MAKECMDGOALS)),)
188 189 190
  KBUILD_MODULES := 1
endif

191
ifeq ($(MAKECMDGOALS),)
192 193 194
  KBUILD_MODULES := 1
endif

195 196
export KBUILD_MODULES KBUILD_BUILTIN KBUILD_VERBOSE
export KBUILD_CHECKSRC KBUILD_SRC
197

198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219
# 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.
220

221 222 223 224
ifeq ($(KBUILD_VERBOSE),1)
  quiet =
  Q =
else
225
  quiet=quiet_
226
  Q = @
227 228
endif

229 230
# If the user is running make -s (silent mode), suppress echoing of
# commands
231 232 233 234 235

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

236 237 238
check_gcc = $(shell if $(CC) $(CFLAGS) $(1) -S -o /dev/null -xc /dev/null > /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi ;)

export quiet Q KBUILD_VERBOSE check_gcc
239

240 241
# Look for make include files relative to root of kernel src
MAKEFLAGS += --include-dir=$(srctree)
242

243 244
# For maximum performance (+ possibly random breakage, uncomment
# the following)
245

246
#MAKEFLAGS += -rR
247

248
# Make variables (CC, etc...)
Linus Torvalds's avatar
Linus Torvalds committed
249 250 251 252 253 254 255 256 257 258

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
259
AWK		= awk
Alan Cox's avatar
Alan Cox committed
260 261
RPM 		:= $(shell if [ -x "/usr/bin/rpmbuild" ]; then echo rpmbuild; \
		    	else echo rpm; fi)
262
GENKSYMS	= scripts/genksyms/genksyms
263
DEPMOD		= /sbin/depmod
264
KALLSYMS	= scripts/kallsyms
Kai Germaschewski's avatar
Kai Germaschewski committed
265
PERL		= perl
266
CHECK		= sparse
Linus Torvalds's avatar
Linus Torvalds committed
267
MODFLAGS	= -DMODULE
268
CFLAGS_MODULE   = $(MODFLAGS)
269
AFLAGS_MODULE   = $(MODFLAGS)
270
LDFLAGS_MODULE  = -r
Linus Torvalds's avatar
Linus Torvalds committed
271
CFLAGS_KERNEL	=
272
AFLAGS_KERNEL	=
273

274
NOSTDINC_FLAGS  = -nostdinc -iwithprefix include
Linus Torvalds's avatar
Linus Torvalds committed
275

276 277 278
CPPFLAGS        := -D__KERNEL__ -Iinclude \
		   $(if $(KBUILD_SRC),-Iinclude2 -I$(srctree)/include)

279
CFLAGS 		:= -Wall -Wstrict-prototypes -Wno-trigraphs \
Dave Jones's avatar
Dave Jones committed
280
	  	   -fno-strict-aliasing -fno-common
281
AFLAGS		:= -D__ASSEMBLY__
282

Linus Torvalds's avatar
Linus Torvalds committed
283
export	VERSION PATCHLEVEL SUBLEVEL EXTRAVERSION KERNELRELEASE ARCH \
284
	CONFIG_SHELL HOSTCC HOSTCFLAGS CROSS_COMPILE AS LD CC \
285
	CPP AR NM STRIP OBJCOPY OBJDUMP MAKE AWK GENKSYMS PERL UTS_MACHINE \
286
	HOSTCXX HOSTCXXFLAGS LDFLAGS_BLOB LDFLAGS_MODULE CHECK
Linus Torvalds's avatar
Linus Torvalds committed
287

288
export CPPFLAGS NOSTDINC_FLAGS OBJCOPYFLAGS LDFLAGS
Kai Germaschewski's avatar
Kai Germaschewski committed
289 290 291
export CFLAGS CFLAGS_KERNEL CFLAGS_MODULE 
export AFLAGS AFLAGS_KERNEL AFLAGS_MODULE

292 293
export MODVERDIR := .tmp_versions

294 295
# The temporary file to save gcc -MD generated dependencies must not
# contain a comma
296
comma := ,
297
depfile = $(subst $(comma),_,$(@D)/.$(@F).d)
298

299
# Files to ignore in find ... statements
Linus Torvalds's avatar
Linus Torvalds committed
300

301 302
RCS_FIND_IGNORE := \( -name SCCS -o -name BitKeeper -o -name .svn -o -name CVS \) -prune -o
RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn --exclude CVS
303

304 305 306
# ===========================================================================
# Rules shared between *config targets and build targets

307 308
# Helpers built in scripts/

309
scripts/docproc scripts/split-include : scripts ;
310

311
.PHONY: scripts scripts/fixdep
312
scripts:
313
	$(Q)$(MAKE) $(build)=scripts
314

315 316 317
scripts/fixdep:
	$(Q)$(MAKE) $(build)=scripts $@

318

319 320 321 322 323 324 325 326
# 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).

327 328 329
no-dot-config-targets := clean mrproper distclean \
			 cscope TAGS tags help %docs check%

330 331
config-targets := 0
mixed-targets  := 0
332 333 334 335 336 337 338 339
dot-config     := 1

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

340 341 342 343 344 345 346 347 348 349 350 351 352
ifneq ($(filter config %config,$(MAKECMDGOALS)),)
	config-targets := 1
	ifneq ($(filter-out config %config,$(MAKECMDGOALS)),)
		mixed-targets := 1
	endif
endif

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

%:: FORCE
353
	$(Q)$(MAKE) -C $(srctree) KBUILD_SRC= $@
354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370

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

%config: scripts/fixdep FORCE
	$(Q)$(MAKE) $(build)=scripts/kconfig $@
config : scripts/fixdep FORCE
	$(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.

371 372 373 374 375 376
# That's our default target when none is given on the command line
# Note that 'modules' will be added as a prerequisite as well, 
# in the CONFIG_MODULES part below

all:	vmlinux

377
# Objects we will link into vmlinux / subdirs we need to visit
378 379 380 381
init-y		:= init/
drivers-y	:= drivers/ sound/
net-y		:= net/
libs-y		:= lib/
382
core-y		:= usr/
383 384
SUBDIRS		:=

385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400
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
401 402
include/linux/autoconf.h: .config
	$(Q)$(MAKE) -f $(srctree)/Makefile silentoldconfig
403 404

endif
405

406
include $(srctree)/arch/$(ARCH)/Makefile
407

408
# Let architecture Makefiles change CPPFLAGS if needed
409 410
CFLAGS := $(CPPFLAGS) $(CFLAGS)
AFLAGS := $(CPPFLAGS) $(AFLAGS)
411

412
core-y		+= kernel/ mm/ fs/ ipc/ security/ crypto/
413 414 415 416 417

SUBDIRS		+= $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
		     $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
		     $(net-y) $(net-m) $(libs-y) $(libs-m)))

418 419
ALL_SUBDIRS     := $(sort $(SUBDIRS) $(patsubst %/,%,$(filter %/, \
		     $(init-n) $(init-) \
420
		     $(core-n) $(core-) $(drivers-n) $(drivers-) \
421
		     $(net-n)  $(net-)  $(libs-n)    $(libs-))))
422 423 424 425 426

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))
427 428 429
libs-y1		:= $(patsubst %/, %/lib.a, $(libs-y))
libs-y2		:= $(patsubst %/, %/built-in.o, $(libs-y))
libs-y		:= $(libs-y1) $(libs-y2)
430

431
# Here goes the main Makefile
432
# ---------------------------------------------------------------------------
Linus Torvalds's avatar
Linus Torvalds committed
433 434


435 436 437 438 439 440
ifdef CONFIG_CC_OPTIMIZE_FOR_SIZE
CFLAGS		+= -Os
else
CFLAGS		+= -O2
endif

441 442 443 444
ifndef CONFIG_FRAME_POINTER
CFLAGS		+= -fomit-frame-pointer
endif

445 446 447 448
ifdef CONFIG_DEBUG_INFO
CFLAGS		+= -g
endif

449 450 451
# warn about C99 declaration after statement
CFLAGS += $(call check_gcc,-Wdeclaration-after-statement,)

Linus Torvalds's avatar
Linus Torvalds committed
452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467
#
# 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

468 469 470 471 472 473 474 475 476
# 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.
477 478
head-y += $(HEAD)
vmlinux-objs := $(head-y) $(init-y) $(core-y) $(libs-y) $(drivers-y) $(net-y)
479

480 481
quiet_cmd_vmlinux__ = LD      $@
define cmd_vmlinux__
482
	$(LD) $(LDFLAGS) $(LDFLAGS_vmlinux) $(head-y) $(init-y) \
Ingo Molnar's avatar
Ingo Molnar committed
483
	--start-group \
484 485 486 487
	$(core-y) \
	$(libs-y) \
	$(drivers-y) \
	$(net-y) \
Ingo Molnar's avatar
Ingo Molnar committed
488
	--end-group \
489
	$(filter .tmp_kallsyms%,$^) \
Ingo Molnar's avatar
Ingo Molnar committed
490 491
	-o $@
endef
492 493 494

#	set -e makes the rule exit immediately on error

495
define rule_vmlinux__
496
	+set -e;							\
497 498
	$(if $(filter .tmp_kallsyms%,$^),,				\
	  echo '  GEN     .version';					\
499
	  . $(srctree)/scripts/mkversion > .tmp_version;		\
500 501
	  mv -f .tmp_version .version;					\
	  $(MAKE) $(build)=init;					\
502 503 504 505
	)								\
	$(if $($(quiet)cmd_vmlinux__),					\
	  echo '  $($(quiet)cmd_vmlinux__)' &&) 			\
	$(cmd_vmlinux__);						\
506 507 508
	echo 'cmd_$@ := $(cmd_vmlinux__)' > $(@D)/.$(@F).cmd
endef

509
define rule_vmlinux
510
	$(rule_vmlinux__); \
511
	$(NM) $@ | grep -v '\(compiled\)\|\(\.o$$\)\|\( [aUw] \)\|\(\.\.ng$$\)\|\(LASH[RL]DI\)' | sort > System.map
512 513
endef

514
LDFLAGS_vmlinux += -T arch/$(ARCH)/kernel/vmlinux.lds.s
515

Ingo Molnar's avatar
Ingo Molnar committed
516
#	Generate section listing all symbols and add it into vmlinux
517
#	It's a three stage process:
518
#	o .tmp_vmlinux1 has all symbols and sections, but __kallsyms is
519
#	  empty
Kai Germaschewski's avatar
Kai Germaschewski committed
520
#	  Running kallsyms on that gives us .tmp_kallsyms1.o with
521
#	  the right size
522
#	o .tmp_vmlinux2 now has a __kallsyms section of the right size,
523
#	  but due to the added section, some addresses have shifted
524 525
#	  From here, we generate a correct .tmp_kallsyms2.o
#	o The correct .tmp_kallsyms2.o is linked into the final vmlinux.
Ingo Molnar's avatar
Ingo Molnar committed
526 527 528

ifdef CONFIG_KALLSYMS

529
kallsyms.o := .tmp_kallsyms2.o
Ingo Molnar's avatar
Ingo Molnar committed
530 531

quiet_cmd_kallsyms = KSYM    $@
532
cmd_kallsyms = $(NM) -n $< | $(KALLSYMS) > $@
533

534 535
.tmp_kallsyms1.o .tmp_kallsyms2.o: %.o: %.S scripts FORCE
	$(call if_changed_dep,as_o_S)
Ingo Molnar's avatar
Ingo Molnar committed
536

537
.tmp_kallsyms%.S: .tmp_vmlinux%
538
	$(call cmd,kallsyms)
Ingo Molnar's avatar
Ingo Molnar committed
539

540
.tmp_vmlinux1: $(vmlinux-objs) arch/$(ARCH)/kernel/vmlinux.lds.s FORCE
541
	+$(call if_changed_rule,vmlinux__)
Ingo Molnar's avatar
Ingo Molnar committed
542

543
.tmp_vmlinux2: $(vmlinux-objs) .tmp_kallsyms1.o arch/$(ARCH)/kernel/vmlinux.lds.s FORCE
544
	$(call if_changed_rule,vmlinux__)
545

546
endif
547

548
#	Finally the vmlinux rule
549

550
vmlinux: $(vmlinux-objs) $(kallsyms.o) arch/$(ARCH)/kernel/vmlinux.lds.s FORCE
551
	$(call if_changed_rule,vmlinux)
552

553 554
#	The actual objects are generated when descending, 
#	make sure no implicit rule kicks in
555

556
$(sort $(vmlinux-objs)) arch/$(ARCH)/kernel/vmlinux.lds.s: $(SUBDIRS) ;
Linus Torvalds's avatar
Linus Torvalds committed
557

558 559
# 	Handle descending into subdirectories listed in $(SUBDIRS)

560
.PHONY: $(SUBDIRS)
561
$(SUBDIRS): prepare-all
562
	$(Q)$(MAKE) $(build)=$@
563

564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586
# 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.

.PHONY: prepare-all prepare prepare0 prepare1

# 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

prepare1:
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
587

588
prepare0: prepare1 include/linux/version.h include/asm include/config/MARKER
589 590 591 592 593
ifdef KBUILD_MODULES
ifeq ($(origin SUBDIRS),file)
	$(Q)rm -rf $(MODVERDIR)
else
	@echo '*** Warning: Overriding SUBDIRS on the command line can cause'
594
	@echo '***          inconsistencies'
595 596
endif
endif
597
	$(if $(CONFIG_MODULES),$(Q)mkdir -p $(MODVERDIR))
598

599 600 601
# All the preparing..
prepare-all: prepare0 prepare

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

605
export AFLAGS_vmlinux.lds.o += -P -C -U$(ARCH)
606

607 608 609
# Single targets
# ---------------------------------------------------------------------------

610
%.s: %.c scripts FORCE
611
	$(Q)$(MAKE) $(build)=$(@D) $@
612
%.i: %.c scripts FORCE
613
	$(Q)$(MAKE) $(build)=$(@D) $@
614
%.o: %.c scripts FORCE
615
	$(Q)$(MAKE) $(build)=$(@D) $@
616
%/:      scripts prepare FORCE
617
	$(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) $(build)=$(@D)
618
%.lst: %.c scripts FORCE
619
	$(Q)$(MAKE) $(build)=$(@D) $@
620
%.s: %.S scripts FORCE
621
	$(Q)$(MAKE) $(build)=$(@D) $@
622
%.o: %.S scripts FORCE
623
	$(Q)$(MAKE) $(build)=$(@D) $@
624

625 626 627
# 	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.
628

629
include/asm:
630 631 632
	@echo '  SYMLINK $@ -> include/asm-$(ARCH)'
	$(Q)if [ ! -d include ]; then mkdir -p include; fi;
	@ln -fsn asm-$(ARCH) $@
633

634
# 	Split autoconf.h into include/linux/config/*
635

Linus Torvalds's avatar
Linus Torvalds committed
636
include/config/MARKER: scripts/split-include include/linux/autoconf.h
637
	@echo '  SPLIT   include/linux/autoconf.h -> include/config/*'
638 639
	@scripts/split-include include/linux/autoconf.h include/config
	@touch $@
Linus Torvalds's avatar
Linus Torvalds committed
640

641
# Generate some files
642
# ---------------------------------------------------------------------------
Linus Torvalds's avatar
Linus Torvalds committed
643

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

647 648
uts_len := 64

649 650
define filechk_version.h
	if expr length "$(KERNELRELEASE)" \> $(uts_len) >/dev/null ; then \
651 652
	  echo '"$(KERNELRELEASE)" exceeds $(uts_len) characters' >&2; \
	  exit 1; \
653
	fi; \
654
	(echo \#define UTS_RELEASE \"$(KERNELRELEASE)\"; \
655 656
	  echo \#define LINUX_VERSION_CODE `expr $(VERSION) \\* 65536 + $(PATCHLEVEL) \\* 256 + $(SUBLEVEL)`; \
	 echo '#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))'; \
657 658 659 660 661
	)
endef

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

663 664
# ---------------------------------------------------------------------------

665 666
.PHONY: depend dep
depend dep:
667
	@echo '*** Warning: make $@ is unnecessary now.'
668

669 670
# ---------------------------------------------------------------------------
# Modules
Linus Torvalds's avatar
Linus Torvalds committed
671 672

ifdef CONFIG_MODULES
673

674 675 676 677
# 	By default, build modules as well

all: modules

678 679
#	Build modules

680
.PHONY: modules
681
modules: $(SUBDIRS) $(if $(KBUILD_BUILTIN),vmlinux)
682
	@echo '  Building modules, stage 2.';
683
	$(Q)$(MAKE) -rR -f $(srctree)/scripts/Makefile.modpost
684

685 686
#	Install modules

Linus Torvalds's avatar
Linus Torvalds committed
687
.PHONY: modules_install
688
modules_install: _modinst_ _modinst_post
Linus Torvalds's avatar
Linus Torvalds committed
689 690 691

.PHONY: _modinst_
_modinst_:
692 693
	@if [ -z "`$(DEPMOD) -V | grep module-init-tools`" ]; then \
		echo "Warning: you may need to install module-init-tools"; \
694
		echo "See http://www.codemonkey.org.uk/docs/post-halloween-2.6.txt";\
695 696
		sleep 1; \
	fi
Linus Torvalds's avatar
Linus Torvalds committed
697 698 699 700
	@rm -rf $(MODLIB)/kernel
	@rm -f $(MODLIB)/build
	@mkdir -p $(MODLIB)/kernel
	@ln -s $(TOPDIR) $(MODLIB)/build
701
	$(Q)$(MAKE) -rR -f $(srctree)/scripts/Makefile.modinst
Linus Torvalds's avatar
Linus Torvalds committed
702

703 704 705 706 707 708 709 710 711 712 713
# 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
714
_modinst_post: _modinst_
715 716
	if [ -r System.map ]; then $(DEPMOD) -ae -F System.map $(depmod_opts) $(KERNELRELEASE); fi

717 718 719
else # CONFIG_MODULES

# Modules not configured
720
# ---------------------------------------------------------------------------
Linus Torvalds's avatar
Linus Torvalds committed
721

722
modules modules_install: FORCE
Linus Torvalds's avatar
Linus Torvalds committed
723 724 725 726 727 728 729
	@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

730
endif # CONFIG_MODULES
Linus Torvalds's avatar
Linus Torvalds committed
731

732 733 734
# Generate asm-offsets.h 
# ---------------------------------------------------------------------------

735
define filechk_gen-asm-offsets
736 737 738 739 740 741 742 743 744 745
	(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 ""; \
746
	 sed -ne "/^->/{s:^->\([^ ]*\) [\$$#]*\([^ ]*\) \(.*\):#define \1 \2 /* \3 */:; s:->::; p;}"; \
747 748 749 750
	 echo ""; \
	 echo "#endif" )
endef

751

752 753 754 755 756
###
# Cleaning is done on three levels.
# make clean     Delete all automatically generated files, including
#                tools and firmware.
# make mrproper  Delete the current configuration, and related files
Kai Germaschewski's avatar
Kai Germaschewski committed
757
#                Any core files spread around are deleted as well
758
# make distclean Remove editor backup files, patch leftover files and the like
759

760
# Files removed with 'make clean'
761
CLEAN_FILES += vmlinux System.map MC*
762

763
# Files removed with 'make mrproper'
764 765
MRPROPER_FILES += \
	include/linux/autoconf.h include/linux/version.h \
766
	.version .config .config.old config.in config.old \
767 768
	.menuconfig.log \
	include/asm \
769
	.hdepend include/linux/modversions.h \
770
	tags TAGS cscope* kernel.spec \
771
	.tmp*
772

773
# Directories removed with 'make mrproper'
774
MRPROPER_DIRS += \
775
	$(MODVERDIR) \
Kai Germaschewski's avatar
Kai Germaschewski committed
776
	.tmp_export-objs \
777
	include/config \
778 779
	include/linux/modules \
	include2
Linus Torvalds's avatar
Linus Torvalds committed
780

781
# clean - Delete all intermediate files
782
#
Kai Germaschewski's avatar
Kai Germaschewski committed
783
clean-dirs += $(addprefix _clean_,$(ALL_SUBDIRS) Documentation/DocBook scripts)
784 785
.PHONY: $(clean-dirs) clean archclean mrproper archmrproper distclean
$(clean-dirs):
786
	$(Q)$(MAKE) $(clean)=$(patsubst _clean_%,%,$@)
787 788 789

quiet_cmd_rmclean = RM  $$(CLEAN_FILES)
cmd_rmclean	  = rm -f $(CLEAN_FILES)
790
clean: archclean $(clean-dirs)
791
	$(call cmd,rmclean)
792
	@find . $(RCS_FIND_IGNORE) \
793
	 	\( -name '*.[oas]' -o -name '*.ko' -o -name '.*.cmd' \
794 795
		-o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \) \
		-type f -print | xargs rm -f
Linus Torvalds's avatar
Linus Torvalds committed
796

797 798 799 800
# mrproper - delete configuration + modules + core files
#
quiet_cmd_mrproper = RM  $$(MRPROPER_DIRS) + $$(MRPROPER_FILES)
cmd_mrproper = rm -rf $(MRPROPER_DIRS) && rm -f $(MRPROPER_FILES)
801 802
mrproper distclean: clean archmrproper
	@echo '  Making $@ in the srctree'
803
	@find . $(RCS_FIND_IGNORE) \
804
	 	\( -name '*.orig' -o -name '*.rej' -o -name '*~' \
Linus Torvalds's avatar
Linus Torvalds committed
805
		-o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
806 807 808 809
	 	-o -name '.*.rej' -o -size 0 \
		-o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \
		-type f -print | xargs rm -f
	$(call cmd,mrproper)
Linus Torvalds's avatar
Linus Torvalds committed
810

811 812 813
# Generate tags for editors
# ---------------------------------------------------------------------------

814
define all-sources
815 816 817 818 819 820
	( find . $(RCS_FIND_IGNORE) \
	       \( -name include -o -name arch \) -prune -o \
	       -name '*.[chS]' -print; \
	  find arch/$(ARCH) $(RCS_FIND_IGNORE) \
	       -name '*.[chS]' -print; \
	  find include $(RCS_FIND_IGNORE) \
821
	       \( -name config -o -name 'asm-*' \) -prune \
822
	       -o -name '*.[chS]' -print; \
823 824 825 826
	  find include/asm-$(ARCH) $(RCS_FIND_IGNORE) \
	       -name '*.[chS]' -print; \
	  find include/asm-generic $(RCS_FIND_IGNORE) \
	       -name '*.[chS]' -print )
827 828
endef

829 830 831 832
quiet_cmd_cscope-file = FILELST cscope.files
      cmd_cscope-file = $(all-sources) > cscope.files

quiet_cmd_cscope = MAKE    cscope.out
833
      cmd_cscope = cscope -k -b -q
834 835 836 837

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

839 840
quiet_cmd_TAGS = MAKE   $@
cmd_TAGS = $(all-sources) | etags -
841 842

# 	Exuberant ctags works better with -I
843 844 845 846

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

TAGS: FORCE
	$(call cmd,TAGS)

tags: FORCE
	$(call cmd,tags)
856

Sam Ravnborg's avatar
Sam Ravnborg committed
857 858 859
# RPM target
# ---------------------------------------------------------------------------

860 861
.PHONY: rpm

862 863 864
# Remove hyphens since they have special meaning in RPM filenames
KERNELPATH=kernel-$(subst -,,$(KERNELRELEASE))

Sam Ravnborg's avatar
Sam Ravnborg committed
865 866 867
#	If you do a make spec before packing the tarball you can rpm -ta it

spec:
868
	$(CONFIG_SHELL) $(srctree)/scripts/mkspec > $(objtree)/kernel.spec
Sam Ravnborg's avatar
Sam Ravnborg committed
869

870 871 872 873
#	a) Build a tar ball
#	b) generate an rpm from it
#	c) and pack the result
#	- Use /. to avoid tar packing just the symlink
Sam Ravnborg's avatar
Sam Ravnborg committed
874 875 876

rpm:	clean spec
	set -e; \
877 878
	cd .. ; \
	ln -sf $(srctree) $(KERNELPATH) ; \
Sam Ravnborg's avatar
Sam Ravnborg committed
879
	tar -cvz $(RCS_TAR_IGNORE) -f $(KERNELPATH).tar.gz $(KERNELPATH)/. ; \
880 881 882 883 884 885
	rm $(KERNELPATH)

	set -e; \
	$(CONFIG_SHELL) $(srctree)/scripts/mkversion > $(objtree)/.tmp_version;\
	mv -f $(objtree)/.tmp_version $(objtree)/.version;

886
	$(RPM) --target $(UTS_MACHINE) -ta ../$(KERNELPATH).tar.gz
887
	rm ../$(KERNELPATH).tar.gz
Sam Ravnborg's avatar
Sam Ravnborg committed
888

889 890 891
# Brief documentation of the typical targets used
# ---------------------------------------------------------------------------

892 893 894
boards := $(wildcard $(srctree)/arch/$(ARCH)/configs/*_defconfig)
boards := $(notdir $(boards))

895 896
help:
	@echo  'Cleaning targets:'
Sam Ravnborg's avatar
Sam Ravnborg committed
897 898
	@echo  '  clean		  - remove most generated files but keep the config'
	@echo  '  mrproper	  - remove all generated files + config + various backup files'
899 900
	@echo  ''
	@echo  'Configuration targets:'
901
	@$(MAKE) -f $(srctree)/scripts/kconfig/Makefile help
902 903
	@echo  ''
	@echo  'Other generic targets:'
Sam Ravnborg's avatar
Sam Ravnborg committed
904 905 906 907
	@echo  '  all		  - Build all targets marked with [*]'
	@echo  '* vmlinux	  - Build the bare kernel'
	@echo  '* modules	  - Build all modules'
	@echo  '  modules_install - Install all modules'
908
	@echo  '  dir/            - Build all files in dir and below'
Sam Ravnborg's avatar
Sam Ravnborg committed
909 910 911
	@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'
912 913
	@echo  ''
	@echo  'Documentation targets:'
914
	@$(MAKE) -f $(srctree)/Documentation/DocBook/Makefile dochelp
915 916
	@echo  ''
	@echo  'Architecture specific targets ($(ARCH)):'
917 918
	@$(if $(archhelp),$(archhelp),\
		echo '  No architecture specific help defined for $(ARCH)')
919
	@echo  ''
920 921 922 923 924
	@$(if $(boards), \
		$(foreach b, $(boards), \
		printf "  %-24s - Build for %s\\n" $(b) $(subst _defconfig,,$(b));) \
		echo '')

Sam Ravnborg's avatar
Sam Ravnborg committed
925
	@echo  '  make V=0|1 [targets] 0 => quiet build (default), 1 => verbose build'
926
	@echo  '  make O=dir [targets] Locate all output files in "dir", including .config'
Sam Ravnborg's avatar
Sam Ravnborg committed
927 928
	@echo  '  make C=1   [targets] Check all c source with checker tool'
	@echo  ''
929
	@echo  'Execute "make" or "make all" to build all targets marked with [*] '
930
	@echo  'For further info see the ./README file'
931

932

933 934
# Documentation targets
# ---------------------------------------------------------------------------
935
%docs: scripts/docproc FORCE
936
	$(Q)$(MAKE) $(build)=Documentation/DocBook $@
937 938 939 940

# Scripts to check various things for consistency
# ---------------------------------------------------------------------------

941
configcheck:
942
	find * $(RCS_FIND_IGNORE) \
943 944
		-name '*.[hcS]' -type f -print | sort \
		| xargs $(PERL) -w scripts/checkconfig.pl
945

946
includecheck:
947
	find * $(RCS_FIND_IGNORE) \
948 949
		-name '*.[hcS]' -type f -print | sort \
		| xargs $(PERL) -w scripts/checkincludes.pl
950

951 952 953 954 955
versioncheck:
	find * $(RCS_FIND_IGNORE) \
		-name '*.[hcS]' -type f -print | sort \
		| xargs $(PERL) -w scripts/checkversion.pl

956 957
endif #ifeq ($(config-targets),1)
endif #ifeq ($(mixed-targets),1)
958

959
# FIXME Should go into a make.lib or something 
960
# ===========================================================================
961

962 963
a_flags = -Wp,-MD,$(depfile) $(AFLAGS) $(AFLAGS_KERNEL) \
	  $(NOSTDINC_FLAGS) $(CPPFLAGS) \
964 965
	  $(modkern_aflags) $(EXTRA_AFLAGS) $(AFLAGS_$(*F).o)

966 967 968
quiet_cmd_as_o_S = AS      $@
cmd_as_o_S       = $(CC) $(a_flags) -c -o $@ $<

969 970
# read all saved command lines

971 972 973
targets := $(wildcard $(sort $(targets)))
cmd_files := $(wildcard .*.cmd $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd))

974
ifneq ($(cmd_files),)
975
  $(cmd_files): ;	# Do not try to update included dependency files
976 977 978
  include $(cmd_files)
endif

979 980 981 982 983 984 985
# 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; \
986
	$(if $($(quiet)cmd_$(1)),echo '  $(subst ','\'',$($(quiet)cmd_$(1)))';) \
987
	$(cmd_$(1)); \
988
	scripts/fixdep $(depfile) $@ '$(subst $$,$$$$,$(subst ','\'',$(cmd_$(1))))' > $(@D)/.$(@F).tmp; \
989 990 991
	rm -f $(depfile); \
	mv -f $(@D)/.$(@F).tmp $(@D)/.$(@F).cmd)

992 993 994 995
# 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)

996 997 998 999 1000
if_changed_rule = $(if $(strip $? \
		               $(filter-out $(cmd_$(1)),$(cmd_$(@F)))\
			       $(filter-out $(cmd_$(@F)),$(cmd_$(1)))),\
	               @$(rule_$(1)))

1001
# If quiet is set, only print short version of command
1002

1003
cmd = @$(if $($(quiet)cmd_$(1)),echo '  $($(quiet)cmd_$(1))' &&) $(cmd_$(1))
1004

1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018
# 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
1019 1020
	@set -e;				\
	echo '  CHK     $@';			\
1021
	mkdir -p $(dir $@);			\
1022
	$(filechk_$(1)) < $< > $@.tmp;		\
1023 1024 1025 1026 1027
	if [ -r $@ ] && cmp -s $@ $@.tmp; then	\
		rm -f $@.tmp;			\
	else					\
		echo '  UPD     $@';		\
		mv -f $@.tmp $@;		\
1028 1029
	fi
endef
1030

Kai Germaschewski's avatar
Kai Germaschewski committed
1031
# Shorthand for $(Q)$(MAKE) -f scripts/Makefile.build obj=dir
1032 1033
# Usage:
# $(Q)$(MAKE) $(build)=dir
1034
build := -f $(if $(KBUILD_SRC),$(srctree)/)scripts/Makefile.build obj
1035

Kai Germaschewski's avatar
Kai Germaschewski committed
1036
# Shorthand for $(Q)$(MAKE) -f scripts/Makefile.clean obj=dir
1037 1038
# Usage:
# $(Q)$(MAKE) $(clean)=dir
1039
clean := -f $(if $(KBUILD_SRC),$(srctree)/)scripts/Makefile.clean obj
1040

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

endif	# skip-makefile
1047

1048
FORCE: