Makefile 27.4 KB
Newer Older
Linus Torvalds's avatar
Linus Torvalds committed
1
VERSION = 2
Linus Torvalds's avatar
Linus Torvalds committed
2 3
PATCHLEVEL = 6
SUBLEVEL = 0
Linus Torvalds's avatar
Linus Torvalds committed
4
EXTRAVERSION = -test4
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 15 16 17 18 19 20 21 22 23 24 25 26 27
# 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.

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

30 31 32 33 34 35
# 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.

36 37
SUBARCH := $(shell uname -m | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ \
				  -e s/arm.*/arm/ -e s/sa110/arm/ \
38
				  -e s/s390x/s390/ -e s/parisc64/parisc/ )
39

Kai Germaschewski's avatar
Kai Germaschewski committed
40 41
# Remove hyphens since they have special meaning in RPM filenames
KERNELPATH=kernel-$(subst -,,$(KERNELRELEASE))
Linus Torvalds's avatar
Linus Torvalds committed
42

43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
# 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
66 67
UTS_MACHINE := $(ARCH)

68
# SHELL used by kbuild
Linus Torvalds's avatar
Linus Torvalds committed
69 70 71
CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
	  else if [ -x /bin/bash ]; then echo /bin/bash; \
	  else echo sh; fi ; fi)
Kai Germaschewski's avatar
Kai Germaschewski committed
72
TOPDIR	:= $(CURDIR)
Linus Torvalds's avatar
Linus Torvalds committed
73 74

HOSTCC  	= gcc
75
HOSTCXX  	= g++
Linus Torvalds's avatar
Linus Torvalds committed
76
HOSTCFLAGS	= -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer
77
HOSTCXXFLAGS	= -O2
Linus Torvalds's avatar
Linus Torvalds committed
78 79


80
# 	That's our default target when none is given on the command line
81 82
#	Note that 'modules' will be added as a prerequisite as well, 
#	in the CONFIG_MODULES part below
83

84
all:	vmlinux
85

86 87
# 	Decide whether to build built-in, modular, or both.
#	Normally, just do built-in.
88

89
KBUILD_MODULES :=
90 91
KBUILD_BUILTIN := 1

92
#	If we have only "make modules", don't compile built-in objects.
93 94 95
#	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.
96 97

ifeq ($(MAKECMDGOALS),modules)
98
  KBUILD_BUILTIN := $(if $(CONFIG_MODVERSIONS),1)
99 100 101 102 103 104
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

105
ifneq ($(filter all modules,$(MAKECMDGOALS)),)
106 107 108
  KBUILD_MODULES := 1
endif

109
ifeq ($(MAKECMDGOALS),)
110 111 112
  KBUILD_MODULES := 1
endif

113
export KBUILD_MODULES KBUILD_BUILTIN KBUILD_VERBOSE KBUILD_CHECKSRC
114

115
# To put more focus on warnings, less verbose as default
116
# Use 'make V=1' to see the full commands
Kai Germaschewski's avatar
Kai Germaschewski committed
117

118 119 120 121 122
ifdef V
  ifeq ("$(origin V)", "command line")
    KBUILD_VERBOSE = $(V)
  endif
endif
Kai Germaschewski's avatar
Kai Germaschewski committed
123
ifndef KBUILD_VERBOSE
124
  KBUILD_VERBOSE = 0 
Kai Germaschewski's avatar
Kai Germaschewski committed
125 126
endif

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

130 131 132 133 134 135 136 137 138
ifdef C
  ifeq ("$(origin C)", "command line")
    KBUILD_CHECKSRC = $(C)
  endif
endif
ifndef KBUILD_CHECKSRC
  KBUILD_CHECKSRC = 0
endif

139
# Do not print 'Entering directory ...'
140

141 142
MAKEFLAGS += --no-print-directory

143 144 145 146 147
# For maximum performance (+ possibly random breakage, uncomment
# the following)

#MAKEFLAGS += -rR

148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
# 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.
170

