Skip to content

Commit 5e02797

Browse files
committed
kbuild: move more module installation code to scripts/Makefile.modinst
Move more relevant code to scripts/Makefile.modinst. Signed-off-by: Masahiro Yamada <masahiroy@kernel.org> Reviewed-by: Nicolas Schier <nicolas@fjasle.eu>
1 parent 2dfec88 commit 5e02797

File tree

2 files changed

+38
-29
lines changed

2 files changed

+38
-29
lines changed

Makefile

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1477,24 +1477,6 @@ endif
14771477

14781478
endif # CONFIG_MODULES
14791479

1480-
modinst_pre :=
1481-
ifneq ($(filter modules_install,$(MAKECMDGOALS)),)
1482-
modinst_pre := __modinst_pre
1483-
endif
1484-
1485-
modules_install: $(modinst_pre)
1486-
PHONY += __modinst_pre
1487-
__modinst_pre:
1488-
@rm -rf $(MODLIB)/kernel
1489-
@rm -f $(MODLIB)/build
1490-
@mkdir -p $(MODLIB)
1491-
ifdef CONFIG_MODULES
1492-
@ln -s $(CURDIR) $(MODLIB)/build
1493-
@sed 's:^\(.*\)\.o$$:kernel/\1.ko:' modules.order > $(MODLIB)/modules.order
1494-
endif
1495-
@cp -f modules.builtin $(MODLIB)/
1496-
@cp -f $(objtree)/modules.builtin.modinfo $(MODLIB)/
1497-
14981480
###
14991481
# Cleaning is done on three levels.
15001482
# make clean Delete most generated files
@@ -1836,12 +1818,15 @@ help:
18361818
@echo ' clean - remove generated files in module directory only'
18371819
@echo ''
18381820

1821+
ifndef CONFIG_MODULES
1822+
modules modules_install: __external_modules_error
18391823
__external_modules_error:
18401824
@echo >&2 '***'
18411825
@echo >&2 '*** The present kernel disabled CONFIG_MODULES.'
18421826
@echo >&2 '*** You cannot build or install external modules.'
18431827
@echo >&2 '***'
18441828
@false
1829+
endif
18451830

18461831
endif # KBUILD_EXTMOD
18471832

@@ -1850,6 +1835,9 @@ endif # KBUILD_EXTMOD
18501835

18511836
PHONY += modules modules_install modules_prepare
18521837

1838+
modules_install:
1839+
$(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modinst
1840+
18531841
ifdef CONFIG_MODULES
18541842

18551843
$(MODORDER): $(build-dir)
@@ -1866,17 +1854,9 @@ PHONY += modules_check
18661854
modules_check: $(MODORDER)
18671855
$(Q)$(CONFIG_SHELL) $(srctree)/scripts/modules-check.sh $<
18681856

1869-
modules_install:
1870-
$(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modinst
1871-
18721857
else # CONFIG_MODULES
18731858

1874-
# Modules not configured
1875-
# ---------------------------------------------------------------------------
1876-
1877-
PHONY += __external_modules_error
1878-
1879-
modules modules_install: __external_modules_error
1859+
modules:
18801860
@:
18811861

18821862
KBUILD_MODULES :=

scripts/Makefile.modinst

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,33 @@ include $(srctree)/scripts/Kbuild.include
1111

1212
install-y :=
1313

14+
ifeq ($(KBUILD_EXTMOD)$(modules_sign_only),)
15+
16+
# remove the old directory and symlink
17+
$(shell rm -fr $(MODLIB)/kernel $(MODLIB)/build)
18+
19+
install-$(CONFIG_MODULES) += $(addprefix $(MODLIB)/, build modules.order)
20+
21+
$(MODLIB)/build: FORCE
22+
$(call cmd,symlink)
23+
24+
quiet_cmd_symlink = SYMLINK $@
25+
cmd_symlink = ln -s $(CURDIR) $@
26+
27+
$(MODLIB)/modules.order: modules.order FORCE
28+
$(call cmd,install_modorder)
29+
30+
quiet_cmd_install_modorder = INSTALL $@
31+
cmd_install_modorder = sed 's:^\(.*\)\.o$$:kernel/\1.ko:' $< > $@
32+
33+
# Install modules.builtin(.modinfo) even when CONFIG_MODULES is disabled.
34+
install-y += $(addprefix $(MODLIB)/, modules.builtin modules.builtin.modinfo)
35+
36+
$(addprefix $(MODLIB)/, modules.builtin modules.builtin.modinfo): $(MODLIB)/%: % FORCE
37+
$(call cmd,install)
38+
39+
endif
40+
1441
modules := $(call read-file, $(MODORDER))
1542

1643
ifeq ($(KBUILD_EXTMOD),)
@@ -31,7 +58,7 @@ suffix-$(CONFIG_MODULE_COMPRESS_ZSTD) := .zst
3158
modules := $(patsubst $(extmod_prefix)%.o, $(dst)/%.ko$(suffix-y), $(modules))
3259
install-$(CONFIG_MODULES) += $(modules)
3360

34-
__modinst: $(modules)
61+
__modinst: $(install-y)
3562
@:
3663

3764
#
@@ -92,14 +119,16 @@ $(dst)/%.ko: $(extmod_prefix)%.ko FORCE
92119
$(call cmd,strip)
93120
$(call cmd,sign)
94121

122+
ifdef CONFIG_MODULES
95123
__modinst: depmod
96124

97125
PHONY += depmod
98-
depmod: $(modules)
126+
depmod: $(install-y)
99127
$(call cmd,depmod)
100128

101129
quiet_cmd_depmod = DEPMOD $(MODLIB)
102130
cmd_depmod = $(srctree)/scripts/depmod.sh $(KERNELRELEASE)
131+
endif
103132

104133
else
105134

0 commit comments

Comments
 (0)