Skip to content

Commit

Permalink
depmod: Add -M parameter to print the value of MODULE_DIRECTORY
Browse files Browse the repository at this point in the history
This is the only value left in kmod.pc.

It is an overkill to create a pkgconfig file for one value.

Also this file was initially introduced, then moved to a different
loaction because its purpose is misunderstood. Using it is awkward
because the binary search path and pkgconfig path must be matched in
case there is a possibility that multiple builds of kmod exist.

As to why multiple build of kmod might exist on a system

 - custom test build
 - build of kbuild that matches some target system which has different
   settings for sysconfdit, distconfdir, or module_directory
 - per-architecture tools on 'multiarch' system that is set up for
   building binaries/boot images for arbitrary architectures
   - when these use a filesystem scheme in which per-architecture
     libraries and modules are stored in per-architecture directories
     Linux sticks out like a sore thumb with all modules in /lib

While in the past it was fine to have One Kmod To Rule Them All because
everything was hardcoded to a fixed value (and all compression methods
and signature options could be built at the same time) this is no longer
the case.

Values for sysconfdir, distconfdir, and module_directory may differ
between systems, and thus a build can be hosted on a system with one set
of values but targeted for a system with different set of values.

The -m option is provided to make it possible to override
module_directory.

However, for the modules to be installed in the correct location by
kernel build the kernel build needs a way to determine the default value
of module_directory, which this -M option provides.

With a corresponding change to the Linux kbuild system installing
modules should just work for both host with arbitrary module_directory
and target for which correctly configured target-depmod is available and
used during build.

There is always the option to pass arbitrary value as argument to the -m
option to build modules for a target system that uses different
module_directory, or to move the installed modules after the fact.
However, that requires somehow examining the target system out-of-band
to determine the correct value, and hardcode such value in a build
script. When working with multiple different targets regularly using a
target-specific depmod is a way to manage the depmod build-time settings
in a standardized way that works equally for other tools.

Signed-off-by: Michal Suchanek <[email protected]>
  • Loading branch information
hramrach committed Sep 30, 2024
1 parent 6f71cce commit 0f7557e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
6 changes: 6 additions & 0 deletions man/depmod.8.scd
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ depmod - Generate modules.dep and map files.
*depmod* [*-e*] [*-E* _Module.symvers_] [*-F* _System.map_] [*-n*] [*-v*] [*-P* _prefix_]
\ \ \ \ \ \ \ \[*-w*] [_version_] [_filename_...]

*depmod* *-M*

# DESCRIPTION

Linux kernel modules can provide services (called "symbols") for other modules
Expand Down Expand Up @@ -80,6 +82,10 @@ rather than the current kernel version (as returned by *uname -r*).
_/tmp/build/kernel-modules/$(uname -r)_ and generates index files under
that same directory.

*-M*
*--moduledir-defualt*
Print the moduledir prefix @MODULE_DIRECTORY@ set at compile time.

*-o* _outdir_
*--outdir* _outdir_
Set the output directory where *depmod* will store any generated file.
Expand Down
7 changes: 6 additions & 1 deletion tools/depmod.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,13 @@ static const char *const default_cfg_paths[] = {
// clang-format on
};

static const char cmdopts_s[] = "aAb:m:o:C:E:F:evnP:wVh";
static const char cmdopts_s[] = "aAb:m:Mo:C:E:F:evnP:wVh";
static const struct option cmdopts[] = {
{ "all", no_argument, 0, 'a' },
{ "quick", no_argument, 0, 'A' },
{ "basedir", required_argument, 0, 'b' },
{ "moduledir", required_argument, 0, 'm' },
{ "moduledir-default", no_argument, 0, 'M' },
{ "outdir", required_argument, 0, 'o' },
{ "config", required_argument, 0, 'C' },
{ "symvers", required_argument, 0, 'E' },
Expand Down Expand Up @@ -96,6 +97,7 @@ static void help(void)
"\t-b, --basedir=DIR Root path (default: /).\n"
"\t-m, --moduledir=DIR Module directory (default: " MODULE_DIRECTORY
").\n"
"\t-M, --moduledir-default Print MODULE_DIRECTORY default value.\n"
"\t-o, --outdir=DIR Output root path (default: same as <basedir>).\n"
"\t-F, --filesyms=FILE Use the file instead of the\n"
"\t current kernel symbols.\n"
Expand Down Expand Up @@ -2932,6 +2934,9 @@ static int do_depmod(int argc, char *argv[])
case 'm':
module_directory = optarg;
break;
case 'M':
puts(MODULE_DIRECTORY);
return EXIT_SUCCESS;
case 'o':
free(out_root);
out_root = path_make_absolute_cwd(optarg);
Expand Down

0 comments on commit 0f7557e

Please sign in to comment.