171 172 173 174
ifeq ($(KBUILD_VERBOSE),1)
  quiet =
  Q =
else
175
  quiet=quiet_
176
  Q = @
177 178
endif

179 180
# If the user is running make -s (silent mode), suppress echoing of
# commands
181 182 183 184 185

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

186
export quiet Q KBUILD_VERBOSE
187

188
# Paths to obj / src tree
189 190 191 192 193 194 195 196

src	:= .
obj	:= .
srctree := .
objtree := .

export srctree objtree

197
# Make variables (CC, etc...)
Linus Torvalds's avatar
Linus Torvalds committed
198 199 200 201 202 203 204 205 206 207

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
208
AWK		= awk
Alan Cox's avatar
Alan Cox committed
209 210
RPM 		:= $(shell if [ -x "/usr/bin/rpmbuild" ]; then echo rpmbuild; \
		    	else echo rpm; fi)
211
GENKSYMS	= scripts/genksyms/genksyms
212
DEPMOD		= /sbin/depmod
213
KALLSYMS	= scripts/kallsyms
Kai Germaschewski's avatar
Kai Germaschewski committed
214
PERL		= perl
215
CHECK		= sparse
Linus Torvalds's avatar
Linus Torvalds committed
216
MODFLAGS	= -DMODULE
217
CFLAGS_MODULE   = $(MODFLAGS)
218
AFLAGS_MODULE   = $(MODFLAGS)
219
LDFLAGS_MODULE  = -r
Linus Torvalds's avatar
Linus Torvalds committed
220
CFLAGS_KERNEL	=
221
AFLAGS_KERNEL	=
222

223
NOSTDINC_FLAGS  = -nostdinc -iwithprefix include
Linus Torvalds's avatar
Linus Torvalds committed
224

225
CPPFLAGS	:= -D__KERNEL__ -Iinclude
226
CFLAGS 		:= -Wall -Wstrict-prototypes -Wno-trigraphs -O2 \
Dave Jones's avatar
Dave Jones committed
227
	  	   -fno-strict-aliasing -fno-common
228
AFLAGS		:= -D__ASSEMBLY__
229

Linus Torvalds's avatar
Linus Torvalds committed
230
export	VERSION PATCHLEVEL SUBLEVEL EXTRAVERSION KERNELRELEASE ARCH \
231
	CONFIG_SHELL TOPDIR HOSTCC HOSTCFLAGS CROSS_COMPILE AS LD CC \
232
	CPP AR NM STRIP OBJCOPY OBJDUMP MAKE AWK GENKSYMS PERL UTS_MACHINE \
233
	HOSTCXX HOSTCXXFLAGS LDFLAGS_BLOB LDFLAGS_MODULE CHECK
Linus Torvalds's avatar
Linus Torvalds committed
234

235
export CPPFLAGS NOSTDINC_FLAGS OBJCOPYFLAGS LDFLAGS
Kai Germaschewski's avatar
Kai Germaschewski committed
236 237 238
export CFLAGS CFLAGS_KERNEL CFLAGS_MODULE 
export AFLAGS AFLAGS_KERNEL AFLAGS_MODULE

239 240
export MODVERDIR := .tmp_versions

241 242
# The temporary file to save gcc -MD generated dependencies must not
# contain a comma
243
comma := ,
244
depfile = $(subst $(comma),_,$(@D)/.$(@F).d)
245

246
# Files to ignore in find ... statements
Linus Torvalds's avatar
Linus Torvalds committed
247

248 249
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
250

251 252 253
# ===========================================================================
# Rules shared between *config targets and build targets

254 255 256 257 258 259
# Helpers built in scripts/

scripts/docproc scripts/fixdep scripts/split-include : scripts ;

.PHONY: scripts
scripts:
260
	$(Q)$(MAKE) $(build)=scripts
261

262

263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304
# 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).

config-targets := 0
mixed-targets  := 0
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
	$(Q)$(MAKE) $@

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.

