2011-11-01 22:14:45 +02:00
|
|
|
# gcc(1) completion -*- shell-script -*-
|
2009-06-05 21:41:31 +02:00
|
|
|
#
|
|
|
|
# The only unusual feature is that we don't parse "gcc --help -v" output
|
|
|
|
# directly, because that would include the options of all the other backend
|
|
|
|
# tools (linker, assembler, preprocessor, etc) without any indication that
|
|
|
|
# you cannot feed such options to the gcc driver directly. (For example, the
|
|
|
|
# linker takes a -z option, but you must type -Wl,-z for gcc.) Instead, we
|
|
|
|
# ask the driver ("g++") for the name of the compiler ("cc1"), and parse the
|
|
|
|
# --help output of the compiler.
|
2009-10-01 20:54:51 +03:00
|
|
|
|
2009-06-05 21:41:31 +02:00
|
|
|
_gcc()
|
|
|
|
{
|
2011-04-20 17:02:27 +03:00
|
|
|
local cur prev words cword
|
|
|
|
_init_completion || return
|
2009-06-05 21:41:31 +02:00
|
|
|
|
2009-10-04 19:42:50 +02:00
|
|
|
_expand || return 0
|
2009-06-05 21:41:31 +02:00
|
|
|
|
2011-04-20 17:02:27 +03:00
|
|
|
local cc backend
|
|
|
|
|
2009-12-30 00:39:59 +01:00
|
|
|
case $1 in
|
2009-10-04 19:42:50 +02:00
|
|
|
gcj)
|
|
|
|
backend=jc1
|
|
|
|
;;
|
|
|
|
gpc)
|
|
|
|
backend=gpc1
|
|
|
|
;;
|
|
|
|
*77)
|
|
|
|
backend=f771
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
backend=cc1 # (near-)universal backend
|
|
|
|
;;
|
|
|
|
esac
|
2009-06-05 21:41:31 +02:00
|
|
|
|
2009-10-04 19:42:50 +02:00
|
|
|
if [[ "$cur" == -* ]]; then
|
add_members, bk, gcc, mtx, munin-run, munindoc, mutt, p4, portinstall, postmap, ri, ypmatch: Avoid stderr spewage when needed commands/dirs are not available.
2011-10-22 11:48:23 +03:00
|
|
|
cc=$( $1 -print-prog-name=$backend 2>/dev/null )
|
|
|
|
[[ $cc ]] || return
|
2009-10-04 19:42:50 +02:00
|
|
|
# sink stderr:
|
|
|
|
# for C/C++/ObjectiveC it's useless
|
|
|
|
# for FORTRAN/Java it's an error
|
|
|
|
COMPREPLY=( $( compgen -W "$( $cc --help 2>/dev/null | \
|
|
|
|
tr '\t' ' ' | \
|
|
|
|
sed -e '/^ *-/!d' -e 's/ *-\([^ ]*\).*/-\1/' | \
|
|
|
|
sort -u )" -- "$cur" ) )
|
|
|
|
else
|
|
|
|
_filedir
|
|
|
|
fi
|
2009-06-05 21:41:31 +02:00
|
|
|
} &&
|
2011-12-20 00:36:39 +02:00
|
|
|
complete -F _gcc gcc g++ g77 gcj gpc &&
|
|
|
|
{
|
|
|
|
cc --version 2>/dev/null | grep -q GCC && complete -F _gcc cc || :
|
|
|
|
c++ --version 2>/dev/null | grep -q GCC && complete -F _gcc c++ || :
|
|
|
|
}
|
2009-10-01 20:54:51 +03:00
|
|
|
|
2009-10-04 19:42:50 +02:00
|
|
|
# ex: ts=4 sw=4 et filetype=sh
|