From 3cd32ed660dc0cc3ab655086130f225010c88bee Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Thu, 17 Sep 2015 13:51:18 +0200 Subject: [PATCH] configure: check if C compiler works Check if the C compiler works to get a useful error message when it doesn't or it's missing. If the CC environment variable is not set, try gcc and then cc. --- configure | 49 +++++++++++++++++++++++++++++-------------------- 1 file changed, 29 insertions(+), 20 deletions(-) diff --git a/configure b/configure index 4497053..92ee063 100755 --- a/configure +++ b/configure @@ -10,26 +10,6 @@ # This configure script determines the operating system type and version -if [ "x${CC}" = "x" ]; then - MYCC="gcc" -else - MYCC="${CC}" -fi - -if [ "x${CFLAGS}" = "x" ]; then - MYCFLAGS="-O2 -g" -else - MYCFLAGS="${CFLAGS}" -fi - -MYCPPFLAGS="${CPPFLAGS}" - -if [ "x${MYCC}" = "xgcc" ]; then - MYCFLAGS="${MYCFLAGS} -Wmissing-prototypes -Wall" -fi - -MYLDFLAGS="${LDFLAGS}" - # ====================================================================== # FUNCTIONS @@ -449,6 +429,35 @@ if [ $feat_refclock = "1" ]; then EXTRA_OBJECTS="$EXTRA_OBJECTS refclock.o refclock_phc.o refclock_pps.o refclock_shm.o refclock_sock.o" fi +MYCC="$CC" +MYCFLAGS="$CFLAGS" +MYCPPFLAGS="$CPPFLAGS" +MYLDFLAGS="$LDFLAGS" + +if [ "x$MYCC" = "x" ]; then + MYCC=gcc + if ! test_code "$MYCC" '' '' '' ''; then + MYCC=cc + if ! test_code "$MYCC" '' '' '' ''; then + echo "error: no C compiler found" + exit 1 + fi + fi +else + if ! test_code "$MYCC" '' '' '' ''; then + echo "error: C compiler $MYCC cannot create executables" + exit 1 + fi +fi + +if [ "x$MYCFLAGS" = "x" ]; then + MYCFLAGS="-O2 -g" +fi + +if [ "x$MYCC" = "xgcc" ]; then + MYCFLAGS="$MYCFLAGS -Wmissing-prototypes -Wall" +fi + if test_code '64-bit time_t' 'time.h' '' '' ' char x[sizeof(time_t) > 4 ? 1 : -1] = {0}; return x[0];'