Makefile 31.5 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 = 2
EXTRAVERSION =-rc1
Linus Torvalds's avatar
Linus Torvalds committed
5

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

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

15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
# 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.

31 32 33 34 35 36 37 38 39
# 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
40
  KBUILD_VERBOSE = 0
41 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
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

82 83 84 85
# That's our default target when none is given on the command line
.PHONY: all
all:
  
86 87
ifneq ($(KBUILD_OUTPUT),)
# Invoke a second make in the output directory, passing relevant variables
88 89 90 91 92
# 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))
93

94
.PHONY: $(MAKECMDGOALS)
95

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

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

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

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

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

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

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

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

170
KBUILD_MODULES :=
171 172
KBUILD_BUILTIN := 1

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

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

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

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

194 195
export KBUILD_MODULES KBUILD_BUILTIN KBUILD_VERBOSE
export KBUILD_CHECKSRC KBUILD_SRC
196

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

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

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

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

235 236 237
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
238

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

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

245
#MAKEFLAGS += -rR
246

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

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

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

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

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

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

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

291 292
export MODVERDIR := .tmp_versions

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

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

300 301
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
302

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

306 307
# Helpers built in scripts/

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

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

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

317

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

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

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

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

339 340 341 342 343 344 345 346 347 348 349 350 351
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
352
	$(Q)$(MAKE) -C $(srctree) KBUILD_SRC= $@
353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369

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.

370 371 372 373 374 375
# 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

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

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

endif
404

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

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

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

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

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

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

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


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

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

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

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

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

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

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

#	set -e makes the rule exit immediately on error

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

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

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

Ingo Molnar's avatar
Ingo Molnar committed
515
#	Generate section listing all symbols and add it into vmlinux
516
#	It's a three stage process:
517
#	o .tmp_vmlinux1 has all symbols and sections, but __kallsyms is
518
#	  empty
Kai Germaschewski's avatar
Kai Germaschewski committed
519
#	  Running kallsyms on that gives us .tmp_kallsyms1.o with
520
#	  the right size
521
#	o .tmp_vmlinux2 now has a __kallsyms section of the right size,
522
#	  but due to the added section, some addresses have shifted
523 524
#	  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
525 526 527

ifdef CONFIG_KALLSYMS

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

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

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

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

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

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

545
endif
546

547
#	Finally the vmlinux rule
548

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

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

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

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

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

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

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

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

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

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

606 607 608
# Single targets
# ---------------------------------------------------------------------------

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

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

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

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

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

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

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

646 647
uts_len := 64

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

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

662 663
# ---------------------------------------------------------------------------

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

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

ifdef CONFIG_MODULES
672

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

all: modules

677 678
#	Build modules

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

684 685
#	Install modules

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

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

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

716 717 718
else # CONFIG_MODULES

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

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

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

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

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

750

751 752 753 754 755
###
# 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
756
#                Any core files spread around are deleted as well
757
# make distclean Remove editor backup files, patch leftover files and the like
758

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

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

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

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

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

796 797 798 799
# mrproper - delete configuration + modules + core files
#
quiet_cmd_mrproper = RM  $$(MRPROPER_DIRS) + $$(MRPROPER_FILES)
cmd_mrproper = rm -rf $(MRPROPER_DIRS) && rm -f $(MRPROPER_FILES)
800 801
mrproper distclean: clean archmrproper
	@echo '  Making $@ in the srctree'
802
	@find . $(RCS_FIND_IGNORE) \
