1# SPDX-License-Identifier: GPL-2.0
2# ==========================================================================
3# Generating modules.builtin
4# ==========================================================================
5
6src := $(obj)
7
8PHONY := __modbuiltin
9__modbuiltin:
10
11include include/config/auto.conf
12# tristate.conf sets tristate variables to uppercase 'Y' or 'M'
13# That way, we get the list of built-in modules in obj-Y
14include include/config/tristate.conf
15
16include scripts/Kbuild.include
17
18ifneq ($(KBUILD_SRC),)
19# Create output directory if not already present
20_dummy := $(shell [ -d $(obj) ] || mkdir -p $(obj))
21endif
22
23# The filename Kbuild has precedence over Makefile
24kbuild-dir := $(if $(filter /%,$(src)),$(src),$(srctree)/$(src))
25kbuild-file := $(if $(wildcard $(kbuild-dir)/Kbuild),$(kbuild-dir)/Kbuild,$(kbuild-dir)/Makefile)
26include $(kbuild-file)
27
28include scripts/Makefile.lib
29__subdir-Y     := $(patsubst %/,%,$(filter %/, $(obj-Y)))
30subdir-Y       += $(__subdir-Y)
31subdir-ym      := $(sort $(subdir-y) $(subdir-Y) $(subdir-m))
32subdir-ym      := $(addprefix $(obj)/,$(subdir-ym))
33obj-Y          := $(addprefix $(obj)/,$(obj-Y))
34
35modbuiltin-subdirs := $(patsubst %,%/modules.builtin, $(subdir-ym))
36modbuiltin-mods    := $(filter %.ko, $(obj-Y:.o=.ko))
37modbuiltin-target  := $(obj)/modules.builtin
38
39__modbuiltin: $(modbuiltin-target) $(subdir-ym)
40	@:
41
42$(modbuiltin-target): $(subdir-ym) FORCE
43	$(Q)(for m in $(modbuiltin-mods); do echo kernel/$$m; done;	\
44	cat /dev/null $(modbuiltin-subdirs)) > $@
45
46PHONY += FORCE
47
48FORCE:
49
50# Descending
51# ---------------------------------------------------------------------------
52
53PHONY += $(subdir-ym)
54$(subdir-ym):
55	$(Q)$(MAKE) $(modbuiltin)=$@
56
57.PHONY: $(PHONY)
58