Skip to contentSkip to conversation

Add find utility functions / exclude files from strip

PATCH Superseded Thomas De Schampheleire 1 participant 4 messages May 8, 2012 – May 15, 2012 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH v5 1/1 Add find utility functions / exclude files from strip

This patch series adds a few utility functions to pkg-utils.mk that help in composing find commands, and uses these functions to exclude user-configured files and directories from being stripped in target-finalize.

Thanks to input from Arnout, the find functions are now much simpler and should be clearly understandable by everyone.

---
v5: line up with latest git
v4: simplify find functions even further; whitespace changes
v3: update based on review comments, remove Python changes for now
v2: simplify find functions

 Config.in            |  19 +++++++++++++++++++
 Makefile             |  10 ++++++++--
 package/pkg-utils.mk |   9 +++++++++
 3 files changed, 36 insertions(+), 2 deletions(-)
#1 lore raw

PATCH v5 1/1 pkg-utils.mk: add utility functions find*clauses and notfirstword

This patch adds a few utility functions to pkg-utils.mk.

Functions finddirclauses and findfileclauses help in building a find command that skips a set of directories and performs operations on a set of files. This pattern can for example be used to keep certain files or directories from being stripped, or to remove certain files from a package installation.

The notfirstword function is the inverse of the 'firstword' function in make:
it returns all but the first word.

---
v5: Take split of Makefile.package.in into account.
v4: simplify find*clauses even further. Thanks, Arnout!
v3: use -path instead of -wholename; fix a bug in finddirclauses. Thanks, Cam.
v2: integrate _cont variants in main find*clauses functions. Thanks, Arnout.

 package/pkg-utils.mk |  9 +++++++++
 1 files changed, 9 insertions(+), 0 deletions(-)
package/pkg-utils.mk +9 -0
@@ -76,6 +76,15 @@ MESSAGE = echo "$(TERM_BOLD)>>> $($(PKG)
 TERM_BOLD := $(shell tput smso)
 TERM_RESET := $(shell tput rmso)
 
+# Utility functions for 'find'
+# findfileclauses(filelist) => -name 'X' -o -name 'Y'
+findfileclauses = $(call notfirstword,$(patsubst %,-o -name '%',$(1)))
+# finddirclauses(base, dirlist) => -path 'base/dirX' -o -path 'base/dirY'
+finddirclauses = $(call notfirstword,$(patsubst %,-o -path '$(1)/%',$(2)))
+
+# Miscellaneous utility functions
+# notfirstword(wordlist): returns all but the first word in wordlist
+notfirstword = $(wordlist 2,$(words $(1)),$(1))
 
 # Needed for the foreach loops to loop over the list of hooks, so that
 # each hook call is properly separated by a newline.
#2 lore raw

PATCH v5 1/1 build: add option to exclude executables/dirs from being stripped

In reply to Thomas De Schampheleire

Sometimes it may be desirable to keep debug symbols for some binaries and libraries on the target. This commit introduces the config option BR2_STRIP_EXCLUDE_FILES, which is interpreted as a list of such binaries and libraries, and the option BR2_STRIP_EXCLUDE_DIRS, which indicates directories excluded from stripping entirely.
These exclusions are passed to the find command in the target-finalize step.

---
v5: line up with latest git
v4: whitespace changes
v3: merge with redundant patch 'stripping: use findfileclauses utility function'
v2: add the possibility to exclude entire directories

 Config.in |  19 +++++++++++++++++++
 Makefile  |  10 ++++++++--
 2 files changed, 27 insertions(+), 2 deletions(-)
Config.in +19 -0
@@ -276,6 +276,25 @@ config BR2_STRIP_none
 	  filesystem.
 endchoice
 
+config BR2_STRIP_EXCLUDE_FILES
+	string "executables that should not be stripped"
+	depends on !BR2_STRIP_none
+	default ""
+	help
+	  You may specify a space-separated list of binaries and libraries
+	  here that should not be stripped on the target.
+
+config BR2_STRIP_EXCLUDE_DIRS
+	string "directories that should be skipped when stripping"
+	depends on !BR2_STRIP_none
+	default ""
+	help
+	  You may specify a space-separated list of directories that should
+	  be skipped when stripping. Binaries and libraries in these
+	  directories will not be touched.
+	  The directories should be specified relative to the target directory,
+	  without leading slash.
+
 choice
 	prompt "gcc optimization level"
 	default BR2_OPTIMIZE_S
Makefile +8 -2
@@ -376,6 +376,13 @@ endif
 
 $(TARGET_DIR): $(BUILD_DIR)/.root
 
+STRIP_FIND_CMD = find $(TARGET_DIR)
+ifneq (,$(call qstrip,$(BR2_STRIP_EXCLUDE_DIRS)))
+STRIP_FIND_CMD += \( $(call finddirclauses,$(TARGET_DIR),$(call qstrip,$(BR2_STRIP_EXCLUDE_DIRS))) \) -prune -o
+endif
+STRIP_FIND_CMD += -type f -perm +111
+STRIP_FIND_CMD += -not \( $(call findfileclauses,libthread_db*.so* $(call qstrip,$(BR2_STRIP_EXCLUDE_FILES))) \) -print
+
 target-finalize:
 ifeq ($(BR2_HAVE_DEVFILES),y)
 	( support/scripts/copy.sh $(STAGING_DIR) $(TARGET_DIR) )
@@ -400,8 +407,7 @@ endif
 ifeq ($(BR2_PACKAGE_PYTHON_PYC_ONLY),y)
 	find $(TARGET_DIR)/usr/lib/ -name '*.py' -print0 | xargs -0 rm -f
 endif
-	find $(TARGET_DIR) -type f -perm +111 '!' -name 'libthread_db*.so*' | \
-		xargs $(STRIPCMD) 2>/dev/null || true
+	$(STRIP_FIND_CMD) | xargs $(STRIPCMD) 2>/dev/null || true
 	find $(TARGET_DIR)/lib/modules -type f -name '*.ko' | \
 		xargs -r $(KSTRIPCMD) || true
 
#3 lore raw

PATCH v5 1/1 Add find utility functions / exclude files from strip

In reply to Thomas De Schampheleire

Hi,

Quoted 15 lines · Thomas De Schampheleire

This patch series adds a few utility functions to pkg-utils.mk that help in composing find commands, and uses these functions to exclude user-configured files and directories from being stripped in target-finalize.

Thanks to input from Arnout, the find functions are now much simpler and should be clearly understandable by everyone.

---
v5: line up with latest git
v4: simplify find functions even further; whitespace changes
v3: update based on review comments, remove Python changes for now
v2: simplify find functions

Quoted 6 lines
?Config.in ? ? ? ? ? ?| ?19 +++++++++++++++++++
?Makefile ? ? ? ? ? ? | ?10 ++++++++--
?package/pkg-utils.mk | ? 9 +++++++++

?3 files changed, 36 insertions(+), 2 deletions(-)

Are there any further comments on this patch series? If not, can we apply it to master or next?

Thanks,
Thomas