# Objects we will link into vmlinux / subdirs we need to visit
305 306 307 308
init-y		:= init/
drivers-y	:= drivers/ sound/
net-y		:= net/
libs-y		:= lib/
309
core-y		:= usr/
310 311 312 313 314 315
SUBDIRS		:=

-include .config

include arch/$(ARCH)/Makefile

316 317 318 319
# Let architecture Makefiles change CPPFLAGS if needed
CFLAGS += $(CPPFLAGS) $(CFLAGS)
AFLAGS += $(CPPFLAGS) $(AFLAGS)

320
core-y		+= kernel/ mm/ fs/ ipc/ security/ crypto/
321 322 323 324 325

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

326 327
ALL_SUBDIRS     := $(sort $(SUBDIRS) $(patsubst %/,%,$(filter %/, \
		     $(init-n) $(init-) \
328
		     $(core-n) $(core-) $(drivers-n) $(drivers-) \
329
		     $(net-n)  $(net-)  $(libs-n)    $(libs-))))
330 331 332 333 334

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))
335 336 337
libs-y1		:= $(patsubst %/, %/lib.a, $(libs-y))
libs-y2		:= $(patsubst %/, %/built-in.o, $(libs-y))
libs-y		:= $(libs-y1) $(libs-y2)
338

339
# Here goes the main Makefile
340
# ---------------------------------------------------------------------------
Linus Torvalds's avatar
Linus Torvalds committed
341
#
342 343 344 345
# If the user gave a *config target, it'll be handled in another
# section below, since in this case we cannot include .config
# Same goes for other targets like clean/mrproper etc, which
# don't need .config, either
Linus Torvalds's avatar
Linus Torvalds committed
346

347 348
#	In this section, we need .config

349
-include .config.cmd
Linus Torvalds's avatar
Linus Torvalds committed
350

351 352 353 354
ifndef CONFIG_FRAME_POINTER
CFLAGS		+= -fomit-frame-pointer
endif

355 356 357 358
ifdef CONFIG_DEBUG_INFO
CFLAGS		+= -g
endif

Linus Torvalds's avatar
Linus Torvalds committed
359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374
#
# 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

375 376 377 378 379 380 381 382 383
# 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.
384 385
head-y += $(HEAD)
vmlinux-objs := $(head-y) $(init-y) $(core-y) $(libs-y) $(drivers-y) $(net-y)
386

387 388
quiet_cmd_vmlinux__ = LD      $@
define cmd_vmlinux__
389
	$(LD) $(LDFLAGS) $(LDFLAGS_vmlinux) $(head-y) $(init-y) \
Ingo Molnar's avatar
Ingo Molnar committed
390
	--start-group \
391 392 393 394
	$(core-y) \
	$(libs-y) \
	$(drivers-y) \
	$(net-y) \
Ingo Molnar's avatar
Ingo Molnar committed
395
	--end-group \
396
	$(filter .tmp_kallsyms%,$^) \
Ingo Molnar's avatar
Ingo Molnar committed
397 398
	-o $@
endef
399 400 401

#	set -e makes the rule exit immediately on error

402
define rule_vmlinux__
403
	+set -e;							\
404 405
	$(if $(filter .tmp_kallsyms%,$^),,				\
	  echo '  GEN     .version';					\
406
	  . $(srctree)/scripts/mkversion > .tmp_version;		\
407 408
	  mv -f .tmp_version .version;					\
	  $(MAKE) $(build)=init;					\
409 410 411 412
	)								\
	$(if $($(quiet)cmd_vmlinux__),					\
	  echo '  $($(quiet)cmd_vmlinux__)' &&) 			\
	$(cmd_vmlinux__);						\
413 414 415
	echo 'cmd_$@ := $(cmd_vmlinux__)' > $(@D)/.$(@F).cmd
endef

416
define rule_vmlinux
417
	$(rule_vmlinux__); \
418
	$(NM) $@ | grep -v '\(compiled\)\|\(\.o$$\)\|\( [aUw] \)\|\(\.\.ng$$\)\|\(LASH[RL]DI\)' | sort > System.map
