summaryrefslogtreecommitdiffstats
path: root/scripts/Makefile.lib
diff options
context:
space:
mode:
authorMichael Forney <forney@google.com>2019-05-27 11:57:28 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2019-05-28 10:36:09 +0200
commitdefe614845cb85b0490ffb2ac5041a3d68615b3b (patch)
tree73f8af271df6eca922c671c0e9592d9bbe89c375 /scripts/Makefile.lib
parentbbb1ebc77319461c2296439a23e5c2d915c020fb (diff)
downloadbarebox-defe614845cb85b0490ffb2ac5041a3d68615b3b.tar.gz
barebox-defe614845cb85b0490ffb2ac5041a3d68615b3b.tar.xz
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", <file mode>, <number of links>, <owner name>, <group name>, <size>, <date and time>, <pathname> but instead of writing the <owner name> and <group name>, it writes the numeric owner and group IDs (this avoids /etc/passwd and /etc/group lookups as well as potential field splitting issues). The <size> 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 <forney@google.com> Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com> [afa: imported script and adjusted barebox stat(1) callsites] Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'scripts/Makefile.lib')
-rw-r--r--scripts/Makefile.lib4
1 files changed, 2 insertions, 2 deletions
diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
index 95eaf522ab..87bff2d296 100644
--- a/scripts/Makefile.lib
+++ b/scripts/Makefile.lib
@@ -341,7 +341,7 @@ cmd_env=$(srctree)/scripts/genenv $(srctree) $(objtree) $@ $<
size_append = printf $(shell \
dec_size=0; \
for F in $1; do \
- fsize=$$(stat -c "%s" $$F); \
+ fsize=$$(${CONFIG_SHELL} "${srctree}/scripts/file-size.sh" $$F);\
dec_size=$$(expr $$dec_size + $$fsize); \
done; \
printf "%08x\n" $$dec_size | \
@@ -446,7 +446,7 @@ quiet_cmd_check_size = CHKSIZE $2
# Check size of a file
quiet_cmd_check_file_size = CHKFILESIZE $2
cmd_check_file_size = set -e; \
- size=`stat -c%s $2`; \
+ size=`${CONFIG_SHELL} "${srctree}/scripts/file-size.sh" $2`; \
max_size=`printf "%d" $3`; \
if [ $$size -gt $$max_size ] ; \
then \