kbuild: generate modules.builtin

To make it easier for module-init-tools and scripts like mkinitrd to
distinguish builtin and missing modules, install a modules.builtin file
listing all builtin modules. This is done by generating an additional
config file (tristate.conf) with tristate options set to uppercase 'Y'
or 'M'. If we source that config file, the builtin modules appear in
obj-Y.

Signed-off-by: Michal Marek <mmarek@suse.cz>
This commit is contained in:
Michal Marek 2009-12-07 16:38:33 +01:00
parent 6299fee7b8
commit bc081dd6e9
7 changed files with 112 additions and 5 deletions

1
.gitignore vendored
View File

@ -22,6 +22,7 @@
*.lst *.lst
*.symtypes *.symtypes
*.order *.order
modules.builtin
*.elf *.elf
*.bin *.bin
*.gz *.gz

View File

@ -1,3 +1,17 @@
Output files
modules.order
--------------------------------------------------
This file records the order in which modules appear in Makefiles. This
is used by modprobe to deterministically resolve aliases that match
multiple modules.
modules.builtin
--------------------------------------------------
This file lists all modules that are built into the kernel. This is used
by modprobe to not fail when trying to load something builtin.
Environment variables Environment variables
KCPPFLAGS KCPPFLAGS

View File

@ -103,6 +103,11 @@ KCONFIG_AUTOCONFIG
This environment variable can be set to specify the path & name of the This environment variable can be set to specify the path & name of the
"auto.conf" file. Its default value is "include/config/auto.conf". "auto.conf" file. Its default value is "include/config/auto.conf".
KCONFIG_TRISTATE
--------------------------------------------------
This environment variable can be set to specify the path & name of the
"tristate.conf" file. Its default value is "include/config/tristate.conf".
KCONFIG_AUTOHEADER KCONFIG_AUTOHEADER
-------------------------------------------------- --------------------------------------------------
This environment variable can be set to specify the path & name of the This environment variable can be set to specify the path & name of the

View File