419 420
endef

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

Ingo Molnar's avatar
Ingo Molnar committed
423
#	Generate section listing all symbols and add it into vmlinux
424
#	It's a three stage process:
425
#	o .tmp_vmlinux1 has all symbols and sections, but __kallsyms is
426
#	  empty
Kai Germaschewski's avatar
Kai Germaschewski committed
427
#	  Running kallsyms on that gives us .tmp_kallsyms1.o with
428
#	  the right size
429
#	o .tmp_vmlinux2 now has a __kallsyms section of the right size,
430
#	  but due to the added section, some addresses have shifted
431 432
#	  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
433 434 435

ifdef CONFIG_KALLSYMS

436
kallsyms.o := .tmp_kallsyms2.o
Ingo Molnar's avatar
Ingo Molnar committed
437 438

quiet_cmd_kallsyms = KSYM    $@
439
cmd_kallsyms = $(NM) -n $< | $(KALLSYMS) > $@
440

441 442
.tmp_kallsyms1.o .tmp_kallsyms2.o: %.o: %.S scripts FORCE
	$(call if_changed_dep,as_o_S)
Ingo Molnar's avatar
Ingo Molnar committed
443

444
.tmp_kallsyms%.S: .tmp_vmlinux%
445
	$(call cmd,kallsyms)
Ingo Molnar's avatar
Ingo Molnar committed
446

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

450
.tmp_vmlinux2: $(vmlinux-objs) .tmp_kallsyms1.o arch/$(ARCH)/kernel/vmlinux.lds.s FORCE
451
	$(call if_changed_rule,vmlinux__)
452

453
endif
454

455
#	Finally the vmlinux rule
456

457
vmlinux: $(vmlinux-objs) $(kallsyms.o) arch/$(ARCH)/kernel/vmlinux.lds.s FORCE
458
	$(call if_changed_rule,vmlinux)
459

460 461
#	The actual objects are generated when descending, 
#	make sure no implicit rule kicks in
462

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

465 466
# 	Handle descending into subdirectories listed in $(SUBDIRS)

467
.PHONY: $(SUBDIRS)
468
$(SUBDIRS): prepare
469
	$(Q)$(MAKE) $(build)=$@
470

471 472
#	Things we need done before we descend to build or make
#	module versions are listed in "prepare"
473 474

.PHONY: prepare
475
prepare: include/linux/version.h include/asm include/config/MARKER
476 477 478 479 480
ifdef KBUILD_MODULES
ifeq ($(origin SUBDIRS),file)
	$(Q)rm -rf $(MODVERDIR)
else
	@echo '*** Warning: Overriding SUBDIRS on the command line can cause'
481
	@echo '***          inconsistencies'
482 483
endif
endif
484
	$(if $(CONFIG_MODULES),$(Q)mkdir -p $(MODVERDIR))
485

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

489
export AFLAGS_vmlinux.lds.o += -P -C -U$(ARCH)
490

491 492 493
# Single targets
# ---------------------------------------------------------------------------

494
%.s: %.c scripts FORCE
495
	$(Q)$(MAKE) $(build)=$(@D) $@
496
%.i: %.c scripts FORCE
497
	$(Q)$(MAKE) $(build)=$(@D) $@
498
%.o: %.c scripts FORCE
499
	$(Q)$(MAKE) $(build)=$(@D) $@
500
%/:      scripts prepare FORCE
501
	$(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) $(build)=$(@D)
502
%.lst: %.c scripts FORCE
503
	$(Q)$(MAKE) $(build)=$(@D) $@
504
%.s: %.S scripts FORCE
505
	$(Q)$(MAKE) $(build)=$(@D) $@
506
%.o: %.S scripts FORCE
507
	$(Q)$(MAKE) $(build)=$(@D) $@
508

509 510 511
# 	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.
512

513
include/asm:
514
	@echo '  Making asm->asm-$(ARCH) symlink'
