]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
configure: check if C compiler works
authorMiroslav Lichvar <mlichvar@redhat.com>
Thu, 17 Sep 2015 11:51:18 +0000 (13:51 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Thu, 17 Sep 2015 13:57:48 +0000 (15:57 +0200)
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

index 4497053c3f5777179aefe43b6abcbf1c35015710..92ee06374494edd7a5a97fcf6de7fd47ece86d0d 100755 (executable)
--- a/configure
+++ b/configure
 
 # 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];'