803
	 	\( -name '*.orig' -o -name '*.rej' -o -name '*~' \
Linus Torvalds's avatar
Linus Torvalds committed
804
		-o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
805 806 807 808
	 	-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
809

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

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

828 829 830
quiet_cmd_cscope = MAKE   $@
cmd_cscope = $(all-sources) | cscope -k -b -i -

831 832
quiet_cmd_TAGS = MAKE   $@
cmd_TAGS = $(all-sources) | etags -
833 834

# 	Exuberant ctags works better with -I
835 836 837 838

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

843 844 845
cscope: FORCE
	$(call cmd,cscope)

846 847 848 849 850
TAGS: FORCE
	$(call cmd,TAGS)

tags: FORCE
	$(call cmd,tags)
851

Sam Ravnborg's avatar
Sam Ravnborg committed
852 853 854
# RPM target
# ---------------------------------------------------------------------------

855 856
.PHONY: rpm

857 858 859
# Remove hyphens since they have special meaning in RPM filenames
KERNELPATH=kernel-$(subst -,,$(KERNELRELEASE))

Sam Ravnborg's avatar
Sam Ravnborg committed
860 861 862
#	If you do a make spec before packing the tarball you can rpm -ta it

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

865 866 867 868
#	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
869 870 871

rpm:	clean spec
	set -e; \
872 873
	cd .. ; \
	ln -sf $(srctree) $(KERNELPATH) ; \
Sam Ravnborg's avatar
Sam Ravnborg committed
874
	tar -cvz $(RCS_TAR_IGNORE) -f $(KERNELPATH).tar.gz $(KERNELPATH)/. ; \
875 876 877 878 879 880
	rm $(KERNELPATH)

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

881
	$(RPM) --target $(UTS_MACHINE) -ta ../$(KERNELPATH).tar.gz
882
	rm ../$(KERNELPATH).tar.gz
Sam Ravnborg's avatar
Sam Ravnborg committed
883

884 885 886 887 888
# Brief documentation of the typical targets used
# ---------------------------------------------------------------------------

help:
	@echo  'Cleaning targets:'
Sam Ravnborg's avatar
Sam Ravnborg committed
889 890
	@echo  '  clean		  - remove most generated files but keep the config'
	@echo  '  mrproper	  - remove all generated files + config + various backup files'
891 892
	@echo  ''
	@echo  'Configuration targets:'
893
	@$(MAKE) -f $(srctree)/scripts/kconfig/Makefile help
894 895
	@echo  ''
	@echo  'Other generic targets:'
Sam Ravnborg's avatar
Sam Ravnborg committed
896 897 898 899
	@echo  '  all		  - Build all targets marked with [*]'
	@echo  '* vmlinux	  - Build the bare kernel'
	@echo  '* modules	  - Build all modules'
	@echo  '  modules_install - Install all modules'
900
	@echo  '  dir/            - Build all files in dir and below'
Sam Ravnborg's avatar
Sam Ravnborg committed
901 902 903
	@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'
904 905
	@echo  ''
	@echo  'Documentation targets:'
906
	@$(MAKE) -f $(srctree)/Documentation/DocBook/Makefile dochelp
907 908
	@echo  ''
	@echo  'Architecture specific targets ($(ARCH)):'
909 910
	@$(if $(archhelp),$(archhelp),\
		echo '  No architecture specific help defined for $(ARCH)')
911
	@echo  ''
Sam Ravnborg's avatar
Sam Ravnborg committed
912
	@echo  '  make V=0|1 [targets] 0 => quiet build (default), 1 => verbose build'
913
	@echo  '  make O=dir [targets] Locate all output files in "dir", including .config'
Sam Ravnborg's avatar
Sam Ravnborg committed
914 915
	@echo  '  make C=1   [targets] Check all c source with checker tool'
	@echo  ''
916
	@echo  'Execute "make" or "make all" to build all targets marked with [*] '
917
	@echo  'For further info see the ./README file'
918

919

920 921
# Documentation targets
# ---------------------------------------------------------------------------
922
%docs: scripts/docproc FORCE
923
	$(Q)$(MAKE) $(build)=Documentation/DocBook $@
924 925 926 927

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

928
configcheck:
929
	find * $(RCS_FIND_IGNORE) \
930 931
		-name '*.[hcS]' -type f -print | sort \
		| xargs $(PERL) -w scripts/checkconfig.pl
932

933
includecheck:
934
	find * $(RCS_FIND_IGNORE) \
935 936
		-name '*.[hcS]' -type f -print | sort \
		| xargs $(PERL) -w scripts/checkincludes.pl
937

938 939 940 941 942
versioncheck:
	find * $(RCS_FIND_IGNORE) \
		-name '*.[hcS]' -type f -print | sort \
		| xargs $(PERL) -w scripts/checkversion.pl

943 944
endif #ifeq ($(config-targets),1)
endif #ifeq ($(mixed-targets),1)
945

946
# FIXME Should go into a make.lib or something 
947
# ===========================================================================
948

949 950
a_flags = -Wp,-MD,$(depfile) $(AFLAGS) $(AFLAGS_KERNEL) \
	  $(NOSTDINC_FLAGS) $(CPPFLAGS) \
951 952
	  $(modkern_aflags) $(EXTRA_AFLAGS) $(AFLAGS_$(*F).o)

953 954 955
quiet_cmd_as_o_S = AS      $@
cmd_as_o_S       = $(CC) $(a_flags) -c -o $@ $<

956 957
# read all saved command lines

958 959 960
targets := $(wildcard $(sort $(targets)))
cmd_files := $(wildcard .*.cmd $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd))