515
	@ln -s asm-$(ARCH) $@
516

517
# 	Split autoconf.h into include/linux/config/*
518

Linus Torvalds's avatar
Linus Torvalds committed
519
include/config/MARKER: scripts/split-include include/linux/autoconf.h
520
	@echo '  SPLIT   include/linux/autoconf.h -> include/config/*'
521 522
	@scripts/split-include include/linux/autoconf.h include/config
	@touch $@
Linus Torvalds's avatar
Linus Torvalds committed
523

524 525 526
# 	if .config is newer than include/linux/autoconf.h, someone tinkered
# 	with it and forgot to run make oldconfig

527
include/linux/autoconf.h: .config scripts/fixdep
528
	$(Q)$(MAKE) $(build)=scripts/kconfig scripts/kconfig/conf
529
	./scripts/kconfig/conf -s arch/$(ARCH)/Kconfig
530

531
# Generate some files
532
# ---------------------------------------------------------------------------
Linus Torvalds's avatar
Linus Torvalds committed
533

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

537 538
uts_len := 64

539 540
define filechk_version.h
	if expr length "$(KERNELRELEASE)" \> $(uts_len) >/dev/null ; then \
541 542
	  echo '"$(KERNELRELEASE)" exceeds $(uts_len) characters' >&2; \
	  exit 1; \
543
	fi; \
544
	(echo \#define UTS_RELEASE \"$(KERNELRELEASE)\"; \
545 546
	  echo \#define LINUX_VERSION_CODE `expr $(VERSION) \\* 65536 + $(PATCHLEVEL) \\* 256 + $(SUBLEVEL)`; \
	 echo '#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))'; \
547 548 549 550 551
	)
endef

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

553 554
# ---------------------------------------------------------------------------

555 556
.PHONY: depend dep
depend dep:
557
	@echo '*** Warning: make $@ is unnecessary now.'
558

559 560
# ---------------------------------------------------------------------------
# Modules
Linus Torvalds's avatar
Linus Torvalds committed
561 562

ifdef CONFIG_MODULES
563

564 565 566 567
# 	By default, build modules as well

all: modules

568 569
#	Build modules

570
.PHONY: modules
571
modules: $(SUBDIRS) $(if $(KBUILD_BUILTIN),vmlinux)
572
	@echo '  Building modules, stage 2.';
573
	$(Q)$(MAKE) -rR -f scripts/Makefile.modpost
574

575 576
#	Install modules

Linus Torvalds's avatar
Linus Torvalds committed
577
.PHONY: modules_install
578
modules_install: _modinst_ _modinst_post
Linus Torvalds's avatar
Linus Torvalds committed
579 580 581 582 583 584 585

.PHONY: _modinst_
_modinst_:
	@rm -rf $(MODLIB)/kernel
	@rm -f $(MODLIB)/build
	@mkdir -p $(MODLIB)/kernel
	@ln -s $(TOPDIR) $(MODLIB)/build
586
	$(Q)$(MAKE) -rR -f scripts/Makefile.modinst
Linus Torvalds's avatar
Linus Torvalds committed
587

588 589 590 591 592 593 594 595 596 597 598
# 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
599
_modinst_post: _modinst_
600 601
	if [ -r System.map ]; then $(DEPMOD) -ae -F System.map $(depmod_opts) $(KERNELRELEASE); fi

602 603 604
else # CONFIG_MODULES

# Modules not configured
605
# ---------------------------------------------------------------------------
Linus Torvalds's avatar
Linus Torvalds committed
606

607
modules modules_install: FORCE
Linus Torvalds's avatar
Linus Torvalds committed
608 609 610 611 612 613 614
	@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

615
endif # CONFIG_MODULES
Linus Torvalds's avatar
Linus Torvalds committed
616

617 618 619
# Generate asm-offsets.h 
# ---------------------------------------------------------------------------

