scripts/bash-completion/make

Source file repositories/reference/linux-study-clean/scripts/bash-completion/make

File Facts

System
Linux kernel
Corpus path
scripts/bash-completion/make
Extension
[no extension]
Size
11263 bytes
Lines
452
Domain
Support Tooling And Documentation
Bucket
scripts
Inferred role
Support Tooling And Documentation: scripts
Status
atlas-only

Why This File Exists

Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.

Dependency Surface

Detected Declarations

Annotated Snippet

# SPDX-License-Identifier: GPL-2.0-only
# bash completion for GNU make with kbuild extension       -*- shell-script -*-

# Load the default completion script for make. It is typically located at
# /usr/share/bash-completion/completions/make, but we do not rely on it.
__kbuild_load_default_make_completion()
{
	local -a dirs=("${BASH_COMPLETION_USER_DIR:-${XDG_DATA_HOME:-$HOME/.local/share}/bash-completion}/completions")
	local ifs=$IFS IFS=: dir compfile this_dir

	for dir in ${XDG_DATA_DIRS:-/usr/local/share:/usr/share}; do
	        dirs+=("$dir"/bash-completion/completions)
	done
	IFS=$ifs

	this_dir="$(realpath "$(dirname "${BASH_SOURCE[0]}")")"

	for dir in "${dirs[@]}"; do
		if [[ ! -d ${dir} || ${dir} = "${this_dir}" ]]; then
			continue
		fi

		for compfile in make make.bash _make; do
			compfile=$dir/$compfile
			# Avoid trying to source dirs; https://bugzilla.redhat.com/903540
			if [[ -f ${compfile} ]] && . "${compfile}" &>/dev/null; then

				__kbuild_default_make_completion=$(
					# shellcheck disable=SC2046 # word splitting is the point here
					set -- $(complete -p make)

					while [[ $# -gt 1 && "$1" != -F ]]; do
						shift
					done

					if [[ "$1" = -F ]]; then
						echo "$2"
					fi
				)

				return
			fi
		done
	done
}

__kbuild_load_default_make_completion

__kbuild_handle_variable()
{
	local var=${1%%=*}
	local cur=${cur#"${var}"=}
	local srctree=$2
	local keywords=()

	case $var in
	ARCH)
		# sub-directories under arch/
		keywords+=($(find "${srctree}/arch" -mindepth 1 -maxdepth 1 -type d -printf '%P\n'))
		# architectures hard-coded in the top Makefile
		keywords+=(i386 x86_64 sparc32 sparc64 parisc64)
		;;
	CROSS_COMPILE)
		# toolchains with a full path
		local cross_compile=()
		local c c2
		_filedir

		for c in "${COMPREPLY[@]}"; do
			# eval for tilde expansion

Annotation

Implementation Notes