Skip to content

Commit 4f19336

Browse files
madscientistSam Ravnborg
authored andcommitted
kbuild: change kbuild to not rely on incorrect GNU make behavior
The kbuild system takes advantage of an incorrect behavior in GNU make. Once this behavior is fixed, all files in the kernel rebuild every time, even if nothing has changed. This patch ensures kbuild works with both the incorrect and correct behaviors of GNU make. For more details on the incorrect behavior, see: http://lists.gnu.org/archive/html/bug-make/2006-03/msg00003.html Changes in this patch: - Keep all targets that are to be marked .PHONY in a variable, PHONY. - Add .PHONY: $(PHONY) to mark them properly. - Remove any $(PHONY) files from the $? list when determining whether targets are up-to-date or not. Signed-off-by: Paul Smith <psmith@gnu.org> Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
1 parent 7b75b13 commit 4f19336

File tree

25 files changed

+144
-75
lines changed

25 files changed

+144
-75
lines changed

Documentation/DocBook/Makefile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ PS_METHOD = $(prefer-db2x)
2828

2929
###
3030
# The targets that may be used.
31-
.PHONY: xmldocs sgmldocs psdocs pdfdocs htmldocs mandocs installmandocs
31+
PHONY += xmldocs sgmldocs psdocs pdfdocs htmldocs mandocs installmandocs
3232

3333
BOOKS := $(addprefix $(obj)/,$(DOCBOOKS))
3434
xmldocs: $(BOOKS)
@@ -211,3 +211,9 @@ clean-dirs := $(patsubst %.xml,%,$(DOCBOOKS))
211211

212212
#man put files in man subdir - traverse down
213213
subdir- := man/
214+
215+
216+
# Declare the contents of the .PHONY variable as phony. We keep that
217+
# information in a variable se we can use it in if_changed and friends.
218+
219+
.PHONY: $(PHONY)

Makefile

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ ifdef O
9595
endif
9696

9797
# That's our default target when none is given on the command line
98-
.PHONY: _all
98+
PHONY := _all
9999
_all:
100100

101101
ifneq ($(KBUILD_OUTPUT),)
@@ -106,7 +106,7 @@ KBUILD_OUTPUT := $(shell cd $(KBUILD_OUTPUT) && /bin/pwd)
106106
$(if $(KBUILD_OUTPUT),, \
107107
$(error output directory "$(saved-output)" does not exist))
108108

109-
.PHONY: $(MAKECMDGOALS)
109+
PHONY += $(MAKECMDGOALS)
110110

111111
$(filter-out _all,$(MAKECMDGOALS)) _all:
112112
$(if $(KBUILD_VERBOSE:1=),@)$(MAKE) -C $(KBUILD_OUTPUT) \
@@ -123,7 +123,7 @@ ifeq ($(skip-makefile),)
123123

124124
# If building an external module we do not care about the all: rule
125125
# but instead _all depend on modules
126-
.PHONY: all
126+
PHONY += all
127127
ifeq ($(KBUILD_EXTMOD),)
128128
_all: all
129129
else
@@ -337,14 +337,14 @@ export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn --exc
337337
# Rules shared between *config targets and build targets
338338

339339
# Basic helpers built in scripts/
340-
.PHONY: scripts_basic
340+
PHONY += scripts_basic
341341
scripts_basic:
342342
$(Q)$(MAKE) $(build)=scripts/basic
343343

344344
# To avoid any implicit rule to kick in, define an empty command.
345345
scripts/basic/%: scripts_basic ;
346346

347-
.PHONY: outputmakefile
347+
PHONY += outputmakefile
348348
# outputmakefile generate a Makefile to be placed in output directory, if
349349
# using a seperate output directory. This allows convinient use
350350
# of make in output directory
@@ -420,7 +420,7 @@ ifeq ($(KBUILD_EXTMOD),)
420420
# Additional helpers built in scripts/
421421
# Carefully list dependencies so we do not try to build scripts twice
422422
# in parrallel
423-
.PHONY: scripts
423+
PHONY += scripts
424424
scripts: scripts_basic include/config/MARKER
425425
$(Q)$(MAKE) $(build)=$(@)
426426

@@ -720,7 +720,7 @@ $(sort $(vmlinux-init) $(vmlinux-main)) $(vmlinux-lds): $(vmlinux-dirs) ;
720720
# make menuconfig etc.
721721
# Error messages still appears in the original language
722722

