From: Sitsofe Wheeler Date: Sat, 23 Sep 2017 21:48:12 +0000 (+0100) Subject: configure: update compiler probing X-Git-Tag: fio-3.2~45^2 X-Git-Url: https://git.kernel.dk/?p=fio.git;a=commitdiff_plain;h=b73af7389a47bb04d841d749eb8a4e996eb5a271;hp=5580d200d7ae49cdb4f30913e3ef2d74e431ff60;ds=sidebyside configure: update compiler probing - Allow clang to be always guessable as a fallback compiler after gcc. This increases the likelihood we have a compiler when one wasn't explicitly set before we search through #define definitions to guess what platform we're targeting. The fallback can be overridden later (e.g. to prefer clang above other fallbacks on specific platforms). - Add comments to explain the preferred compiler search (inspired by comments in QEMU's ./configure). - Change from only checking $CC to also checking $cross_prefix before overriding. - Switch from setting CC to setting cc when overriding. This fixes the case where cc is "gcc" but CC is "i686-w64-mingw32-gcc" on Cygwin64 when building a 32 bit fio. - Because it is now possible for no compiler to be set, bail out with an explicit error message if we find this is the case. - Add macOS/Darwin to the platforms that prefer clang as the fallback compiler. - Minor refactoring. Signed-off-by: Sitsofe Wheeler --- diff --git a/configure b/configure index cefd6103..749cb1fb 100755 --- a/configure +++ b/configure @@ -225,7 +225,20 @@ if test "$show_help" = "yes" ; then fi cross_prefix=${cross_prefix-${CROSS_COMPILE}} -cc="${CC-${cross_prefix}gcc}" +# Preferred compiler (can be overriden later after we know the platform): +# ${CC} (if set) +# ${cross_prefix}gcc (if cross-prefix specified) +# gcc if available +# clang if available +if test -z "${CC}${cross_prefix}"; then + if has gcc; then + cc=gcc + elif has clang; then + cc=clang + fi +else + cc="${CC-${cross_prefix}gcc}" +fi if check_define __ANDROID__ ; then targetos="Android" @@ -301,16 +314,16 @@ SunOS) CYGWIN*) # We still force some options, so keep this message here. echo "Forcing some known good options on Windows" - if test -z "$CC" ; then + if test -z "${CC}${cross_prefix}"; then if test ! -z "$build_32bit_win" && test "$build_32bit_win" = "yes"; then - CC="i686-w64-mingw32-gcc" + cc="i686-w64-mingw32-gcc" if test -e "../zlib/contrib/vstudio/vc14/x86/ZlibStatReleaseWithoutAsm/zlibstat.lib"; then echo "Building with zlib support" output_sym "CONFIG_ZLIB" echo "LIBS=../zlib/contrib/vstudio/vc14/x86/ZlibStatReleaseWithoutAsm/zlibstat.lib" >> $config_host_mak fi else - CC="x86_64-w64-mingw32-gcc" + cc="x86_64-w64-mingw32-gcc" if test -e "../zlib/contrib/vstudio/vc14/x64/ZlibStatReleaseWithoutAsm/zlibstat.lib"; then echo "Building with zlib support" output_sym "CONFIG_ZLIB" @@ -340,11 +353,24 @@ CYGWIN*) tls_thread="yes" static_assert="yes" ipv6="yes" - echo "CC=$CC" >> $config_host_mak echo "BUILD_CFLAGS=$CFLAGS -I../zlib -include config-host.h -D_GNU_SOURCE" >> $config_host_mak ;; esac +# Now we know the target platform we can have another guess at the preferred +# compiler when it wasn't explictly set +if test -z "${CC}${cross_prefix}"; then + if test "$targetos" = "FreeBSD" || test "$targetos" = "Darwin"; then + if has clang; then + cc=clang + fi + fi +fi +if test -z "$cc"; then + echo "configure: failed to find compiler" + exit 1 +fi + if test ! -z "$cpu" ; then # command line argument : @@ -415,18 +441,6 @@ case "$cpu" in ;; esac -if test -z "$CC" ; then - if test "$targetos" = "FreeBSD"; then - if has clang; then - CC=clang - else - CC=gcc - fi - fi -fi - -cc="${CC-${cross_prefix}gcc}" - ########################################## # check cross compile