Is it meaningful to execute "make modules_install" without executing "make modules"? - linux

From KernelBuild tutorial from http://kernelnewbies.org, I don't see "make modules" command. This article only executes "make" command before "sudo make modules_install install".
But from make help output:
all - Build all targets marked with [*]
* vmlinux - Build the bare kernel
* modules - Build all modules
modules_install - Install all modules to INSTALL_MOD_PATH (default: /)
It seems that without "make modules" command, there is no need to execute "make modules_install" command. Is it meaningful to execute "make modules_install" without executing "make modules"?

Is it meaningful to execute “make modules_install” without executing “make modules”?
Yes, but only if you have already executed make before the make modules_install. You can't execute modules_install if modules weren't built with the make modules or just make. There is only one difference between make and make modules: the make modules compiles only modules or source code which is set as
obj-CONFIG_OPTION_NAME=m
in the Makefile. If you want just to build Linux kernel, just use make, the make modules already included there.

No, if you understand the procedure correctly.
make modules This will just compile all modules just like any other program. Creating object files.
make modules_install Once your files are compiled without any error then this command will put generated .so files to the appropriate directories.
So if you run modules_install without make modules then there will be nothing to copy.
I hope this helps.

Related

What does make install do when compiling GCC from source code?

I am trying to compile GCC from source. After make finishes, I could not find the GCC binary executable. Here is the configure command I used:
../gcc-svn/configure --prefix=/home/user/Documents/mygcc
Here are my questions specifically:
What should I expect make install does?
Is make install going to do more compilation or just moves some files to ~/Documents/mygcc? If it is the latter where the GCC executable resides?
Any other directory in my system also get affected by make install?
Thank you in advance.

Building an out-of-tree kernel module with separate source and build directories via autoconf

Given a package that uses autoconf (a configure script) to provide both a user-mode application and a kernel driver, with a directory structure like this:
configure.ac
configure
Makefile.am
user
Makefile.am
user.c
driver
Makefile.am
Kbuild.in
driver.c
This successfully configures and builds both user and driver when configured locally (run ./configure --options).
However a useful feature of configure scripts is that you can have a separate source and build directory, simply by running the script from the build directory, eg:
mkdir build && cd build && ../configure --options
This works fine for the user app, but I'm having trouble getting the kernel driver to build in this context. In the driver's Makefile.am I have the following, as suggested in this answer:
modules:
$(MAKE) -C "$(LINUX_SOURCE_DIR)" M="#abs_builddir#" src="#abs_srcdir#" modules
But this fails to compile, as it's expecting the Kbuild or Makefile to be in src, but they're actually in M. Omitting src does let it find the Kbuild but it then fails to find the actual source files (no rule to make target //path/in/build//driver.o).
Using O= as some other answers suggest is not correct, as this specifies the path to find the kernel's output files (.config etc) and these are still in the LINUX_SOURCE_DIR. (So trying to use it results in various other missing-file errors.)
I'm hoping for a solution that doesn't require modifying any actual Kbuild scripts, since those are outside my package's control.
Thus far the best option I've come up with is to copy/link all the module source files into the build directory before calling Kbuild, which is not ideal. I'm hoping there's a hidden setting that can be used for this.

How to install Kernel Modules from Source Code. Error while make process

I want to install the kernel modules to lib/modules/ . Actually there has to be created a folder in lib/modules/(uname-r) after doing make modules , but there are only created 3 folders called "build", "kernel" and "source". I also get an error after make modules:
DEPMOD 3.4.79
WARNING: COULDN't open directory /lib/modules/3.4.79: No such file or direcoty
FATAL: Could not open /lib/modules/3.4.79/modules.dep.temp for writing: No suhc file or directory
make: *** [_modinst_post] Error 1
Indeed there is no directory called that, but how can I add it?
Did you try \"make modules_install\"?
to install modules
make modules_install
to install kernel
make install
Out-of-tree modules
For the benefit of future Googlers, this is what Buildroot 2018.05 does to install out-of-tree modules for LInux v4.19:
cd linux_kernel_source
mkdir -p /build/dir/default/x86_64/target/lib/modules/4.19.0/extra
/usr/bin/make -f ./scripts/Makefile.modinst
mkdir -p /build/dir/default/x86_64/target/lib/modules/4.19.0/extra
cp /build/dir/default/x86_64/build/kernel_modules-1.0/./buildroot_dep.ko /build/dir/default/x86_64/target/lib/modules/4.19.0/extra
/build/dir/default/x86_64/host/bin/x86_64-buildroot-linux-uclibc-strip --strip-debug /build/dir/default/x86_64/target/lib/modules/4.19.0/extra/buildroot_dep.ko
/bin/bash ./scripts/depmod.sh /build/dir/default/x86_64/host/sbin/depmod 4.19.0
So we can see that it uses the ./scripts/Makefile.modinst and ./scripts/depmod.sh in tree scripts, plus some ugly manual copying of the modules.
Found by building a package that contains kernel modules with V=1 and kernel_modules_package_name-reconfigure and simplifying the output commands, works every time :-).
The only missing question is how depmod was obtained, so we do another verbose build with host-kmod-reconfigure, and basically obtain:
./configure
--prefix="/build/dir/default/x86_64/host"
--sysconfdir="/build/dir/default/x86_64/host/etc"
--localstatedir="/build/dir/default/x86_64/host/var"
where the source is obtained from: https://git.kernel.org/pub/scm/utils/kernel/kmod/kmod.git
In tree modules are installed with make modules_install as mentioned at: How to install Kernel Modules from Source Code. Error while make process

