# 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
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
# suppress error, as this fails when it contains a space
eval "c2=${c}"2>/dev/null || continue if [[ ${c} == *-elfedit && ! -d ${c2} && -x ${c2} ]]; then
cross_compile+=("${c%elfedit}")
fi
done
# toolchains in the PATH environment while read -r c; do if [[ ${c} == *-elfedit ]]; then
keywords+=("${c%elfedit}")
fi
done < <(compgen -c)
COMPREPLY=()
_filedir -d
# Add cross_compile directly without passing it to compgen.
# Otherwise, toolchain paths with a tilde do not work.
# e.g.)
# CROSS_COMPILE=~/0day/gcc-14.2.0-nolibc/aarch64-linux/bin/aarch64-linux-
COMPREPLY+=("${cross_compile[@]}")
;;
LLVM)
# LLVM=1 uses the default'clang' etc.
keywords+=(1)
# suffix for a particular version. LLVM=-18 uses 'clang-18' etc. while read -r c; do if [[ ${c} == clang-[0-9]* ]]; then
keywords+=("${c#clang}")
fi
done < <(compgen -c)
# directory path to LLVM toolchains
_filedir -d
;;
KCONFIG_ALLCONFIG)
# KCONFIG_ALLCONFIG=1 selects the default fragment
keywords+=(1)
# or the path to a fragment file
_filedir
;;
C | KBUILD_CHECKSRC)
keywords+=(12)
;;
V | KBUILD_VERBOSE)
keywords+=({,1}{,2})
;;
W | KBUILD_EXTRA_WARN)
keywords+=({,1}{,2}{,3}{,c}{,e})
;;
KBUILD_ABS_SRCTREE | KBUILD_MODPOST_NOFINAL | KBUILD_MODPOST_WARN | \
CLIPPY | KBUILD_CLIPPY | KCONFIG_NOSILENTUPDATE | \
KCONFIG_OVERWRITECONFIG | KCONFIG_WARN_UNKNOWN_SYMBOL | \
KCONFIG_WERROR )
keywords+=(1)
;;
INSTALL_MOD_STRIP)
keywords+=(1 --strip-debug --strip-unneeded)
;;
O | KBUILD_OUTPUT | M | KBUILD_EXTMOD | MO | KBUILD_EXTMOD_OUTPUT | *_PATH)
# variables that take a directory.
_filedir -d return
;;
KBUILD_EXTRA_SYMBOL | KBUILD_KCONFIG | KCONFIG_CONFIG)
# variables that take a file.
_filedir return
esac
# Check the -C, -f options and 'source' symlink. Return the source tree we are
# working in.
__kbuild_get_srctree()
{
local words=("$@")
local cwd makef_dir
# see if a path was specified with -C/--directory for ((i = 1; i < ${#words[@]}; i++)); do if [[ ${words[i]} == -@(C|-directory) ]]; then
# eval for tilde expansion.
# suppress error, as this fails when it contains a space
eval "cwd=${words[i + 1]}"2>/dev/null break
fi
done
if [[ -z ${cwd} ]]; then
cwd=.
fi
# see if a Makefile was specified with -f/--file/--makefile for ((i = 1; i < ${#words[@]}; i++)); do if [[ ${words[i]} == -@(f|-?(make)file) ]]; then
# eval for tilde expansion
# suppress error, as this fails when it contains a space
eval "makef_dir=${words[i + 1]%/*}" 2>/dev/null break
fi
done
if [ -z "${makef_dir}" ]; then
makef_dir=${cwd}
elif [[ ${makef_dir} != /* ]]; then makef_dir=${cwd}/${makef_dir} fi
#If${makef_dir}isabuilddirectorycreatedbytheO=option,there #isasymboliclink'source',whichpointstothekernelsourcetree. if[[-L${makef_dir}/source]];then makef_dir=$(readlink"${makef_dir}/source") fi
#If'kernel'and'Documentation'directoriesarefound,weassumethis #isakerneltree.Otherwise,wefallbacktothegenericruleprovided #bythebash-completionproject. if[[!-d${srctree}/kernel||!-d${srctree}/Documentation]];then if[-n"${__kbuild_default_make_completion}"];then "${__kbuild_default_make_completion}""$@" fi return fi
if [[ ${cur} != /* && ${cur} != *//* ]]; then localdirsrcarchkbuild_filetmp srcarch=$(__kbuild_get_srcarch"${words[@]}")
#singlebuild dir=${cur} whiletrue;do
if [[ ${dir} == */* ]]; then
dir=${dir%/*} else dir=. fi
#Searchfor'Kbuild'or'Makefile'intheparent #directories(maynotbeadirectparent) if[[-f${srctree}/${dir}/Kbuild]];then kbuild_file=${srctree}/${dir}/Kbuild break fi if[[-f${srctree}/${dir}/Makefile]];then kbuild_file=${srctree}/${dir}/Makefile break fi
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.