620
define filechk_gen-asm-offsets
621 622 623 624 625 626 627 628 629 630
	(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 ""; \
631
	 sed -ne "/^->/{s:^->\([^ ]*\) [\$$#]*\([^ ]*\) \(.*\):#define \1 \2 /* \3 */:; s:->::; p;}"; \
632 633 634 635
	 echo ""; \
	 echo "#endif" )
endef

636

637 638 639 640 641
###
# 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
642
#                Any core files spread around are deleted as well
643
# make distclean Remove editor backup files, patch leftover files and the like
644

645
# Files removed with 'make clean'
646
CLEAN_FILES += vmlinux System.map MC*
647

648
# Files removed with 'make mrproper'
649 650
MRPROPER_FILES += \
	include/linux/autoconf.h include/linux/version.h \
651
	.version .config .config.old config.in config.old \
652 653
	.menuconfig.log \
	include/asm \
654
	.hdepend include/linux/modversions.h \
655
	tags TAGS cscope kernel.spec \
656
	.tmp*
657

658
# Directories removed with 'make mrproper'
659
MRPROPER_DIRS += \
660
	$(MODVERDIR) \
Kai Germaschewski's avatar
Kai Germaschewski committed
661
	.tmp_export-objs \
662
	include/config \
663
	include/linux/modules
Linus Torvalds's avatar
Linus Torvalds committed
664

665
# clean - Delete all intermediate files
666
#
Kai Germaschewski's avatar
Kai Germaschewski committed
667
clean-dirs += $(addprefix _clean_,$(ALL_SUBDIRS) Documentation/DocBook scripts)
668 669
.PHONY: $(clean-dirs) clean archclean mrproper archmrproper distclean
$(clean-dirs):
670
	$(Q)$(MAKE) $(clean)=$(patsubst _clean_%,%,$@)
671 672 673

quiet_cmd_rmclean = RM  $$(CLEAN_FILES)
cmd_rmclean	  = rm -f $(CLEAN_FILES)
674
clean: archclean $(clean-dirs)
675
	$(call cmd,rmclean)
676
	@find . $(RCS_FIND_IGNORE) \
677
	 	\( -name '*.[oas]' -o -name '*.ko' -o -name '.*.cmd' \
678 679
		-o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \) \
		-type f -print | xargs rm -f
Linus Torvalds's avatar
Linus Torvalds committed
680

681 682 683 684
# mrproper - delete configuration + modules + core files
#
quiet_cmd_mrproper = RM  $$(MRPROPER_DIRS) + $$(MRPROPER_FILES)
cmd_mrproper = rm -rf $(MRPROPER_DIRS) && rm -f $(MRPROPER_FILES)
685 686
mrproper distclean: clean archmrproper
	@echo '  Making $@ in the srctree'
687
	@find . $(RCS_FIND_IGNORE) \
688
	 	\( -name '*.orig' -o -name '*.rej' -o -name '*~' \
Linus Torvalds's avatar
Linus Torvalds committed
689
		-o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
690 691 692 693
	 	-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
694

695 696 697
# Generate tags for editors
# ---------------------------------------------------------------------------

698
define all-sources
699 700 701 702 703 704
	( 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) \
705
	       \( -name config -o -name 'asm-*' \) -prune \
706
	       -o -name '*.[chS]' -print; \
707 708 709 710
	  find include/asm-$(ARCH) $(RCS_FIND_IGNORE) \
	       -name '*.[chS]' -print; \
	  find include/asm-generic $(RCS_FIND_IGNORE) \
	       -name '*.[chS]' -print )
711 712
endef

713 714 715
quiet_cmd_cscope = MAKE   $@
cmd_cscope = $(all-sources) | cscope -k -b -i -

716 717
quiet_cmd_TAGS = MAKE   $@
cmd_TAGS = $(all-sources) | etags -
718 719

# 	Exuberant ctags works better with -I
720 721 722 723

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

728 729 730
cscope: FORCE
	$(call cmd,cscope)

731 732 733 734 735
TAGS: FORCE
	$(call cmd,TAGS)

tags: FORCE
	$(call cmd,tags)
