root/Makefile

Revision 24, 35.9 kB (checked in by dkaplan1, 3 years ago)

Configured now for P4 test box
Includes benchmark code for lcall/lret and int/iret
Adds new ring=X argument to insmod to specify ring to be loaded into
Fixes scheduling issue where driver thread not always picked first

Line 
1 VERSION = 2
2 PATCHLEVEL = 6
3 SUBLEVEL = 7
4 EXTRAVERSION = -kgdb-ringcycle
5 NAME=Zonked Quokka
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 print "Entering directory ..."
14 MAKEFLAGS += --no-print-directory
15
16 # We are using a recursive build, so we need to do a little thinking
17 # to get the ordering right.
18 #
19 # Most importantly: sub-Makefiles should only ever modify files in
20 # their own directory. If in some directory we have a dependency on
21 # a file in another dir (which doesn't happen often, but it's of
22 # unavoidable when linking the built-in.o targets which finally
23 # turn into vmlinux), we will call a sub make in that other dir, and
24 # after that we are sure that everything which is in that other dir
25 # is now up to date.
26 #
27 # The only cases where we need to modify files which have global
28 # effects are thus separated out and done before the recursive
29 # descending is started. They are now explicitly listed as the
30 # prepare rule.
31
32 # To put more focus on warnings, be less verbose as default
33 # Use 'make V=1' to see the full commands
34
35 ifdef V
36   ifeq ("$(origin V)", "command line")
37     KBUILD_VERBOSE = $(V)
38   endif
39 endif
40 ifndef KBUILD_VERBOSE
41   KBUILD_VERBOSE = 0
42 endif
43
44 # Call sparse as part of compilation of C files
45 # Use 'make C=1' to enable sparse checking
46
47 ifdef C
48   ifeq ("$(origin C)", "command line")
49     KBUILD_CHECKSRC = $(C)
50   endif
51 endif
52 ifndef KBUILD_CHECKSRC
53   KBUILD_CHECKSRC = 0
54 endif
55
56 # Use make M=dir to specify direcotry of external module to build
57 # Old syntax make ... SUBDIRS=$PWD is still supported
58 # Setting the environment variable KBUILD_EXTMOD take precedence
59 ifdef SUBDIRS
60   KBUILD_EXTMOD ?= $(SUBDIRS)
61 endif
62 ifdef M
63   ifeq ("$(origin M)", "command line")
64     KBUILD_EXTMOD := $(M)
65   endif
66 endif
67
68
69 # kbuild supports saving output files in a separate directory.
70 # To locate output files in a separate directory two syntax'es are supported.
71 # In both cases the working directory must be the root of the kernel src.
72 # 1) O=
73 # Use "make O=dir/to/store/output/files/"
74 #
75 # 2) Set KBUILD_OUTPUT
76 # Set the environment variable KBUILD_OUTPUT to point to the directory
77 # where the output files shall be placed.
78 # export KBUILD_OUTPUT=dir/to/store/output/files/
79 # make
80 #
81 # The O= assigment takes precedence over the KBUILD_OUTPUT environment variable.
82
83
84 # KBUILD_SRC is set on invocation of make in OBJ directory
85 # KBUILD_SRC is not intended to be used by the regular user (for now)
86 ifeq ($(KBUILD_SRC),)
87
88 # OK, Make called in directory where kernel src resides
89 # Do we want to locate output files in a separate directory?
90 ifdef O
91   ifeq ("$(origin O)", "command line")
92     KBUILD_OUTPUT := $(O)
93   endif
94 endif
95
96 # That's our default target when none is given on the command line
97 .PHONY: _all
98 _all:
99
100 ifneq ($(KBUILD_OUTPUT),)
101 # Invoke a second make in the output directory, passing relevant variables
102 # check that the output directory actually exists
103 saved-output := $(KBUILD_OUTPUT)
104 KBUILD_OUTPUT := $(shell cd $(KBUILD_OUTPUT) && /bin/pwd)
105 $(if $(wildcard $(KBUILD_OUTPUT)),, \
106      $(error output directory "$(saved-output)" does not exist))
107
108 .PHONY: $(MAKECMDGOALS)
109
110 $(filter-out _all,$(MAKECMDGOALS)) _all:
111         $(if $(KBUILD_VERBOSE:1=),@)$(MAKE) -C $(KBUILD_OUTPUT)         \
112         KBUILD_SRC=$(CURDIR)         KBUILD_VERBOSE=$(KBUILD_VERBOSE)   \
113         KBUILD_CHECK=$(KBUILD_CHECK) KBUILD_EXTMOD="$(KBUILD_EXTMOD)"   \
114         -f $(CURDIR)/Makefile $@
115
116 # Leave processing to above invocation of make
117 skip-makefile := 1
118 endif # ifneq ($(KBUILD_OUTPUT),)
119 endif # ifeq ($(KBUILD_SRC),)
120
121 # We process the rest of the Makefile if this is the final invocation of make
122 ifeq ($(skip-makefile),)
123
124 # If building an external module we do not care about the all: rule
125 # but instead _all depend on modules
126 .PHONY: all
127 ifeq ($(KBUILD_EXTMOD),)
128 _all: all
129 else
130 _all: modules
131 endif
132
133 # Make sure we're not wasting cpu-cycles doing locale handling, yet do make
134 # sure error messages appear in the user-desired language
135 ifdef LC_ALL
136 LANG := $(LC_ALL)
137 LC_ALL :=
138 endif
139 LC_COLLATE := C
140 LC_CTYPE := C
141 export LANG LC_ALL LC_COLLATE LC_CTYPE
142
143 srctree         := $(if $(KBUILD_SRC),$(KBUILD_SRC),$(CURDIR))
144 TOPDIR          := $(srctree)
145 # FIXME - TOPDIR is obsolete, use srctree/objtree
146 objtree         := $(CURDIR)
147 src             := $(srctree)
148 obj             := $(objtree)
149
150 VPATH           := $(srctree)
151
152 export srctree objtree VPATH TOPDIR
153
154 KERNELRELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
155
156 # SUBARCH tells the usermode build what the underlying arch is.  That is set
157 # first, and if a usermode build is happening, the "ARCH=um" on the command
158 # line overrides the setting of ARCH below.  If a native build is happening,
159 # then ARCH is assigned, getting whatever value it gets normally, and
160 # SUBARCH is subsequently ignored.
161
162 SUBARCH := $(shell uname -m | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ \
163                                   -e s/arm.*/arm/ -e s/sa110/arm/ \
164                                   -e s/s390x/s390/ -e s/parisc64/parisc/ )
165
166 # Cross compiling and selecting different set of gcc/bin-utils
167 # ---------------------------------------------------------------------------
168 #
169 # When performing cross compilation for other architectures ARCH shall be set
170 # to the target architecture. (See arch/* for the possibilities).
171 # ARCH can be set during invocation of make:
172 # make ARCH=ia64
173 # Another way is to have ARCH set in the environment.
174 # The default ARCH is the host where make is executed.
175
176 # CROSS_COMPILE specify the prefix used for all executables used
177 # during compilation. Only gcc and related bin-utils executables
178 # are prefixed with $(CROSS_COMPILE).
179 # CROSS_COMPILE can be set on the command line
180 # make CROSS_COMPILE=ia64-linux-
181 # Alternatively CROSS_COMPILE can be set in the environment.
182 # Default value for CROSS_COMPILE is not to prefix executables
183 # Note: Some architectures assign CROSS_COMPILE in their arch/*/Makefile
184
185 ARCH            ?= $(SUBARCH)
186 CROSS_COMPILE   ?=
187
188 # Architecture as present in compile.h
189 UTS_MACHINE := $(ARCH)
190
191 # SHELL used by kbuild
192 CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
193           else if [ -x /bin/bash ]; then echo /bin/bash; \
194           else echo sh; fi ; fi)
195
196 #HOSTCC         = gcc-3.3
197 HOSTCC          = gcc32
198 HOSTCXX         = g++-3.3
199 HOSTCFLAGS      = -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer
200 HOSTCXXFLAGS    = -O2
201
202 #       Decide whether to build built-in, modular, or both.
203 #       Normally, just do built-in.
204
205 KBUILD_MODULES :=
206 KBUILD_BUILTIN := 1
207
208 #       If we have only "make modules", don't compile built-in objects.
209 #       When we're building modules with modversions, we need to consider
210 #       the built-in objects during the descend as well, in order to
211 #       make sure the checksums are uptodate before we record them.
212
213 ifeq ($(MAKECMDGOALS),modules)
214   KBUILD_BUILTIN := $(if $(CONFIG_MODVERSIONS),1)
215 endif
216
217 #       If we have "make <whatever> modules", compile modules
218 #       in addition to whatever we do anyway.
219 #       Just "make" or "make all" shall build modules as well
220
221 ifneq ($(filter all _all modules,$(MAKECMDGOALS)),)
222   KBUILD_MODULES := 1
223 endif
224
225 ifeq ($(MAKECMDGOALS),)
226   KBUILD_MODULES := 1
227 endif
228
229 export KBUILD_MODULES KBUILD_BUILTIN KBUILD_VERBOSE
230 export KBUILD_CHECKSRC KBUILD_SRC KBUILD_EXTMOD
231
232 # Beautify output
233 # ---------------------------------------------------------------------------
234 #
235 # Normally, we echo the whole command before executing it. By making
236 # that echo $($(quiet)$(cmd)), we now have the possibility to set
237 # $(quiet) to choose other forms of output instead, e.g.
238 #
239 #         quiet_cmd_cc_o_c = Compiling $(RELDIR)/$@
240 #         cmd_cc_o_c       = $(CC) $(c_flags) -c -o $@ $<
241 #
242 # If $(quiet) is empty, the whole command will be printed.
243 # If it is set to "quiet_", only the short version will be printed.
244 # If it is set to "silent_", nothing wil be printed at all, since
245 # the variable $(silent_cmd_cc_o_c) doesn't exist.
246 #
247 # A simple variant is to prefix commands with $(Q) - that's usefull
248 # for commands that shall be hidden in non-verbose mode.
249 #
250 #       $(Q)ln $@ :<
251 #
252 # If KBUILD_VERBOSE equals 0 then the above command will be hidden.
253 # If KBUILD_VERBOSE equals 1 then the above command is displayed.
254
255 ifeq ($(KBUILD_VERBOSE),1)
256   quiet =
257   Q =
258 else
259   quiet=quiet_
260   Q = @
261 endif
262
263 # If the user is running make -s (silent mode), suppress echoing of
264 # commands
265
266 ifneq ($(findstring s,$(MAKEFLAGS)),)
267   quiet=silent_
268 endif
269
270 check_gcc = $(shell if $(CC) $(CFLAGS) $(1) -S -o /dev/null -xc /dev/null > /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi ;)
271
272 export quiet Q KBUILD_VERBOSE check_gcc
273
274 # Look for make include files relative to root of kernel src
275 MAKEFLAGS += --include-dir=$(srctree)
276
277 # For maximum performance (+ possibly random breakage, uncomment
278 # the following)
279
280 #MAKEFLAGS += -rR
281
282 # Make variables (CC, etc...)
283
284 AS              = $(CROSS_COMPILE)as
285 LD              = $(CROSS_COMPILE)ld
286 CC              = $(CROSS_COMPILE)gcc32
287 CPP             = $(CC) -E
288 AR              = $(CROSS_COMPILE)ar
289 NM              = $(CROSS_COMPILE)nm
290 STRIP           = $(CROSS_COMPILE)strip
291 OBJCOPY         = $(CROSS_COMPILE)objcopy
292 OBJDUMP         = $(CROSS_COMPILE)objdump
293 AWK             = awk
294 RPM             := $(shell if [ -x "/usr/bin/rpmbuild" ]; then echo rpmbuild; \
295                         else echo rpm; fi)
296 GENKSYMS        = scripts/genksyms/genksyms
297 DEPMOD          = /sbin/depmod
298 KALLSYMS        = scripts/kallsyms
299 PERL            = perl
300 CHECK           = sparse
301 MODFLAGS        = -DMODULE
302 CFLAGS_MODULE   = $(MODFLAGS)
303 AFLAGS_MODULE   = $(MODFLAGS)
304 LDFLAGS_MODULE  = -r
305 CFLAGS_KERNEL   =
306 AFLAGS_KERNEL   =
307
308 NOSTDINC_FLAGS  = -nostdinc -iwithprefix include
309
310 CPPFLAGS        := -D__KERNEL__ -Iinclude \
311                    $(if $(KBUILD_SRC),-Iinclude2 -I$(srctree)/include)
312
313 CFLAGS          := -Wall -Wstrict-prototypes -Wno-trigraphs \
314                    -fno-strict-aliasing -fno-common
315 AFLAGS          := -D__ASSEMBLY__
316
317 export  VERSION PATCHLEVEL SUBLEVEL EXTRAVERSION KERNELRELEASE ARCH \
318         CONFIG_SHELL HOSTCC HOSTCFLAGS CROSS_COMPILE AS LD CC \
319         CPP AR NM STRIP OBJCOPY OBJDUMP MAKE AWK GENKSYMS PERL UTS_MACHINE \
320         HOSTCXX HOSTCXXFLAGS LDFLAGS_BLOB LDFLAGS_MODULE CHECK
321
322 export CPPFLAGS NOSTDINC_FLAGS OBJCOPYFLAGS LDFLAGS
323 export CFLAGS CFLAGS_KERNEL CFLAGS_MODULE
324 export AFLAGS AFLAGS_KERNEL AFLAGS_MODULE
325
326 # When compiling out-of-tree modules, put MODVERDIR in the module
327 # tree rather than in the kernel tree. The kernel tree might
328 # even be read-only.
329 export MODVERDIR := $(if $(KBUILD_EXTMOD),$(firstword $(KBUILD_EXTMOD))/).tmp_versions
330
331 # The temporary file to save gcc -MD generated dependencies must not
332 # contain a comma
333 comma := ,
334 depfile = $(subst $(comma),_,$(@D)/.$(@F).d)
335
336 # Files to ignore in find ... statements
337
338 RCS_FIND_IGNORE := \( -name SCCS -o -name BitKeeper -o -name .svn -o -name CVS \) -prune -o
339 RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn --exclude CVS
340
341 # ===========================================================================
342 # Rules shared between *config targets and build targets
343
344 # Basic helpers built in scripts/
345 .PHONY: scripts_basic
346 scripts_basic:
347         $(Q)$(MAKE) $(build)=scripts/basic
348
349 # To make sure we do not include .config for any of the *config targets
350 # catch them early, and hand them over to scripts/kconfig/Makefile
351 # It is allowed to specify more targets when calling make, including
352 # mixing *config targets and build targets.
353 # For example 'make oldconfig all'.
354 # Detect when mixed targets is specified, and make a second invocation
355 # of make so .config is not included in this case either (for *config).
356
357 no-dot-config-targets := clean mrproper distclean \
358                          cscope TAGS tags help %docs check%
359
360 config-targets := 0
361 mixed-targets  := 0
362 dot-config     := 1
363
364 ifneq ($(filter $(no-dot-config-targets), $(MAKECMDGOALS)),)
365         ifeq ($(filter-out $(no-dot-config-targets), $(MAKECMDGOALS)),)
366                 dot-config := 0
367         endif
368 endif
369
370 ifeq ($(KBUILD_EXTMOD),)
371         ifneq ($(filter config %config,$(MAKECMDGOALS)),)
372                 config-targets := 1
373                 ifneq ($(filter-out config %config,$(MAKECMDGOALS)),)
374                         mixed-targets := 1
375                 endif
376         endif
377 endif
378
379 ifeq ($(mixed-targets),1)
380 # ===========================================================================
381 # We're called with mixed targets (*config and build targets).
382 # Handle them one by one.
383
384 %:: FORCE
385         $(Q)$(MAKE) -C $(srctree) KBUILD_SRC= $@
386
387 else
388 ifeq ($(config-targets),1)
389 # ===========================================================================
390 # *config targets only - make sure prerequisites are updated, and descend
391 # in scripts/kconfig to make the *config target
392
393 config: scripts_basic FORCE
394         $(Q)$(MAKE) $(build)=scripts/kconfig $@
395 %config: scripts_basic FORCE
396         $(Q)$(MAKE) $(build)=scripts/kconfig $@
397
398 else
399 # ===========================================================================
400 # Build targets only - this includes vmlinux, arch specific targets, clean
401 # targets and others. In general all targets except *config targets.
402
403 ifeq ($(KBUILD_EXTMOD),)
404
405
406 # Additional helpers built in scripts/
407 # Carefully list dependencies so we do not try to build scripts twice
408 # in parrallel
409 .PHONY: scripts
410 scripts: scripts_basic include/config/MARKER
411         $(Q)$(MAKE) $(build)=$(@)
412
413 scripts_basic: include/linux/autoconf.h
414
415
416 # That's our default target when none is given on the command line
417 # Note that 'modules' will be added as a prerequisite as well,
418 # in the CONFIG_MODULES part below
419
420 all:    vmlinux
421
422 # Objects we will link into vmlinux / subdirs we need to visit
423 init-y          := init/
424 drivers-y       := drivers/ sound/
425 net-y           := net/
426 libs-y          := lib/
427 core-y          := usr/
428 endif # KBUILD_EXTMOD
429
430 ifeq ($(dot-config),1)
431 # In this section, we need .config
432
433 # Read in dependencies to all Kconfig* files, make sure to run
434 # oldconfig if changes are detected.
435 -include .config.cmd
436
437 include .config
438
439 # If .config needs to be updated, it will be done via the dependency
440 # that autoconf has on .config.
441 # To avoid any implicit rule to kick in, define an empty command
442 .config: ;
443
444 # If .config is newer than include/linux/autoconf.h, someone tinkered
445 # with it and forgot to run make oldconfig
446 include/linux/autoconf.h: .config
447         $(Q)$(MAKE) -f $(srctree)/Makefile silentoldconfig
448 else
449 # Dummy target needed, because used as prerequisite
450 include/linux/autoconf.h: ;
451 endif
452
453 include $(srctree)/arch/$(ARCH)/Makefile
454
455 ifdef CONFIG_CC_OPTIMIZE_FOR_SIZE
456 CFLAGS          += -Os
457 else
458 CFLAGS          += -O2
459 endif
460
461 ifndef CONFIG_FRAME_POINTER
462 CFLAGS          += -fomit-frame-pointer
463 else
464 CFLAGS          += -fno-omit-frame-pointer
465 endif
466
467 ifdef CONFIG_DEBUG_INFO
468 CFLAGS          += -g
469 endif
470
471 # warn about C99 declaration after statement
472 CFLAGS += $(call check_gcc,-Wdeclaration-after-statement,)
473
474 #
475 # INSTALL_PATH specifies where to place the updated kernel and system map
476 # images.  Uncomment if you want to place them anywhere other than root.
477 #
478
479 #export INSTALL_PATH=/boot
480
481 #
482 # INSTALL_MOD_PATH specifies a prefix to MODLIB for module directory
483 # relocations required by build roots.  This is not defined in the
484 # makefile but the arguement can be passed to make if needed.
485 #
486
487 MODLIB  := $(INSTALL_MOD_PATH)/lib/modules/$(KERNELRELEASE)
488 export MODLIB
489
490
491 ifeq ($(KBUILD_EXTMOD),)
492 core-y          += kernel/ mm/ fs/ ipc/ security/ crypto/
493
494 vmlinux-dirs    := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
495                      $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
496                      $(net-y) $(net-m) $(libs-y) $(libs-m)))
497
498 vmlinux-alldirs := $(sort $(vmlinux-dirs) $(patsubst %/,%,$(filter %/, \
499                      $(init-n) $(init-) \
500                      $(core-n) $(core-) $(drivers-n) $(drivers-) \
501                      $(net-n)  $(net-)  $(libs-n)    $(libs-))))
502
503 init-y          := $(patsubst %/, %/built-in.o, $(init-y))
504 core-y          := $(patsubst %/, %/built-in.o, $(core-y))
505 drivers-y       := $(patsubst %/, %/built-in.o, $(drivers-y))
506 net-y           := $(patsubst %/, %/built-in.o, $(net-y))
507 libs-y1         := $(patsubst %/, %/lib.a, $(libs-y))
508 libs-y2         := $(patsubst %/, %/built-in.o, $(libs-y))
509 libs-y          := $(libs-y1) $(libs-y2)
510
511
512 # Build vmlinux
513 # ---------------------------------------------------------------------------
514
515 #       This is a bit tricky: If we need to relink vmlinux, we want
516 #       the version number incremented, which means recompile init/version.o
517 #       and relink init/init.o. However, we cannot do this during the
518 #       normal descending-into-subdirs phase, since at that time
519 #       we cannot yet know if we will need to relink vmlinux.
520 #       So we descend into init/ inside the rule for vmlinux again.
521 head-y += $(HEAD)
522 vmlinux-objs := $(head-y) $(init-y) $(core-y) $(libs-y) $(drivers-y) $(net-y)
523
524 quiet_cmd_vmlinux__ = LD      $@
525 define cmd_vmlinux__
526         $(LD) $(LDFLAGS) $(LDFLAGS_vmlinux) $(head-y) $(init-y) \
527         --start-group \
528         $(core-y) \
529         $(libs-y) \
530         $(drivers-y) \
531         $(net-y) \
532         --end-group \
533         $(filter .tmp_kallsyms%,$^) \
534         -o $@
535 endef
536
537 #       set -e makes the rule exit immediately on error
538
539 define rule_vmlinux__
540         +set -e;                                                        \
541         $(if $(filter .tmp_kallsyms%,$^),,                              \
542           echo '  GEN     .version';                                    \
543           . $(srctree)/scripts/mkversion > .tmp_version;                \
544           mv -f .tmp_version .version;                                  \
545           $(MAKE) $(build)=init;                                        \
546         )                                                               \
547         $(if $($(quiet)cmd_vmlinux__),                                  \
548           echo '  $($(quiet)cmd_vmlinux__)' &&)                         \
549         $(cmd_vmlinux__);                                               \
550         echo 'cmd_$@ := $(cmd_vmlinux__)' > $(@D)/.$(@F).cmd
551 endef
552
553 define rule_vmlinux
554         $(rule_vmlinux__); \
555         $(NM) $@ | grep -v '\(compiled\)\|\(\.o$$\)\|\( [aUw] \)\|\(\.\.ng$$\)\|\(LASH[RL]DI\)' | sort > System.map
556 endef
557
558 LDFLAGS_vmlinux += -T arch/$(ARCH)/kernel/vmlinux.lds.s
559
560 #       Generate section listing all symbols and add it into vmlinux
561 #       It's a three stage process:
562 #       o .tmp_vmlinux1 has all symbols and sections, but __kallsyms is
563 #         empty
564 #         Running kallsyms on that gives us .tmp_kallsyms1.o with
565 #         the right size
566 #       o .tmp_vmlinux2 now has a __kallsyms section of the right size,
567 #         but due to the added section, some addresses have shifted
568 #         From here, we generate a correct .tmp_kallsyms2.o
569 #       o The correct .tmp_kallsyms2.o is linked into the final vmlinux.
570
571 ifdef CONFIG_KALLSYMS
572
573 kallsyms.o := .tmp_kallsyms2.o
574
575 quiet_cmd_kallsyms = KSYM    $@
576 cmd_kallsyms = $(NM) -n $< | $(KALLSYMS) $(foreach x,$(CONFIG_KALLSYMS_ALL),--all-symbols) > $@
577
578 .tmp_kallsyms1.o .tmp_kallsyms2.o: %.o: %.S scripts FORCE
579         $(call if_changed_dep,as_o_S)
580
581 .tmp_kallsyms%.S: .tmp_vmlinux%
582         $(call cmd,kallsyms)
583
584 .tmp_vmlinux1: $(vmlinux-objs) arch/$(ARCH)/kernel/vmlinux.lds.s FORCE
585         +$(call if_changed_rule,vmlinux__)
586
587 .tmp_vmlinux2: $(vmlinux-objs) .tmp_kallsyms1.o arch/$(ARCH)/kernel/vmlinux.lds.s FORCE
588         $(call if_changed_rule,vmlinux__)
589
590 endif
591
592 #       Finally the vmlinux rule
593
594 vmlinux: $(vmlinux-objs) $(kallsyms.o) arch/$(ARCH)/kernel/vmlinux.lds.s FORCE
595         $(call if_changed_rule,vmlinux)
596
597 #       The actual objects are generated when descending,
598 #       make sure no implicit rule kicks in
599
600 $(sort $(vmlinux-objs)) arch/$(ARCH)/kernel/vmlinux.lds.s: $(vmlinux-dirs) ;
601
602 #       Handle descending into subdirectories listed in $(vmlinux-dirs)
603
604 .PHONY: $(vmlinux-dirs)
605 $(vmlinux-dirs): prepare-all scripts
606         $(Q)$(MAKE) $(build)=$@
607
608 # Things we need to do before we recursively start building the kernel
609 # or the modules are listed in "prepare-all".
610 # A multi level approach is used. prepare1 is updated first, then prepare0.
611 # prepare-all is the collection point for the prepare targets.
612
613 .PHONY: prepare-all prepare prepare0 prepare1
614
615 # prepare1 is used to check if we are building in a separate output directory,
616 # and if so do:
617 # 1) Check that make has not been executed in the kernel src $(srctree)
618 # 2) Create the include2 directory, used for the second asm symlink
619
620 prepare1:
621 ifneq ($(KBUILD_SRC),)
622         @echo '  Using $(srctree) as source for kernel'
623         $(Q)if [ -h $(srctree)/include/asm -o -f $(srctree)/.config ]; then \
624                 echo "  $(srctree) is not clean, please run 'make mrproper'";\
625                 echo "  in the '$(srctree)' directory.";\
626                 /bin/false; \
627         fi;
628         $(Q)if [ ! -d include2 ]; then mkdir -p include2; fi;
629         $(Q)ln -fsn $(srctree)/include/asm-$(ARCH) include2/asm
630 endif
631
632 prepare0: prepare1 include/linux/version.h include/asm include/config/MARKER
633 ifneq ($(KBUILD_MODULES),)
634         $(Q)rm -rf $(MODVERDIR)
635         $(Q)mkdir -p $(MODVERDIR)
636 endif
637
638 # All the preparing..
639 prepare-all: prepare0 prepare
640
641 #       Leave this as default for preprocessing vmlinux.lds.S, which is now
642 #       done in arch/$(ARCH)/kernel/Makefile
643
644 export AFLAGS_vmlinux.lds.o += -P -C -U$(ARCH)
645
646 # Single targets
647 # ---------------------------------------------------------------------------
648
649 %.s: %.c scripts FORCE
650         $(Q)$(MAKE) $(build)=$(@D) $@
651 %.i: %.c scripts FORCE
652         $(Q)$(MAKE) $(build)=$(@D) $@
653 %.o: %.c scripts FORCE
654         $(Q)$(MAKE) $(build)=$(@D) $@
655 %/:      scripts prepare FORCE
656         $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) $(build)=$(@D)
657 %.lst: %.c scripts FORCE
658         $(Q)$(MAKE) $(build)=$(@D) $@
659 %.s: %.S scripts FORCE
660         $(Q)$(MAKE) $(build)=$(@D) $@
661 %.o: %.S scripts FORCE
662         $(Q)$(MAKE) $(build)=$(@D) $@
663
664 #       FIXME: The asm symlink changes when $(ARCH) changes. That's
665 #       hard to detect, but I suppose "make mrproper" is a good idea
666 #       before switching between archs anyway.
667
668 include/asm:
669         @echo '  SYMLINK $@ -> include/asm-$(ARCH)'
670         $(Q)if [ ! -d include ]; then mkdir -p include; fi;
671         @ln -fsn asm-$(ARCH) $@
672
673 #       Split autoconf.h into include/linux/config/*
674
675 include/config/MARKER: include/linux/autoconf.h
676         @echo '  SPLIT   include/linux/autoconf.h -> include/config/*'
677         @scripts/basic/split-include include/linux/autoconf.h include/config
678         @touch $@
679
680 # Generate some files
681 # ---------------------------------------------------------------------------
682
683 #       version.h changes when $(KERNELRELEASE) etc change, as defined in
684 #       this Makefile
685
686 uts_len := 64
687
688 define filechk_version.h
689         if [ `echo -n "$(KERNELRELEASE)" | wc -c ` -gt $(uts_len) ]; then \
690           echo '"$(KERNELRELEASE)" exceeds $(uts_len) characters' >&2; \
691           exit 1; \
692         fi; \
693         (echo \#define UTS_RELEASE \"$(KERNELRELEASE)\"; \
694           echo \#define LINUX_VERSION_CODE `expr $(VERSION) \\* 65536 + $(PATCHLEVEL) \\* 256 + $(SUBLEVEL)`; \
695          echo '#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))'; \
696         )
697 endef
698
699 include/linux/version.h: Makefile
700         $(call filechk,version.h)
701
702 # ---------------------------------------------------------------------------
703
704 .PHONY: depend dep
705 depend dep:
706         @echo '*** Warning: make $@ is unnecessary now.'
707
708 # ---------------------------------------------------------------------------
709 # Modules
710
711 ifdef CONFIG_MODULES
712
713 #       By default, build modules as well
714
715 all: modules
716
717 #       Build modules
718
719 .PHONY: modules
720 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux)
721         @echo '  Building modules, stage 2.';
722         $(Q)$(MAKE) -rR -f $(srctree)/scripts/Makefile.modpost
723
724
725 # Target to prepare building external modules
726 .PHONY: modules_prepare
727 modules_prepare: prepare-all scripts
728
729 # Target to install modules
730 .PHONY: modules_install
731 modules_install: _modinst_ _modinst_post
732
733 .PHONY: _modinst_
734 _modinst_:
735         @if [ -z "`$(DEPMOD) -V | grep module-init-tools`" ]; then \
736                 echo "Warning: you may need to install module-init-tools"; \
737                 echo "See http://www.codemonkey.org.uk/docs/post-halloween-2.6.txt";\
738                 sleep 1; \
739         fi
740         @rm -rf $(MODLIB)/kernel
741         @rm -f $(MODLIB)/build
742         @mkdir -p $(MODLIB)/kernel
743         @ln -s $(TOPDIR) $(MODLIB)/build
744         $(Q)$(MAKE) -rR -f $(srctree)/scripts/Makefile.modinst
745
746 # If System.map exists, run depmod.  This deliberately does not have a
747 # dependency on System.map since that would run the dependency tree on
748 # vmlinux.  This depmod is only for convenience to give the initial
749 # boot a modules.dep even before / is mounted read-write.  However the
750 # boot script depmod is the master version.
751 ifeq "$(strip $(INSTALL_MOD_PATH))" ""
752 depmod_opts     :=
753 else
754 depmod_opts     := -b $(INSTALL_MOD_PATH) -r
755 endif
756 .PHONY: _modinst_post
757 _modinst_post: _modinst_
758         if [ -r System.map ]; then $(DEPMOD) -ae -F System.map $(depmod_opts) $(KERNELRELEASE); fi
759
760 else # CONFIG_MODULES
761
762 # Modules not configured
763 # ---------------------------------------------------------------------------
764
765 modules modules_install: FORCE
766         @echo
767         @echo "The present kernel configuration has modules disabled."
768         @echo "Type 'make config' and enable loadable module support."
769         @echo "Then build a kernel with module support enabled."
770         @echo
771         @exit 1
772
773 endif # CONFIG_MODULES
774
775 # Generate asm-offsets.h
776 # ---------------------------------------------------------------------------
777
778 define filechk_gen-asm-offsets
779         (set -e; \
780          echo "#ifndef __ASM_OFFSETS_H__"; \
781          echo "#define __ASM_OFFSETS_H__"; \
782          echo "/*"; \
783          echo " * DO NOT MODIFY."; \
784          echo " *"; \
785          echo " * This file was generated by arch/$(ARCH)/Makefile"; \
786          echo " *"; \
787          echo " */"; \
788          echo ""; \
789          sed -ne "/^->/{s:^->\([^ ]*\) [\$$#]*\([^ ]*\) \(.*\):#define \1 \2 /* \3 */:; s:->::; p;}"; \
790          echo ""; \
791          echo "#endif" )
792 endef
793
794
795 ###
796 # Cleaning is done on three levels.
797 # make clean     Delete most generated files
798 #                Leave enough to build external modules
799 # make mrproper  Delete the current configuration, and all generated files
800 # make distclean Remove editor backup files, patch leftover files and the like
801
802 # Directories & files removed with 'make clean'
803 CLEAN_DIRS  += $(MODVERDIR)
804 CLEAN_FILES +=  vmlinux System.map kernel.spec \
805                 .tmp_kallsyms* .tmp_version .tmp_vmlinux*
806
807 # Directories & files removed with 'make mrproper'
808 MRPROPER_DIRS  += include/config include2
809 MRPROPER_FILES += .config .config.old include/asm .version \
810                   include/linux/autoconf.h include/linux/version.h \
811                   Module.symvers tags TAGS cscope*
812
813 # clean - Delete most, but leave enough to build external modules
814 #
815 clean: rm-dirs  := $(CLEAN_DIRS)
816 clean: rm-files := $(CLEAN_FILES)
817 clean-dirs      := $(addprefix _clean_,$(vmlinux-alldirs))
818
819 .PHONY: $(clean-dirs) clean archclean
820 $(clean-dirs):
821         $(Q)$(MAKE) $(clean)=$(patsubst _clean_%,%,$@)
822
823 clean: archclean $(clean-dirs)
824         $(call cmd,rmdirs)
825         $(call cmd,rmfiles)
826         @find . $(RCS_FIND_IGNORE) \
827                 \( -name '*.[oas]' -o -name '*.ko' -o -name '.*.cmd' \
828                 -o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \) \
829                 -type f -print | xargs rm -f
830
831 # mrproper - Delete all generated files, including .config
832 #
833 mrproper: rm-dirs  := $(wildcard $(MRPROPER_DIRS))
834 mrproper: rm-files := $(wildcard $(MRPROPER_FILES))
835 mrproper-dirs      := $(addprefix _mrproper_,Documentation/DocBook scripts)
836
837 .PHONY: $(mrproper-dirs) mrproper archmrproper
838 $(mrproper-dirs):
839         $(Q)$(MAKE) $(clean)=$(patsubst _mrproper_%,%,$@)
840
841 mrproper: clean archmrproper $(mrproper-dirs)
842         $(call cmd,rmdirs)
843         $(call cmd,rmfiles)
844
845 # distclean
846 #
847 .PHONY: distclean
848
849 distclean: mrproper
850         @find . $(RCS_FIND_IGNORE) \
851                 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
852                 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
853                 -o -name '.*.rej' -o -size 0 \
854                 -o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \
855                 -type f -print | xargs rm -f
856
857 # RPM target
858 # ---------------------------------------------------------------------------
859
860 .PHONY: rpm
861
862 # Remove hyphens since they have special meaning in RPM filenames
863 KERNELPATH=kernel-$(subst -,,$(KERNELRELEASE))
864
865 #       If you do a make spec before packing the tarball you can rpm -ta it
866
867 spec:
868         $(CONFIG_SHELL) $(srctree)/scripts/mkspec > $(objtree)/kernel.spec
869
870 #       a) Build a tar ball
871 #       b) ge