Rules.make 18.4 KB
Newer Older
Linus Torvalds's avatar
Linus Torvalds committed
1 2 3 4
#
# This file contains rules which are shared between multiple Makefiles.
#

5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
# Some standard vars

comma   := ,
empty   :=
space   := $(empty) $(empty)

# Figure out paths
# ---------------------------------------------------------------------------
# Find the path relative to the toplevel dir, $(RELDIR), and express
# the toplevel dir as a relative path from this dir, $(TOPDIR_REL)

ifeq ($(findstring $(TOPDIR),$(CURDIR)),)
  # Can only happen when something is built out of tree
  RELDIR := $(CURDIR)
  TOPDIR_REL := $(TOPDIR)
else
  RELDIR := $(subst $(TOPDIR)/,,$(CURDIR))
  TOPDIR_REL := $(subst $(space),,$(foreach d,$(subst /, ,$(RELDIR)),../))
endif
24

25 26 27 28 29 30 31 32 33 34 35 36
# Some paths for the Makefiles to use
# ---------------------------------------------------------------------------

# Usage:
#
# $(obj)/target.o                     : target.o in the build dir
# $(src)/target.c                     : target.c in the source dir
# $(objtree)/include/linux/version.h  : Some file relative to the build
#					dir root
# $(srctree)/include/linux/module.h   : Some file relative to the source
#				        dir root
#
37
# $(obj) and $(src) can only be used in the section after
38 39 40 41 42 43 44 45
# include $(TOPDIR)/Rules.make, i.e for generated files and the like.
# Intentionally.
#
# We don't support separate source / object yet, so these are just
# placeholders for now

obj := .
src := .
46 47 48 49

# For use in the quiet output

echo_target = $(RELDIR)/$@
50

51 52 53
# Figure out what we need to build from the various variables
# ===========================================================================

Kai Germaschewski's avatar
Kai Germaschewski committed
54 55 56
# When an object is listed to be built compiled-in and modular,
# only build the compiled-in version

57
obj-m := $(filter-out $(obj-y),$(obj-m))
Linus Torvalds's avatar
Linus Torvalds committed
58

59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
# Handle objects in subdirs
# ---------------------------------------------------------------------------
# o if we encounter foo/ in $(obj-y), replace it by foo/built-in.o
#   and add the directory to the list of dirs to descend into: $(subdir-y)
# o if we encounter foo/ in $(obj-m), remove it from $(obj-m) 
#   and add the directory to the list of dirs to descend into: $(subdir-m)

__subdir-y	:= $(patsubst %/,%,$(filter %/, $(obj-y)))
subdir-y	+= $(__subdir-y)
__subdir-m	:= $(patsubst %/,%,$(filter %/, $(obj-m)))
subdir-m	+= $(__subdir-m)
__subdir-n	:= $(patsubst %/,%,$(filter %/, $(obj-n)))
subdir-n	+= $(__subdir-n)
__subdir-	:= $(patsubst %/,%,$(filter %/, $(obj-)))
subdir-		+= $(__subdir-)
obj-y		:= $(patsubst %/, %/built-in.o, $(obj-y))
obj-m		:= $(filter-out %/, $(obj-m))

77
# Subdirectories we need to descend into
78

79
subdir-ym	:= $(sort $(subdir-y) $(subdir-m))
Linus Torvalds's avatar
Linus Torvalds committed
80

81 82 83 84 85 86
# export.o is never a composite object, since $(export-objs) has a
# fixed meaning (== objects which EXPORT_SYMBOL())
__obj-y = $(filter-out export.o,$(obj-y))
__obj-m = $(filter-out export.o,$(obj-m))

# if $(foo-objs) exists, foo.o is a composite object 
Kai Germaschewski's avatar
Kai Germaschewski committed
87 88
__multi-used-y := $(sort $(foreach m,$(__obj-y), $(if $($(m:.o=-objs)), $(m))))
__multi-used-m := $(sort $(foreach m,$(__obj-m), $(if $($(m:.o=-objs)), $(m))))
89 90 91 92 93 94 95 96 97 98 99

