as-compiler-flag.m4 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. dnl as-compiler-flag.m4 0.1.0
  2. dnl autostars m4 macro for detection of compiler flags
  3. dnl David Schleef <ds@schleef.org>
  4. dnl $Id: as-compiler-flag.m4,v 1.1 2005/12/15 23:35:19 ds Exp $
  5. dnl AS_COMPILER_FLAG(CFLAGS, ACTION-IF-ACCEPTED, [ACTION-IF-NOT-ACCEPTED])
  6. dnl Tries to compile with the given CFLAGS.
  7. dnl Runs ACTION-IF-ACCEPTED if the compiler can compile with the flags,
  8. dnl and ACTION-IF-NOT-ACCEPTED otherwise.
  9. AC_DEFUN([AS_COMPILER_FLAG],
  10. [
  11. AC_MSG_CHECKING([to see if compiler understands $1])
  12. save_CFLAGS="$CFLAGS"
  13. CFLAGS="$CFLAGS $1"
  14. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],[])], [flag_ok=yes], [flag_ok=no])
  15. CFLAGS="$save_CFLAGS"
  16. if test "X$flag_ok" = Xyes ; then
  17. m4_ifvaln([$2],[$2])
  18. true
  19. else
  20. m4_ifvaln([$3],[$3])
  21. true
  22. fi
  23. AC_MSG_RESULT([$flag_ok])
  24. ])
  25. dnl AS_COMPILER_FLAGS(VAR, FLAGS)
  26. dnl Tries to compile with the given CFLAGS.
  27. AC_DEFUN([AS_COMPILER_FLAGS],
  28. [
  29. list=$2
  30. flags_supported=""
  31. flags_unsupported=""
  32. AC_MSG_CHECKING([for supported compiler flags])
  33. for each in $list
  34. do
  35. save_CFLAGS="$CFLAGS"
  36. CFLAGS="$CFLAGS $each"
  37. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],[])], [flag_ok=yes], [flag_ok=no])
  38. CFLAGS="$save_CFLAGS"
  39. if test "X$flag_ok" = Xyes ; then
  40. flags_supported="$flags_supported $each"
  41. else
  42. flags_unsupported="$flags_unsupported $each"
  43. fi
  44. done
  45. AC_MSG_RESULT([$flags_supported])
  46. if test "X$flags_unsupported" != X ; then
  47. AC_MSG_WARN([unsupported compiler flags: $flags_unsupported])
  48. fi
  49. $1="$$1 $flags_supported"
  50. ])