Questions tagged [kbuild]

kbuild is the build system used by the Linux kernel.

kbuild is a build framework based on GNU make and a standard set of cross platform tools. It was originally developed for the Linux Kernel, but is now used in other projects such as crosstool-ng, buildroot, ltib, etc.

kbuild is extremely powerful and tries to hide most of its complexity in templates so that the actual makefiles are relatively easy to understand and write. There are two distinct parts of kbuild; A set of tools and languages for describing configuration variables and Gnu make template code to drive the actual build process.

There are stock documentation for different topics,

The Gnu make harness for the Linux kernel is in the main Makefile and Kbuild.include. The tools for configuring variable (and processing the Kconfig language) are in a kconfig directory. Obviously other projects such as buildroot, and crosstool-ng use modified versions.

The two aspects are found in files within the kernel source. They are a Kconfig file defining variables that can be defined by the tools. The second portion is a Makefile, which uses the Kconfig output (usually .config) to guide the build process through normal Gnu make rules, templates and macros.

144 questions
50
votes
2 answers

What exactly does Linux kernel's `make defconfig` do?

I can use the following command to create a Linux kernel .config file based on a specified architecture default for a custom ARM-based board: ARCH=arm make defconfig KBUILD_DEFCONFIG=var_som_mx6_android_defconfig I thought that this command more or…
Michael Burr
  • 333,147
  • 50
  • 533
  • 760
31
votes
2 answers

How to create a defconfig file from a .config?

I have done make menuconfig for a board defconfig and modified few configurations. When I select save, a new .config was created in the Kernel top directory. I want to create new defconfig for this .config file created. Can I copy the .config as a…
user3693586
  • 1,227
  • 5
  • 18
  • 40
31
votes
2 answers

How to get the .config from a Linux kernel image?

I have a Linux kernel image in elf format and I want to find out what .config file was used to build this kernel. When I do an objdump of the image, I see a section called kernel_config_data that contains text but does not look like the config file.…
user2050283
  • 562
  • 1
  • 4
  • 9
24
votes
1 answer

How does kbuild actually work?

When i'm developing a linux driver, i've read about how to write linux kbuild makefile through this document I know kbuild system use makefile variables such as obj-y obj-m to determine what to build and how to build. But what i'm confused about is…
demonguy
  • 1,977
  • 5
  • 22
  • 34
22
votes
3 answers

How to use make and compile as C99?

I'm trying to compile a linux kernel module using a Makefile: obj-m += main.o all: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules clean: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean Which gives me: main.c:54:…
djTeller
  • 515
  • 2
  • 5
  • 14
18
votes
3 answers

What are the codes such as CC, LD and CC[M] output when compiling the Linux kernel?

While compiling Linux from scratch I realize that there are compile codes that appear while compiling. For example CC filename , LD filename, CC[M] filename. What do these codes mean?
Mike G
  • 4,829
  • 11
  • 47
  • 76
12
votes
3 answers

Adding support for menuconfig / Kconfig in my project

I am planning to add support for menuconfig in my project. The project is not associated with Linux kernel so, I have to write everything from scratch in menuconfig and Makefile. How do I add support for menuconfig and create Kconfig and make the…
user435739
10
votes
6 answers

Building an out-of-tree Linux kernel module in a separate object directory

I'm confronting the Linux kernel build system (Kbuild, kernel ≥2.6.28) with the directory structure and build system for a larger project. Our project contains an out-of-tree Linux kernel module, and our directory structure looks like this…
Gilles 'SO- stop being evil'
  • 104,111
  • 38
  • 209
  • 254
6
votes
1 answer

How to add a dependency on a generated source file in Kbuild?

Let generate_testapi.py be a script in my Linux kernel module's source tree, that ingests mymod_test.h and generates a interface source file toward userland (ioctl, debugfs, you name it), and lets name this $(obj)/mymod_test_interfaces.gen.c. In the…
datenwolf
  • 159,371
  • 13
  • 185
  • 298
5
votes
2 answers

U-Boot 2020.04: Probing SPI flash fails - Invalid bus 0 (err=-19)

I'm just compiled U-Boot 2020.04 for a PINE64 ROCK64 media board. It compiles fine without errors. But I run into an issue when I try to probe the SPI flash. The output from U-Boot command line: => sf probe Invalid bus 0 (err=-19) Failed to…
user10008009
5
votes
2 answers

cmake : specify linux kernel module output build directory

Here is my cmake to build linux kernle hello world module. if ( UNIX ) # Version number set ( DRV_MAJOR 1 ) set ( DRV_MINOR 0 ) set ( DRV_PATCH 0 ) set ( DRV_VERSION ${DRV_MAJOR}.${DRV_MINOR}.${DRV_PATCH} ) configure_file(…
Dmitry
  • 1,912
  • 2
  • 18
  • 29
5
votes
1 answer

Adding compile-time definitions in Kconfig in Linux kernel

I understand there is an option to add compile-time macros/definitions to the Kconfig file that can be used in the code. (For example, some definition of a constant, like a #define).
fashasha
  • 481
  • 2
  • 7
  • 19
5
votes
1 answer

Building an out-of-tree Linux kernel modules which share object files with exported symbols

Imagine a project, which needs to build two linux kernel modules, with the following layout of sources tree: modules/ |--common/ | `--common_data.c |--mod1/ | `--mod1_main.c `--mod2/ `--mod2_main.c The common_data.o object file needs to be…
Dima Chumak
  • 139
  • 1
  • 4
5
votes
2 answers

Debugging or verbose mode for Kconfig?

I'm working with a LeopardBoard DM368 and I want to enable some video hardware. The relevant modules are vpfe-capture, isif, and tvp7002. I've written a defconfig file with what I believe to be the correct set of CONFIG_FOO parameters for…
Will Ware
  • 475
  • 5
  • 17
4
votes
2 answers

Makefile variable substitution apparently not done even though := is used in declaration

I have a main kernel module with which other kernel modules communicate. I have structured the modules like this (conceptually): main module/ | \drivers/ | |\driver1 …
Shahbaz
  • 46,337
  • 19
  • 116
  • 182
1
2 3
9 10