# FIXME: Rip this out later
# Backwards compatibility: if a composite object is listed in
# $(list-multi), skip it here, since the Makefile will have an explicit
# link rule for it

multi-used-y := $(filter-out $(list-multi),$(__multi-used-y))
multi-used-m := $(filter-out $(list-multi),$(__multi-used-m))

# Build list of the parts of our composite objects, our composite
# objects depend on those (obviously)
Kai Germaschewski's avatar
Kai Germaschewski committed
100 101
multi-objs-y := $(foreach m, $(multi-used-y), $($(m:.o=-objs)))
multi-objs-m := $(foreach m, $(multi-used-m), $($(m:.o=-objs)))
102

Kai Germaschewski's avatar
Kai Germaschewski committed
103 104 105 106 107
# $(subdir-obj-y) is the list of objects in $(obj-y) which do not live
# in the local directory
subdir-obj-y := $(foreach o,$(obj-y),$(if $(filter-out $(o),$(notdir $(o))),$(o)))

# Replace multi-part objects by their individual parts, look at local dir only
108
real-objs-y := $(foreach m, $(filter-out $(subdir-obj-y), $(obj-y)), $(if $($(m:.o=-objs)),$($(m:.o=-objs)),$(m))) $(EXTRA_TARGETS)
Kai Germaschewski's avatar
Kai Germaschewski committed
109
real-objs-m := $(foreach m, $(obj-m), $(if $($(m:.o=-objs)),$($(m:.o=-objs)),$(m)))
110

111 112
# Only build module versions for files which are selected to be built
export-objs := $(filter $(export-objs),$(real-objs-y) $(real-objs-m))
113

114 115 116 117
# The temporary file to save gcc -MD generated dependencies must not
# contain a comma
depfile = $(subst $(comma),_,$(@D)/.$(@F).d)

118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
# We're called for one of three purposes:
# o fastdep: build module version files (.ver) for $(export-objs) in
#   the current directory
# o modules_install: install the modules in the current directory
# o build: When no target is given, first_rule is the default and
#   will build the built-in and modular objects in this dir
#   (or a subset thereof, depending on $(KBUILD_MODULES),$(KBUILD_BUILTIN)
#   When targets are given directly (like foo.o), we just build these
#   targets (That happens when someone does make some/dir/foo.[ois])

ifeq ($(MAKECMDGOALS),fastdep)

# ===========================================================================
# Module versions
# ===========================================================================

134 135 136 137 138 139 140 141 142 143 144 145
ifeq ($(strip $(export-objs)),)

# If we don't export any symbols in this dir, just descend
# ---------------------------------------------------------------------------

fastdep: sub_dirs
	@echo -n

else

# This sets version suffixes on exported symbols
# ---------------------------------------------------------------------------
146 147 148 149 150 151 152 153 154 155 156 157 158 159

MODVERDIR := $(TOPDIR)/include/linux/modules/$(RELDIR)

#
# Added the SMP separator to stop module accidents between uniprocessor
# and SMP Intel boxes - AC - from bits by Michael Chastain
#

ifdef CONFIG_SMP
	genksyms_smp_prefix := -p smp_
else
	genksyms_smp_prefix := 
endif

160 161 162 163
#	Don't include modversions.h, we're just about to generate it here.

CFLAGS_MODULE := $(filter-out -include $(HPATH)/linux/modversions.h,$(CFLAGS_MODULE))

Kai Germaschewski's avatar
Kai Germaschewski committed
164 165 166
$(addprefix $(MODVERDIR)/,$(real-objs-y:.o=.ver)): modkern_cflags := $(CFLAGS_KERNEL)
$(addprefix $(MODVERDIR)/,$(real-objs-m:.o=.ver)): modkern_cflags := $(CFLAGS_MODULE)
$(addprefix $(MODVERDIR)/,$(export-objs:.o=.ver)): export_flags   := -D__GENKSYMS__
167