How to recompile just a single kernel module?

Usually kernel source are stored in /usr/src/linux-2.6.x/.
To avoid to recompile the entire kernel if I modify a module's source, how can I recompile just that module?
Switch to the root directory of your source tree and run the following command:
$ make modules SUBDIRS=drivers/the_module_directory
And to install the compiled module:
$ make modules_install SUBDIRS=drivers/the_module_directory
Note: As lunakid mentions, the latter command might not build the module first, so be careful.
since kernel versions 3.x.x and 4.x.x the procedure gets more complicated (but there is a hope, so keep reading):
make distclean if you haven't just cloned a new source but used to build other modules before
create new folder somewhere for the module source (example: extra)
and copy only source files (from the kernel source or somewhere else) related to the module needed to be build into this new folder
copy /boot/config-`uname -r` file (example: /boot/config-4.8.0-46-generic) into kernel source folder file .config and run make oldconfig. if the module belongs to the kernel source, verify if it has been enabled by calling make menuconfig, by searching for the module and applying letter 'M' if necessary
kernel source root Makefile has to be altered with exact version components matching the current running one (you may verify with make kernelversion if it matches exactly the uname -rone)
there is been a strong suggestion to build scripts also before with
make scripts
make prepare and make modules_prepare has to be executed prior to the actual module build
Module.symvers has to be copied from the target system headers folder corresponding running kernel version /usr/src/linux-headers-`uname -r`/Module.symvers (example: /usr/src/linux-headers-3.13.0-117-generic/Module.symvers) into the newly created module source files folder prepared for the module compilation (the one extra in example).
create new Makefile inside module source compilation folder having following line: obj-y += <module_source_file_name>.o or if the source code is complicated, use the guidance from here
only then it's the right time to build module with make -C <kernel source path> M=the_module_directory (example: make -C . M=extra/)
Use command modprobe --dump-modversion <module_name>.ko to verify CRC match between module exporting API and corresponding values in Module.symvers. in case of failure use command modinfo <module_name>.ko instead
verify if kernel.release file content match exactly the one from headers of the current running version. if you'll discover + appended at the end, it means you've been compiling git clonned source and your experimental modifications caused build system to compromise the localversion string by adding + at the end.
if only + has been discovered at the tail of kernel.release stored value and it's a mismatch with the exact name of the target running kernel,
the solution would be following:
commit all your changes, force release tag to shift above your modifications with the git tag -a <tag version> -f command. then rebuild your modules from step 8
You can pass the path to the module name or module directory to make as parameter.
make path/to/the/module/itself.ko
make path/to/the/module/directory/
In case you have edited just code in drivers/net/ethernet/intel/e1000/e1000_main.c file
Build the module.
make scripts prepare modules_prepare
make -C . M=drivers/net/ethernet/intel/e1000
Install the module.
cp drivers/net/ethernet/intel/e1000/e1000.ko /lib/modules/5.1.15/kernel/drivers/net/ethernet/intel/e1000/e1000.ko
make -C /lib/modules/$(uname -r)/build M=$(pwd) modules
make -C /lib/modules/$(uname -r)/build M=$(pwd) modules_install
https://askubuntu.com/questions/515407/how-recipe-to-build-only-one-kernel-module

Compiling ODE code in Linux

I have downloaded ode-0.11.1 and I am able to compile source code by modifying the Makefile provided with the demos, but I can't figure out how to manually compile and link the code I need as a standalone.
I tried probing at the Makefile and substituting the macros manually, as well as running it and checking the output.
Does anyone know how to do this?
OpenDE, or ODE, is configured with GNU autoconf/automake tools.
This means that you need to invoke ./configure before you can build the package.
To see all the options, use:
$ ./configure --help
An invokation to ./configure will often need a target where to install to.
A typical invokation would look like this:
$ ./configure --prefix=$HOME --with-trimesh=opcode
$ make install
This will install OpenDE in your home directory.
If you omit the --prefix argument, the default /usr/local will be used, and you will need root permissions to install.
The example invokation will also include support for triangle meshes using OPCODE.

Resources