Skip to content

Commit

Permalink
kbuild: change kbuild to not rely on incorrect GNU make behavior
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
madscientist authored and Sam Ravnborg committed Mar 5, 2006
1 parent 7b75b13 commit 4f19336
Show file tree
Hide file tree
Showing 25 changed files with 144 additions and 75 deletions.
8 changes: 7 additions & 1 deletion Documentation/DocBook/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ PS_METHOD = $(prefer-db2x)

###
# The targets that may be used.
.PHONY: xmldocs sgmldocs psdocs pdfdocs htmldocs mandocs installmandocs
PHONY += xmldocs sgmldocs psdocs pdfdocs htmldocs mandocs installmandocs

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

#man put files in man subdir - traverse down
subdir- := man/


# Declare the contents of the .PHONY variable as phony. We keep that
# information in a variable se we can use it in if_changed and friends.

.PHONY: $(PHONY)
64 changes: 35 additions & 29 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ ifdef O
endif

# That's our default target when none is given on the command line
.PHONY: _all
PHONY := _all
_all:

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

.PHONY: $(MAKECMDGOALS)
PHONY += $(MAKECMDGOALS)

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

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

# Basic helpers built in scripts/
.PHONY: scripts_basic
PHONY += scripts_basic
scripts_basic:
$(Q)$(MAKE) $(build)=scripts/basic

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

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

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

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

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

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

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

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

# ---------------------------------------------------------------------------

.PHONY: depend dep
PHONY += depend dep
depend dep:
@echo '*** Warning: make $@ is unnecessary now.'

Expand All @@ -872,21 +872,21 @@ all: modules

# Build modules

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


# Target to prepare building external modules
.PHONY: modules_prepare
PHONY += modules_prepare
modules_prepare: prepare scripts

# Target to install modules
.PHONY: modules_install
PHONY += modules_install
modules_install: _modinst_ _modinst_post

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

Expand Down Expand Up @@ -956,7 +956,7 @@ clean: rm-dirs := $(CLEAN_DIRS)
clean: rm-files := $(CLEAN_FILES)
clean-dirs := $(addprefix _clean_,$(srctree) $(vmlinux-alldirs))

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

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

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

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

# distclean
#
.PHONY: distclean
PHONY += distclean

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

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

%pkg: FORCE
$(Q)$(MAKE) -f $(package-dir)/Makefile $@
Expand Down Expand Up @@ -1092,12 +1092,12 @@ else # KBUILD_EXTMOD

# We are always building modules
KBUILD_MODULES := 1
.PHONY: crmodverdir
PHONY += crmodverdir
crmodverdir:
$(Q)rm -rf $(MODVERDIR)
$(Q)mkdir -p $(MODVERDIR)

.PHONY: $(objtree)/Module.symvers
PHONY += $(objtree)/Module.symvers
$(objtree)/Module.symvers:
@test -e $(objtree)/Module.symvers || ( \
echo; \
Expand All @@ -1106,19 +1106,19 @@ $(objtree)/Module.symvers:
echo )

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

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

.PHONY: modules_install
PHONY += modules_install
modules_install: _emodinst_ _emodinst_post

install-dir := $(if $(INSTALL_MOD_DIR),$(INSTALL_MOD_DIR),extra)
.PHONY: _emodinst_
install-dir := $(if $(INSTALL_MOD_DIR),$(INSTALL_MOD_DIR),extra)
PHONY += _emodinst_
_emodinst_:
$(Q)rm -rf $(MODLIB)/$(install-dir)
$(Q)mkdir -p $(MODLIB)/$(install-dir)
Expand All @@ -1133,13 +1133,13 @@ quiet_cmd_depmod = DEPMOD $(KERNELRELEASE)
$(KERNELRELEASE); \
fi

.PHONY: _emodinst_post
PHONY += _emodinst_post
_emodinst_post: _emodinst_
$(call cmd,depmod)

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

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

Expand All @@ -1161,7 +1161,7 @@ help:
@echo ''

# Dummies...
.PHONY: prepare scripts
PHONY += prepare scripts
prepare: ;
scripts: ;
endif # KBUILD_EXTMOD
Expand Down Expand Up @@ -1274,7 +1274,7 @@ namespacecheck:
endif #ifeq ($(config-targets),1)
endif #ifeq ($(mixed-targets),1)

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

endif # skip-makefile

PHONY += FORCE
FORCE:


# Declare the contents of the .PHONY variable as phony. We keep that
# information in a variable se we can use it in if_changed and friends.
.PHONY: $(PHONY)
5 changes: 4 additions & 1 deletion arch/arm/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#
# arch/arm/Makefile
#
# This file is included by the global makefile so that you can add your own
# architecture-specific flags and dependencies.
#
# This file is subject to the terms and conditions of the GNU General Public
# License. See the file "COPYING" in the main directory of this archive
# for more details.
Expand Down Expand Up @@ -176,7 +179,7 @@ endif

archprepare: maketools

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

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

.PHONY: initrd FORCE
PHONY += initrd FORCE
initrd:
@test "$(INITRD_PHYS)" != "" || \
(echo This machine does not support INITRD; exit -1)
Expand Down
5 changes: 4 additions & 1 deletion arch/arm/boot/bootp/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#
# linux/arch/arm/boot/bootp/Makefile
#
# This file is included by the global makefile so that you can add your own
# architecture-specific flags and dependencies.
#

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

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

.PHONY: $(INITRD) FORCE
PHONY += $(INITRD) FORCE
7 changes: 5 additions & 2 deletions arch/arm26/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#
# arch/arm26/Makefile
#
# This file is included by the global makefile so that you can add your own
# architecture-specific flags and dependencies.
#
# This file is subject to the terms and conditions of the GNU General Public
# License. See the file "COPYING" in the main directory of this archive
# for more details.
Expand Down Expand Up @@ -49,9 +52,9 @@ all: zImage

boot := arch/arm26/boot

.PHONY: maketools FORCE
PHONY += maketools FORCE
maketools: FORCE


# Convert bzImage to zImage
bzImage: vmlinux
Expand Down
5 changes: 4 additions & 1 deletion arch/arm26/boot/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#
# arch/arm26/boot/Makefile
#
# This file is included by the global makefile so that you can add your own
# architecture-specific flags and dependencies.
#
# This file is subject to the terms and conditions of the GNU General Public
# License. See the file "COPYING" in the main directory of this archive
# for more details.
Expand Down Expand Up @@ -60,7 +63,7 @@ $(obj)/xipImage: vmlinux FORCE
@echo ' Kernel: $@ is ready'
endif

.PHONY: initrd
PHONY += initrd
initrd:
@test "$(INITRD_PHYS)" != "" || \
(echo This machine does not support INITRD; exit -1)
Expand Down
4 changes: 2 additions & 2 deletions arch/i386/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ AFLAGS += $(mflags-y)

boot := arch/i386/boot

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

all: bzImage

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

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

.PHONY: boot compressed check
PHONY += boot compressed check

all: compressed unwcheck

Expand Down
Loading

0 comments on commit 4f19336

Please sign in to comment.