From defe614845cb85b0490ffb2ac5041a3d68615b3b Mon Sep 17 00:00:00 2001 From: Michael Forney Date: Mon, 27 May 2019 11:57:28 +0200 Subject: kbuild: Use ls(1) instead of stat(1) to obtain file size stat(1) is not standardized and different implementations have their own (conflicting) flags for querying the size of a file. ls(1) provides the same information (value of st.st_size) in the 5th column, except when the file is a character or block device. This output is standardized[0]. The -n option turns on -l, which writes lines formatted like "%s %u %s %s %u %s %s\n", , , , , , , but instead of writing the and , it writes the numeric owner and group IDs (this avoids /etc/passwd and /etc/group lookups as well as potential field splitting issues). The field is specified as "the value that would be returned for the file in the st_size field of struct stat". To avoid duplicating logic in several locations in the tree, create scripts/file-size.sh and update callers to use that instead of stat(1). [0] http://pubs.opengroup.org/onlinepubs/9699919799/utilities/ls.html#tag_20_73_10 Signed-off-by: Michael Forney Signed-off-by: Masahiro Yamada [afa: imported script and adjusted barebox stat(1) callsites] Signed-off-by: Ahmad Fatoum Signed-off-by: Sascha Hauer --- defaultenv/Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'defaultenv') diff --git a/defaultenv/Makefile b/defaultenv/Makefile index 950ac29a3c..e030355a40 100644 --- a/defaultenv/Makefile +++ b/defaultenv/Makefile @@ -20,7 +20,8 @@ $(obj)/barebox_default_env: FORCE quiet_cmd_env_h = ENVH $@ cmd_env_h = cat $< | (cd $(obj) && $(objtree)/scripts/bin2c "__aligned(4) default_environment") > $@; \ - echo "static const int default_environment_uncompress_size=`stat -c%s $(obj)/barebox_default_env`;" >> $@ + echo "static const int default_environment_uncompress_size=`${CONFIG_SHELL} \"${srctree}/scripts/file-size.sh\" $(obj)/barebox_default_env`;" >> $@ + $(obj)/barebox_default_env.h: $(obj)/barebox_default_env$(DEFAULT_COMPRESSION_SUFFIX) FORCE $(call if_changed,env_h) -- cgit v1.2.3