736

Sam Ravnborg's avatar
Sam Ravnborg committed
737 738 739
# RPM target
# ---------------------------------------------------------------------------

740 741
.PHONY: rpm

Sam Ravnborg's avatar
Sam Ravnborg committed
742 743 744
#	If you do a make spec before packing the tarball you can rpm -ta it

spec:
745
	. $(srctree)/scripts/mkspec >kernel.spec
Sam Ravnborg's avatar
Sam Ravnborg committed
746 747

#	Build a tar ball, generate an rpm from it and pack the result
Kai Germaschewski's avatar
Kai Germaschewski committed
748
#	There are two bits of magic here
Sam Ravnborg's avatar
Sam Ravnborg committed
749 750 751 752 753 754 755 756 757 758 759 760 761 762
#	1) The use of /. to avoid tar packing just the symlink
#	2) Removing the .dep files as they have source paths in them that
#	   will become invalid

rpm:	clean spec
	find . $(RCS_FIND_IGNORE) \
		\( -size 0 -o -name .depend -o -name .hdepend \) \
		-type f -print | xargs rm -f
	set -e; \
	cd $(TOPDIR)/.. ; \
	ln -sf $(TOPDIR) $(KERNELPATH) ; \
	tar -cvz $(RCS_TAR_IGNORE) -f $(KERNELPATH).tar.gz $(KERNELPATH)/. ; \
	rm $(KERNELPATH) ; \
	cd $(TOPDIR) ; \
Alan Cox's avatar
Alan Cox committed
763 764
	$(CONFIG_SHELL) $(srctree)/scripts/mkversion > .tmp_version ; \
	mv -f .tmp_version .version; \
Alan Cox's avatar
Alan Cox committed
765
	$(RPM) -ta $(TOPDIR)/../$(KERNELPATH).tar.gz ; \
Sam Ravnborg's avatar
Sam Ravnborg committed
766 767
	rm $(TOPDIR)/../$(KERNELPATH).tar.gz

768 769 770 771 772
# Brief documentation of the typical targets used
# ---------------------------------------------------------------------------

help:
	@echo  'Cleaning targets:'
Sam Ravnborg's avatar
Sam Ravnborg committed
773 774
	@echo  '  clean		  - remove most generated files but keep the config'
	@echo  '  mrproper	  - remove all generated files + config + various backup files'
775 776
	@echo  ''
	@echo  'Configuration targets:'
777
	@$(MAKE) -f scripts/kconfig/Makefile help
778 779
	@echo  ''
	@echo  'Other generic targets:'
Sam Ravnborg's avatar
Sam Ravnborg committed
780 781 782 783
	@echo  '  all		  - Build all targets marked with [*]'
	@echo  '* vmlinux	  - Build the bare kernel'
	@echo  '* modules	  - Build all modules'
	@echo  '  modules_install - Install all modules'
784
	@echo  '  dir/            - Build all files in dir and below'
Sam Ravnborg's avatar
Sam Ravnborg committed
785 786 787
	@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'
788 789
	@echo  ''
	@echo  'Documentation targets:'
790
	@$(MAKE) -f Documentation/DocBook/Makefile dochelp
791 792
	@echo  ''
	@echo  'Architecture specific targets ($(ARCH)):'
793 794
	@$(if $(archhelp),$(archhelp),\
		echo '  No architecture specific help defined for $(ARCH)')
795
	@echo  ''
Sam Ravnborg's avatar
Sam Ravnborg committed
796 797 798
	@echo  '  make V=0|1 [targets] 0 => quiet build (default), 1 => verbose build'
	@echo  '  make C=1   [targets] Check all c source with checker tool'
	@echo  ''
799
	@echo  'Execute "make" or "make all" to build all targets marked with [*] '
800
	@echo  'For further info see the ./README file'
801

802

803 804
# Documentation targets
# ---------------------------------------------------------------------------
805
%docs: scripts/docproc FORCE
806
	$(Q)$(MAKE) $(build)=Documentation/DocBook $@
