Makefile: add --remove-destination to cp calls.

This avoids overwriting the busybox binary (and bricking the system)
by following a symlink when busybox and other module both provide
a command with the same filename.

Signed-off-by: Daniel Pineda <daniel.pineda@puri.sm>
This commit is contained in:
Daniel Pineda 2023-02-21 14:15:25 -06:00
parent 17ac64bdf1
commit b51fda22c1
No known key found for this signature in database
GPG Key ID: 902C199C68C4B327

View File

@ -234,7 +234,7 @@ define do-copy =
if cmp --quiet "$1" "$2" ; then \ if cmp --quiet "$1" "$2" ; then \
echo "$(DATE) UNCHANGED $(1:$(pwd)/%=%)" ; \ echo "$(DATE) UNCHANGED $(1:$(pwd)/%=%)" ; \
fi ; \ fi ; \
cp -a "$1" "$2" ; \ cp -a --remove-destination "$1" "$2" ; \
) )
@sha256sum "$(2:$(pwd)/%=%)" @sha256sum "$(2:$(pwd)/%=%)"
endef endef
@ -415,7 +415,7 @@ $(call map, define_module, $(modules-y))
# #
define install = define install =
@-mkdir -p "$(dir $2)" @-mkdir -p "$(dir $2)"
$(call do,INSTALL,$2,cp -a "$1" "$2") $(call do,INSTALL,$2,cp -a --remove-destination "$1" "$2")
endef endef
# #
@ -424,7 +424,7 @@ endef
# #
define initrd_bin_add = define initrd_bin_add =
$(initrd_bin_dir)/$(notdir $1): $1 $(initrd_bin_dir)/$(notdir $1): $1
$(call do,INSTALL-BIN,$$(<:$(pwd)/%=%),cp -a "$$<" "$$@") $(call do,INSTALL-BIN,$$(<:$(pwd)/%=%),cp -a --remove-destination "$$<" "$$@")
@$(CROSS)strip --preserve-dates "$$@" 2>&-; true @$(CROSS)strip --preserve-dates "$$@" 2>&-; true
initrd_bins += $(initrd_bin_dir)/$(notdir $1) initrd_bins += $(initrd_bin_dir)/$(notdir $1)
endef endef