@ -464,7 +464,7 @@ ifeq ($(KBUILD_EXTMOD),)
# Carefully list dependencies so we do not try to build scripts twice # Carefully list dependencies so we do not try to build scripts twice
# in parallel # in parallel
PHONY += scripts PHONY += scripts
scripts: scripts_basic include/config/auto.conf scripts: scripts_basic include/config/auto.conf include/config/tristate.conf
$(Q)$(MAKE) $(build)=$(@) $(Q)$(MAKE) $(build)=$(@)
# Objects we will link into vmlinux / subdirs we need to visit # Objects we will link into vmlinux / subdirs we need to visit
@ -491,7 +491,7 @@ $(KCONFIG_CONFIG) include/config/auto.conf.cmd: ;
# with it and forgot to run make oldconfig. # with it and forgot to run make oldconfig.
# if auto.conf.cmd is missing then we are probably in a cleaned tree so # if auto.conf.cmd is missing then we are probably in a cleaned tree so
# we execute the config step to be sure to catch updated Kconfig files # we execute the config step to be sure to catch updated Kconfig files
include/config/auto.conf: $(KCONFIG_CONFIG) include/config/auto.conf.cmd include/config/%.conf: $(KCONFIG_CONFIG) include/config/auto.conf.cmd
$(Q)$(MAKE) -f $(srctree)/Makefile silentoldconfig $(Q)$(MAKE) -f $(srctree)/Makefile silentoldconfig
else else
# external modules needs include/generated/autoconf.h and include/config/auto.conf # external modules needs include/generated/autoconf.h and include/config/auto.conf
@ -876,6 +876,9 @@ $(sort $(vmlinux-init) $(vmlinux-main)) $(vmlinux-lds): $(vmlinux-dirs) ;
PHONY += $(vmlinux-dirs) PHONY += $(vmlinux-dirs)
$(vmlinux-dirs): prepare scripts $(vmlinux-dirs): prepare scripts
$(Q)$(MAKE) $(build)=$@ $(Q)$(MAKE) $(build)=$@
ifdef CONFIG_MODULES
$(Q)$(MAKE) $(modbuiltin)=$@
endif
# Build the kernel release string # Build the kernel release string
# #
@ -1080,6 +1083,7 @@ all: modules
PHONY += modules PHONY += modules
modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux)
$(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
$(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.builtin) > $(objtree)/modules.builtin
@$(kecho) ' Building modules, stage 2.'; @$(kecho) ' Building modules, stage 2.';
$(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
$(Q)$(MAKE) -f $(srctree)/scripts/Makefile.fwinst obj=firmware __fw_modbuild $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.fwinst obj=firmware __fw_modbuild
@ -1109,6 +1113,7 @@ _modinst_:
ln -s $(objtree) $(MODLIB)/build ; \ ln -s $(objtree) $(MODLIB)/build ; \
fi fi
@cp -f $(objtree)/modules.order $(MODLIB)/ @cp -f $(objtree)/modules.order $(MODLIB)/
@cp -f $(objtree)/modules.builtin $(MODLIB)/
$(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modinst $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modinst
# This depmod is only for convenience to give the initial # This depmod is only for convenience to give the initial
@ -1169,7 +1174,7 @@ clean: archclean $(clean-dirs)
\( -name '*.[oas]' -o -name '*.ko' -o -name '.*.cmd' \ \( -name '*.[oas]' -o -name '*.ko' -o -name '.*.cmd' \
-o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \ -o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \
-o -name '*.symtypes' -o -name 'modules.order' \ -o -name '*.symtypes' -o -name 'modules.order' \
-o -name '.tmp_*.o.*' \ -o modules.order -o -name '.tmp_*.o.*' \
-o -name '*.gcno' \) -type f -print | xargs rm -f -o -name '*.gcno' \) -type f -print | xargs rm -f
# mrproper - Delete all generated files, including .config # mrproper - Delete all generated files, including .config
@ -1367,7 +1372,8 @@ $(clean-dirs):
clean: rm-dirs := $(MODVERDIR) clean: rm-dirs := $(MODVERDIR)
clean: rm-files := $(KBUILD_EXTMOD)/Module.symvers \ clean: rm-files := $(KBUILD_EXTMOD)/Module.symvers \
$(KBUILD_EXTMOD)/modules.order $(KBUILD_EXTMOD)/modules.order \
$(KBUILD_EXTMOD)/modules.builtin
clean: $(clean-dirs) clean: $(clean-dirs)
$(call cmd,rmdirs) $(call cmd,rmdirs)
$(call cmd,rmfiles) $(call cmd,rmfiles)

View File

@ -149,6 +149,12 @@ ld-option = $(call try-run,\
# $(Q)$(MAKE) $(build)=dir # $(Q)$(MAKE) $(build)=dir
build := -f $(if $(KBUILD_SRC),$(srctree)/)scripts/Makefile.build obj build := -f $(if $(KBUILD_SRC),$(srctree)/)scripts/Makefile.build obj
###
# Shorthand for $(Q)$(MAKE) -f scripts/Makefile.modbuiltin obj=
# Usage:
# $(Q)$(MAKE) $(modbuiltin)=dir
modbuiltin := -f $(if $(KBUILD_SRC),$(srctree)/)scripts/Makefile.modbuiltin obj
# Prefix -I with $(srctree) if it is not an absolute path. # Prefix -I with $(srctree) if it is not an absolute path.
# skip if -I has no parameter # skip if -I has no parameter
addtree = $(if $(patsubst -I%,%,$(1)), \ addtree = $(if $(patsubst -I%,%,$(1)), \

View File

@ -0,0 +1,55 @@
# ==========================================================================
# Generating modules.builtin
# ==========================================================================
src := $(obj)
PHONY := __modbuiltin
__modbuiltin:
-include include/config/auto.conf
# tristate.conf sets tristate variables to uppercase 'Y' or 'M'
# That way, we get the list of built-in modules in obj-Y
-include include/config/tristate.conf
include scripts/Kbuild.include
# The filename Kbuild has precedence over Makefile
kbuild-dir := $(if $(filter /%,$(src)),$(src),$(srctree)/$(src))
kbuild-file := $(if $(wildcard $(kbuild-dir)/Kbuild),$(kbuild-dir)/Kbuild,$(kbuild-dir)/Makefile)
include $(kbuild-file)
include scripts/Makefile.lib
__subdir-Y := $(patsubst %/,%,$(filter %/, $(obj-Y)))
subdir-Y += $(__subdir-Y)
subdir-ym := $(sort $(subdir-y) $(subdir-Y) $(subdir-m))
subdir-ym := $(addprefix $(obj)/,$(subdir-ym))
obj-Y := $(addprefix $(obj)/,$(obj-Y))
modbuiltin-subdirs := $(patsubst %,%/modules.builtin, $(subdir-ym))
modbuiltin-mods := $(filter %.ko, $(obj-Y:.o=.ko))
modbuiltin-target := $(obj)/modules.builtin
__modbuiltin: $(modbuiltin-target) $(subdir-ym)
@:
$(modbuiltin-target): $(subdir-ym) FORCE
$(Q)(for m in $(modbuiltin-mods); do echo kernel/$$m; done; \
cat /dev/null $(modbuiltin-subdirs)) > $@
PHONY += FORCE
FORCE:
# Descending
# ---------------------------------------------------------------------------
PHONY += $(subdir-ym)
$(subdir-ym):
$(Q)$(MAKE) $(modbuiltin)=$@
# Declare the contents of the .PHONY variable as phony. We keep that
# information in a variable se we can use it in if_changed and friends.
.PHONY: $(PHONY)

View File

@ -677,7 +677,7 @@ int conf_write_autoconf(void)
struct symbol *sym; struct symbol *sym;
const char *str; const char *str;
const char *name; const char *name;
FILE *out, *out_h; FILE *out, *tristate, *out_h;
time_t now; time_t now;
int i, l; int i, l;
@ -692,9 +692,16 @@ int conf_write_autoconf(void)
if (!out) if (!out)
return 1; return 1;
tristate = fopen(".tmpconfig_tristate", "w");
if (!tristate) {
fclose(out);
return 1;
}
out_h = fopen(".tmpconfig.h", "w"); out_h = fopen(".tmpconfig.h", "w");
if (!out_h) { if (!out_h) {
fclose(out); fclose(out);
fclose(tristate);
return 1; return 1;
} }
@ -707,6 +714,9 @@ int conf_write_autoconf(void)
"# %s" "# %s"
"#\n", "#\n",
sym_get_string_value(sym), ctime(&now)); sym_get_string_value(sym), ctime(&now));
fprintf(tristate, "#\n"
"# Automatically generated - do not edit\n"
"\n");
fprintf(out_h, "/*\n" fprintf(out_h, "/*\n"
" * Automatically generated C config: don't edit\n" " * Automatically generated C config: don't edit\n"
" * Linux kernel version: %s\n" " * Linux kernel version: %s\n"
@ -727,10 +737,14 @@ int conf_write_autoconf(void)
break; break;
case mod: case mod:
fprintf(out, "CONFIG_%s=m\n", sym->name); fprintf(out, "CONFIG_%s=m\n", sym->name);
fprintf(tristate, "CONFIG_%s=M\n", sym->name);
fprintf(out_h, "#define CONFIG_%s_MODULE 1\n", sym->name); fprintf(out_h, "#define CONFIG_%s_MODULE 1\n", sym->name);
break; break;
case yes: case yes:
fprintf(out, "CONFIG_%s=y\n", sym->name); fprintf(out, "CONFIG_%s=y\n", sym->name);
if (sym->type == S_TRISTATE)
fprintf(tristate, "CONFIG_%s=Y\n",
sym->name);
fprintf(out_h, "#define CONFIG_%s 1\n", sym->name); fprintf(out_h, "#define CONFIG_%s 1\n", sym->name);
break; break;
} }
@ -772,6 +786,7 @@ int conf_write_autoconf(void)
} }
} }
fclose(out); fclose(out);
fclose(tristate);
fclose(out_h); fclose(out_h);
name = getenv("KCONFIG_AUTOHEADER"); name = getenv("KCONFIG_AUTOHEADER");
@ -779,6 +794,11 @@ int conf_write_autoconf(void)
name = "include/generated/autoconf.h"; name = "include/generated/autoconf.h";
if (rename(".tmpconfig.h", name)) if (rename(".tmpconfig.h", name))
return 1; return 1;
name = getenv("KCONFIG_TRISTATE");
if (!name)
name = "include/config/tristate.conf";
if (rename(".tmpconfig_tristate", name))
return 1;
name = conf_get_autoconfig_name(); name = conf_get_autoconfig_name();
/* /*
* This must be the last step, kbuild has a dependency on auto.conf * This must be the last step, kbuild has a dependency on auto.conf