723-
.PHONY: $(vmlinux-dirs)
723+
PHONY += $(vmlinux-dirs)
724724
$(vmlinux-dirs): prepare scripts
725725
$(Q)$(MAKE) $(build)=$@
726726

@@ -773,10 +773,10 @@ kernelrelease = $(KERNELVERSION)$(localver-full)
773773
# version.h and scripts_basic is processed / created.
774774

775775
# Listed in dependency order
776-
.PHONY: prepare archprepare prepare0 prepare1 prepare2 prepare3
776+
PHONY += prepare archprepare prepare0 prepare1 prepare2 prepare3
777777

778778
# prepare-all is deprecated, use prepare as valid replacement
779-
.PHONY: prepare-all
779+
PHONY += prepare-all
780780

781781
# prepare3 is used to check if we are building in a separate output directory,
782782
# and if so do:
@@ -857,7 +857,7 @@ include/linux/version.h: $(srctree)/Makefile .config .kernelrelease FORCE
857857

858858
# ---------------------------------------------------------------------------
859859

860-
.PHONY: depend dep
860+
PHONY += depend dep
861861
depend dep:
862862
@echo '*** Warning: make $@ is unnecessary now.'
863863

@@ -872,21 +872,21 @@ all: modules
872872

873873
# Build modules
874874

875-
.PHONY: modules
875+
PHONY += modules
876876
modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux)
877877
@echo ' Building modules, stage 2.';
878878
$(Q)$(MAKE) -rR -f $(srctree)/scripts/Makefile.modpost
879879

880880

881881
# Target to prepare building external modules
882-
.PHONY: modules_prepare
882+
PHONY += modules_prepare
883883
modules_prepare: prepare scripts
884884

885885
# Target to install modules
886-
.PHONY: modules_install
886+
PHONY += modules_install
887887
modules_install: _modinst_ _modinst_post
888888

889-
.PHONY: _modinst_
889+
PHONY += _modinst_
890890
_modinst_:
891891
@if [ -z "`$(DEPMOD) -V 2>/dev/null | grep module-init-tools`" ]; then \
892892
echo "Warning: you may need to install module-init-tools"; \
@@ -913,7 +913,7 @@ depmod_opts :=
913913
else
914914
depmod_opts := -b $(INSTALL_MOD_PATH) -r
915915
endif
916-
.PHONY: _modinst_post
916+
PHONY += _modinst_post
917917
_modinst_post: _modinst_
918918
if [ -r System.map -a -x $(DEPMOD) ]; then $(DEPMOD) -ae -F System.map $(depmod_opts) $(KERNELRELEASE); fi
919919

@@ -956,7 +956,7 @@ clean: rm-dirs := $(CLEAN_DIRS)
956956
clean: rm-files := $(CLEAN_FILES)
957957
clean-dirs := $(addprefix _clean_,$(srctree) $(vmlinux-alldirs))
958958

959-
.PHONY: $(clean-dirs) clean archclean
959+
PHONY += $(clean-dirs) clean archclean
960960
$(clean-dirs):
961961
$(Q)$(MAKE) $(clean)=$(patsubst _clean_%,%,$@)
962962

@@ -974,7 +974,7 @@ mrproper: rm-dirs := $(wildcard $(MRPROPER_DIRS))
974974
mrproper: rm-files := $(wildcard $(MRPROPER_FILES))
975975
mrproper-dirs := $(addprefix _mrproper_,Documentation/DocBook scripts)
976976

977-
.PHONY: $(mrproper-dirs) mrproper archmrproper
977+
PHONY += $(mrproper-dirs) mrproper archmrproper
978978
$(mrproper-dirs):
979979
$(Q)$(MAKE) $(clean)=$(patsubst _mrproper_%,%,$@)
980980

@@ -984,7 +984,7 @@ mrproper: clean archmrproper $(mrproper-dirs)
984984

985985
# distclean
986986
#
987-
.PHONY: distclean
987+
PHONY += distclean
988988

989989
distclean: mrproper
990990
@find $(srctree) $(RCS_FIND_IGNORE) \
@@ -1000,7 +1000,7 @@ distclean: mrproper
10001000
# rpm target kept for backward compatibility
10011001
package-dir := $(srctree)/scripts/package
10021002

1003-
.PHONY: %-pkg rpm
1003+
PHONY += %-pkg rpm
10041004

