[Buildroot] [RFC] [PATCH] Add targetclean Makefile target

Martin Hicks mort at bork.org
Thu Mar 17 19:11:21 UTC 2011


Hi,

I have scripts that hack around with the root filesystem prior to
image creation, so I wanted a way to remove $(TARGET_DIR) and
reinstall it without doing a wholesale 'make clean; make'.  This is
what I came up with.  It only works with external toolchain.

Comments?  This seems fragile, but it also doesn't require that
every package have an uninstall target, and additionally handles the
case where pre-image-generation scripts mangle contents of $TARGET_DIR

mh



>From b660dba844ddbdcafdfb5eff443a206563f98d7a Mon Sep 17 00:00:00 2001
From: Martin Hicks <mort at bork.org>
Date: Thu, 17 Mar 2011 15:05:12 -0400
Subject: [PATCH] Add 'targetclean' option to remove $(TARGET_DIR)

This removes $(TARGET_DIR), but also removes stamp files so that the
next invocation of 'make' properly reinstalls $(TARGET_DIR) from scratch.

Signed-off-by: Martin Hicks <mort at bork.org>
---
 Makefile                                 |   10 ++++++++++
 toolchain/toolchain-external/ext-tool.mk |   28 +++++++++++++++++++++-------
 2 files changed, 31 insertions(+), 7 deletions(-)

diff --git a/Makefile b/Makefile
index 7ae3787..1b1acbf 100644
--- a/Makefile
+++ b/Makefile
@@ -637,6 +637,15 @@ ifeq ($(O),output)
 endif
 	rm -rf $(CONFIG_DIR)/.config $(CONFIG_DIR)/.config.old $(CONFIG_DIR)/.auto.deps
 
+targetclean: erase-fakeroots
+	-rm -rf $(TARGET_DIR) $(BUILD_DIR)/.root
+	-find output/build -maxdepth 2 -name .stamp_target_installed -exec rm -f {} \;
+	-rm -f output/stamps/*-toolchain-target-installed
+	-rm -f output/build/.customize
+ifeq ($(strip $(BR2_LINUX_KERNEL_CUSTOM_DIRECTORY)),y)
+	-rm -f $(LINUX26_DIR)/.stamp_installed
+endif
+
 configured: dirs kernel-headers uclibc-config busybox-config linux26-config
 
 prepatch:	gcc-patched gdb-patched uclibc-patched
@@ -647,6 +656,7 @@ help:
 	@echo 'Cleaning:'
 	@echo '  clean                  - delete all files created by build'
 	@echo '  distclean              - delete all non-source files (including .config)'
+	@echo '  targetclean            - delete all files from target and target install stamps'
 	@echo
 	@echo 'Build:'
 	@echo '  all                    - make world'
diff --git a/toolchain/toolchain-external/ext-tool.mk b/toolchain/toolchain-external/ext-tool.mk
index f6249ef..e13226f 100644
--- a/toolchain/toolchain-external/ext-tool.mk
+++ b/toolchain/toolchain-external/ext-tool.mk
@@ -42,7 +42,7 @@
 #  cross-compiler binaries remains external, all libraries and headers
 #  are imported into the Buildroot tree.
 
-uclibc: dependencies $(STAMP_DIR)/ext-toolchain-installed
+uclibc: dependencies $(STAMP_DIR)/ext-toolchain-target-installed $(STAMP_DIR)/ext-toolchain-staging-installed
 
 LIB_EXTERNAL_LIBS=ld*.so libc.so libcrypt.so libdl.so libgcc_s.so libm.so libnsl.so libresolv.so librt.so libutil.so
 ifeq ($(BR2_TOOLCHAIN_EXTERNAL_GLIBC),y)
@@ -171,7 +171,25 @@ $(STAMP_DIR)/ext-toolchain-checked:
 # and the variant-specific sysroot, then copy the needed libraries to
 # the $(TARGET_DIR) and copy the whole sysroot (libraries and headers)
 # to $(STAGING_DIR).
-$(STAMP_DIR)/ext-toolchain-installed: $(TOOLCHAIN_EXTERNAL_DEPENDENCIES)
+$(STAMP_DIR)/ext-toolchain-staging-installed: $(TOOLCHAIN_EXTERNAL_DEPENDENCIES)
+	$(Q)SYSROOT_DIR=`$(TARGET_CC_NO_SYSROOT) -print-sysroot 2>/dev/null` ; \
+	if test -z "$${SYSROOT_DIR}" ; then \
+		SYSROOT_DIR=`readlink -f $$(LANG=C $(TARGET_CC_NO_SYSROOT) -print-file-name=libc.a) |sed -r -e 's:usr/lib/libc\.a::;'` ; \
+	fi ; \
+	if test -z "$${SYSROOT_DIR}" ; then \
+		@echo "External toolchain doesn't support --sysroot. Cannot use." ; \
+		exit 1 ; \
+	fi ; \
+	ARCH_SUBDIR=`$(TARGET_CC_NO_SYSROOT) $(TARGET_CFLAGS) -print-multi-directory` ; \
+	ARCH_SYSROOT_DIR=$${SYSROOT_DIR}/$${ARCH_SUBDIR} ; \
+	echo "Copy external toolchain sysroot to staging..." ; \
+	$(call copy_toolchain_sysroot,$${SYSROOT_DIR},$${ARCH_SYSROOT_DIR},$${ARCH_SUBDIR}) ; \
+	if [ -L $${ARCH_SYSROOT_DIR}/lib64 ] ; then \
+		$(call create_lib64_symlinks) ; \
+	fi ; \
+	touch $@
+
+$(STAMP_DIR)/ext-toolchain-target-installed: $(STAMP_DIR)/ext-toolchain-staging-installed
 	$(Q)SYSROOT_DIR=`$(TARGET_CC_NO_SYSROOT) -print-sysroot 2>/dev/null` ; \
 	if test -z "$${SYSROOT_DIR}" ; then \
 		SYSROOT_DIR=`readlink -f $$(LANG=C $(TARGET_CC_NO_SYSROOT) -print-file-name=libc.a) |sed -r -e 's:usr/lib/libc\.a::;'` ; \
@@ -190,9 +208,5 @@ $(STAMP_DIR)/ext-toolchain-installed: $(TOOLCHAIN_EXTERNAL_DEPENDENCIES)
 	for libs in $(USR_LIB_EXTERNAL_LIBS); do \
 		$(call copy_toolchain_lib_root,$${ARCH_SYSROOT_DIR},$$libs,/usr/lib); \
 	done ; \
-	echo "Copy external toolchain sysroot to staging..." ; \
-	$(call copy_toolchain_sysroot,$${SYSROOT_DIR},$${ARCH_SYSROOT_DIR},$${ARCH_SUBDIR}) ; \
-	if [ -L $${ARCH_SYSROOT_DIR}/lib64 ] ; then \
-		$(call create_lib64_symlinks) ; \
-	fi ; \
 	touch $@
+
-- 
1.5.6.5



More information about the buildroot mailing list