168
c_flags = -Wp,-MD,$(depfile) $(CFLAGS) $(NOSTDINC_FLAGS) \
169 170 171
	  $(modkern_cflags) $(EXTRA_CFLAGS) $(CFLAGS_$(*F).o) \
	  -DKBUILD_BASENAME=$(subst $(comma),_,$(subst -,_,$(*F))) \
	  $(export_flags) 
172

173 174 175 176
# Our objects only depend on modversions.h, not on the individual .ver
# files (fix-dep filters them), so touch modversions.h if any of the .ver
# files changes

177
quiet_cmd_cc_ver_c = MKVER   include/linux/modules/$(RELDIR)/$*.ver
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196
cmd_cc_ver_c = $(CPP) $(c_flags) $< | $(GENKSYMS) $(genksyms_smp_prefix) \
		 -k $(VERSION).$(PATCHLEVEL).$(SUBLEVEL) > $@.tmp

# Okay, let's explain what's happening in rule_make_cc_ver_c:
# o echo the command
# o execute the command
# o If the $(CPP) fails, we won't notice because it's output is piped
#   to $(GENKSYMS) which does not fail. We recognize this case by
#   looking if the generated $(depfile) exists, though.
# o If the .ver file changed, touch modversions.h, which is our maker
#   of any changed .ver files.
# o Move command line and deps into their normal .*.cmd place.  

define rule_cc_ver_c
	$(if $($(quiet)cmd_cc_ver_c),echo '  $($(quiet)cmd_cc_ver_c)';) \
	$(cmd_cc_ver_c); \
	if [ ! -r $(depfile) ]; then exit 1; fi; \
	$(TOPDIR)/scripts/fixdep $(depfile) $@ $(TOPDIR) '$(cmd_cc_ver_c)' > $(@D)/.$(@F).tmp; \
	rm -f $(depfile); \
197
	if [ ! -r $@ ] || cmp -s $@ $@.tmp; then \
198
	  touch $(TOPDIR)/include/linux/modversions.h; \
199 200
	fi; \
	mv -f $@.tmp $@
201
	mv -f $(@D)/.$(@F).tmp $(@D)/.$(@F).cmd
202 203 204
endef

$(MODVERDIR)/%.ver: %.c FORCE
205
	@$(call if_changed_rule,cc_ver_c)
206

207 208
targets := $(addprefix $(MODVERDIR)/,$(export-objs:.o=.ver))

209
fastdep: $(targets) sub_dirs
210 211 212 213 214 215 216 217 218 219 220 221
	@mkdir -p $(TOPDIR)/.tmp_export-objs/modules/$(RELDIR)
	@touch $(addprefix $(TOPDIR)/.tmp_export-objs/modules/$(RELDIR)/,$(export-objs:.o=.ver))

endif # export-objs 

else # ! fastdep
ifeq ($(MAKECMDGOALS),modules_install)

# ==========================================================================
# Installing modules
# ==========================================================================

222
.PHONY: modules_install
223

224
modules_install: sub_dirs
225 226 227 228 229 230 231 232 233 234 235 236
ifneq ($(obj-m),)
	@echo Installing modules in $(MODLIB)/kernel/$(RELDIR)
	@mkdir -p $(MODLIB)/kernel/$(RELDIR)
	@cp $(obj-m) $(MODLIB)/kernel/$(RELDIR)
else
	@echo -n
endif

else # ! modules_install

# ==========================================================================
# Building
237
# ==========================================================================
238

Kai Germaschewski's avatar
Kai Germaschewski committed
239 240 241
# If a Makefile does define neither O_TARGET nor L_TARGET,
# use a standard O_TARGET named "built-in.o"

242 243 244 245 246 247
ifndef O_TARGET
ifndef L_TARGET
O_TARGET := built-in.o
endif
endif

248
#	The echo suppresses the "Nothing to be done for first_rule"
249 250 251
first_rule: $(if $(KBUILD_BUILTIN),$(O_TARGET) $(L_TARGET) $(EXTRA_TARGETS)) \
	    $(if $(KBUILD_MODULES),$(obj-m)) \
	    sub_dirs
252
	@echo -n
Linus Torvalds's avatar
Linus Torvalds committed
253

254 255 256
# Compile C sources (.c)
# ---------------------------------------------------------------------------

257
# Default is built-in, unless we know otherwise
258 259
modkern_cflags := $(CFLAGS_KERNEL)

260 261 262
$(real-objs-m)        : modkern_cflags := $(CFLAGS_MODULE)
$(real-objs-m:.o=.i)  : modkern_cflags := $(CFLAGS_MODULE)
$(real-objs-m:.o=.lst): modkern_cflags := $(CFLAGS_MODULE)
263

264 265 266 267
$(export-objs)        : export_flags   := $(EXPORT_FLAGS)
$(export-objs:.o=.i)  : export_flags   := $(EXPORT_FLAGS)
$(export-objs:.o=.s)  : export_flags   := $(EXPORT_FLAGS)
$(export-objs:.o=.lst): export_flags   := $(EXPORT_FLAGS)
268

269
c_flags = -Wp,-MD,$(depfile) $(CFLAGS) $(NOSTDINC_FLAGS) \
270 271 272
	  $(modkern_cflags) $(EXTRA_CFLAGS) $(CFLAGS_$(*F).o) \
	  -DKBUILD_BASENAME=$(subst $(comma),_,$(subst -,_,$(*F))) \
	  $(export_flags) 
273

274
quiet_cmd_cc_s_c = CC      $(echo_target)
275
cmd_cc_s_c       = $(CC) $(c_flags) -S -o $@ $< 
276

277
%.s: %.c FORCE
278
	$(call if_changed_dep,cc_s_c)
279

280
quiet_cmd_cc_i_c = CPP     $(echo_target)
281
cmd_cc_i_c       = $(CPP) $(c_flags)   -o $@ $<
Linus Torvalds's avatar
Linus Torvalds committed
282

283
%.i: %.c FORCE
284
	$(call if_changed_dep,cc_i_c)
285

286
quiet_cmd_cc_o_c = CC      $(echo_target)
287
cmd_cc_o_c       = $(CC) $(c_flags) -c -o $@ $<
Linus Torvalds's avatar
Linus Torvalds committed
288

289
%.o: %.c FORCE
290
	$(call if_changed_dep,cc_o_c)
Linus Torvalds's avatar
Linus Torvalds committed
291

292 293
quiet_cmd_cc_lst_c = MKLST   $(echo_target)
cmd_cc_lst_c       = $(CC) $(c_flags) -g -c -o $*.o $< && $(TOPDIR)/scripts/makelst $*.o $(TOPDIR)/System.map $(OBJDUMP) > $@
294 295

%.lst: %.c FORCE
296
	$(call if_changed_dep,cc_lst_c)
297

298 299
# Compile assembler sources (.S)
# ---------------------------------------------------------------------------
Linus Torvalds's avatar
Linus Torvalds committed
300

301 302 303 304 305
modkern_aflags := $(AFLAGS_KERNEL)

$(real-objs-m)      : modkern_aflags := $(AFLAGS_MODULE)
$(real-objs-m:.o=.s): modkern_aflags := $(AFLAGS_MODULE)

306
a_flags = -Wp,-MD,$(depfile) $(AFLAGS) $(NOSTDINC_FLAGS) \
307
	  $(modkern_aflags) $(EXTRA_AFLAGS) $(AFLAGS_$(*F).o)
308

309
quiet_cmd_as_s_S = CPP     $(echo_target)
310
cmd_as_s_S       = $(CPP) $(a_flags)   -o $@ $< 
311