807 808 809 810 811

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

checkconfig:
812
	find * $(RCS_FIND_IGNORE) \
813 814
		-name '*.[hcS]' -type f -print | sort \
		| xargs $(PERL) -w scripts/checkconfig.pl
815 816

checkincludes:
817
	find * $(RCS_FIND_IGNORE) \
818 819
		-name '*.[hcS]' -type f -print | sort \
		| xargs $(PERL) -w scripts/checkincludes.pl
820

821 822
endif #ifeq ($(config-targets),1)
endif #ifeq ($(mixed-targets),1)
823

824
# FIXME Should go into a make.lib or something 
825
# ===========================================================================
826

827
a_flags = -Wp,-MD,$(depfile) $(AFLAGS) $(AFLAGS_KERNEL) $(NOSTDINC_FLAGS) \
828 829
	  $(modkern_aflags) $(EXTRA_AFLAGS) $(AFLAGS_$(*F).o)

830 831 832
quiet_cmd_as_o_S = AS      $@
cmd_as_o_S       = $(CC) $(a_flags) -c -o $@ $<

833 834
# read all saved command lines

835 836 837
targets := $(wildcard $(sort $(targets)))
cmd_files := $(wildcard .*.cmd $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd))

838
ifneq ($(cmd_files),)
839
  $(cmd_files): ;	# Do not try to update included dependency files
840 841 842
  include $(cmd_files)
endif

843 844 845 846 847 848 849
# 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; \
850
	$(if $($(quiet)cmd_$(1)),echo '  $(subst ','\'',$($(quiet)cmd_$(1)))';) \
851
	$(cmd_$(1)); \
852
	scripts/fixdep $(depfile) $@ '$(subst $$,$$$$,$(subst ','\'',$(cmd_$(1))))' > $(@D)/.$(@F).tmp; \
853 854 855
	rm -f $(depfile); \
	mv -f $(@D)/.$(@F).tmp $(@D)/.$(@F).cmd)

856 857 858 859
# 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)

860 861 862 863 864
if_changed_rule = $(if $(strip $? \
		               $(filter-out $(cmd_$(1)),$(cmd_$(@F)))\
			       $(filter-out $(cmd_$(@F)),$(cmd_$(1)))),\
	               @$(rule_$(1)))

865
# If quiet is set, only print short version of command
866

867
cmd = @$(if $($(quiet)cmd_$(1)),echo '  $($(quiet)cmd_$(1))' &&) $(cmd_$(1))
868

869 870 871 872 873 874 875 876 877 878 879 880 881 882
# 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
883 884 885
	@set -e;				\
	echo '  CHK     $@';			\
	$(filechk_$(1)) < $< > $@.tmp;		\
886 887 888 889 890
	if [ -r $@ ] && cmp -s $@ $@.tmp; then	\
		rm -f $@.tmp;			\
	else					\
		echo '  UPD     $@';		\
		mv -f $@.tmp $@;		\
891 892
	fi
endef
893

Kai Germaschewski's avatar
Kai Germaschewski committed
894
# Shorthand for $(Q)$(MAKE) -f scripts/Makefile.build obj=dir
895 896 897 898
# Usage:
# $(Q)$(MAKE) $(build)=dir
build := -f scripts/Makefile.build obj

Kai Germaschewski's avatar
Kai Germaschewski committed
899
# Shorthand for $(Q)$(MAKE) -f scripts/Makefile.clean obj=dir
900 901 902 903
# Usage:
# $(Q)$(MAKE) $(clean)=dir
clean := -f scripts/Makefile.clean obj

904 905
#	$(call descend,<dir>,<target>)
#	Recursively call a sub-make in <dir> with target <target>
Kai Germaschewski's avatar
Kai Germaschewski committed
906
# Usage is deprecated, because make does not see this as an invocation of make.
907
descend =$(Q)$(MAKE) -f scripts/Makefile.build obj=$(1) $(2)
908

909
FORCE: