More gcc flags via configure.ac (copied from xscreensaver)
authorJoachim Breitner <mail@joachim-breitner.de>
Sat, 12 Dec 2009 21:03:25 +0000 (22:03 +0100)
committerJoachim Breitner <mail@joachim-breitner.de>
Sat, 12 Dec 2009 21:03:25 +0000 (22:03 +0100)
configure.ac

index 6f0d58e..bb6a049 100644 (file)
@@ -98,7 +98,110 @@ AC_SUBST(HACK_CONF_DIR)
 
 
 # Checks for programs.
+
+###############################################################################
+#
+#       Function to figure out how to run the compiler.
+#
+###############################################################################
+
+AC_DEFUN(AC_PROG_CC_ANSI,
+ [AC_PROG_CC
+
+  if test -z "$GCC"; then
+    # not using GCC
+    AC_MSG_CHECKING(how to request ANSI compilation)
+    case "$host" in
+      *-hpux* )
+        AC_MSG_RESULT(HPUX: adding -Ae)
+        CC="$CC -Ae"
+      ;;
+      *-aix* )
+        AC_MSG_RESULT(AIX: adding -qlanglvl=ansi -qhalt=e)
+        CC="$CC -qlanglvl=ansi -qhalt=e"
+      ;;
+      *-dec-* )
+        AC_MSG_RESULT(DEC: adding -std1 -ieee)
+        CC="$CC -std1"
+      ;;
+      *)
+        AC_MSG_RESULT(no idea)
+      ;;
+    esac
+  else
+    # using GCC
+    case "$host" in
+      *-solaris*)
+        AC_MSG_RESULT(Solaris: adding -D__EXTENSIONS__)
+        CC="$CC -D__EXTENSIONS__"
+      ;;
+    esac
+  fi
+
+  OBJCC="$CC"
+
+  AC_MSG_CHECKING([whether the compiler works on ANSI C])
+  AC_TRY_RUN([ main(int ac, char **av) { return 0; } ],
+     AC_MSG_RESULT(yes),
+     AC_MSG_RESULT(no)
+     AC_MSG_ERROR(Couldn't build even a trivial ANSI C program: check CC.),
+     AC_MSG_ERROR(Couldn't build even a trivial ANSI C program: check CC.))
+
+  if test -n "$GCC"; then
+    AC_MSG_RESULT(Turning on gcc compiler warnings.)
+    CC="$CC -pedantic -Wall -Wstrict-prototypes -Wnested-externs -Wmissing-prototypes"
+    OBJCC="$OBJCC -Wall"
+    # As of gcc 3.4, we have "-Wdeclaration-after-statement"
+    # and so perhaps now we can do without -pedantic?
+  else
+    case "$host" in
+      *-irix5* |*-irix6.[0-3]* )
+        AC_MSG_RESULT(Turning on SGI compiler warnings.)
+        CC="$CC -fullwarn -use_readonly_const -rdata_shared -g3"
+      ;;
+#     *-dec-osf* )
+#       if test -z "$GCC"; then
+#         AC_MSG_RESULT(Turning on DEC C compiler warnings.)
+#         CC="$CC -migrate -w0 -verbose -warnprotos"
+#       fi
+#     ;;
+    esac
+  fi
+])
+
+###############################################################################
+#
+#       Check for availability of various gcc command-line options.
+#
+###############################################################################
+
+AC_DEFUN(AC_CHECK_GCC_ARG,
+ [if test -n "$GCC"; then
+   AC_CACHE_CHECK([whether gcc accepts [$2]],
+     ac_cv_gcc_accepts_[$1],
+    [rm -rf conftest.$ac_ext
+     touch conftest.$ac_ext
+     if ( ( gcc -c [$2] conftest.$ac_ext -o/dev/null >/dev/null ) 2>&1 | \
+          grep unrecognized >/dev/null ); then
+       ac_cv_gcc_accepts_[$1]=no
+     else
+       ac_cv_gcc_accepts_[$1]=yes
+       CC="$CC [$2]"
+     fi])
+   ac_gcc_accepts_[$1]="$ac_cv_gcc_accepts_[$1]"
+  fi
+])
+
+AC_DEFUN(AC_NO_LONG_STRING_WARNINGS,
+         [AC_CHECK_GCC_ARG(no_overlength, -Wno-overlength-strings)])
+
+AC_DEFUN(AC_NO_MISPLACED_DECLARATIONS,
+         [AC_CHECK_GCC_ARG(no_decl_after, -Wdeclaration-after-statement)])
+
 AC_PROG_CC
+AC_PROG_CC_ANSI
+AC_NO_LONG_STRING_WARNINGS
+AC_NO_MISPLACED_DECLARATIONS
 AC_PROG_INSTALL
 AC_PROG_MAKE_SET