312
%.s: %.S FORCE
313
	$(call if_changed_dep,as_s_S)
314

315
quiet_cmd_as_o_S = AS      $(echo_target)
316
cmd_as_o_S       = $(CC) $(a_flags) -c -o $@ $<
Linus Torvalds's avatar
Linus Torvalds committed
317

318
%.o: %.S FORCE
319
	$(call if_changed_dep,as_o_S)
Linus Torvalds's avatar
Linus Torvalds committed
320

321 322
targets += $(real-objs-y) $(real-objs-m) $(EXTRA_TARGETS) $(MAKECMDGOALS)

323 324 325
# Build the compiled-in targets
# ---------------------------------------------------------------------------

Kai Germaschewski's avatar
Kai Germaschewski committed
326
# To build objects in subdirs, we need to descend into the directories
327
$(sort $(subdir-obj-y)): sub_dirs ;
Linus Torvalds's avatar
Linus Torvalds committed
328 329 330 331 332

#
# Rule to compile a set of .o files into one .o file
#
ifdef O_TARGET
333
quiet_cmd_link_o_target = LD      $(echo_target)
334 335
# If the list of objects to link is empty, just create an empty O_TARGET
cmd_link_o_target = $(if $(strip $(obj-y)),\
336
		      $(LD) $(LDFLAGS) $(EXTRA_LDFLAGS) -r -o $@ $(filter $(obj-y), $^),\
337 338
		      rm -f $@; $(AR) rcs $@)

339
$(O_TARGET): $(obj-y) FORCE
340
	$(call if_changed,link_o_target)
341 342

targets += $(O_TARGET)
Linus Torvalds's avatar
Linus Torvalds committed
343 344 345 346 347 348
endif # O_TARGET

#
# Rule to compile a set of .o files into one .a file
#
ifdef L_TARGET
349
quiet_cmd_link_l_target = AR      $(echo_target)
350 351
cmd_link_l_target = rm -f $@; $(AR) $(EXTRA_ARFLAGS) rcs $@ $(obj-y)

352
$(L_TARGET): $(obj-y) FORCE
353
	$(call if_changed,link_l_target)
354 355

targets += $(L_TARGET)
Linus Torvalds's avatar
Linus Torvalds committed
356 357
endif

358 359 360 361
#
# Rule to link composite objects
#

362
quiet_cmd_link_multi = LD      $(echo_target)
363
cmd_link_multi = $(LD) $(LDFLAGS) $(EXTRA_LDFLAGS) -r -o $@ $(filter $($(basename $@)-objs),$^)
364

Kai Germaschewski's avatar
Kai Germaschewski committed
365 366 367 368
# We would rather have a list of rules like
# 	foo.o: $(foo-objs)
# but that's not so easy, so we rather make all composite objects depend
# on the set of all their parts
369
$(multi-used-y) : %.o: $(multi-objs-y) FORCE
370
	$(call if_changed,link_multi)
371

372
$(multi-used-m) : %.o: $(multi-objs-m) FORCE
373
	$(call if_changed,link_multi)
Linus Torvalds's avatar
Linus Torvalds committed
374

375 376
targets += $(multi-used-y) $(multi-used-m)

377 378 379 380 381 382 383
# Compile programs on the host
# ===========================================================================

host-progs-single     := $(foreach m,$(host-progs),$(if $($(m)-objs),,$(m)))
host-progs-multi      := $(foreach m,$(host-progs),$(if $($(m)-objs),$(m)))
host-progs-multi-objs := $(foreach m,$(host-progs-multi),$($(m)-objs))

384
quiet_cmd_host_cc__c  = HOSTCC  $(echo_target)
385
cmd_host_cc__c        = $(HOSTCC) -Wp,-MD,$(depfile) \
386 387
			$(HOSTCFLAGS) $(HOST_EXTRACFLAGS) \
			$(HOST_LOADLIBES) -o $@ $<
388 389 390 391

