Perform module install actions only if the object area module is newer than install area module, and only announce the updated modules. This saves 10's of seconds for a single CPU make, saves a few seconds for a parallel make, and reduces output clutter for an incremental make. Example: % touch drivers/virtio/virtio_ring.c % make modules modules_install DESCEND objtool CALL scripts/atomic/check-atomics.sh CALL scripts/checksyscalls.sh CC [M] drivers/virtio/virtio_ring.o Building modules, stage 2. MODPOST 2592 modules LD [M] drivers/virtio/virtio_ring.ko INSTALL drivers/virtio/virtio_ring.ko DEPMOD 5.1.0-rc3 Signed-off-by: Steve Sistare <steven.sistare@xxxxxxxxxx> --- Makefile | 1 - scripts/Makefile.modinst | 30 +++++++++++++++++++++++------- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 4988dcc..8f58e27 100644 --- a/Makefile +++ b/Makefile @@ -1286,7 +1286,6 @@ modules_install: _modinst_ _modinst_post PHONY += _modinst_ _modinst_: - @rm -rf $(MODLIB)/kernel @rm -f $(MODLIB)/source @mkdir -p $(MODLIB)/kernel @ln -s $(abspath $(srctree)) $(MODLIB)/source diff --git a/scripts/Makefile.modinst b/scripts/Makefile.modinst index 0dae402..062fdca6 100644 --- a/scripts/Makefile.modinst +++ b/scripts/Makefile.modinst @@ -10,6 +10,12 @@ include scripts/Kbuild.include # +ifeq ($(quiet),quiet_) + mod_announce_cmd := echo +else + mod_announce_cmd := true +endif + __modules := $(sort $(shell grep -h '\.ko$$' /dev/null $(wildcard $(MODVERDIR)/*.mod))) modules := $(patsubst %.o,%.ko,$(wildcard $(__modules:.ko=.o))) @@ -17,14 +23,24 @@ PHONY += $(modules) __modinst: $(modules) @: -# Don't stop modules_install if we can't sign external modules. -quiet_cmd_modules_install = INSTALL $@ +# Perform install actions only if the tree module is newer than the installed +# module. Create the latter with a final move command to avoid a broken +# installed module if one of the intermediate commands fails. Suppress +# quiet_cmd so that only updated modules are announced. Don't stop +# modules_install if we can't sign external modules. + +quiet_cmd_modules_install = cmd_modules_install = \ - mkdir -p $(2) ; \ - cp $@ $(2) ; \ - $(mod_strip_cmd) $(2)/$(notdir $@) ; \ - $(mod_sign_cmd) $(2)/$(notdir $@) $(patsubst %,|| true,$(KBUILD_EXTMOD)) ; \ - $(mod_compress_cmd) $(2)/$(notdir $@) + if [[ $@ -nt $(2)/$(notdir $@) ]]; then \ + $(mod_announce_cmd) ' INSTALL' $@ ; \ + mkdir -p $(2) ; \ + tmpfile=$(2)/.$(notdir $@).tmp ; \ + cp $@ $$tmpfile ; \ + $(mod_strip_cmd) $$tmpfile ; \ + $(mod_sign_cmd) $$tmpfile $(patsubst %,|| true,$(KBUILD_EXTMOD)) ; \ + $(mod_compress_cmd) $$tmpfile ; \ + mv $$tmpfile $(2)/$(notdir $@) ; \ + fi # Modules built outside the kernel source tree go into extra by default INSTALL_MOD_DIR ?= extra -- 1.8.3.1