From bf2737d1cbcf0e85857e759efaa261ed3fa449cf Mon Sep 17 00:00:00 2001 From: Sam Ravnborg Date: Fri, 11 Oct 2002 00:24:45 +0200 Subject: kbuild: Distributed clean infrastructure Today there is a huge list of files in the top-level Makefile that is deleted during make clean and make mrproper. This patch add infrastructure to get rid of this centralised list. Within a makefile simply use: clean-files := files-to-be-deleted or eventually clean-rule := command to be executed to delete files Files specified by host-progs and EXTRA_TARGETS are deleted during cleaning, and the same is all *.[oas] .*.cmd .*.tmp .*.d in the visited directories. Deleting core files is moved down to mrporper time Patches utilising this and the centralised list will dismiss. Based on a concept originally made by Kai Germaschewski --- Rules.make | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) (limited to 'Rules.make') diff --git a/Rules.make b/Rules.make index 1b06db4c2b91..bd4ebc76a49b 100644 --- a/Rules.make +++ b/Rules.make @@ -87,6 +87,7 @@ obj-m := $(filter-out %/, $(obj-m)) # Subdirectories we need to descend into subdir-ym := $(sort $(subdir-y) $(subdir-m)) +subdir-ymn := $(sort $(subdir-ym) $(subdir-n) $(subdir-)) # export.o is never a composite object, since $(export-objs) has a # fixed meaning (== objects which EXPORT_SYMBOL()) @@ -113,6 +114,10 @@ real-objs-m := $(foreach m, $(obj-m), $(if $($(m:.o=-objs)),$($(m:.o=-objs)),$(m # Only build module versions for files which are selected to be built export-objs := $(filter $(export-objs),$(real-objs-y) $(real-objs-m)) +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)) + # Add subdir path EXTRA_TARGETS := $(addprefix $(obj)/,$(EXTRA_TARGETS)) @@ -127,12 +132,19 @@ multi-used-m := $(addprefix $(obj)/,$(multi-used-m)) multi-objs-y := $(addprefix $(obj)/,$(multi-objs-y)) multi-objs-m := $(addprefix $(obj)/,$(multi-objs-m)) subdir-ym := $(addprefix $(obj)/,$(subdir-ym)) +subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn)) +clean-files := $(addprefix $(obj)/,$(clean-files)) +host-progs := $(addprefix $(obj)/,$(host-progs)) +host-progs-single := $(addprefix $(obj)/,$(host-progs-single)) +host-progs-multi := $(addprefix $(obj)/,$(host-progs-multi)) +host-progs-multi-objs := $(addprefix $(obj)/,$(host-progs-multi-objs)) # The temporary file to save gcc -MD generated dependencies must not # contain a comma depfile = $(subst $(comma),_,$(@D)/.$(@F).d) -# We're called for one of three purposes: +# We're called for one of four purposes: +# o subdirclean: Delete intermidiate files in the current directory # o fastdep: build module version files (.ver) for $(export-objs) in # the current directory # o modules_install: install the modules in the current directory @@ -142,6 +154,13 @@ depfile = $(subst $(comma),_,$(@D)/.$(@F).d) # 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),subdirclean) +subdirclean: $(subdir-ymn) + @/bin/true + @rm -f $(EXTRA_TARGETS) $(host-progs) $(clean-files) \ + $(addprefix $(obj)/,*.[oas] .*.cmd .*.tmp .*.d) + @$(clean-rule) +else ifeq ($(MAKECMDGOALS),fastdep) # =========================================================================== @@ -399,14 +418,6 @@ targets += $(multi-used-y) $(multi-used-m) # 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)) -host-progs := $(addprefix $(obj)/,$(host-progs)) -host-progs-single := $(addprefix $(obj)/,$(host-progs-single)) -host-progs-multi := $(addprefix $(obj)/,$(host-progs-multi)) -host-progs-multi-objs := $(addprefix $(obj)/,$(host-progs-multi-objs)) - quiet_cmd_host_cc__c = HOSTCC $(echo_target) cmd_host_cc__c = $(HOSTCC) -Wp,-MD,$(depfile) \ $(HOSTCFLAGS) $(HOST_EXTRACFLAGS) \ @@ -431,6 +442,7 @@ $(host-progs-multi): %: $(host-progs-multi-objs) FORCE targets += $(host-progs-single) $(host-progs-multi-objs) $(host-progs-multi) +endif # ! subdirclean endif # ! modules_install endif # ! fastdep @@ -480,9 +492,9 @@ cmd_gzip = gzip -f -9 < $< > $@ # Descending # --------------------------------------------------------------------------- -.PHONY: $(subdir-ym) +.PHONY: $(subdir-ymn) -$(subdir-ym): +$(subdir-ymn): +@$(call descend,$@,$(MAKECMDGOALS)) # Add FORCE to the prequisites of a target to force it to be always rebuilt. -- cgit v1.2.3 From c3ef0e8389e22306f6ce56a2b7c234da7d7bafaf Mon Sep 17 00:00:00 2001 From: Kai Germaschewski Date: Sun, 13 Oct 2002 07:56:24 -0500 Subject: kbuild: More cleaning work... o Having .config depend on all Config.in's via a find is annoying, since it causes a long break before "make" actually gets going. Comment it out for now. o Fix some "make -j" issues with generating module versions. o Unify "make distclean" and "make mrproper", they were doing nearly the same thing anyway. o Use the new "make clean" infrastructure for arch/i386/boot/ and scripts/ o Reorganize the "make clean" stuff a little, do the find -name '*.[oas]' | xargs rm -f from the top-level Makefile again and only use the per-subdir rule for special cases like generated files, host-progs and the like. --- Makefile | 45 ++++++++++++++++++-------------------- Rules.make | 14 ++++++++---- arch/i386/Makefile | 2 +- arch/i386/boot/Makefile | 7 ++---- arch/i386/boot/compressed/Makefile | 4 ---- scripts/Makefile | 9 ++++---- scripts/lxdialog/Makefile | 3 --- 7 files changed, 38 insertions(+), 46 deletions(-) (limited to 'Rules.make') diff --git a/Makefile b/Makefile index 2ee1e894092f..78de51a75a75 100644 --- a/Makefile +++ b/Makefile @@ -239,7 +239,7 @@ ifdef include-config # If .config doesn't exist - tough luck -.config: arch/$(ARCH)/config.in $(shell find . -name Config.in) +.config: arch/$(ARCH)/config.in # FIXME $(shell find . -name Config.in) @echo '***' @if [ -f $@ ]; then \ echo '*** The tree was updated, so your .config may be'; \ @@ -456,18 +456,23 @@ include/linux/version.h: Makefile depend dep: .hdepend -# .hdepend is our (misnomed) marker for whether we've run +# .hdepend is our (misnomed) marker for whether we've # generated module versions -.hdepend: $(if $(filter dep depend,$(MAKECMDGOALS)),FORCE) +make-versions := $(strip $(if $(filter dep depend,$(MAKECMDGOALS)),1) \ + $(if $(wildcard .hdepend),,1)) + +.hdepend: prepare FORCE +ifneq ($(make-versions),) @$(MAKE) include/linux/modversions.h @touch $@ +endif ifdef CONFIG_MODVERSIONS # Update modversions.h, but only if it would change. -include/linux/modversions.h: scripts/fixdep prepare FORCE +include/linux/modversions.h: FORCE @rm -rf .tmp_export-objs @$(MAKE) $(patsubst %,_sfdep_%,$(SUBDIRS)) @echo -n ' Generating $@' @@ -688,42 +693,34 @@ MRPROPER_DIRS += \ include/config \ include/linux/modules -# clean - Delete all intermidiate files +# clean - Delete all intermediate files # -clean-dirs += $(ALL_SUBDIRS) Documentation/DocBook -cleanprint: - @echo ' Cleaning the srctree' +clean-dirs += $(ALL_SUBDIRS) Documentation/DocBook scripts -$(addprefix _clean_,$(clean-dirs)): cleanprint +$(addprefix _clean_,$(clean-dirs)): +@$(call descend,$(patsubst _clean_%,%,$@), subdirclean) quiet_cmd_rmclean = RM $$(CLEAN_FILES) cmd_rmclean = rm -f $(CLEAN_FILES) clean: archclean $(addprefix _clean_,$(clean-dirs)) $(call cmd,rmclean) + @find . $(RCS_FIND_IGNORE) \ + \( -name '*.[oas]' -o -name '.*.cmd' -o -name '.*.d' \ + -o -name '.*.tmp' \) -type f -print | xargs rm -f # mrproper - delete configuration + modules + core files # quiet_cmd_mrproper = RM $$(MRPROPER_DIRS) + $$(MRPROPER_FILES) cmd_mrproper = rm -rf $(MRPROPER_DIRS) && rm -f $(MRPROPER_FILES) -mrproper: clean archmrproper - @echo ' Making mrproper in the srctree' - @find . $(RCS_FIND_IGNORE) \ - \( -name .depend -o -name .\*.cmd -o -name core \) \ - -type f -print | xargs rm -f - $(call cmd,mrproper) - +@$(call descend,scripts,mrproper) - -# distclean - remove all temporaries left behind by patch, vi, emacs etc. -# -distclean: mrproper - @echo ' Making distclean in the srctree' +mrproper distclean: clean archmrproper + @echo ' Making $@ in the srctree' @find . $(RCS_FIND_IGNORE) \ - \( -not -type d \) -and \ \( -name '*.orig' -o -name '*.rej' -o -name '*~' \ -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \ - -o -name '.*.rej' -o -name '.SUMS' -o -size 0 \) -type f \ - -print | xargs rm -f + -o -name '.*.rej' -o -size 0 \ + -o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \ + -type f -print | xargs rm -f + $(call cmd,mrproper) # Generate tags for editors # --------------------------------------------------------------------------- diff --git a/Rules.make b/Rules.make index 6ed53f769e0d..56e62f97f333 100644 --- a/Rules.make +++ b/Rules.make @@ -155,11 +155,17 @@ depfile = $(subst $(comma),_,$(@D)/.$(@F).d) # targets (That happens when someone does make some/dir/foo.[ois]) ifeq ($(MAKECMDGOALS),subdirclean) + +__clean-files := $(wildcard $(EXTRA_TARGETS) $(host-progs) $(clean-files)) + subdirclean: $(subdir-ymn) +ifneq ($(strip $(__clean-files) $(clean-rule)),) + rm -f $(__clean-files) + $(clean-rule) +else @/bin/true - @rm -f $(EXTRA_TARGETS) $(host-progs) $(clean-files) \ - $(addprefix $(obj)/,*.[oas] .*.cmd .*.tmp .*.d) - @$(clean-rule) +endif + else ifeq ($(MAKECMDGOALS),fastdep) @@ -180,7 +186,7 @@ else # This sets version suffixes on exported symbols # --------------------------------------------------------------------------- -MODVERDIR := include/linux/modules/ +MODVERDIR := include/linux/modules # # Added the SMP separator to stop module accidents between uniprocessor diff --git a/arch/i386/Makefile b/arch/i386/Makefile index 9d822af70fcb..7d5862c05d40 100644 --- a/arch/i386/Makefile +++ b/arch/i386/Makefile @@ -86,6 +86,6 @@ install: vmlinux +@$(call makeboot,BOOTIMAGE=$(BOOTIMAGE) install) archclean: - +@$(call makeboot,clean) + +@$(call makeboot,subdirclean) archmrproper: diff --git a/arch/i386/boot/Makefile b/arch/i386/boot/Makefile index 3369bfc67700..b06bab8ccd43 100644 --- a/arch/i386/boot/Makefile +++ b/arch/i386/boot/Makefile @@ -28,6 +28,8 @@ SVGA_MODE := -DSVGA_MODE=NORMAL_VGA EXTRA_TARGETS := vmlinux.bin bootsect bootsect.o \ setup setup.o zImage bzImage +subdir- := compressed + host-progs := tools/build # Default @@ -79,11 +81,6 @@ zlilo: $(BOOTIMAGE) install: $(BOOTIMAGE) sh $(src)/install.sh $(KERNELRELEASE) $(BOOTIMAGE) System.map "$(INSTALL_PATH)" -clean: - @echo 'Cleaning up (boot)' - @rm -f $(host-progs) $(EXTRA_TARGETS) - +@$(call descend,$(obj)/compressed) clean - archhelp: @echo '* bzImage - Compressed kernel image (arch/$(ARCH)/boot/bzImage)' @echo ' install - Install kernel using' diff --git a/arch/i386/boot/compressed/Makefile b/arch/i386/boot/compressed/Makefile index 53af39a4408e..16383b2df2fb 100644 --- a/arch/i386/boot/compressed/Makefile +++ b/arch/i386/boot/compressed/Makefile @@ -24,7 +24,3 @@ LDFLAGS_piggy.o := -r --format binary --oformat elf32-i386 -T $(obj)/piggy.o: $(obj)/vmlinux.scr $(obj)/vmlinux.bin.gz FORCE $(call if_changed,ld) - -clean: - @echo 'Cleaning up (boot/compressed)' - @rm -f $(EXTRA_TARGETS) diff --git a/scripts/Makefile b/scripts/Makefile index 0921e79c6c79..6032efe0f0aa 100644 --- a/scripts/Makefile +++ b/scripts/Makefile @@ -11,6 +11,8 @@ EXTRA_TARGETS := fixdep split-include docproc conmakehash +subdir- := lxdialog + # Yikes. We need to build this stuff here even if the user only wants # modules. @@ -24,6 +26,8 @@ KBUILD_BUILTIN := 1 host-progs := fixdep split-include conmakehash docproc tkparse tkparse-objs := tkparse.o tkcond.o tkgen.o +clean-files := kconfig.tk + include $(TOPDIR)/Rules.make # In reality kconfig.tk should depend on all Config.in files, @@ -56,8 +60,3 @@ lxdialog: # fixdep is needed to compile other host programs $(obj)/split-include $(obj)/docproc $(addprefix $(obj)/,$(tkparse-objs)) \ $(obj)/conmakehash lxdialog: $(obj)/fixdep - -mrproper: - @rm -f $(host-progs) $(addprefix $(obj)/,$(tkparse-objs) kconfig.tk core) - @$(call descend,scripts/lxdialog,mrproper) - diff --git a/scripts/lxdialog/Makefile b/scripts/lxdialog/Makefile index da5e5a1ab32d..252c5bf86cd1 100644 --- a/scripts/lxdialog/Makefile +++ b/scripts/lxdialog/Makefile @@ -42,6 +42,3 @@ ncurses: echo ;\ exit 1 ;\ fi - -mrproper: - @rm -f $(host-progs) $(addprefix $(obj)/,$(lxdialog-objs)) -- cgit v1.2.3