m4: Add macro to check for OBJC specific compiler (warning) flags
authorSebastian Dröge <sebastian.droege@collabora.co.uk>
Wed, 30 May 2012 09:10:13 +0000 (11:10 +0200)
committerSebastian Dröge <sebastian.droege@collabora.co.uk>
Wed, 30 May 2012 09:11:21 +0000 (11:11 +0200)
See bug #643939.

m4/as-compiler-flag.m4
m4/as-objc.m4 [deleted file]
m4/gst-error.m4

index 882a4c7..8bb853a 100644 (file)
@@ -62,3 +62,35 @@ AC_DEFUN([AS_CXX_COMPILER_FLAG],
   AC_MSG_RESULT([$flag_ok])
 ])
 
+dnl AS_OBJC_COMPILER_FLAG(CPPFLAGS, ACTION-IF-ACCEPTED, [ACTION-IF-NOT-ACCEPTED])
+dnl Tries to compile with the given CPPFLAGS.
+dnl Runs ACTION-IF-ACCEPTED if the compiler can compile with the flags,
+dnl and ACTION-IF-NOT-ACCEPTED otherwise.
+
+AC_DEFUN([AS_OBJC_COMPILER_FLAG],
+[
+  AC_REQUIRE([AC_PROG_OBJC])
+
+  AC_MSG_CHECKING([to see if Objective C compiler understands $1])
+
+  save_CPPFLAGS="$CPPFLAGS"
+  CPPFLAGS="$CPPFLAGS $1"
+
+  AC_LANG_PUSH([Objective C])
+
+  AC_TRY_COMPILE([ ], [], [flag_ok=yes], [flag_ok=no])
+  CPPFLAGS="$save_CPPFLAGS"
+
+  if test "X$flag_ok" = Xyes ; then
+    $2
+    true
+  else
+    $3
+    true
+  fi
+
+  AC_LANG_POP([Objective C])
+
+  AC_MSG_RESULT([$flag_ok])
+])
+
diff --git a/m4/as-objc.m4 b/m4/as-objc.m4
deleted file mode 100644 (file)
index 1e7066a..0000000
+++ /dev/null
@@ -1,56 +0,0 @@
-
-
-# AC_PROG_OBJC([LIST-OF-COMPILERS])
-#
-AC_DEFUN([AS_PROG_OBJC],
-[
-AC_CHECK_TOOLS(OBJC,
-       [m4_default([$1], [objcc objc gcc cc CC])],
-       none)
-AC_SUBST(OBJC)
-OBJC_LDFLAGS="-lobjc"
-AC_SUBST(OBJC_LDFLAGS)
-if test "x$OBJC" != xnone ; then
-  _AM_DEPENDENCIES(OBJC)
-  AC_MSG_CHECKING([if Objective C compiler works])
-  cat >>conftest.m <<EOF
-#include <objc/Object.h>
-@interface Moo:Object
-{
-}
-- moo;
-int main();
-@end
-
-@implementation Moo
-- moo
-{
-  exit(0);
-}
-
-int main()
-{
-  id moo;
-  moo = [[Moo new]];
-  [[moo moo]];
-  return 1;
-}
-@end
-EOF
-  ${OBJC} conftest.m ${OBJC_LDFLAGS} >&5 2>&5
-  if test -f a.out -o -f a.exe ; then
-    result=yes
-  else
-    result=no
-    echo failed program is: >&5
-    cat conftest.m >&5
-  fi
-  rm -f conftest.m a.out a.exe
-  AC_MSG_RESULT([$result])
-else
-  _AM_DEPENDENCIES(OBJC)
-fi
-
-])
-
-
index f8f2364..d21e324 100644 (file)
@@ -196,6 +196,94 @@ AC_DEFUN([AG_GST_SET_ERROR_CXXFLAGS],
   AC_MSG_NOTICE([set ERROR_CXXFLAGS to $ERROR_CXXFLAGS])
 ])
 
