Skip to content

Commit

Permalink
kbuild: Accept absolute paths in clean-files and introduce clean-dirs
Browse files Browse the repository at this point in the history
Teach kbuild to accept absolute paths in clean-files. This avoids using
clean-rules in several places.
Introduced clean-dirs to delete complete directories.
Kept clean-rule - but do not print anything when used.
Cleaned up a few places now the infrastructure are improved.

Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
  • Loading branch information
Sam Ravnborg committed Aug 9, 2004
1 parent cb4f38e commit 94869f8
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 16 deletions.
4 changes: 1 addition & 3 deletions Documentation/DocBook/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,7 @@ clean-files := $(DOCBOOKS) \
$(patsubst %.sgml, %.9, $(DOCBOOKS)) \
$(C-procfs-example)

ifneq ($(wildcard $(patsubst %.html,%,$(HTML))),)
clean-rule := rm -rf $(wildcard $(patsubst %.html,%,$(HTML)))
endif
clean-dirs := $(patsubst %.sgml,%,$(DOCBOOKS))

#man put files in man subdir - traverse down
subdir- := man/
13 changes: 11 additions & 2 deletions Documentation/kbuild/makefiles.txt
Original file line number Diff line number Diff line change
Expand Up @@ -547,8 +547,17 @@ Additional files can be specified in kbuild makefiles by use of $(clean-files).
clean-files := devlist.h classlist.h

When executing "make clean", the two files "devlist.h classlist.h" will
be deleted. Kbuild knows that files specified by $(clean-files) are
located in the same directory as the makefile.
be deleted. Kbuild will assume files to be in same relative directory as the
Makefile except if an absolute path is specified (path starting with '/').

To delete a directory hirachy use:
Example:
#scripts/package/Makefile
clean-dirs := $(objtree)/debian/

This will delete the directory debian, including all subdirectories.
Kbuild will assume the directories to be in the same relative path as the
Makefile if no absolute path is specified (path does not start with '/').

Usually kbuild descends down in subdirectories due to "obj-* := dir/",
but in the architecture makefiles where the kbuild infrastructure
Expand Down
30 changes: 22 additions & 8 deletions scripts/Makefile.clean
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,35 @@ subdir-ymn := $(sort $(subdir-ym) $(subdir-n) $(subdir-))
# Add subdir path

subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
__clean-files := $(wildcard $(addprefix $(obj)/, \
$(extra-y) $(EXTRA_TARGETS) $(always) $(host-progs) \
$(targets) $(clean-files)))
__clean-files := $(extra-y) $(EXTRA_TARGETS) $(always) $(host-progs) \
$(targets) $(clean-files)
__clean-files := $(wildcard \
$(addprefix $(obj)/, $(filter-out /%, $(__clean-files))) \
$(filter /%, $(__clean-files)))
__clean-dirs := $(wildcard \
$(addprefix $(obj)/, $(filter-out /%, $(clean-dirs))) \
$(filter /%, $(clean-dirs)))

# ==========================================================================

quiet_cmd_clean = CLEAN $(obj)
cmd_clean = rm -f $(__clean-files); $(clean-rule)
quiet_cmd_clean = CLEAN $(obj)
cmd_clean = rm -f $(__clean-files)
quiet_cmd_cleandir = CLEAN $(__clean-dirs)
cmd_cleandir = rm -rf $(__clean-dirs)


__clean: $(subdir-ymn)
ifneq ($(strip $(__clean-files) $(clean-rule)),)
ifneq ($(strip $(__clean-files)),)
+$(call cmd,clean)
else
@:
endif
ifneq ($(strip $(__clean-dirs)),)
+$(call cmd,cleandir)
endif
ifneq ($(strip $(clean-rule)),)
+$(clean-rule)
endif
@:


# ===========================================================================
# Generic stuff
Expand Down
6 changes: 3 additions & 3 deletions scripts/package/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ rpm-pkg rpm: $(objtree)/kernel.spec
$(RPM) --target $(UTS_MACHINE) -ta ../$(KERNELPATH).tar.gz
rm ../$(KERNELPATH).tar.gz

clean-rule += rm -f $(objtree)/kernel.spec
clean-files := $(objtree)/kernel.spec

# binrpm-pkg
.PHONY: binrpm-pkg
Expand All @@ -67,7 +67,7 @@ binrpm-pkg: $(objtree)/binkernel.spec

$(RPM) --define "_builddir $(srctree)" --target $(UTS_MACHINE) -bb $<

clean-rule += rm -f $(objtree)/binkernel.spec
clean-files += $(objtree)/binkernel.spec

# Deb target
# ---------------------------------------------------------------------------
Expand All @@ -77,7 +77,7 @@ deb-pkg:
$(MAKE)
$(CONFIG_SHELL) $(srctree)/scripts/package/builddeb

clean-rule += && rm -rf $(objtree)/debian/
clean-dirs += $(objtree)/debian/


# Help text displayed when executing 'make help'
Expand Down

0 comments on commit 94869f8

Please sign in to comment.