make targets
make or make all builds the targets: vmlinux, bzImage and modules, see also the ./README file.
make help prints a summary of make targets:
Cleaning targets
clean | Remove most generated files but keep the .config and enough build support to build external modules |
mrproper | Remove all generated files, config and various backup files |
distclean | mrproper and remove editor backup and patch files |
Configuration targets
config | Update current config utilising a line-oriented («plain-text») program |
nconfig | Update current config utilising a ncurses menu based program (requires ncurses) |
menuconfig | Update current config utilising a menu based (menus, radiolists, dialogs) program: mconf, see scripts/kconfig/mconf.c. Requires ncurses. |
xconfig | Update current config utilising a Qt based front-end (qconf, see scripts/kconfig/qconf.cc) |
gconfig | Update current config utilising a GTK+ based front-end |
oldconfig | Update current config utilising a provided .config as base (Default all questions based on the contents of your existing ./.config file and asking about new config symbols.) |
olddefconfig | Same as oldconfig but sets new symbols to their default value without prompting |
defconfig | Creates a new configuration file (typically .config) with default values from arch/$SRCARCH/configs/defconfig or arch/$SRCARCH/configs/${PLATFORM}_defconfig, depending on the architecture. |
localmodconfig | Update current config disabling modules not loaded (lsmod) except those preserved by LMC_KEEP environment variable. Disables any module option that is not needed for the loaded modules. |
localyesconfig | Update current config converting local mods to core except those preserved by LMC_KEEP environment variable |
savedefconfig | Save current config as ./defconfig (minimal config) |
allnoconfig | New config where all options are answered with no (n) |
allyesconfig | New config where all options are accepted with yes (y) |
allmodconfig | New config selecting modules (answering with m) when possible |
alldefconfig | New config with all symbols set to default |
randconfig | New config with random answers to all options |
yes2modconfig | Change answers from yes to mod if possible |
mod2yesconfig | Change answers from mod to yes if possible |
mod2noconfig | Change answers from mod to no if possible |
listnewconfig | List new CONFIG options |
helpnewconfig | List new options and help text |
tinyconfig | Configure the tiniest possible kernel |
testconfig | Run Kconfig unit tests (requires python3 and pytest) |
${PLATFORM}_defconfig creates a ./.config file by using the default symbol values from arch/$ARCH/configs/${PLATFORM}_defconfig. Use make help to get a list of all available platforms of your architecture.
When executing
make with one of these targets, the executable
scripts/kconfig/conf is called with the corresponding command line option.
Generation of «identifier index files» for editors
tags | Generate tags file for editors. Requires ctags binary to be installed separately. |
TAGS | Generate tags file for editors. Requires etags binary to be installed separately. |
cscope | Generates a cscope index. Requires cscope binary to be installed separately. |
gtags | Generate GNU global index. Requires gtags binary to be installed separately. |
Other generic targets
all | Build vmlinux, modules and bzImage. |
vmlinux | Build the bare kernel (i. e. vmlinux). Compare with target bzImage. |
modules | Build all modules |
modules_install | Install all modules to INSTALL_MOD_PATH (default: /). This target essentially invokes make -f ./scripts/Makefile.modinst and ./scripts/depmod.sh depmod … |
dir/ | Build all files in dir and below |
dir/file.[ois] | Build specified target only |
dir/file.ll | Build the LLVM assembly file (requires compiler support for LLVM assembly generation) |
dir/file.lst | Build specified mixed source/assembly target only (requires a recent binutils and recent build (System.map)) |
dir/file.ko | Build module including final link |
modules_prepare | Set up for building external modules |
kernelrelease | Output the release version string (use with make -s) |
kernelversion | Output the version stored in Makefile (use with make -s) |
image_name | Output the image name (use with make -s) |
headers_install | Installs kernel headers to INSTALL_HDR_PATH (default: ./usr). The headers are sanitized to make them suitable for use by userspace programs. Requires rsync. See also scripts/headers_install.sh and Documentation/kbuild/headers_install.rst. |
headers | I learned about this target via Linux from scratch. Unlike the target headers_install, headers does not require rsync to be installed. |
Static analysers
checkstack | Generate a list of stack hogs |
versioncheck | Sanity check on version.h usage |
includecheck | Check for duplicate included header files |
export_report | List the usages of all exported symbols |
headerdep | Detect inclusion cycles in headers |
coccicheck | Check with Coccinelle |
clang-analyzer | Check with clang static analyzer |
clang-tidy | Check with clang-tidy |
Tools
nsdeps | Generate missing symbol namespace dependencies |
Kernel selftest
kselftest | Build and run kernel selftest Build, install, and boot kernel before running kselftest on it. Run as root for full coverage |
kselftest-all | Build kernel selftest |
kselftest-install | Build and install kernel selftest |
kselftest-clean | Remove all generated kselftest files |
kselftest-merge | Merge all the config dependencies of kselftest to existing .config. |
Rust targets
rustavailable | Checks whether the Rust toolchain is available and, if not, explains why. (make LLVM=1 rustavailable triggers the same logic used by Kconfig to determine whter RUST_IS_AVAILABLE should be enabled). |
rustfmt | Reformat all the Rust code in the kernel |
rustfmtcheck | Checks if all the Rust code in the kernel is formatted, printing a diff otherwise. |
rustdoc | Generate Rust documentation (requires kernel .config) |
rusttest | Runs the Rust tests (requires kernel .config; downloads external repos) |
rust-analyzer | Generate rust-project.json rust-analyzer support file (requires kernel .config) |
dir/file.[os] | Build specified target only |
dir/file.rsi | Build macro expanded source, similar to C preprocessing. Run with RUSTFMT=n to skip reformatting if needed. The output is not intended to be compilable. |
dir/file.ll | Build the LLVM assembly file |
Userspace tools targets
use make tools/help or cd tools; make help
Kernel packaging
rpm-pkg | Build both source and binary RPM kernel packages |
srcrpm-pkg | Build only the source kernel RPM package |
binrpm-pkg | Build only the binary kernel RPM package |
deb-pkg | Build both source and binary deb kernel packages |
srcdeb-pkg | Build only the source kernel deb package |
bindeb-pkg | Build only the binary kernel deb package |
snap-pkg | Build only the binary kernel snap package (will connect to external hosts) |
dir-pkg | Build the kernel as a plain directory structure |
tar-pkg | Build the kernel as an uncompressed tarball |
targz-pkg | Build the kernel as a gzip compressed tarball |
tarbz2-pkg | Build the kernel as a bzip2 compressed tarball |
tarxz-pkg | Build the kernel as a xz compressed tarball |
tarzst-pkg | Build the kernel as a zstd compressed tarball |
perf-tar-src-pkg | Build the perf source tarball with no compression |
perf-targz-src-pkg | Build the perf source tarball with gzip compression |
perf-tarbz2-src-pkg | Build the perf source tarball with bz2 compression |
perf-tarxz-src-pkg | Build the perf source tarball with xz compression |
perf-tarzst-src-pkg | Build the perf source tarball with zst compression |
Documentation targets
htmldocs | HTML |
texinfodocs | Texinfo |
infodocs | Info |
latexdocs | LaTeX |
pdfdocs | PDF |
epubdocs | EPUB |
xmldocs | XML |
linkcheckdocs | check for broken external links (will connect to external hosts) |
refcheckdocs | check for references to non-existing files under Documentation |
cleandocs | clean all generated files. Compare with make mrproper |
make SPHINXDIRS="s1 s2" [target] Generate only docs of folder s1, s2
valid values for SPHINXDIRS are: PCI RCU accel accounting admin-guide arch block bpf cdrom core-api cpu-freq crypto dev-tools devicetree doc-guide driver-api fault-injection fb filesystems firmware-guide fpga gpu hid hwmon i2c iio infiniband input isdn kbuild kernel-hacking leds livepatch locking loongarch maintainer mhi mips misc-devices mm netlabel networking pcmcia peci power powerpc process riscv rust s390 scheduler scsi security sound spi staging target timers tools trace translations usb userspace-api virt w1 watchdog wmi
make SPHINX_CONF={conf-file} [target]: use additional sphinx-build configuration. This is e.g. useful to build with nit-picking config.
make DOCS_THEME={sphinx-theme}: selects a different Sphinx theme.
make DOCS_CSS={a .css file}: adds a DOCS_CSS override file for html/epub output.
The default location for the generated documents is Documentation/output
Architecture specific targets (x86)
bzImage | Compressed kernel image (arch/x86/boot/bzImage). Compare with vmlinux |
install | Install kernel using (your) ~/bin/installkernel or (distribution) /sbin/installkernel or install to $(INSTALL_PATH) and run LILO |
fdimage | Create 1.4MB boot floppy image (arch/x86/boot/fdimage) |
fdimage144 | Create 1.4MB boot floppy image (arch/x86/boot/fdimage) |
fdimage288 | Create 2.8MB boot floppy image (arch/x86/boot/fdimage) |
hdimage | Create a BIOS/EFI hard disk image (arch/x86/boot/hdimage) |
isoimage | Create a boot CD-ROM image (arch/x86/boot/image.iso) |
kvm_guest.config | Enable Kconfig items for running this kernel as a KVM guest |
xen.config | Enable Kconfig items for running this kernel as a Xen guest |
x86_debug.config | Enable tip tree debugging options for testing. See also kernel/configs/x86_debug.config |
i386_defconfig | Build for i386 |
x86_64_defconfig | Build for x86_64 |
Targets bzdisk, fdimage*, hdimage and isoimage also accept: FDARGS="…" arguments and FDINITRD=file for the booted kernel
Others
Other, undocumented(?) targets include:
prepare | scripts/setlocalversion suggests to run make prepare if include/config/auto.conf does not exist. |
syncconfig | This target seems to eventually result in calling scripts/kconfig/conf --syncconfig Kconfig. (scripts/kconfig/Makefile notes that syncconfig has become an internal implementation detail and is deprecated for external use). TODO: Does syncconfig create include/config/auto.conf, include/config/tristate.conf, include/generated/autoconf.h and some (empty?) include/config/*.h files? |
scripts_gdb | Builds the gdb scripts (possibly related to config option CONFIG_GDB_SCRIPTS and the gdb directory under scripts/); seems to create the symbolic link vmlinux-gdb.py pointing to scripts/gdb/vmlinux-gdb.py |
scripts_basic | Likely related to the basic directory under scripts/ |
outputmakefile | Generates a Makefile in the output directory (if using a separately output directory) to conveniently use make in the output directory. |
Variables
KCONFIG_CONFIG
KCONFIG_CONFIG allows to specify a non-default config file (the default being
.config):
make KCONFIG_CONFIG=config-lean
V
make V=n [targets]
| 1 | verbose build - echoes the whole command line |
| 2 | give reason why target is rebuilt |
V=1 and V=2 can be combined with V=12
The value that was passed with V= is assigned to the KBUILD_VERBOSE variable in makefiles.
This macro can be used in makefiles to tell why a target got built.
C
Call a source code checker (named $CHECK) as part of the C compilation.
make C=1 [targets]
| 1 | Check re-compiled c source with $CHECK |
| 2 | Force check of all c source with $CHECK (regardless of whether they're re-compiled or not) |
The default of $CHECK is sparse.
Documentation/dev-tools/sparse.rst has more details on sparse.
The value that was passed with C= is assigned to the KBUILD_CHECKSRC variable in makefiles.
Sparse defines the the __CHECKER__ preprocessor symbol.
M
make M=… (or the environment variable KBUILD_EXTMOD) specifies the directory of external modules to build.
The value that was passed with V= is assigned to the KBUILD_EXTMOD variable in makefiles.
O
make O=dir [targets]: Locate all output files in dir, including .config
O (or the environment variable KBUILD_OUTPUT specifies the directory where output (= generated?) files will be saved.
By default, this directory is the current working directory.
The value that was passed with V= is assigned to the KBUILD_OUTPUT variable in makefiles.
W
make W=n [targets] - Enable extra build checks, value of n:
| 1 | warnings which may be relevant and do not occur too often |
| 2 | warnings which occur quite often but may still be relevant |
| 3 | more obscure warnings, can most likely be ignored |
| e | warnings are being treated as errors |
Multiple levels can be combined with W=12 or W=123
See also
scripts/Makefile.extrawarn.
ARCH
ARCH can be set for cross compiling and select a different set of gcc/bin-utils.
make ARCH=ia64
Note: ARCH (for example i386 or x86_64) is not necessarily the same as SRCARCH (x86 in these two cases).
See also the CROSS_COMPILE variable to set the prefix for executables used during compilation.
LLVM
make LLVM=1 …: builds the kernel with a complete LLVM toolchain (which is currently (Aug. 2023)) the best supported setup.
For architectures that don't suppert a full LLVM toolchain, make CC=clang … should be used.
CLIPPY
make CLIPPY=1 enables clippy (a linter) as part of the Rust compilation.
The value that was passed with C= is assigned to the KBUILD_CLIPPY variable in makefiles.
Others
make RECORDMCOUNT_WARN=1 [targets]: Warn about ignored mcount sections
make CLIPPY=1 … runs clippy (a Rust linter).
tools
Make and install a tool:
$ make -C tools <tool>_install
Creating a localmodconfig for another machine
To create a localmodconfig for another machine, store the lsmod of that machine into a file and pass it in as a LSMOD parameter.
Also, you can preserve modules in certain folders or kconfig files by specifying their paths in parameter LMC_KEEP.
target$ lsmod > /tmp/mylsmod
target$ scp /tmp/mylsmod host:/tmp
host$ make LSMOD=/tmp/mylsmod LMC_KEEP="drivers/usb:drivers/gpu:fs" localmodconfig
The above also works when cross compiling.
Kbuild output format
The Kbuild output has two components and is written with the following printf format: " %-7s %s\n", for example:
CC drivers/gpu/drm/virtio/virtgpu_ioctl.o
CC drivers/gpu/drm/virtio/virtgpu_prime.o
CC drivers/gpu/drm/virtio/virtgpu_trace_points.o
CC drivers/gpu/drm/virtio/virtgpu_submit.o
AR drivers/gpu/drm/virtio/built-in.a
TODO
As per a comment in kernel/configs/debug.config, make can be called with the two targets
make ARCH=arm64 defconfig debug.config
As per comment in tools/testing/selftest/Makefile:
make quicktest=1 run_tests
make quicktest=1 kselftest