- Linux: 2.6.37-rc6.
[linux-flexiantxendom0-3.2.10.git] / Makefile
1 VERSION = 2
2 PATCHLEVEL = 6
3 SUBLEVEL = 37
4 EXTRAVERSION = -rc6
5 NAME = Flesh-Eating Bats with Fangs
6
7 # *DOCUMENTATION*
8 # To see a list of typical targets execute "make help"
9 # More info can be located in ./README
10 # Comments in this file are targeted only to the developer, do not
11 # expect to learn how to build the kernel reading this file.
12
13 # Do not:
14 # o  use make's built-in rules and variables
15 #    (this increases performance and avoids hard-to-debug behaviour);
16 # o  print "Entering directory ...";
17 MAKEFLAGS += -rR --no-print-directory
18
19 # Avoid funny character set dependencies
20 unexport LC_ALL
21 LC_COLLATE=C
22 LC_NUMERIC=C
23 export LC_COLLATE LC_NUMERIC
24
25 # We are using a recursive build, so we need to do a little thinking
26 # to get the ordering right.
27 #
28 # Most importantly: sub-Makefiles should only ever modify files in
29 # their own directory. If in some directory we have a dependency on
30 # a file in another dir (which doesn't happen often, but it's often
31 # unavoidable when linking the built-in.o targets which finally
32 # turn into vmlinux), we will call a sub make in that other dir, and
33 # after that we are sure that everything which is in that other dir
34 # is now up to date.
35 #
36 # The only cases where we need to modify files which have global
37 # effects are thus separated out and done before the recursive
38 # descending is started. They are now explicitly listed as the
39 # prepare rule.
40
41 # To put more focus on warnings, be less verbose as default
42 # Use 'make V=1' to see the full commands
43
44 ifeq ("$(origin V)", "command line")
45   KBUILD_VERBOSE = $(V)
46 endif
47 ifndef KBUILD_VERBOSE
48   KBUILD_VERBOSE = 0
49 endif
50
51 # Call a source code checker (by default, "sparse") as part of the
52 # C compilation.
53 #
54 # Use 'make C=1' to enable checking of only re-compiled files.
55 # Use 'make C=2' to enable checking of *all* source files, regardless
56 # of whether they are re-compiled or not.
57 #
58 # See the file "Documentation/sparse.txt" for more details, including
59 # where to get the "sparse" utility.
60
61 ifeq ("$(origin C)", "command line")
62   KBUILD_CHECKSRC = $(C)
63 endif
64 ifndef KBUILD_CHECKSRC
65   KBUILD_CHECKSRC = 0
66 endif
67
68 # Call message checker as part of the C compilation
69 #
70 # Use 'make D=1' to enable checking
71 # Use 'make D=2' to create the message catalog
72
73 ifdef D
74   ifeq ("$(origin D)", "command line")
75     KBUILD_KMSG_CHECK = $(D)
76   endif
77 endif
78 ifndef KBUILD_KMSG_CHECK
79   KBUILD_KMSG_CHECK = 0
80 endif
81
82 # Use make M=dir to specify directory of external module to build
83 # Old syntax make ... SUBDIRS=$PWD is still supported
84 # Setting the environment variable KBUILD_EXTMOD take precedence
85 ifdef SUBDIRS
86   KBUILD_EXTMOD ?= $(SUBDIRS)
87 endif
88
89 ifeq ("$(origin M)", "command line")
90   KBUILD_EXTMOD := $(M)
91 endif
92
93 # kbuild supports saving output files in a separate directory.
94 # To locate output files in a separate directory two syntaxes are supported.
95 # In both cases the working directory must be the root of the kernel src.
96 # 1) O=
97 # Use "make O=dir/to/store/output/files/"
98 #
99 # 2) Set KBUILD_OUTPUT
100 # Set the environment variable KBUILD_OUTPUT to point to the directory
101 # where the output files shall be placed.
102 # export KBUILD_OUTPUT=dir/to/store/output/files/
103 # make
104 #
105 # The O= assignment takes precedence over the KBUILD_OUTPUT environment
106 # variable.
107
108
109 # KBUILD_SRC is set on invocation of make in OBJ directory
110 # KBUILD_SRC is not intended to be used by the regular user (for now)
111 ifeq ($(KBUILD_SRC),)
112
113 # OK, Make called in directory where kernel src resides
114 # Do we want to locate output files in a separate directory?
115 ifeq ("$(origin O)", "command line")
116   KBUILD_OUTPUT := $(O)
117 endif
118
119 # That's our default target when none is given on the command line
120 PHONY := _all
121 _all:
122
123 # Cancel implicit rules on top Makefile
124 $(CURDIR)/Makefile Makefile: ;
125
126 ifneq ($(KBUILD_OUTPUT),)
127 # Invoke a second make in the output directory, passing relevant variables
128 # check that the output directory actually exists
129 saved-output := $(KBUILD_OUTPUT)
130 KBUILD_OUTPUT := $(shell cd $(KBUILD_OUTPUT) && /bin/pwd)
131 $(if $(KBUILD_OUTPUT),, \
132      $(error output directory "$(saved-output)" does not exist))
133
134 PHONY += $(MAKECMDGOALS) sub-make
135
136 $(filter-out _all sub-make $(CURDIR)/Makefile, $(MAKECMDGOALS)) _all: sub-make
137         $(Q)@:
138
139 sub-make: FORCE
140         $(if $(KBUILD_VERBOSE:1=),@)$(MAKE) -C $(KBUILD_OUTPUT) \
141         KBUILD_SRC=$(CURDIR) \
142         KBUILD_EXTMOD="$(KBUILD_EXTMOD)" -f $(CURDIR)/Makefile \
143         $(filter-out _all sub-make,$(MAKECMDGOALS))
144
145 # Leave processing to above invocation of make
146 skip-makefile := 1
147 endif # ifneq ($(KBUILD_OUTPUT),)
148 endif # ifeq ($(KBUILD_SRC),)
149
150 # We process the rest of the Makefile if this is the final invocation of make
151 ifeq ($(skip-makefile),)
152
153 # If building an external module we do not care about the all: rule
154 # but instead _all depend on modules
155 PHONY += all
156 ifeq ($(KBUILD_EXTMOD),)
157 _all: all
158 else
159 _all: modules
160 endif
161
162 srctree         := $(if $(KBUILD_SRC),$(KBUILD_SRC),$(CURDIR))
163 objtree         := $(CURDIR)
164 src             := $(srctree)
165 obj             := $(objtree)
166
167 VPATH           := $(srctree)$(if $(KBUILD_EXTMOD),:$(KBUILD_EXTMOD))
168
169 export srctree objtree VPATH
170
171
172 # SUBARCH tells the usermode build what the underlying arch is.  That is set
173 # first, and if a usermode build is happening, the "ARCH=um" on the command
174 # line overrides the setting of ARCH below.  If a native build is happening,
175 # then ARCH is assigned, getting whatever value it gets normally, and 
176 # SUBARCH is subsequently ignored.
177
178 SUBARCH := $(shell uname -m | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ \
179                                   -e s/arm.*/arm/ -e s/sa110/arm/ \
180                                   -e s/s390x/s390/ -e s/parisc64/parisc/ \
181                                   -e s/ppc.*/powerpc/ -e s/mips.*/mips/ \
182                                   -e s/sh[234].*/sh/ )
183
184 # Cross compiling and selecting different set of gcc/bin-utils
185 # ---------------------------------------------------------------------------
186 #
187 # When performing cross compilation for other architectures ARCH shall be set
188 # to the target architecture. (See arch/* for the possibilities).
189 # ARCH can be set during invocation of make:
190 # make ARCH=ia64
191 # Another way is to have ARCH set in the environment.
192 # The default ARCH is the host where make is executed.
193
194 # CROSS_COMPILE specify the prefix used for all executables used
195 # during compilation. Only gcc and related bin-utils executables
196 # are prefixed with $(CROSS_COMPILE).
197 # CROSS_COMPILE can be set on the command line
198 # make CROSS_COMPILE=ia64-linux-
199 # Alternatively CROSS_COMPILE can be set in the environment.
200 # A third alternative is to store a setting in .config so that plain
201 # "make" in the configured kernel build directory always uses that.
202 # Default value for CROSS_COMPILE is not to prefix executables
203 # Note: Some architectures assign CROSS_COMPILE in their arch/*/Makefile
204 export KBUILD_BUILDHOST := $(SUBARCH)
205 ARCH            ?= $(SUBARCH)
206 CROSS_COMPILE   ?= $(CONFIG_CROSS_COMPILE:"%"=%)
207
208 # Architecture as present in compile.h
209 UTS_MACHINE     := $(ARCH)
210 SRCARCH         := $(ARCH)
211
212 # Additional ARCH settings for x86
213 ifeq ($(ARCH),i386)
214         SRCARCH := x86
215 endif
216 ifeq ($(ARCH),x86_64)
217         SRCARCH := x86
218 endif
219
220 # Additional ARCH settings for sparc
221 ifeq ($(ARCH),sparc32)
222        SRCARCH := sparc
223 endif
224 ifeq ($(ARCH),sparc64)
225        SRCARCH := sparc
226 endif
227
228 # Additional ARCH settings for sh
229 ifeq ($(ARCH),sh64)
230        SRCARCH := sh
231 endif
232
233 # Where to locate arch specific headers
234 hdr-arch  := $(SRCARCH)
235
236 ifeq ($(ARCH),m68knommu)
237        hdr-arch  := m68k
238 endif
239
240 KCONFIG_CONFIG  ?= .config
241
242 # SHELL used by kbuild
243 CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
244           else if [ -x /bin/bash ]; then echo /bin/bash; \
245           else echo sh; fi ; fi)
246
247 HOSTCC       = gcc
248 HOSTCXX      = g++
249 HOSTCFLAGS   = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
250 HOSTCXXFLAGS = -O2
251
252 # Decide whether to build built-in, modular, or both.
253 # Normally, just do built-in.
254
255 KBUILD_MODULES :=
256 KBUILD_BUILTIN := 1
257
258 #       If we have only "make modules", don't compile built-in objects.
259 #       When we're building modules with modversions, we need to consider
260 #       the built-in objects during the descend as well, in order to
261 #       make sure the checksums are up to date before we record them.
262
263 ifeq ($(MAKECMDGOALS),modules)
264   KBUILD_BUILTIN := $(if $(CONFIG_MODVERSIONS),1)
265 endif
266
267 #       If we have "make <whatever> modules", compile modules
268 #       in addition to whatever we do anyway.
269 #       Just "make" or "make all" shall build modules as well
270
271 ifneq ($(filter all _all modules,$(MAKECMDGOALS)),)
272   KBUILD_MODULES := 1
273 endif
274
275 ifeq ($(MAKECMDGOALS),)
276   KBUILD_MODULES := 1
277 endif
278
279 export KBUILD_MODULES KBUILD_BUILTIN
280 export KBUILD_CHECKSRC KBUILD_SRC KBUILD_EXTMOD
281
282 # Beautify output
283 # ---------------------------------------------------------------------------
284 #
285 # Normally, we echo the whole command before executing it. By making
286 # that echo $($(quiet)$(cmd)), we now have the possibility to set
287 # $(quiet) to choose other forms of output instead, e.g.
288 #
289 #         quiet_cmd_cc_o_c = Compiling $(RELDIR)/$@
290 #         cmd_cc_o_c       = $(CC) $(c_flags) -c -o $@ $<
291 #
292 # If $(quiet) is empty, the whole command will be printed.
293 # If it is set to "quiet_", only the short version will be printed. 
294 # If it is set to "silent_", nothing will be printed at all, since
295 # the variable $(silent_cmd_cc_o_c) doesn't exist.
296 #
297 # A simple variant is to prefix commands with $(Q) - that's useful
298 # for commands that shall be hidden in non-verbose mode.
299 #
300 #       $(Q)ln $@ :<
301 #
302 # If KBUILD_VERBOSE equals 0 then the above command will be hidden.
303 # If KBUILD_VERBOSE equals 1 then the above command is displayed.
304
305 ifeq ($(KBUILD_VERBOSE),1)
306   quiet =
307   Q =
308 else
309   quiet=quiet_
310   Q = @
311 endif
312
313 # If the user is running make -s (silent mode), suppress echoing of
314 # commands
315
316 ifneq ($(findstring s,$(MAKEFLAGS)),)
317   quiet=silent_
318 endif
319
320 export quiet Q KBUILD_VERBOSE
321
322
323 # Look for make include files relative to root of kernel src
324 MAKEFLAGS += --include-dir=$(srctree)
325
326 # We need some generic definitions (do not try to remake the file).
327 $(srctree)/scripts/Kbuild.include: ;
328 include $(srctree)/scripts/Kbuild.include
329
330 # Make variables (CC, etc...)
331
332 AS              = $(CROSS_COMPILE)as
333 LD              = $(CROSS_COMPILE)ld
334 CC              = $(CROSS_COMPILE)gcc
335 CPP             = $(CC) -E
336 AR              = $(CROSS_COMPILE)ar
337 NM              = $(CROSS_COMPILE)nm
338 STRIP           = $(CROSS_COMPILE)strip
339 OBJCOPY         = $(CROSS_COMPILE)objcopy
340 OBJDUMP         = $(CROSS_COMPILE)objdump
341 AWK             = awk
342 GENKSYMS        = scripts/genksyms/genksyms
343 INSTALLKERNEL  := installkernel
344 DEPMOD          = /sbin/depmod
345 KALLSYMS        = scripts/kallsyms
346 PERL            = perl
347 CHECK           = sparse
348
349 CHECKFLAGS     := -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ \
350                   -Wbitwise -Wno-return-void $(CF)
351 KMSG_CHECK      = $(srctree)/scripts/kmsg-doc
352 CFLAGS_MODULE   =
353 AFLAGS_MODULE   =
354 LDFLAGS_MODULE  =
355 CFLAGS_KERNEL   =
356 AFLAGS_KERNEL   =
357 CFLAGS_GCOV     = -fprofile-arcs -ftest-coverage
358
359
360 # Use LINUXINCLUDE when you must reference the include/ directory.
361 # Needed to be compatible with the O= option
362 LINUXINCLUDE    := -I$(srctree)/arch/$(hdr-arch)/include -Iinclude \
363                    $(if $(KBUILD_SRC), -I$(srctree)/include) \
364                    -include include/generated/autoconf.h
365
366 KBUILD_CPPFLAGS := -D__KERNEL__
367
368 KBUILD_CFLAGS   := -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
369                    -fno-strict-aliasing -fno-common \
370                    -Werror-implicit-function-declaration \
371                    -Wno-format-security \
372                    -fno-delete-null-pointer-checks
373 KBUILD_AFLAGS_KERNEL :=
374 KBUILD_CFLAGS_KERNEL :=
375 KBUILD_AFLAGS   := -D__ASSEMBLY__
376 KBUILD_AFLAGS_MODULE  := -DMODULE
377 KBUILD_CFLAGS_MODULE  := -DMODULE
378 KBUILD_LDFLAGS_MODULE := -T $(srctree)/scripts/module-common.lds
379
380 # Warn about unsupported modules in kernels built inside Autobuild
381 ifneq ($(wildcard /.buildenv),)
382 CFLAGS          += -DUNSUPPORTED_MODULES=2
383 endif
384
385 # Read KERNELRELEASE from include/config/kernel.release (if it exists)
386 KERNELRELEASE = $(shell cat include/config/kernel.release 2> /dev/null)
387 KERNELVERSION = $(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
388
389 export VERSION PATCHLEVEL SUBLEVEL KERNELRELEASE KERNELVERSION
390 export ARCH SRCARCH CONFIG_SHELL HOSTCC HOSTCFLAGS CROSS_COMPILE AS LD CC
391 export CPP AR NM STRIP OBJCOPY OBJDUMP
392 export MAKE AWK GENKSYMS INSTALLKERNEL PERL UTS_MACHINE
393 export HOSTCXX HOSTCXXFLAGS LDFLAGS_MODULE CHECK CHECKFLAGS
394
395 export KBUILD_CPPFLAGS NOSTDINC_FLAGS LINUXINCLUDE OBJCOPYFLAGS LDFLAGS
396 export KBUILD_CFLAGS CFLAGS_KERNEL CFLAGS_MODULE CFLAGS_GCOV
397 export KBUILD_AFLAGS AFLAGS_KERNEL AFLAGS_MODULE
398 export KBUILD_AFLAGS_MODULE KBUILD_CFLAGS_MODULE KBUILD_LDFLAGS_MODULE
399 export KBUILD_AFLAGS_KERNEL KBUILD_CFLAGS_KERNEL
400 export KBUILD_KMSG_CHECK KMSG_CHECK
401
402 # When compiling out-of-tree modules, put MODVERDIR in the module
403 # tree rather than in the kernel tree. The kernel tree might
404 # even be read-only.
405 export MODVERDIR := $(if $(KBUILD_EXTMOD),$(firstword $(KBUILD_EXTMOD))/).tmp_versions
406
407 # Files to ignore in find ... statements
408
409 RCS_FIND_IGNORE := \( -name SCCS -o -name BitKeeper -o -name .svn -o -name CVS -o -name .pc -o -name .hg -o -name .git \) -prune -o
410 export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn --exclude CVS --exclude .pc --exclude .hg --exclude .git
411
412 # ===========================================================================
413 # Rules shared between *config targets and build targets
414
415 # Basic helpers built in scripts/
416 PHONY += scripts_basic
417 scripts_basic:
418         $(Q)$(MAKE) $(build)=scripts/basic
419         $(Q)rm -f .tmp_quiet_recordmcount
420
421 # To avoid any implicit rule to kick in, define an empty command.
422 scripts/basic/%: scripts_basic ;
423
424 PHONY += outputmakefile
425 # outputmakefile generates a Makefile in the output directory, if using a
426 # separate output directory. This allows convenient use of make in the
427 # output directory.
428 outputmakefile:
429 ifneq ($(KBUILD_SRC),)
430         $(Q)ln -fsn $(srctree) source
431         $(Q)$(CONFIG_SHELL) $(srctree)/scripts/mkmakefile \
432             $(srctree) $(objtree) $(VERSION) $(PATCHLEVEL)
433 endif
434
435 # To make sure we do not include .config for any of the *config targets
436 # catch them early, and hand them over to scripts/kconfig/Makefile
437 # It is allowed to specify more targets when calling make, including
438 # mixing *config targets and build targets.
439 # For example 'make oldconfig all'.
440 # Detect when mixed targets is specified, and make a second invocation
441 # of make so .config is not included in this case either (for *config).
442
443 no-dot-config-targets := clean mrproper distclean \
444                          cscope TAGS tags help %docs check% coccicheck \
445                          include/linux/version.h headers_% \
446                          kernelversion %src-pkg
447
448 config-targets := 0
449 mixed-targets  := 0
450 dot-config     := 1
451
452 ifneq ($(filter $(no-dot-config-targets), $(MAKECMDGOALS)),)
453         ifeq ($(filter-out $(no-dot-config-targets), $(MAKECMDGOALS)),)
454                 dot-config := 0
455         endif
456 endif
457
458 ifeq ($(KBUILD_EXTMOD),)
459         ifneq ($(filter config %config,$(MAKECMDGOALS)),)
460                 config-targets := 1
461                 ifneq ($(filter-out config %config,$(MAKECMDGOALS)),)
462                         mixed-targets := 1
463                 endif
464         endif
465 endif
466
467 ifeq ($(mixed-targets),1)
468 # ===========================================================================
469 # We're called with mixed targets (*config and build targets).
470 # Handle them one by one.
471
472 %:: FORCE
473         $(Q)$(MAKE) -C $(srctree) KBUILD_SRC= $@
474
475 else
476 ifeq ($(config-targets),1)
477 # ===========================================================================
478 # *config targets only - make sure prerequisites are updated, and descend
479 # in scripts/kconfig to make the *config target
480
481 # Read arch specific Makefile to set KBUILD_DEFCONFIG as needed.
482 # KBUILD_DEFCONFIG may point out an alternative default configuration
483 # used for 'make defconfig'
484 include $(srctree)/arch/$(SRCARCH)/Makefile
485 export KBUILD_DEFCONFIG KBUILD_KCONFIG
486
487 config: scripts_basic outputmakefile FORCE
488         $(Q)mkdir -p include/linux include/config
489         $(Q)$(MAKE) $(build)=scripts/kconfig $@
490
491 %config: scripts_basic outputmakefile FORCE
492         $(Q)mkdir -p include/linux include/config
493         $(Q)$(MAKE) $(build)=scripts/kconfig $@
494
495 else
496 # ===========================================================================
497 # Build targets only - this includes vmlinux, arch specific targets, clean
498 # targets and others. In general all targets except *config targets.
499
500 ifeq ($(KBUILD_EXTMOD),)
501 # Additional helpers built in scripts/
502 # Carefully list dependencies so we do not try to build scripts twice
503 # in parallel
504 PHONY += scripts
505 scripts: scripts_basic include/config/auto.conf include/config/tristate.conf
506         $(Q)$(MAKE) $(build)=$(@)
507
508 # Objects we will link into vmlinux / subdirs we need to visit
509 init-y          := init/
510 drivers-y       := drivers/ sound/ firmware/
511 net-y           := net/
512 libs-y          := lib/
513 core-y          := usr/
514 endif # KBUILD_EXTMOD
515
516 ifeq ($(dot-config),1)
517 # Read in config
518 -include include/config/auto.conf
519
520 ifeq ($(KBUILD_EXTMOD),)
521 # Read in dependencies to all Kconfig* files, make sure to run
522 # oldconfig if changes are detected.
523 -include include/config/auto.conf.cmd
524
525 # To avoid any implicit rule to kick in, define an empty command
526 $(KCONFIG_CONFIG) include/config/auto.conf.cmd: ;
527
528 # If .config is newer than include/config/auto.conf, someone tinkered
529 # with it and forgot to run make oldconfig.
530 # if auto.conf.cmd is missing then we are probably in a cleaned tree so
531 # we execute the config step to be sure to catch updated Kconfig files
532 include/config/%.conf: $(KCONFIG_CONFIG) include/config/auto.conf.cmd
533         $(Q)$(MAKE) -f $(srctree)/Makefile silentoldconfig
534 else
535 # external modules needs include/generated/autoconf.h and include/config/auto.conf
536 # but do not care if they are up-to-date. Use auto.conf to trigger the test
537 PHONY += include/config/auto.conf
538
539 include/config/auto.conf:
540         $(Q)test -e include/generated/autoconf.h -a -e $@ || (          \
541         echo;                                                           \
542         echo "  ERROR: Kernel configuration is invalid.";               \
543         echo "         include/generated/autoconf.h or $@ are missing.";\
544         echo "         Run 'make oldconfig && make prepare' on kernel src to fix it.";  \
545         echo;                                                           \
546         /bin/false)
547
548 endif # KBUILD_EXTMOD
549
550 else
551 # Dummy target needed, because used as prerequisite
552 include/config/auto.conf: ;
553 endif # $(dot-config)
554
555 # The all: target is the default when no target is given on the
556 # command line.
557 # This allow a user to issue only 'make' to build a kernel including modules
558 # Defaults to vmlinux, but the arch makefile usually adds further targets
559 all: vmlinux
560
561 ifdef CONFIG_CC_OPTIMIZE_FOR_SIZE
562 KBUILD_CFLAGS   += -Os
563 else
564 KBUILD_CFLAGS   += -O2
565 endif
566
567 include $(srctree)/arch/$(SRCARCH)/Makefile
568
569 ifneq ($(CONFIG_FRAME_WARN),0)
570 KBUILD_CFLAGS += $(call cc-option,-Wframe-larger-than=${CONFIG_FRAME_WARN})
571 endif
572
573 # Force gcc to behave correct even for buggy distributions
574 ifndef CONFIG_CC_STACKPROTECTOR
575 KBUILD_CFLAGS += $(call cc-option, -fno-stack-protector)
576 endif
577
578 ifdef CONFIG_FRAME_POINTER
579 KBUILD_CFLAGS   += -fno-omit-frame-pointer -fno-optimize-sibling-calls
580 else
581 # Some targets (ARM with Thumb2, for example), can't be built with frame
582 # pointers.  For those, we don't have FUNCTION_TRACER automatically
583 # select FRAME_POINTER.  However, FUNCTION_TRACER adds -pg, and this is
584 # incompatible with -fomit-frame-pointer with current GCC, so we don't use
585 # -fomit-frame-pointer with FUNCTION_TRACER.
586 ifndef CONFIG_FUNCTION_TRACER
587 KBUILD_CFLAGS   += -fomit-frame-pointer
588 endif
589 endif
590
591 ifdef CONFIG_UNWIND_INFO
592 KBUILD_CFLAGS   += -fasynchronous-unwind-tables
593 LDFLAGS_vmlinux += --eh-frame-hdr
594 endif
595
596 ifdef CONFIG_DEBUG_INFO
597 KBUILD_CFLAGS   += -g
598 KBUILD_AFLAGS   += -gdwarf-2
599 endif
600
601 ifdef CONFIG_DEBUG_INFO_REDUCED
602 KBUILD_CFLAGS   += $(call cc-option, -femit-struct-debug-baseonly)
603 endif
604
605 ifdef CONFIG_FUNCTION_TRACER
606 KBUILD_CFLAGS   += -pg
607 ifdef CONFIG_DYNAMIC_FTRACE
608         ifdef CONFIG_HAVE_C_RECORDMCOUNT
609                 BUILD_C_RECORDMCOUNT := y
610                 export BUILD_C_RECORDMCOUNT
611         endif
612 endif
613 endif
614
615 # We trigger additional mismatches with less inlining
616 ifdef CONFIG_DEBUG_SECTION_MISMATCH
617 KBUILD_CFLAGS += $(call cc-option, -fno-inline-functions-called-once)
618 endif
619
620 # arch Makefile may override CC so keep this after arch Makefile is included
621 NOSTDINC_FLAGS += -nostdinc -isystem $(shell $(CC) -print-file-name=include)
622 CHECKFLAGS     += $(NOSTDINC_FLAGS)
623
624 # warn about C99 declaration after statement
625 KBUILD_CFLAGS += $(call cc-option,-Wdeclaration-after-statement,)
626
627 # disable pointer signed / unsigned warnings in gcc 4.0
628 KBUILD_CFLAGS += $(call cc-option,-Wno-pointer-sign,)
629
630 # disable invalid "can't wrap" optimizations for signed / pointers
631 KBUILD_CFLAGS   += $(call cc-option,-fno-strict-overflow)
632
633 # conserve stack if available
634 KBUILD_CFLAGS   += $(call cc-option,-fconserve-stack)
635
636 # check for 'asm goto'
637 ifeq ($(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-goto.sh $(CC)), y)
638         KBUILD_CFLAGS += -DCC_HAVE_ASM_GOTO
639 endif
640
641 # Add user supplied CPPFLAGS, AFLAGS and CFLAGS as the last assignments
642 # But warn user when we do so
643 warn-assign = \
644 $(warning "WARNING: Appending $$K$(1) ($(K$(1))) from $(origin K$(1)) to kernel $$$(1)")
645
646 ifneq ($(KCPPFLAGS),)
647         $(call warn-assign,CPPFLAGS)
648         KBUILD_CPPFLAGS += $(KCPPFLAGS)
649 endif
650 ifneq ($(KAFLAGS),)
651         $(call warn-assign,AFLAGS)
652         KBUILD_AFLAGS += $(KAFLAGS)
653 endif
654 ifneq ($(KCFLAGS),)
655         $(call warn-assign,CFLAGS)
656         KBUILD_CFLAGS += $(KCFLAGS)
657 endif
658
659 # Use --build-id when available.
660 LDFLAGS_BUILD_ID = $(patsubst -Wl$(comma)%,%,\
661                               $(call cc-ldoption, -Wl$(comma)--build-id,))
662 KBUILD_LDFLAGS_MODULE += $(LDFLAGS_BUILD_ID)
663 LDFLAGS_vmlinux += $(LDFLAGS_BUILD_ID)
664
665 ifeq ($(CONFIG_STRIP_ASM_SYMS),y)
666 LDFLAGS_vmlinux += $(call ld-option, -X,)
667 endif
668
669 # Default kernel image to build when no specific target is given.
670 # KBUILD_IMAGE may be overruled on the command line or
671 # set in the environment
672 # Also any assignments in arch/$(ARCH)/Makefile take precedence over
673 # this default value
674 export KBUILD_IMAGE ?= vmlinux
675
676 #
677 # INSTALL_PATH specifies where to place the updated kernel and system map
678 # images. Default is /boot, but you can set it to other values
679 export  INSTALL_PATH ?= /boot
680
681 #
682 # INSTALL_MOD_PATH specifies a prefix to MODLIB for module directory
683 # relocations required by build roots.  This is not defined in the
684 # makefile but the argument can be passed to make if needed.
685 #
686
687 MODLIB  = $(INSTALL_MOD_PATH)/lib/modules/$(KERNELRELEASE)
688 export MODLIB
689
690 #
691 #  INSTALL_MOD_STRIP, if defined, will cause modules to be
692 #  stripped after they are installed.  If INSTALL_MOD_STRIP is '1', then
693 #  the default option --strip-debug will be used.  Otherwise,
694 #  INSTALL_MOD_STRIP will used as the options to the strip command.
695
696 ifdef INSTALL_MOD_STRIP
697 ifeq ($(INSTALL_MOD_STRIP),1)
698 mod_strip_cmd = $(STRIP) --strip-debug
699 else
700 mod_strip_cmd = $(STRIP) $(INSTALL_MOD_STRIP)
701 endif # INSTALL_MOD_STRIP=1
702 else
703 mod_strip_cmd = true
704 endif # INSTALL_MOD_STRIP
705 export mod_strip_cmd
706
707
708 ifeq ($(KBUILD_EXTMOD),)
709 core-y          += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
710
711 vmlinux-dirs    := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
712                      $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
713                      $(net-y) $(net-m) $(libs-y) $(libs-m)))
714
715 vmlinux-alldirs := $(sort $(vmlinux-dirs) $(patsubst %/,%,$(filter %/, \
716                      $(init-n) $(init-) \
717                      $(core-n) $(core-) $(drivers-n) $(drivers-) \
718                      $(net-n)  $(net-)  $(libs-n)    $(libs-))))
719
720 init-y          := $(patsubst %/, %/built-in.o, $(init-y))
721 core-y          := $(patsubst %/, %/built-in.o, $(core-y))
722 drivers-y       := $(patsubst %/, %/built-in.o, $(drivers-y))
723 net-y           := $(patsubst %/, %/built-in.o, $(net-y))
724 libs-y1         := $(patsubst %/, %/lib.a, $(libs-y))
725 libs-y2         := $(patsubst %/, %/built-in.o, $(libs-y))
726 libs-y          := $(libs-y1) $(libs-y2)
727
728 # Build vmlinux
729 # ---------------------------------------------------------------------------
730 # vmlinux is built from the objects selected by $(vmlinux-init) and
731 # $(vmlinux-main). Most are built-in.o files from top-level directories
732 # in the kernel tree, others are specified in arch/$(ARCH)/Makefile.
733 # Ordering when linking is important, and $(vmlinux-init) must be first.
734 #
735 # vmlinux
736 #   ^
737 #   |
738 #   +-< $(vmlinux-init)
739 #   |   +--< init/version.o + more
740 #   |
741 #   +--< $(vmlinux-main)
742 #   |    +--< driver/built-in.o mm/built-in.o + more
743 #   |
744 #   +-< kallsyms.o (see description in CONFIG_KALLSYMS section)
745 #
746 # vmlinux version (uname -v) cannot be updated during normal
747 # descending-into-subdirs phase since we do not yet know if we need to
748 # update vmlinux.
749 # Therefore this step is delayed until just before final link of vmlinux -
750 # except in the kallsyms case where it is done just before adding the
751 # symbols to the kernel.
752 #
753 # System.map is generated to document addresses of all kernel symbols
754
755 vmlinux-init := $(head-y) $(init-y)
756 vmlinux-main := $(core-y) $(libs-y) $(drivers-y) $(net-y)
757 vmlinux-all  := $(vmlinux-init) $(vmlinux-main)
758 vmlinux-lds  := arch/$(SRCARCH)/kernel/vmlinux.lds
759 export KBUILD_VMLINUX_OBJS := $(vmlinux-all)
760
761 # Rule to link vmlinux - also used during CONFIG_KALLSYMS
762 # May be overridden by arch/$(ARCH)/Makefile
763 quiet_cmd_vmlinux__ ?= LD      $@
764       cmd_vmlinux__ ?= $(LD) $(LDFLAGS) $(LDFLAGS_vmlinux) -o $@ \
765       -T $(vmlinux-lds) $(vmlinux-init)                          \
766       --start-group $(vmlinux-main) --end-group                  \
767       $(filter-out $(vmlinux-lds) $(vmlinux-init) $(vmlinux-main) vmlinux.o FORCE ,$^)
768
769 # Generate new vmlinux version
770 quiet_cmd_vmlinux_version = GEN     .version
771       cmd_vmlinux_version = set -e;                     \
772         if [ ! -r .version ]; then                      \
773           rm -f .version;                               \
774           echo 1 >.version;                             \
775         else                                            \
776           mv .version .old_version;                     \
777           expr 0$$(cat .old_version) + 1 >.version;     \
778         fi;                                             \
779         $(MAKE) $(build)=init
780
781 # Generate System.map
782 quiet_cmd_sysmap = SYSMAP
783       cmd_sysmap = $(CONFIG_SHELL) $(srctree)/scripts/mksysmap
784
785 # Link of vmlinux
786 # If CONFIG_KALLSYMS is set .version is already updated
787 # Generate System.map and verify that the content is consistent
788 # Use + in front of the vmlinux_version rule to silent warning with make -j2
789 # First command is ':' to allow us to use + in front of the rule
790 define rule_vmlinux__
791         :
792         $(if $(CONFIG_KALLSYMS),,+$(call cmd,vmlinux_version))
793
794         $(call cmd,vmlinux__)
795         $(Q)echo 'cmd_$@ := $(cmd_vmlinux__)' > $(@D)/.$(@F).cmd
796
797         $(Q)$(if $($(quiet)cmd_sysmap),                                      \
798           echo '  $($(quiet)cmd_sysmap)  System.map' &&)                     \
799         $(cmd_sysmap) $@ System.map;                                         \
800         if [ $$? -ne 0 ]; then                                               \
801                 rm -f $@;                                                    \
802                 /bin/false;                                                  \
803         fi;
804         $(verify_kallsyms)
805 endef
806
807
808 ifdef CONFIG_KALLSYMS
809 # Generate section listing all symbols and add it into vmlinux $(kallsyms.o)
810 # It's a three stage process:
811 # o .tmp_vmlinux1 has all symbols and sections, but __kallsyms is
812 #   empty
813 #   Running kallsyms on that gives us .tmp_kallsyms1.o with
814 #   the right size - vmlinux version (uname -v) is updated during this step
815 # o .tmp_vmlinux2 now has a __kallsyms section of the right size,
816 #   but due to the added section, some addresses have shifted.
817 #   From here, we generate a correct .tmp_kallsyms2.o
818 # o The correct .tmp_kallsyms2.o is linked into the final vmlinux.
819 # o Verify that the System.map from vmlinux matches the map from
820 #   .tmp_vmlinux2, just in case we did not generate kallsyms correctly.
821 # o If CONFIG_KALLSYMS_EXTRA_PASS is set, do an extra pass using
822 #   .tmp_vmlinux3 and .tmp_kallsyms3.o.  This is only meant as a
823 #   temporary bypass to allow the kernel to be built while the
824 #   maintainers work out what went wrong with kallsyms.
825
826 ifdef CONFIG_KALLSYMS_EXTRA_PASS
827 last_kallsyms := 3
828 else
829 last_kallsyms := 2
830 endif
831
832 kallsyms.o := .tmp_kallsyms$(last_kallsyms).o
833
834 define verify_kallsyms
835         $(Q)$(if $($(quiet)cmd_sysmap),                                      \
836           echo '  $($(quiet)cmd_sysmap)  .tmp_System.map' &&)                \
837           $(cmd_sysmap) .tmp_vmlinux$(last_kallsyms) .tmp_System.map
838         $(Q)cmp -s System.map .tmp_System.map ||                             \
839                 (echo Inconsistent kallsyms data;                            \
840                  echo Try setting CONFIG_KALLSYMS_EXTRA_PASS;                \
841                  rm .tmp_kallsyms* ; /bin/false )
842 endef
843
844 # Update vmlinux version before link
845 # Use + in front of this rule to silent warning about make -j1
846 # First command is ':' to allow us to use + in front of this rule
847 cmd_ksym_ld = $(cmd_vmlinux__)
848 define rule_ksym_ld
849         : 
850         +$(call cmd,vmlinux_version)
851         $(call cmd,vmlinux__)
852         $(Q)echo 'cmd_$@ := $(cmd_vmlinux__)' > $(@D)/.$(@F).cmd
853 endef
854
855 # Generate .S file with all kernel symbols
856 quiet_cmd_kallsyms = KSYM    $@
857       cmd_kallsyms = $(NM) -n $< | $(KALLSYMS) \
858                      $(if $(CONFIG_KALLSYMS_ALL),--all-symbols) > $@
859
860 .tmp_kallsyms1.o .tmp_kallsyms2.o .tmp_kallsyms3.o: %.o: %.S scripts FORCE
861         $(call if_changed_dep,as_o_S)
862
863 .tmp_kallsyms%.S: .tmp_vmlinux% $(KALLSYMS)
864         $(call cmd,kallsyms)
865
866 # .tmp_vmlinux1 must be complete except kallsyms, so update vmlinux version
867 .tmp_vmlinux1: $(vmlinux-lds) $(vmlinux-all) FORCE
868         $(call if_changed_rule,ksym_ld)
869
870 .tmp_vmlinux2: $(vmlinux-lds) $(vmlinux-all) .tmp_kallsyms1.o FORCE
871         $(call if_changed,vmlinux__)
872
873 .tmp_vmlinux3: $(vmlinux-lds) $(vmlinux-all) .tmp_kallsyms2.o FORCE
874         $(call if_changed,vmlinux__)
875
876 # Needs to visit scripts/ before $(KALLSYMS) can be used.
877 $(KALLSYMS): scripts ;
878
879 # Generate some data for debugging strange kallsyms problems
880 debug_kallsyms: .tmp_map$(last_kallsyms)
881
882 .tmp_map%: .tmp_vmlinux% FORCE
883         ($(OBJDUMP) -h $< | $(AWK) '/^ +[0-9]/{print $$4 " 0 " $$2}'; $(NM) $<) | sort > $@
884
885 .tmp_map3: .tmp_map2
886
887 .tmp_map2: .tmp_map1
888
889 endif # ifdef CONFIG_KALLSYMS
890
891 # Do modpost on a prelinked vmlinux. The finally linked vmlinux has
892 # relevant sections renamed as per the linker script.
893 quiet_cmd_vmlinux-modpost = LD      $@
894       cmd_vmlinux-modpost = $(LD) $(LDFLAGS) -r -o $@                          \
895          $(vmlinux-init) --start-group $(vmlinux-main) --end-group             \
896          $(filter-out $(vmlinux-init) $(vmlinux-main) FORCE ,$^)
897 define rule_vmlinux-modpost
898         :
899         +$(call cmd,vmlinux-modpost)
900         $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost $@
901         $(Q)echo 'cmd_$@ := $(cmd_vmlinux-modpost)' > $(dot-target).cmd
902 endef
903
904 # vmlinux image - including updated kernel symbols
905 vmlinux: $(vmlinux-lds) $(vmlinux-init) $(vmlinux-main) vmlinux.o $(kallsyms.o) FORCE
906 ifdef CONFIG_HEADERS_CHECK
907         $(Q)$(MAKE) -f $(srctree)/Makefile headers_check
908 endif
909 ifdef CONFIG_SAMPLES
910         $(Q)$(MAKE) $(build)=samples
911 endif
912 ifdef CONFIG_BUILD_DOCSRC
913         $(Q)$(MAKE) $(build)=Documentation
914 endif
915         $(call vmlinux-modpost)
916         $(call if_changed_rule,vmlinux__)
917         $(Q)rm -f .old_version
918
919 # build vmlinux.o first to catch section mismatch errors early
920 ifdef CONFIG_KALLSYMS
921 .tmp_vmlinux1: vmlinux.o
922 endif
923
924 modpost-init := $(filter-out init/built-in.o, $(vmlinux-init))
925 vmlinux.o: $(modpost-init) $(vmlinux-main) FORCE
926         $(call if_changed_rule,vmlinux-modpost)
927
928 # The actual objects are generated when descending, 
929 # make sure no implicit rule kicks in
930 $(sort $(vmlinux-init) $(vmlinux-main)) $(vmlinux-lds): $(vmlinux-dirs) ;
931
932 # Handle descending into subdirectories listed in $(vmlinux-dirs)
933 # Preset locale variables to speed up the build process. Limit locale
934 # tweaks to this spot to avoid wrong language settings when running
935 # make menuconfig etc.
936 # Error messages still appears in the original language
937
938 PHONY += $(vmlinux-dirs)
939 $(vmlinux-dirs): prepare scripts
940         $(Q)$(MAKE) $(build)=$@
941
942 # Store (new) KERNELRELASE string in include/config/kernel.release
943 include/config/kernel.release: include/config/auto.conf FORCE
944         $(Q)rm -f $@
945         $(Q)echo "$(KERNELVERSION)$$($(CONFIG_SHELL) $(srctree)/scripts/setlocalversion $(srctree))" > $@
946
947
948 # Things we need to do before we recursively start building the kernel
949 # or the modules are listed in "prepare".
950 # A multi level approach is used. prepareN is processed before prepareN-1.
951 # archprepare is used in arch Makefiles and when processed asm symlink,
952 # version.h and scripts_basic is processed / created.
953
954 # Listed in dependency order
955 PHONY += prepare archprepare prepare0 prepare1 prepare2 prepare3
956
957 # prepare3 is used to check if we are building in a separate output directory,
958 # and if so do:
959 # 1) Check that make has not been executed in the kernel src $(srctree)
960 prepare3: include/config/kernel.release
961 ifneq ($(KBUILD_SRC),)
962         @$(kecho) '  Using $(srctree) as source for kernel'
963         $(Q)if [ -f $(srctree)/.config -o -d $(srctree)/include/config ]; then \
964                 echo "  $(srctree) is not clean, please run 'make mrproper'";\
965                 echo "  in the '$(srctree)' directory.";\
966                 /bin/false; \
967         fi;
968 endif
969
970 # prepare2 creates a makefile if using a separate output directory
971 prepare2: prepare3 outputmakefile
972
973 prepare1: prepare2 include/linux/version.h include/generated/utsrelease.h \
974                    include/config/auto.conf
975         $(cmd_crmodverdir)
976
977 archprepare: prepare1 scripts_basic
978
979 prepare0: archprepare FORCE
980         $(Q)$(MAKE) $(build)=.
981         $(Q)$(MAKE) $(build)=. missing-syscalls
982
983 # All the preparing..
984 prepare: prepare0
985
986 # Generate some files
987 # ---------------------------------------------------------------------------
988
989 # KERNELRELEASE can change from a few different places, meaning version.h
990 # needs to be updated, so this check is forced on all builds
991
992 uts_len := 64
993 define filechk_utsrelease.h
994         if [ `echo -n "$(KERNELRELEASE)" | wc -c ` -gt $(uts_len) ]; then \
995           echo '"$(KERNELRELEASE)" exceeds $(uts_len) characters' >&2;    \
996           exit 1;                                                         \
997         fi;                                                               \
998         (echo \#define UTS_RELEASE \"$(KERNELRELEASE)\";)
999 endef
1000
1001 define filechk_version.h
1002         (echo \#define LINUX_VERSION_CODE $(shell                             \
1003         expr $(VERSION) \* 65536 + $(PATCHLEVEL) \* 256 + $(SUBLEVEL));     \
1004         echo '#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))';)
1005 endef
1006
1007 include/linux/version.h: $(srctree)/Makefile FORCE
1008         $(call filechk,version.h)
1009
1010 include/generated/utsrelease.h: include/config/kernel.release FORCE
1011         $(call filechk,utsrelease.h)
1012
1013 PHONY += headerdep
1014 headerdep:
1015         $(Q)find include/ -name '*.h' | xargs --max-args 1 scripts/headerdep.pl
1016
1017 # ---------------------------------------------------------------------------
1018
1019 PHONY += depend dep
1020 depend dep:
1021         @echo '*** Warning: make $@ is unnecessary now.'
1022
1023 # ---------------------------------------------------------------------------
1024 # Firmware install
1025 INSTALL_FW_PATH=$(INSTALL_MOD_PATH)/lib/firmware/$(KERNELRELEASE)
1026 export INSTALL_FW_PATH
1027
1028 PHONY += firmware_install
1029 firmware_install: FORCE
1030         @mkdir -p $(objtree)/firmware
1031         $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.fwinst obj=firmware __fw_install
1032
1033 # ---------------------------------------------------------------------------
1034 # Kernel headers
1035
1036 #Default location for installed headers
1037 export INSTALL_HDR_PATH = $(objtree)/usr
1038
1039 hdr-inst := -rR -f $(srctree)/scripts/Makefile.headersinst obj
1040
1041 # If we do an all arch process set dst to asm-$(hdr-arch)
1042 hdr-dst = $(if $(KBUILD_HEADERS), dst=include/asm-$(hdr-arch), dst=include/asm)
1043
1044 PHONY += __headers
1045 __headers: include/linux/version.h scripts_basic FORCE
1046         $(Q)$(MAKE) $(build)=scripts scripts/unifdef
1047
1048 PHONY += headers_install_all
1049 headers_install_all:
1050         $(Q)$(CONFIG_SHELL) $(srctree)/scripts/headers.sh install
1051
1052 PHONY += headers_install
1053 headers_install: __headers
1054         $(if $(wildcard $(srctree)/arch/$(hdr-arch)/include/asm/Kbuild),, \
1055         $(error Headers not exportable for the $(SRCARCH) architecture))
1056         $(Q)$(MAKE) $(hdr-inst)=include
1057         $(Q)$(MAKE) $(hdr-inst)=arch/$(hdr-arch)/include/asm $(hdr-dst)
1058
1059 PHONY += headers_check_all
1060 headers_check_all: headers_install_all
1061         $(Q)$(CONFIG_SHELL) $(srctree)/scripts/headers.sh check
1062
1063 PHONY += headers_check
1064 headers_check: headers_install
1065         $(Q)$(MAKE) $(hdr-inst)=include HDRCHECK=1
1066         $(Q)$(MAKE) $(hdr-inst)=arch/$(hdr-arch)/include/asm $(hdr-dst) HDRCHECK=1
1067
1068 # ---------------------------------------------------------------------------
1069 # Modules
1070
1071 ifdef CONFIG_MODULES
1072
1073 # By default, build modules as well
1074
1075 all: modules
1076
1077 #       Build modules
1078 #
1079 #       A module can be listed more than once in obj-m resulting in
1080 #       duplicate lines in modules.order files.  Those are removed
1081 #       using awk while concatenating to the final file.
1082
1083 PHONY += modules
1084 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin
1085         $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
1086         @$(kecho) '  Building modules, stage 2.';
1087         $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
1088         $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.fwinst obj=firmware __fw_modbuild
1089
1090 modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
1091         $(Q)$(AWK) '!x[$$0]++' $^ > $(objtree)/modules.builtin
1092
1093 %/modules.builtin: include/config/auto.conf
1094         $(Q)$(MAKE) $(modbuiltin)=$*
1095
1096
1097 # Target to prepare building external modules
1098 PHONY += modules_prepare
1099 modules_prepare: prepare scripts
1100
1101 # Target to install modules
1102 PHONY += modules_install
1103 modules_install: _modinst_ _modinst_post
1104
1105 PHONY += _modinst_
1106 _modinst_:
1107         @if [ -z "`$(DEPMOD) -V 2>/dev/null | grep module-init-tools`" ]; then \
1108                 echo "Warning: you may need to install module-init-tools"; \
1109                 echo "See http://www.codemonkey.org.uk/docs/post-halloween-2.6.txt";\
1110                 sleep 1; \
1111         fi
1112         @rm -rf $(MODLIB)/kernel
1113         @rm -f $(MODLIB)/source
1114         @mkdir -p $(MODLIB)/kernel
1115         @ln -s $(srctree) $(MODLIB)/source
1116         @if [ ! $(objtree) -ef  $(MODLIB)/build ]; then \
1117                 rm -f $(MODLIB)/build ; \
1118                 ln -s $(objtree) $(MODLIB)/build ; \
1119         fi
1120         @cp -f $(objtree)/modules.order $(MODLIB)/
1121         @cp -f $(objtree)/modules.builtin $(MODLIB)/
1122         $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modinst
1123
1124 # This depmod is only for convenience to give the initial
1125 # boot a modules.dep even before / is mounted read-write.  However the
1126 # boot script depmod is the master version.
1127 PHONY += _modinst_post
1128 _modinst_post: _modinst_
1129         $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.fwinst obj=firmware __fw_modinst
1130         $(call cmd,depmod)
1131
1132 else # CONFIG_MODULES
1133
1134 # Modules not configured
1135 # ---------------------------------------------------------------------------
1136
1137 modules modules_install: FORCE
1138         @echo
1139         @echo "The present kernel configuration has modules disabled."
1140         @echo "Type 'make config' and enable loadable module support."
1141         @echo "Then build a kernel with module support enabled."
1142         @echo
1143         @exit 1
1144
1145 endif # CONFIG_MODULES
1146
1147 ###
1148 # Cleaning is done on three levels.
1149 # make clean     Delete most generated files
1150 #                Leave enough to build external modules
1151 # make mrproper  Delete the current configuration, and all generated files
1152 # make distclean Remove editor backup files, patch leftover files and the like
1153
1154 # Directories & files removed with 'make clean'
1155 CLEAN_DIRS  += $(MODVERDIR)
1156 CLEAN_FILES +=  vmlinux System.map \
1157                 .tmp_kallsyms* .tmp_version .tmp_vmlinux* .tmp_System.map
1158
1159 # Directories & files removed with 'make mrproper'
1160 MRPROPER_DIRS  += include/config usr/include include/generated
1161 MRPROPER_FILES += .config .config.old .version .old_version             \
1162                   include/linux/version.h                               \
1163                   Module.symvers tags TAGS cscope*
1164
1165 # clean - Delete most, but leave enough to build external modules
1166 #
1167 clean: rm-dirs  := $(CLEAN_DIRS)
1168 clean: rm-files := $(CLEAN_FILES)
1169 clean-dirs      := $(addprefix _clean_, . $(vmlinux-alldirs) Documentation)
1170
1171 PHONY += $(clean-dirs) clean archclean
1172 $(clean-dirs):
1173         $(Q)$(MAKE) $(clean)=$(patsubst _clean_%,%,$@)
1174
1175 clean: archclean
1176
1177 # mrproper - Delete all generated files, including .config
1178 #
1179 mrproper: rm-dirs  := $(wildcard $(MRPROPER_DIRS))
1180 mrproper: rm-files := $(wildcard $(MRPROPER_FILES))
1181 mrproper-dirs      := $(addprefix _mrproper_,Documentation/DocBook scripts)
1182
1183 PHONY += $(mrproper-dirs) mrproper archmrproper
1184 $(mrproper-dirs):
1185         $(Q)$(MAKE) $(clean)=$(patsubst _mrproper_%,%,$@)
1186
1187 mrproper: clean archmrproper $(mrproper-dirs)
1188         $(call cmd,rmdirs)
1189         $(call cmd,rmfiles)
1190
1191 # distclean
1192 #
1193 PHONY += distclean
1194
1195 distclean: mrproper
1196         @find $(srctree) $(RCS_FIND_IGNORE) \
1197                 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
1198                 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
1199                 -o -name '.*.rej' -o -size 0 \
1200                 -o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \
1201                 -type f -print | xargs rm -f
1202
1203
1204 # Packaging of the kernel to various formats
1205 # ---------------------------------------------------------------------------
1206 # rpm target kept for backward compatibility
1207 package-dir     := $(srctree)/scripts/package
1208
1209 %src-pkg: FORCE
1210         $(Q)$(MAKE) $(build)=$(package-dir) $@
1211 %pkg: include/config/kernel.release FORCE
1212         $(Q)$(MAKE) $(build)=$(package-dir) $@
1213 rpm: include/config/kernel.release FORCE
1214         $(Q)$(MAKE) $(build)=$(package-dir) $@
1215
1216
1217 # Brief documentation of the typical targets used
1218 # ---------------------------------------------------------------------------
1219
1220 boards := $(wildcard $(srctree)/arch/$(SRCARCH)/configs/*_defconfig)
1221 boards := $(notdir $(boards))
1222 board-dirs := $(dir $(wildcard $(srctree)/arch/$(SRCARCH)/configs/*/*_defconfig))
1223 board-dirs := $(sort $(notdir $(board-dirs:/=)))
1224
1225 help:
1226         @echo  'Cleaning targets:'
1227         @echo  '  clean           - Remove most generated files but keep the config and'
1228         @echo  '                    enough build support to build external modules'
1229         @echo  '  mrproper        - Remove all generated files + config + various backup files'
1230         @echo  '  distclean       - mrproper + remove editor backup and patch files'
1231         @echo  ''
1232         @echo  'Configuration targets:'
1233         @$(MAKE) -f $(srctree)/scripts/kconfig/Makefile help
1234         @echo  ''
1235         @echo  'Other generic targets:'
1236         @echo  '  all             - Build all targets marked with [*]'
1237         @echo  '* vmlinux         - Build the bare kernel'
1238         @echo  '* modules         - Build all modules'
1239         @echo  '  modules_install - Install all modules to INSTALL_MOD_PATH (default: /)'
1240         @echo  '  firmware_install- Install all firmware to INSTALL_FW_PATH'
1241         @echo  '                    (default: $$(INSTALL_MOD_PATH)/lib/firmware)'
1242         @echo  '  dir/            - Build all files in dir and below'
1243         @echo  '  dir/file.[oisS] - Build specified target only'
1244         @echo  '  dir/file.lst    - Build specified mixed source/assembly target only'
1245         @echo  '                    (requires a recent binutils and recent build (System.map))'
1246         @echo  '  dir/file.ko     - Build module including final link'
1247         @echo  '  modules_prepare - Set up for building external modules'
1248         @echo  '  tags/TAGS       - Generate tags file for editors'
1249         @echo  '  cscope          - Generate cscope index'
1250         @echo  '  kernelrelease   - Output the release version string'
1251         @echo  '  kernelversion   - Output the version stored in Makefile'
1252         @echo  '  headers_install - Install sanitised kernel headers to INSTALL_HDR_PATH'; \
1253          echo  '                    (default: $(INSTALL_HDR_PATH))'; \
1254          echo  ''
1255         @echo  'Static analysers'
1256         @echo  '  checkstack      - Generate a list of stack hogs'
1257         @echo  '  namespacecheck  - Name space analysis on compiled kernel'
1258         @echo  '  versioncheck    - Sanity check on version.h usage'
1259         @echo  '  includecheck    - Check for duplicate included header files'
1260         @echo  '  export_report   - List the usages of all exported symbols'
1261         @echo  '  headers_check   - Sanity check on exported headers'
1262         @echo  '  headerdep       - Detect inclusion cycles in headers'
1263         @$(MAKE) -f $(srctree)/scripts/Makefile.help checker-help
1264         @echo  ''
1265         @echo  'Kernel packaging:'
1266         @$(MAKE) $(build)=$(package-dir) help
1267         @echo  ''
1268         @echo  'Documentation targets:'
1269         @$(MAKE) -f $(srctree)/Documentation/DocBook/Makefile dochelp
1270         @echo  ''
1271         @echo  'Architecture specific targets ($(SRCARCH)):'
1272         @$(if $(archhelp),$(archhelp),\
1273                 echo '  No architecture specific help defined for $(SRCARCH)')
1274         @echo  ''
1275         @$(if $(boards), \
1276                 $(foreach b, $(boards), \
1277                 printf "  %-24s - Build for %s\\n" $(b) $(subst _defconfig,,$(b));) \
1278                 echo '')
1279         @$(if $(board-dirs), \
1280                 $(foreach b, $(board-dirs), \
1281                 printf "  %-16s - Show %s-specific targets\\n" help-$(b) $(b);) \
1282                 printf "  %-16s - Show all of the above\\n" help-boards; \
1283                 echo '')
1284
1285         @echo  '  make V=0|1 [targets] 0 => quiet build (default), 1 => verbose build'
1286         @echo  '  make V=2   [targets] 2 => give reason for rebuild of target'
1287         @echo  '  make O=dir [targets] Locate all output files in "dir", including .config'
1288         @echo  '  make C=1   [targets] Check all c source with $$CHECK (sparse by default)'
1289         @echo  '  make C=2   [targets] Force check of all c source with $$CHECK'
1290         @echo  ''
1291         @echo  'Execute "make" or "make all" to build all targets marked with [*] '
1292         @echo  'For further info see the ./README file'
1293
1294
1295 help-board-dirs := $(addprefix help-,$(board-dirs))
1296
1297 help-boards: $(help-board-dirs)
1298
1299 boards-per-dir = $(notdir $(wildcard $(srctree)/arch/$(SRCARCH)/configs/$*/*_defconfig))
1300
1301 $(help-board-dirs): help-%:
1302         @echo  'Architecture specific targets ($(SRCARCH) $*):'
1303         @$(if $(boards-per-dir), \
1304                 $(foreach b, $(boards-per-dir), \
1305                 printf "  %-24s - Build for %s\\n" $*/$(b) $(subst _defconfig,,$(b));) \
1306                 echo '')
1307
1308
1309 # Documentation targets
1310 # ---------------------------------------------------------------------------
1311 %docs: scripts_basic FORCE
1312         $(Q)$(MAKE) $(build)=Documentation/DocBook $@
1313
1314 else # KBUILD_EXTMOD
1315
1316 ###
1317 # External module support.
1318 # When building external modules the kernel used as basis is considered
1319 # read-only, and no consistency checks are made and the make
1320 # system is not used on the basis kernel. If updates are required
1321 # in the basis kernel ordinary make commands (without M=...) must
1322 # be used.
1323 #
1324 # The following are the only valid targets when building external
1325 # modules.
1326 # make M=dir clean     Delete all automatically generated files
1327 # make M=dir modules   Make all modules in specified dir
1328 # make M=dir           Same as 'make M=dir modules'
1329 # make M=dir modules_install
1330 #                      Install the modules built in the module directory
1331 #                      Assumes install directory is already created
1332
1333 # We are always building modules
1334 KBUILD_MODULES := 1
1335 PHONY += crmodverdir
1336 crmodverdir:
1337         $(cmd_crmodverdir)
1338
1339 PHONY += $(objtree)/Module.symvers
1340 $(objtree)/Module.symvers:
1341         @test -e $(objtree)/Module.symvers || ( \
1342         echo; \
1343         echo "  WARNING: Symbol version dump $(objtree)/Module.symvers"; \
1344         echo "           is missing; modules will have no dependencies and modversions."; \
1345         echo )
1346
1347 module-dirs := $(addprefix _module_,$(KBUILD_EXTMOD))
1348 PHONY += $(module-dirs) modules
1349 $(module-dirs): crmodverdir $(objtree)/Module.symvers
1350         $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
1351
1352 modules: $(module-dirs)
1353         @$(kecho) '  Building modules, stage 2.';
1354         $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
1355
1356 PHONY += modules_install
1357 modules_install: _emodinst_ _emodinst_post
1358
1359 install-dir := $(if $(INSTALL_MOD_DIR),$(INSTALL_MOD_DIR),extra)
1360 PHONY += _emodinst_
1361 _emodinst_:
1362         $(Q)mkdir -p $(MODLIB)/$(install-dir)
1363         $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modinst
1364
1365 PHONY += _emodinst_post
1366 _emodinst_post: _emodinst_
1367         $(call cmd,depmod)
1368
1369 clean-dirs := $(addprefix _clean_,$(KBUILD_EXTMOD))
1370
1371 PHONY += $(clean-dirs) clean
1372 $(clean-dirs):
1373         $(Q)$(MAKE) $(clean)=$(patsubst _clean_%,%,$@)
1374
1375 clean:  rm-dirs := $(MODVERDIR)
1376 clean: rm-files := $(KBUILD_EXTMOD)/Module.symvers
1377
1378 help:
1379         @echo  '  Building external modules.'
1380         @echo  '  Syntax: make -C path/to/kernel/src M=$$PWD target'
1381         @echo  ''
1382         @echo  '  modules         - default target, build the module(s)'
1383         @echo  '  modules_install - install the module'
1384         @echo  '  clean           - remove generated files in module directory only'
1385         @echo  ''
1386
1387 # Dummies...
1388 PHONY += prepare scripts
1389 prepare: ;
1390 scripts: ;
1391 endif # KBUILD_EXTMOD
1392
1393 clean: $(clean-dirs)
1394         $(call cmd,rmdirs)
1395         $(call cmd,rmfiles)
1396         @find $(or $(KBUILD_EXTMOD), .) $(RCS_FIND_IGNORE) \
1397                 \( -name '*.[oas]' -o -name '*.ko' -o -name '.*.cmd' \
1398                 -o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \
1399                 -o -name '*.symtypes' -o -name 'modules.order' \
1400                 -o -name modules.builtin -o -name '.tmp_*.o.*' \
1401                 -o -name '*.gcno' \) -type f -print | xargs rm -f
1402
1403 # Generate tags for editors
1404 # ---------------------------------------------------------------------------
1405 quiet_cmd_tags = GEN     $@
1406       cmd_tags = $(CONFIG_SHELL) $(srctree)/scripts/tags.sh $@
1407
1408 tags TAGS cscope: FORCE
1409         $(call cmd,tags)
1410
1411 # Scripts to check various things for consistency
1412 # ---------------------------------------------------------------------------
1413
1414 includecheck:
1415         find * $(RCS_FIND_IGNORE) \
1416                 -name '*.[hcS]' -type f -print | sort \
1417                 | xargs $(PERL) -w $(srctree)/scripts/checkincludes.pl
1418
1419 versioncheck:
1420         find * $(RCS_FIND_IGNORE) \
1421                 -name '*.[hcS]' -type f -print | sort \
1422                 | xargs $(PERL) -w $(srctree)/scripts/checkversion.pl
1423
1424 coccicheck:
1425         $(Q)$(CONFIG_SHELL) $(srctree)/scripts/$@
1426
1427 namespacecheck:
1428         $(PERL) $(srctree)/scripts/namespace.pl
1429
1430 export_report:
1431         $(PERL) $(srctree)/scripts/export_report.pl
1432
1433 endif #ifeq ($(config-targets),1)
1434 endif #ifeq ($(mixed-targets),1)
1435
1436 PHONY += checkstack kernelrelease kernelversion
1437
1438 # UML needs a little special treatment here.  It wants to use the host
1439 # toolchain, so needs $(SUBARCH) passed to checkstack.pl.  Everyone
1440 # else wants $(ARCH), including people doing cross-builds, which means
1441 # that $(SUBARCH) doesn't work here.
1442 ifeq ($(ARCH), um)
1443 CHECKSTACK_ARCH := $(SUBARCH)
1444 else
1445 CHECKSTACK_ARCH := $(ARCH)
1446 endif
1447 checkstack:
1448         $(OBJDUMP) -d vmlinux $$(find . -name '*.ko') | \
1449         $(PERL) $(src)/scripts/checkstack.pl $(CHECKSTACK_ARCH)
1450
1451 kernelrelease:
1452         @echo "$(KERNELVERSION)$$($(CONFIG_SHELL) $(srctree)/scripts/setlocalversion $(srctree))"
1453
1454 kernelversion:
1455         @echo $(KERNELVERSION)
1456
1457 # Single targets
1458 # ---------------------------------------------------------------------------
1459 # Single targets are compatible with:
1460 # - build with mixed source and output
1461 # - build with separate output dir 'make O=...'
1462 # - external modules
1463 #
1464 #  target-dir => where to store outputfile
1465 #  build-dir  => directory in kernel source tree to use
1466
1467 ifeq ($(KBUILD_EXTMOD),)
1468         build-dir  = $(patsubst %/,%,$(dir $@))
1469         target-dir = $(dir $@)
1470 else
1471         zap-slash=$(filter-out .,$(patsubst %/,%,$(dir $@)))
1472         build-dir  = $(KBUILD_EXTMOD)$(if $(zap-slash),/$(zap-slash))
1473         target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
1474 endif
1475
1476 %.s: %.c prepare scripts FORCE
1477         $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
1478 %.i: %.c prepare scripts FORCE
1479         $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
1480 %.o: %.c prepare scripts FORCE
1481         $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
1482 %.lst: %.c prepare scripts FORCE
1483         $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
1484 %.s: %.S prepare scripts FORCE
1485         $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
1486 %.o: %.S prepare scripts FORCE
1487         $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
1488 %.symtypes: %.c prepare scripts FORCE
1489         $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
1490
1491 # Modules
1492 /: prepare scripts FORCE
1493         $(cmd_crmodverdir)
1494         $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
1495         $(build)=$(build-dir)
1496 %/: prepare scripts FORCE
1497         $(cmd_crmodverdir)
1498         $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
1499         $(build)=$(build-dir)
1500 %.ko: prepare scripts FORCE
1501         $(cmd_crmodverdir)
1502         $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1)   \
1503         $(build)=$(build-dir) $(@:.ko=.o)
1504         $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
1505
1506 # FIXME Should go into a make.lib or something 
1507 # ===========================================================================
1508
1509 quiet_cmd_rmdirs = $(if $(wildcard $(rm-dirs)),CLEAN   $(wildcard $(rm-dirs)))
1510       cmd_rmdirs = rm -rf $(rm-dirs)
1511
1512 quiet_cmd_rmfiles = $(if $(wildcard $(rm-files)),CLEAN   $(wildcard $(rm-files)))
1513       cmd_rmfiles = rm -f $(rm-files)
1514
1515 # Run depmod only if we have System.map and depmod is executable
1516 quiet_cmd_depmod = DEPMOD  $(KERNELRELEASE)
1517       cmd_depmod = \
1518         if [ -r System.map -a -x $(DEPMOD) ]; then                              \
1519                 $(DEPMOD) -ae -F System.map                                     \
1520                 $(if $(strip $(INSTALL_MOD_PATH)), -b $(INSTALL_MOD_PATH) )     \
1521                 $(KERNELRELEASE);                                               \
1522         fi
1523
1524 # Create temporary dir for module support files
1525 # clean it up only when building all modules
1526 cmd_crmodverdir = $(Q)mkdir -p $(MODVERDIR) \
1527                   $(if $(KBUILD_MODULES),; rm -f $(MODVERDIR)/*)
1528
1529 a_flags = -Wp,-MD,$(depfile) $(KBUILD_AFLAGS) $(AFLAGS_KERNEL) \
1530           $(KBUILD_AFLAGS_KERNEL)                              \
1531           $(NOSTDINC_FLAGS) $(LINUXINCLUDE) $(KBUILD_CPPFLAGS) \
1532           $(modkern_aflags) $(EXTRA_AFLAGS) $(AFLAGS_$(basetarget).o)
1533
1534 quiet_cmd_as_o_S = AS      $@
1535 cmd_as_o_S       = $(CC) $(a_flags) -c -o $@ $<
1536
1537 # read all saved command lines
1538
1539 targets := $(wildcard $(sort $(targets)))
1540 cmd_files := $(wildcard .*.cmd $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd))
1541
1542 ifneq ($(cmd_files),)
1543   $(cmd_files): ;       # Do not try to update included dependency files
1544   include $(cmd_files)
1545 endif
1546
1547 # Shorthand for $(Q)$(MAKE) -f scripts/Makefile.clean obj=dir
1548 # Usage:
1549 # $(Q)$(MAKE) $(clean)=dir
1550 clean := -f $(if $(KBUILD_SRC),$(srctree)/)scripts/Makefile.clean obj
1551
1552 endif   # skip-makefile
1553
1554 PHONY += FORCE
1555 FORCE:
1556
1557 # Declare the contents of the .PHONY variable as phony.  We keep that
1558 # information in a variable so we can use it in if_changed and friends.
1559 .PHONY: $(PHONY)