-if test -z "$wrapper" ; then
-printf "checking whether compiler is gcc... "
-if fnmatch '*gcc\ version*' "$($CC -v 2>&1)" ; then
-echo yes
-printf "checking whether to build musl-gcc wrapper... "
-wrapper=yes
-while read line ; do
-case "$line" in */ld-musl-*) wrapper=no ;; esac
-done <<EOF
-$($CC -dumpspecs)
-EOF
-echo $wrapper
+tryflag CFLAGS_TRY -Werror=unknown-warning-option
+tryflag CFLAGS_TRY -Werror=unused-command-line-argument
+tryflag CFLAGS_TRY -Werror=ignored-optimization-argument
+tryldflag LDFLAGS_TRY -Werror=unknown-warning-option
+tryldflag LDFLAGS_TRY -Werror=unused-command-line-argument
+
+#
+# Need to know if the compiler is gcc or clang to decide which toolchain
+# wrappers to build.
+#
+printf "checking for C compiler family... "
+cc_ver="$(LC_ALL=C $CC -v 2>&1)"
+cc_family=unknown
+if fnmatch '*gcc\ version*' "$cc_ver" ; then
+cc_family=gcc
+elif fnmatch '*clang\ version*' "$cc_ver" ; then
+cc_family=clang
+fi
+echo "$cc_family"
+
+#
+# Figure out toolchain wrapper to build
+#
+if test "$wrapper" = auto || test "$wrapper" = detect ; then
+echo "#include <stdlib.h>" > "$tmpc"
+echo "#if ! __GLIBC__" >> "$tmpc"
+echo "#error no" >> "$tmpc"
+echo "#endif" >> "$tmpc"
+printf "checking for toolchain wrapper to build... "
+if test "$wrapper" = auto && ! $CC -c -o /dev/null "$tmpc" >/dev/null 2>&1 ; then
+echo "none"
+elif test "$cc_family" = gcc ; then
+gcc_wrapper=yes
+echo "gcc"
+elif test "$cc_family" = clang ; then
+clang_wrapper=yes
+echo "clang"