$(host-progs-single): %: %.c FORCE
	$(call if_changed_dep,host_cc__c)

392
quiet_cmd_host_cc_o_c = HOSTCC  $(echo_target)
393
cmd_host_cc_o_c       = $(HOSTCC) -Wp,-MD,$(depfile) \
394 395 396 397 398
			$(HOSTCFLAGS) $(HOST_EXTRACFLAGS) -c -o $@ $<

$(host-progs-multi-objs): %.o: %.c FORCE
	$(call if_changed_dep,host_cc_o_c)

399
quiet_cmd_host_cc__o  = HOSTLD  $(echo_target)
400 401 402 403
cmd_host_cc__o        = $(HOSTCC) $(HOSTLDFLAGS) -o $@ $($@-objs) \
			$(HOST_LOADLIBES)

$(host-progs-multi): %: $(host-progs-multi-objs) FORCE
404
	$(call if_changed,host_cc__o)
405

406
targets += $(host-progs-single) $(host-progs-multi-objs) $(host-progs-multi) 
407

408 409
endif # ! modules_install
endif # ! fastdep
Linus Torvalds's avatar
Linus Torvalds committed
410

411 412 413
# Shipped files
# ===========================================================================

414
quiet_cmd_shipped = SHIPPED $(echo_target)
415
cmd_shipped = cat $< > $@
416

417
%:: %_shipped
418
	$(call cmd,shipped)
419

420 421 422 423 424 425
# Commands useful for building a boot image
# ===========================================================================
# 
#	Use as following:
#
#	target: source(s) FORCE
426
#		$(if_changed,ld/objcopy/gzip)
427 428 429 430 431 432 433
#
#	and add target to EXTRA_TARGETS so that we know we have to
#	read in the saved command line

# Linking
# ---------------------------------------------------------------------------

434
quiet_cmd_ld = LD      $(echo_target)
435 436 437 438 439 440
cmd_ld = $(LD) $(LDFLAGS) $(EXTRA_LDFLAGS) $(LDFLAGS_$@) \
	       $(filter-out FORCE,$^) -o $@ 

# Objcopy
# ---------------------------------------------------------------------------

441
quiet_cmd_objcopy = OBJCOPY $(echo_target)
442 443 444 445 446
cmd_objcopy = $(OBJCOPY) $(OBJCOPYFLAGS) $< $@

# Gzip
# ---------------------------------------------------------------------------

447
quiet_cmd_gzip = GZIP    $(echo_target)
448 449
cmd_gzip = gzip -f -9 < $< > $@

450 451 452
# ===========================================================================
# Generic stuff
# ===========================================================================
453

454 455 456 457 458 459 460 461 462 463
# Descending
# ---------------------------------------------------------------------------

.PHONY: sub_dirs $(subdir-ym)

sub_dirs: $(subdir-ym)

$(subdir-ym):
	@$(MAKE) -C $@ $(MAKECMDGOALS)

464 465
# Add FORCE to the prequisites of a target to force it to be always rebuilt.
# ---------------------------------------------------------------------------
466

467
.PHONY: FORCE
468

469
FORCE:
Linus Torvalds's avatar
Linus Torvalds committed
470 471 472 473 474 475 476

#
# This sets version suffixes on exported symbols
# Separate the object into "normal" objects and "exporting" objects
# Exporting objects are: all objects that define symbol tables
#

477 478 479 480 481 482 483 484
# ---------------------------------------------------------------------------
# Check if command line has changed

# Usage:
# normally one uses rules like
#
# %.o: %.c
# 	<command line>
Linus Torvalds's avatar
Linus Torvalds committed
485
#
486 487
# However, these only rebuild the target when the source has changed,
# but not when e.g. the command or the flags on the command line changed.
Linus Torvalds's avatar
Linus Torvalds committed
488
#
489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506
# This extension allows to do the following:
#
# command = <command line>
#
# %.o: %.c dummy
#	$(call if_changed,command)
#
# which will make sure to rebuild the target when either its prerequisites
# change or the command line changes
#
# The magic works as follows:
# The addition of dummy to the dependencies causes the rule for rebuilding
# to be always executed. However, the if_changed function will generate
# an empty command when 
# o none of the prequesites changed (i.e $? is empty)
# o the command line did not change (we compare the old command line,
#   which is saved in .<target>.o, to the current command line using
#   the two filter-out commands)
Linus Torvalds's avatar
Linus Torvalds committed
507

