| 1 |
.. SPDX-License-Identifier: GPL-2.0-only |
| 2 |
|
| 3 |
========================== |
| 4 |
Bash completion for Kbuild |
| 5 |
========================== |
| 6 |
|
| 7 |
The kernel build system is written using Makefiles, and Bash completion |
| 8 |
for the `make` command is available through the `bash-completion`_ project. |
| 9 |
|
| 10 |
However, the Makefiles for the kernel build are complex. The generic completion |
| 11 |
rules for the `make` command do not provide meaningful suggestions for the |
| 12 |
kernel build system, except for the options of the `make` command itself. |
| 13 |
|
| 14 |
To enhance completion for various variables and targets, the kernel source |
| 15 |
includes its own completion script at `scripts/bash-completion/make`. |
| 16 |
|
| 17 |
This script provides additional completions when working within the kernel tree. |
| 18 |
Outside the kernel tree, it defaults to the generic completion rules for the |
| 19 |
`make` command. |
| 20 |
|
| 21 |
Prerequisites |
| 22 |
============= |
| 23 |
|
| 24 |
The script relies on helper functions provided by `bash-completion`_ project. |
| 25 |
Please ensure it is installed on your system. On most distributions, you can |
| 26 |
install the `bash-completion` package through the standard package manager. |
| 27 |
|
| 28 |
How to use |
| 29 |
========== |
| 30 |
|
| 31 |
You can source the script directly:: |
| 32 |
|
| 33 |
$ source scripts/bash-completion/make |
| 34 |
|
| 35 |
Or, you can copy it into the search path for Bash completion scripts. |
| 36 |
For example:: |
| 37 |
|
| 38 |
$ mkdir -p ~/.local/share/bash-completion/completions |
| 39 |
$ cp scripts/bash-completion/make ~/.local/share/bash-completion/completions/ |
| 40 |
|
| 41 |
Details |
| 42 |
======= |
| 43 |
|
| 44 |
The 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 |
|
| 52 |
If none of the above are met, it falls back to the generic completion rules. |
| 53 |
|
| 54 |
The 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 |
|
| 61 |
Some variables offer intelligent behavior. For instance, `CROSS_COMPILE=` |
| 62 |
followed by a TAB displays installed toolchains. The list of defconfig files |
| 63 |
shown depends on the value of the `ARCH=` variable. |
| 64 |
|
| 65 |
.. _bash-completion: https://github.com/scop/bash-completion/ |