xref: /linux/Documentation/kbuild/bash-completion.rst (revision 1260ed77798502de9c98020040d2995008de10cc)
1.. SPDX-License-Identifier: GPL-2.0-only
2
3==========================
4Bash completion for Kbuild
5==========================
6
7The kernel build system is written using Makefiles, and Bash completion
8for the `make` command is available through the `bash-completion`_ project.
9
10However, the Makefiles for the kernel build are complex. The generic completion
11rules for the `make` command do not provide meaningful suggestions for the
12kernel build system, except for the options of the `make` command itself.
13
14To enhance completion for various variables and targets, the kernel source
15includes its own completion script at `scripts/bash-completion/make`.
16
17This script provides additional completions when working within the kernel tree.
18Outside the kernel tree, it defaults to the generic completion rules for the
19`make` command.
20
21Prerequisites
22=============
23
24The script relies on helper functions provided by `bash-completion`_ project.
25Please ensure it is installed on your system. On most distributions, you can
26install the `bash-completion` package through the standard package manager.
27
28How to use
29==========
30
31You can source the script directly::
32
33  $ source scripts/bash-completion/make
34
35Or, you can copy it into the search path for Bash completion scripts.
36For example::
37
38  $ mkdir -p ~/.local/share/bash-completion/completions
39  $ cp scripts/bash-completion/make ~/.local/share/bash-completion/completions/
40
41Details
42=======
43
44The additional completion for Kbuild is enabled in the following cases:
45
46 - You are in the root directory of the kernel source.
47 - You are in the top-level build directory created by the O= option
48   (checked via the `source` symlink pointing to the kernel source).
49 - The -C make option specifies the kernel source or build directory.
50 - The -f make option specifies a file in the kernel source or build directory.
51
52If none of the above are met, it falls back to the generic completion rules.
53
54The completion supports:
55
56  - Commonly used targets, such as `all`, `menuconfig`, `dtbs`, etc.
57  - Make (or environment) variables, such as `ARCH`, `LLVM`, etc.
58  - Single-target builds (`foo/bar/baz.o`)
59  - Configuration files (`*_defconfig` and `*.config`)
60
61Some variables offer intelligent behavior. For instance, `CROSS_COMPILE=`
62followed by a TAB displays installed toolchains. The list of defconfig files
63shown depends on the value of the `ARCH=` variable.
64
65.. _bash-completion: https://github.com/scop/bash-completion/
66