508 509 510 511 512 513 514
# Read all saved command lines and dependencies for the $(targets) we
# may be building above, using $(if_changed{,_dep}). As an
# optimization, we don't need to read them if the target does not
# exist, we will rebuild anyway in that case.

targets := $(wildcard $(sort $(targets)))
cmd_files := $(wildcard $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd))
Linus Torvalds's avatar
Linus Torvalds committed
515

516 517
ifneq ($(cmd_files),)
  include $(cmd_files)
Linus Torvalds's avatar
Linus Torvalds committed
518 519
endif

520 521 522
# function to only execute the passed command if necessary

if_changed = $(if $(strip $? \
523 524 525 526 527 528
		          $(filter-out $(cmd_$(1)),$(cmd_$@))\
			  $(filter-out $(cmd_$@),$(cmd_$(1)))),\
	@set -e; \
	$(if $($(quiet)cmd_$(1)),echo '  $($(quiet)cmd_$(1))';) \
	$(cmd_$(1)); \
	echo 'cmd_$@ := $(cmd_$(1))' > $(@D)/.$(@F).cmd)
529

530 531 532 533

# execute the command and also postprocess generated .d dependencies
# file

534
if_changed_dep = $(if $(strip $? $(filter-out FORCE $(wildcard $^),$^)\
535 536 537
		          $(filter-out $(cmd_$(1)),$(cmd_$@))\
			  $(filter-out $(cmd_$@),$(cmd_$(1)))),\
	@set -e; \
538
	$(if $($(quiet)cmd_$(1)),echo '  $($(quiet)cmd_$(1))';) \
539
	$(cmd_$(1)); \
540 541
	$(TOPDIR)/scripts/fixdep $(depfile) $@ $(TOPDIR) '$(cmd_$(1))' > $(@D)/.$(@F).tmp; \
	rm -f $(depfile); \
542
	mv -f $(@D)/.$(@F).tmp $(@D)/.$(@F).cmd)
543

544 545 546 547 548 549 550 551 552 553 554
# Usage: $(call if_changed_rule,foo)
# will check if $(cmd_foo) changed, or any of the prequisites changed,
# and if so will execute $(rule_foo)

if_changed_rule = $(if $(strip $? \
		               $(filter-out $(cmd_$(1)),$(cmd_$@))\
			       $(filter-out $(cmd_$@),$(cmd_$(1)))),\
			@set -e; \
			mkdir -p $(dir $@); \
			$(rule_$(1)))

555 556
# If quiet is set, only print short version of command

557
cmd = @$(if $($(quiet)cmd_$(1)),echo '  $($(quiet)cmd_$(1))' &&) $(cmd_$(1))
558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576

# do_cmd is a shorthand used to support both compressed, verbose
# and silent output in a single line.
# Compared to cmd described avobe, do_cmd does no rely on any variables 
# previously assigned a value.
#
# Usage $(call do_cmd,CMD   $@,cmd_to_execute bla bla)
# Example:
# $(call do_cmd,CP $@,cp -b $< $@)
# make -s => nothing will be printed
# make KBUILD_VERBOSE=1 => cp -b path/to/src.file path/to/dest.file
# make KBUILD_VERBOSE=0 =>   CP path/to/dest.file
define do_cmd
        @$(if $(filter quiet_,$(quiet)), echo '  $(1)' &&,
           $(if $(filter silent_,$(quiet)),,
             echo "$(2)" &&)) \
        $(2)
endef