Skip to content

Commit

Permalink
toolchain-funcs.eclass: Add helpful tc-is-{gcc,clang} wrappers
Browse files Browse the repository at this point in the history
  • Loading branch information
mgorny committed Jun 26, 2016
1 parent 2fea606 commit 6984a5b
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
28 changes: 28 additions & 0 deletions eclass/tests/toolchain-funcs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,41 @@ export CC=gcc
)
tend $?

tbegin "tc-is-gcc (gcc)"
(
export CC=gcc
tc-is-gcc
)
tend $?

tbegin "! tc-is-clang (gcc)"
(
export CC=gcc
! tc-is-clang
)
tend $?

if type -P clang &>/dev/null; then
tbegin "tc-get-compiler-type (clang)"
(
export CC=clang
[[ $(tc-get-compiler-type) == clang ]]
)
tend $?

tbegin "! tc-is-gcc (clang)"
(
export CC=clang
! tc-is-gcc
)
tend $?

tbegin "tc-is-clang (clang)"
(
export CC=clang
tc-is-clang
)
tend $?
fi

if type -P pathcc &>/dev/null; then
Expand Down
12 changes: 12 additions & 0 deletions eclass/toolchain-funcs.eclass
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,18 @@ tc-get-compiler-type() {
esac
}

# @FUNCTION: tc-is-gcc
# @RETURN: Shell true if the current compiler is GCC, false otherwise.
tc-is-gcc() {
[[ $(tc-get-compiler-type) == gcc ]]
}

# @FUNCTION: tc-is-clang
# @RETURN: Shell true if the current compiler is clang, false otherwise.
tc-is-clang() {
[[ $(tc-get-compiler-type) == clang ]]
}

# Internal func. The first argument is the version info to expand.
# Query the preprocessor to improve compatibility across different
# compilers rather than maintaining a --version flag matrix. #335943
Expand Down

0 comments on commit 6984a5b

Please sign in to comment.