Skip to content

Commit 3e3005d

Browse files
committed
kbuild: unify modules(_install) for in-tree and external modules
If you attempt to build or install modules ('make modules(_install)' with CONFIG_MODULES disabled, you will get a clear error message, but nothing for external module builds. Factor out the modules and modules_install rules into the common part, so you will get the same error message when you try to build external modules with CONFIG_MODULES=n. Signed-off-by: Masahiro Yamada <[email protected]>
1 parent 4b97ec0 commit 3e3005d

File tree

1 file changed

+36
-49
lines changed

1 file changed

+36
-49
lines changed

Makefile

Lines changed: 36 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1458,7 +1458,6 @@ endif
14581458

14591459
PHONY += modules
14601460
modules: $(if $(KBUILD_BUILTIN),vmlinux) modules_check modules_prepare
1461-
$(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
14621461

14631462
PHONY += modules_check
14641463
modules_check: modules.order
@@ -1476,12 +1475,9 @@ PHONY += modules_prepare
14761475
modules_prepare: prepare
14771476
$(Q)$(MAKE) $(build)=scripts scripts/module.lds
14781477

1479-
# Target to install modules
1480-
PHONY += modules_install
1481-
modules_install: _modinst_ _modinst_post
1482-
1483-
PHONY += _modinst_
1484-
_modinst_:
1478+
modules_install: __modinst_pre
1479+
PHONY += __modinst_pre
1480+
__modinst_pre:
14851481
@rm -rf $(MODLIB)/kernel
14861482
@rm -f $(MODLIB)/source
14871483
@mkdir -p $(MODLIB)/kernel
@@ -1493,35 +1489,13 @@ _modinst_:
14931489
@sed 's:^:kernel/:' modules.order > $(MODLIB)/modules.order
14941490
@cp -f modules.builtin $(MODLIB)/
14951491
@cp -f $(objtree)/modules.builtin.modinfo $(MODLIB)/
1496-
$(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modinst
1497-
1498-
# This depmod is only for convenience to give the initial
1499-
# boot a modules.dep even before / is mounted read-write. However the
1500-
# boot script depmod is the master version.
1501-
PHONY += _modinst_post
1502-
_modinst_post: _modinst_
1503-
$(call cmd,depmod)
15041492

15051493
ifeq ($(CONFIG_MODULE_SIG), y)
15061494
PHONY += modules_sign
15071495
modules_sign:
15081496
$(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modsign
15091497
endif
15101498

1511-
else # CONFIG_MODULES
1512-
1513-
# Modules not configured
1514-
# ---------------------------------------------------------------------------
1515-
1516-
PHONY += modules modules_install
1517-
modules modules_install:
1518-
@echo >&2
1519-
@echo >&2 "The present kernel configuration has modules disabled."
1520-
@echo >&2 "Type 'make config' and enable loadable module support."
1521-
@echo >&2 "Then build a kernel with module support enabled."
1522-
@echo >&2
1523-
@exit 1
1524-
15251499
endif # CONFIG_MODULES
15261500

15271501
###
@@ -1769,24 +1743,9 @@ KBUILD_BUILTIN :=
17691743
KBUILD_MODULES := 1
17701744

17711745
build-dirs := $(KBUILD_EXTMOD)
1772-
PHONY += modules
1773-
modules: $(MODORDER)
1774-
$(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
1775-
17761746
$(MODORDER): descend
17771747
@:
17781748

1779-
PHONY += modules_install
1780-
modules_install: _emodinst_ _emodinst_post
1781-
1782-
PHONY += _emodinst_
1783-
_emodinst_:
1784-
$(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modinst
1785-
1786-
PHONY += _emodinst_post
1787-
_emodinst_post: _emodinst_
1788-
$(call cmd,depmod)
1789-
17901749
compile_commands.json: $(extmod-prefix)compile_commands.json
17911750
PHONY += compile_commands.json
17921751

@@ -1809,6 +1768,39 @@ PHONY += prepare modules_prepare
18091768

18101769
endif # KBUILD_EXTMOD
18111770

1771+
# ---------------------------------------------------------------------------
1772+
# Modules
1773+
1774+
PHONY += modules modules_install
1775+
1776+
ifdef CONFIG_MODULES
1777+
1778+
modules: $(MODORDER)
1779+
$(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
1780+
1781+
quiet_cmd_depmod = DEPMOD $(KERNELRELEASE)
1782+
cmd_depmod = $(CONFIG_SHELL) $(srctree)/scripts/depmod.sh $(DEPMOD) \
1783+
$(KERNELRELEASE)
1784+
1785+
modules_install:
1786+
$(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modinst
1787+
$(call cmd,depmod)
1788+
1789+
else # CONFIG_MODULES
1790+
1791+
# Modules not configured
1792+
# ---------------------------------------------------------------------------
1793+
1794+
modules modules_install:
1795+
@echo >&2 '***'
1796+
@echo >&2 '*** The present kernel configuration has modules disabled.'
1797+
@echo >&2 '*** To use the module feature, please run "make menuconfig" etc.'
1798+
@echo >&2 '*** to enable CONFIG_MODULES.'
1799+
@echo >&2 '***'
1800+
@exit 1
1801+
1802+
endif # CONFIG_MODULES
1803+
18121804
# Single targets
18131805
# ---------------------------------------------------------------------------
18141806
# To build individual files in subdirectories, you can do like this:
@@ -1997,11 +1989,6 @@ tools/%: FORCE
19971989
quiet_cmd_rmfiles = $(if $(wildcard $(rm-files)),CLEAN $(wildcard $(rm-files)))
19981990
cmd_rmfiles = rm -rf $(rm-files)
19991991

2000-
# Run depmod only if we have System.map and depmod is executable
2001-
quiet_cmd_depmod = DEPMOD $(KERNELRELEASE)
2002-
cmd_depmod = $(CONFIG_SHELL) $(srctree)/scripts/depmod.sh $(DEPMOD) \
2003-
$(KERNELRELEASE)
2004-
20051992
# read saved command lines for existing targets
20061993
existing-targets := $(wildcard $(sort $(targets)))
20071994

0 commit comments

Comments
 (0)