[klibc] kbuild: make clean
Sam Ravnborg
sam at ravnborg.org
Sun Aug 7 01:30:48 PDT 2005
kbuild: make clean
Just copied over scripts/Makefile.clean and a few
modifications later it worked.
Signed-off-by: Sam Ravnborg <sam at ravnborg.org>
---
commit 50b7344b545588cbc413081ed19c625ffaa6a5ef
tree 02219f03a654b6ee87e6ce07f7474452d3ba79dd
parent 19e2ffa06ebdef2b16d3f69ca400fcfb93b32a61
author Sam Ravnborg <sam at mars.(none)> Sun, 07 Aug 2005 10:29:02 +0200
committer Sam Ravnborg <sam at mars.(none)> Sun, 07 Aug 2005 10:29:02 +0200
Kbuild | 2 +
Makefile | 11 ++----
klcc/Kbuild | 3 ++
klibc/syscalls/Kbuild | 2 +
scripts/Makefile.clean | 96 ++++++++++++++++++++++++++++++++++++++++++++++++
5 files changed, 105 insertions(+), 9 deletions(-)
diff --git a/Kbuild b/Kbuild
--- a/Kbuild
+++ b/Kbuild
@@ -14,4 +14,4 @@ $(obj)/all:
# Directories to visit during clean and install
-subdir- := klibc ash utils gzip usr/kinit
+subdir- := scripts/basic klcc klibc ash utils gzip usr/kinit
diff --git a/Makefile b/Makefile
--- a/Makefile
+++ b/Makefile
@@ -2,8 +2,8 @@ VERSION := $(shell cat version)
SRCROOT = .
# kbuild compatibility
-export srctree := .
-export objtree := .
+export srctree := $(shell pwd)
+export objtree := $(shell pwd)
export KLIBCSRC := klibc
export KLIBCINC := include
export KLIBCOBJ := klibc
@@ -86,11 +86,8 @@ klcc:
klibc:
$(Q)$(MAKE) $(klibc)=.
-local-clean:
- rm -f klibc.config klcc
-
-local-spotless: local-clean
- rm -f klibc.spec *~ tags
+clean:
+ $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.clean obj=.
install: all
$(Q)$(MAKE) -f $(srctree)/scripts/Kbuild.install obj=.
diff --git a/klcc/Kbuild b/klcc/Kbuild
--- a/klcc/Kbuild
+++ b/klcc/Kbuild
@@ -30,3 +30,6 @@ $(obj)/$(KLIBCCROSS)klcc: $(src)/makeklc
$(PERL) $< $(srctree)/$(src)/klcc.in $(obj)/$(KLIBCCROSS)klibc.config \
$(shell bash -c 'type -p $(PERL)') > $@ || ( rm -f $@ ; exit 1 )
chmod a+x $@
+
+# Cleaning targets
+clean-files := $(KLIBCCROSS)klibc.config $(KLIBCCROSS)klcc
diff --git a/klibc/syscalls/Kbuild b/klibc/syscalls/Kbuild
--- a/klibc/syscalls/Kbuild
+++ b/klibc/syscalls/Kbuild
@@ -22,7 +22,7 @@ targets += SYSCALLS.i syscalls.nrs
targets += $(syscall-objs)
# Side effect of running syscalls.pl
-clean-files += $(KLIBCINC)/klibc/havesyscall.h
+clean-files += $(objtree)/$(KLIBCINC)/klibc/havesyscall.h
# All the syscall stubs
clean-files += *.o *.S *.c
diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean
new file mode 100644
--- /dev/null
+++ b/scripts/Makefile.clean
@@ -0,0 +1,96 @@
+# ==========================================================================
+# Cleaning up
+# ==========================================================================
+
+src := $(obj)
+
+.PHONY: __clean
+__clean:
+
+# Shorthand for $(Q)$(MAKE) scripts/Makefile.clean obj=dir
+# Usage:
+# $(Q)$(MAKE) $(clean)=dir
+clean := -f $(if $(KBUILD_SRC),$(srctree)/)scripts/Makefile.clean obj
+
+# The filename Kbuild has precedence over Makefile
+kbuild-dir := $(if $(filter /%,$(src)),$(src),$(srctree)/$(src))
+include $(if $(wildcard $(kbuild-dir)/Kbuild), $(kbuild-dir)/Kbuild, $(kbuild-dir)/Makefile)
+
+# Figure out what we need to build from the various variables
+# ==========================================================================
+
+__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-)
+
+# Subdirectories we need to descend into
+
+subdir-ym := $(sort $(subdir-y) $(subdir-m))
+subdir-ymn := $(sort $(subdir-ym) $(subdir-n) $(subdir-))
+
+# Add subdir path
+
+subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
+
+# build a list of files to remove, usually releative to the current
+# directory
+
+__clean-files := $(extra-y) $(EXTRA_TARGETS) $(always) \
+ $(targets) $(clean-files) \
+ $(host-progs) \
+ $(hostprogs-y) $(hostprogs-m) $(hostprogs-)
+
+# as clean-files is given relative to the current directory, this adds
+# a $(obj) prefix, except for absolute paths
+
+__clean-files := $(wildcard \
+ $(addprefix $(obj)/, $(filter-out /%, $(__clean-files))) \
+ $(filter /%, $(__clean-files)))
+
+# as clean-dirs is given relative to the current directory, this adds
+# a $(obj) prefix, except for absolute paths
+
+__clean-dirs := $(wildcard \
+ $(addprefix $(obj)/, $(filter-out /%, $(clean-dirs))) \
+ $(filter /%, $(clean-dirs)))
+
+# ==========================================================================
+
+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)),)
+ +$(call cmd,clean)
+endif
+ifneq ($(strip $(__clean-dirs)),)
+ +$(call cmd,cleandir)
+endif
+ifneq ($(strip $(clean-rule)),)
+ +$(clean-rule)
+endif
+ @:
+
+
+# ===========================================================================
+# Generic stuff
+# ===========================================================================
+
+# Descending
+# ---------------------------------------------------------------------------
+
+.PHONY: $(subdir-ymn)
+$(subdir-ymn):
+ $(Q)$(MAKE) $(clean)=$@
+
+# If quiet is set, only print short version of command
+
+cmd = @$(if $($(quiet)cmd_$(1)),echo ' $($(quiet)cmd_$(1))' &&) $(cmd_$(1))
More information about the klibc
mailing list