10051005
%pkg: FORCE
10061006
$(Q)$(MAKE) -f $(package-dir)/Makefile $@
@@ -1092,12 +1092,12 @@ else # KBUILD_EXTMOD
10921092

10931093
# We are always building modules
10941094
KBUILD_MODULES := 1
1095-
.PHONY: crmodverdir
1095+
PHONY += crmodverdir
10961096
crmodverdir:
10971097
$(Q)rm -rf $(MODVERDIR)
10981098
$(Q)mkdir -p $(MODVERDIR)
10991099

1100-
.PHONY: $(objtree)/Module.symvers
1100+
PHONY += $(objtree)/Module.symvers
11011101
$(objtree)/Module.symvers:
11021102
@test -e $(objtree)/Module.symvers || ( \
11031103
echo; \
@@ -1106,19 +1106,19 @@ $(objtree)/Module.symvers:
11061106
echo )
11071107

11081108
module-dirs := $(addprefix _module_,$(KBUILD_EXTMOD))
1109-
.PHONY: $(module-dirs) modules
1109+
PHONY += $(module-dirs) modules
11101110
$(module-dirs): crmodverdir $(objtree)/Module.symvers
11111111
$(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
11121112

11131113
modules: $(module-dirs)
11141114
@echo ' Building modules, stage 2.';
11151115
$(Q)$(MAKE) -rR -f $(srctree)/scripts/Makefile.modpost
11161116

1117-
.PHONY: modules_install
1117+
PHONY += modules_install
11181118
modules_install: _emodinst_ _emodinst_post
11191119

1120-
install-dir := $(if $(INSTALL_MOD_DIR),$(INSTALL_MOD_DIR),extra)
1121-
.PHONY: _emodinst_
1120+
install-dir := $(if $(INSTALL_MOD_DIR),$(INSTALL_MOD_DIR),extra)
1121+
PHONY += _emodinst_
11221122
_emodinst_:
11231123
$(Q)rm -rf $(MODLIB)/$(install-dir)
11241124
$(Q)mkdir -p $(MODLIB)/$(install-dir)
@@ -1133,13 +1133,13 @@ quiet_cmd_depmod = DEPMOD $(KERNELRELEASE)
11331133
$(KERNELRELEASE); \
11341134
fi
11351135

1136-
.PHONY: _emodinst_post
1136+
PHONY += _emodinst_post
11371137
_emodinst_post: _emodinst_
11381138
$(call cmd,depmod)
11391139

11401140
clean-dirs := $(addprefix _clean_,$(KBUILD_EXTMOD))
11411141

1142-
.PHONY: $(clean-dirs) clean
1142+
PHONY += $(clean-dirs) clean
11431143
$(clean-dirs):
11441144
$(Q)$(MAKE) $(clean)=$(patsubst _clean_%,%,$@)
11451145

@@ -1161,7 +1161,7 @@ help:
11611161
@echo ''
11621162

11631163
# Dummies...
1164-
.PHONY: prepare scripts
1164+
PHONY += prepare scripts
11651165
prepare: ;
11661166
scripts: ;
11671167
endif # KBUILD_EXTMOD
@@ -1274,7 +1274,7 @@ namespacecheck:
12741274
endif #ifeq ($(config-targets),1)
12751275
endif #ifeq ($(mixed-targets),1)
12761276

1277-
.PHONY: checkstack
1277+
PHONY += checkstack
12781278
checkstack:
12791279
$(OBJDUMP) -d vmlinux $$(find . -name '*.ko') | \
12801280
$(PERL) $(src)/scripts/checkstack.pl $(ARCH)
@@ -1357,4 +1357,10 @@ clean := -f $(if $(KBUILD_SRC),$(srctree)/)scripts/Makefile.clean obj
13571357

13581358
endif # skip-makefile
13591359

1360+
PHONY += FORCE
13601361
FORCE:
1362+
1363+
1364+
# Declare the contents of the .PHONY variable as phony. We keep that
1365+
# information in a variable se we can use it in if_changed and friends.
1366+
.PHONY: $(PHONY)

arch/arm/Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
#
22
# arch/arm/Makefile
33
#
4+
# This file is included by the global makefile so that you can add your own
5+
# architecture-specific flags and dependencies.
6+
#
47
# This file is subject to the terms and conditions of the GNU General Public
58
# License. See the file "COPYING" in the main directory of this archive
69
# for more details.
@@ -176,7 +179,7 @@ endif
176179

177180
archprepare: maketools
178181

179-
.PHONY: maketools FORCE
182+
PHONY += maketools FORCE
180183
maketools: include/linux/version.h include/asm-arm/.arch FORCE
181184
$(Q)$(MAKE) $(build)=arch/arm/tools include/asm-arm/mach-types.h
182185

arch/arm/boot/Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
#
22
# arch/arm/boot/Makefile
33
#
4+
# This file is included by the global makefile so that you can add your own
5+
# architecture-specific flags and dependencies.
6+
#
47
# This file is subject to the terms and conditions of the GNU General Public
58
# License. See the file "COPYING" in the main directory of this archive
69
# for more details.
@@ -73,7 +76,7 @@ $(obj)/bootpImage: $(obj)/bootp/bootp FORCE
7376
$(call if_changed,objcopy)
7477
@echo ' Kernel: $@ is ready'
7578

76-
.PHONY: initrd FORCE
79+
PHONY += initrd FORCE
7780
initrd:
7881
@test "$(INITRD_PHYS)" != "" || \
7982
(echo This machine does not support INITRD; exit -1)

arch/arm/boot/bootp/Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
#
22
# linux/arch/arm/boot/bootp/Makefile
33
#
4+
# This file is included by the global makefile so that you can add your own
5+
# architecture-specific flags and dependencies.
6+
#
47

58
LDFLAGS_bootp :=-p --no-undefined -X \
69
--defsym initrd_phys=$(INITRD_PHYS) \
@@ -21,4 +24,4 @@ $(obj)/kernel.o: arch/arm/boot/zImage FORCE
2124

2225
$(obj)/initrd.o: $(INITRD) FORCE
2326

24-
.PHONY: $(INITRD) FORCE
27+
PHONY += $(INITRD) FORCE

arch/arm26/Makefile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
#
22
# arch/arm26/Makefile
33
#
4+
# This file is included by the global makefile so that you can add your own
5+
# architecture-specific flags and dependencies.
6+
#
47
# This file is subject to the terms and conditions of the GNU General Public
58
# License. See the file "COPYING" in the main directory of this archive
69
# for more details.
@@ -49,9 +52,9 @@ all: zImage
4952

5053
boot := arch/arm26/boot
5154

52-
.PHONY: maketools FORCE
55+
PHONY += maketools FORCE
5356
maketools: FORCE
54-
57+
5558

5659
# Convert bzImage to zImage
5760
bzImage: vmlinux

arch/arm26/boot/Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
#
22
# arch/arm26/boot/Makefile
33
#
4+
# This file is included by the global makefile so that you can add your own
5+
# architecture-specific flags and dependencies.
6+
#
47
# This file is subject to the terms and conditions of the GNU General Public
58
# License. See the file "COPYING" in the main directory of this archive
69
# for more details.
@@ -60,7 +63,7 @@ $(obj)/xipImage: vmlinux FORCE
6063
@echo ' Kernel: $@ is ready'
6164
endif
6265

63-
.PHONY: initrd
66+
PHONY += initrd
6467
initrd:
6568
@test "$(INITRD_PHYS)" != "" || \
6669
(echo This machine does not support INITRD; exit -1)

arch/i386/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ AFLAGS += $(mflags-y)
9999

100100
boot := arch/i386/boot
101101

102-
.PHONY: zImage bzImage compressed zlilo bzlilo \
103-
zdisk bzdisk fdimage fdimage144 fdimage288 install
102+
PHONY += zImage bzImage compressed zlilo bzlilo \
103+
zdisk bzdisk fdimage fdimage144 fdimage288 install
104104

105105
all: bzImage
106106

arch/ia64/Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
#
22
# ia64/Makefile
33
#
4+
# This file is included by the global makefile so that you can add your own
5+
# architecture-specific flags and dependencies.
6+
#
47
# This file is subject to the terms and conditions of the GNU General Public
58
# License. See the file "COPYING" in the main directory of this archive
69
# for more details.
@@ -62,7 +65,7 @@ drivers-$(CONFIG_OPROFILE) += arch/ia64/oprofile/
6265

6366
boot := arch/ia64/hp/sim/boot
6467

65-
.PHONY: boot compressed check
68+
PHONY += boot compressed check
6669

6770
all: compressed unwcheck
6871

0 commit comments

Comments
 (0)