+dnl Sets WARNING_OBJCFLAGS and ERROR_OBJCFLAGS to something the compiler 
+dnl will accept and AC_SUBST them so they are available in Makefile
+dnl
+dnl WARNING_OBJCFLAGS will contain flags to make the compiler emit more
+dnl   warnings.
+dnl ERROR_OBJCFLAGS will contain flags to make those warnings fatal,
+dnl   unless ADD-WERROR is set to "no"
+dnl 
+dnl If MORE_FLAGS is set, tries to add each of the given flags
+dnl to WARNING_CFLAGS if the compiler supports them. Each flag is 
+dnl tested separately.
+dnl
+dnl These flags can be overridden at make time:
+dnl make ERROR_OBJCFLAGS=
+AC_DEFUN([AG_GST_SET_ERROR_OBJCFLAGS],
+[
+  AC_REQUIRE([AC_PROG_OBJC])
+  AC_REQUIRE([AS_OBJC_COMPILER_FLAG])
+
+  ERROR_OBJCFLAGS=""
+  WARNING_OBJCFLAGS=""
+
+  dnl if we support -Wall, set it unconditionally
+  AS_OBJC_COMPILER_FLAG(-Wall, WARNING_OBJCFLAGS="$WARNING_OBJCFLAGS -Wall")
+
+  dnl if asked for, add -Werror if supported
+  if test "x$1" != "xno"
+  then
+    AS_OBJC_COMPILER_FLAG(-Werror, ERROR_OBJCFLAGS="$ERROR_OBJCFLAGS -Werror")
+
+    if test "x$ERROR_OBJCFLAGS" != "x"
+    then
+        dnl add exceptions
+        AS_OBJC_COMPILER_FLAG([-Wno-non-virtual-dtor], ERROR_OBJCFLAGS="$ERROR_OBJCFLAGS -Wno-non-virtual-dtor")
+
+       dnl Add -fno-strict-aliasing for GLib versions before 2.19.8
+       dnl as before G_LOCK and friends caused strict aliasing compiler
+       dnl warnings.
+       PKG_CHECK_EXISTS([glib-2.0 < 2.19.8], [
+         AS_OBJC_COMPILER_FLAG([-fno-strict-aliasing],
+           ERROR_OBJCFLAGS="$ERROR_OBJCFLAGS -fno-strict-aliasing")
+         ])
+    else
+      dnl if -Werror isn't suported, try -errwarn=%all
+      AS_OBJC_COMPILER_FLAG([-errwarn=%all], ERROR_OBJCFLAGS="$ERROR_OBJCFLAGS -errwarn=%all")
+      if test "x$ERROR_OBJCFLAGS" != "x"; then
+        dnl try -errwarn=%all,no%E_EMPTY_DECLARATION,
+        dnl no%E_STATEMENT_NOT_REACHED,no%E_ARGUEMENT_MISMATCH,
+        dnl no%E_MACRO_REDEFINED (Sun Forte case)
+        dnl For Forte we need disable "empty declaration" warning produced by un-needed semicolon
+        dnl "statement not reached" disabled because there is g_assert_not_reached () in some places
+        dnl "macro redefined" because of gst/gettext.h
+        dnl FIXME: is it really supposed to be 'ARGUEMENT' and not 'ARGUMENT'?
+        dnl FIXME: do any of these work with the c++ compiler? if not, why
+        dnl do we check at all?
+        for f in 'no%E_EMPTY_DECLARATION' \
+                 'no%E_STATEMENT_NOT_REACHED' \
+                 'no%E_ARGUEMENT_MISMATCH' \
+                 'no%E_MACRO_REDEFINED' \
+                 'no%E_LOOP_NOT_ENTERED_AT_TOP'
+        do
+          AS_OBJC_COMPILER_FLAG([-errwarn=%all,$f], ERROR_OBJCFLAGS="$ERROR_OBJCFLAGS,$f")
+        done
+      fi
+    fi
+  fi
+
+  if test "x$2" != "x"
+  then
+    UNSUPPORTED=""
+    list="$2"
+    for each in $list
+    do
+      AS_OBJC_COMPILER_FLAG($each,
+          WARNING_OBJCFLAGS="$WARNING_OBJCFLAGS $each",
+          UNSUPPORTED="$UNSUPPORTED $each")
+    done
+    if test "X$UNSUPPORTED" != X ; then
+      AC_MSG_NOTICE([unsupported compiler flags: $UNSUPPORTED])
+    fi
+  fi
+
+  AC_SUBST(WARNING_OBJCFLAGS)
+  AC_SUBST(ERROR_OBJCFLAGS)
+  AC_MSG_NOTICE([set WARNING_OBJCFLAGS to $WARNING_OBJCFLAGS])
+  AC_MSG_NOTICE([set ERROR_OBJCFLAGS to $ERROR_OBJCFLAGS])
+])
+
 dnl Sets the default error level for debugging messages
 AC_DEFUN([AG_GST_SET_LEVEL_DEFAULT],
 [