961
ifneq ($(cmd_files),)
962
  $(cmd_files): ;	# Do not try to update included dependency files
963 964 965
  include $(cmd_files)
endif

966 967 968 969 970 971 972
# 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; \
973
	$(if $($(quiet)cmd_$(1)),echo '  $(subst ','\'',$($(quiet)cmd_$(1)))';) \
974
	$(cmd_$(1)); \
975
	scripts/fixdep $(depfile) $@ '$(subst $$,$$$$,$(subst ','\'',$(cmd_$(1))))' > $(@D)/.$(@F).tmp; \
976 977 978
	rm -f $(depfile); \
	mv -f $(@D)/.$(@F).tmp $(@D)/.$(@F).cmd)

979 980 981 982
# 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)

983 984 985 986 987
if_changed_rule = $(if $(strip $? \
		               $(filter-out $(cmd_$(1)),$(cmd_$(@F)))\
			       $(filter-out $(cmd_$(@F)),$(cmd_$(1)))),\
	               @$(rule_$(1)))

988
# If quiet is set, only print short version of command
989

990
cmd = @$(if $($(quiet)cmd_$(1)),echo '  $($(quiet)cmd_$(1))' &&) $(cmd_$(1))
991

992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005
# 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
1006 1007
	@set -e;				\
	echo '  CHK     $@';			\
1008
	mkdir -p $(dir $@);			\
1009
	$(filechk_$(1)) < $< > $@.tmp;		\
1010 1011 1012 1013 1014
	if [ -r $@ ] && cmp -s $@ $@.tmp; then	\
		rm -f $@.tmp;			\
	else					\
		echo '  UPD     $@';		\
		mv -f $@.tmp $@;		\
1015 1016
	fi
endef
1017

Kai Germaschewski's avatar
Kai Germaschewski committed
1018
# Shorthand for $(Q)$(MAKE) -f scripts/Makefile.build obj=dir
1019 1020
# Usage:
# $(Q)$(MAKE) $(build)=dir
1021
build := -f $(if $(KBUILD_SRC),$(srctree)/)scripts/Makefile.build obj
1022

Kai Germaschewski's avatar
Kai Germaschewski committed
1023
# Shorthand for $(Q)$(MAKE) -f scripts/Makefile.clean obj=dir
1024 1025
# Usage:
# $(Q)$(MAKE) $(clean)=dir
1026
clean := -f $(if $(KBUILD_SRC),$(srctree)/)scripts/Makefile.clean obj
1027

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

endif	# skip-makefile
1034

1035
FORCE: