[PATCH util-macros 1/1] Add XORG_PROJECT_ALL_CFLAGS for X.Org project compiler options

Gaetan Nadon memsize at videotron.ca
Fri Mar 5 07:38:22 PST 2010


This macro is defined as containing a set of required compiler options for
all X.Org modules, including xserver, libraries, drivers, fonts and apps.
Additional compiler options are added locally by the each module.

These options are set in each module makefile like this:
AM_CFLAGS = $(PROJECT_ALL_CFLAGS) ...
See Automake 27.6 Flag Variables Ordering.

All Makefile.am should have it for C code targets for the following reasons:
 - Provides a hook for an emergency system fix due to compiler behavior change
 - Allow for an easy way to experiment various compiler options on the system
   on a private local build
 - Implement project wide policies such as warning flags

As an organizing principle, this macro does not contain discrete compiler
options but rather aggregates macros containing options based on
their categories.

Backward compatibility: the variable CWARNFLAGS is still available for older
modules using it. Modules requesting version 1.7.0 or higher
should not use it.

Signed-off-by: Gaetan Nadon <memsize at videotron.ca>
---
 xorg-macros.m4.in |  171 +++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 165 insertions(+), 6 deletions(-)

diff --git a/xorg-macros.m4.in b/xorg-macros.m4.in
index 478e5fe..79de080 100644
--- a/xorg-macros.m4.in
+++ b/xorg-macros.m4.in
@@ -36,6 +36,8 @@ dnl DEALINGS IN THE SOFTWARE.
 #
 # See the "minimum version" comment for each macro you use to see what 
 # version you require.
+# "xorg_macros_needed" is required by XORG_PROJECT_ALL_CFLAGS related macros
+#
 m4_defun([XORG_MACROS_VERSION],[
 m4_define([vers_have], [@VERSION@])
 m4_define([maj_have], m4_substr(vers_have, 0, m4_index(vers_have, [.])))
@@ -47,6 +49,7 @@ m4_if(m4_version_compare(vers_have, [$1]), -1,
 m4_undefine([vers_have])
 m4_undefine([maj_have])
 m4_undefine([maj_needed])
+m4_define([xorg_macros_needed],[$1])
 ]) # XORG_MACROS_VERSION
 
 # XORG_PROG_RAWCPP()
@@ -304,7 +307,7 @@ AC_SUBST(MAKE_PDF)
 AC_SUBST(MAKE_HTML)
 ]) # XORG_CHECK_DOCBOOK
 
-# XORG_WITH_XMLTO
+# XORG_WITH_XMLTO([MIN-VERSION])
 # ----------------
 # Minimum version: 1.5.0
 #
@@ -352,6 +355,20 @@ elif test "x$use_xmlto" = x"no" ; then
 else
    AC_MSG_ERROR([--with-xmlto expects 'yes' or 'no'])
 fi
+m4_ifval([$1],
+[if test "$have_xmlto" = yes; then
+    # scrape the xmlto version
+    AC_MSG_CHECKING([the xmlto version])
+    xmlto_version=`$XMLTO --version 2>/dev/null | cut -d' ' -f3`
+    AC_MSG_RESULT([$xmlto_version])
+    AS_VERSION_COMPARE([$xmlto_version], [$1],
+        [if test "x$use_xmlto" = xauto; then
+            AC_MSG_WARN([xmlto version $xmlto_version found, but $1 needed])
+            have_xmlto=no
+        else
+            AC_MSG_ERROR([xmlto version $xmlto_version found, but $1 needed])
+        fi])
+fi])
 AM_CONDITIONAL([HAVE_XMLTO], [test "$have_xmlto" = yes])
 ]) # XORG_CHECK_XMLTO
 
@@ -870,11 +887,12 @@ AM_CONDITIONAL(MAKE_LINT_LIB, [test x$make_lint_lib != xno])
 # XORG_CWARNFLAGS
 # ---------------
 # Minimum version: 1.2.0
+# Deprecated since 1.7.0. Use XORG_PROJECT_ALL_CFLAGS
 #
 # Defines CWARNFLAGS to enable C compiler warnings.
 #
 AC_DEFUN([XORG_CWARNFLAGS], [
-AC_REQUIRE([AC_PROG_CC])
+AC_REQUIRE([XORG_STRICT_OPTION])
 if  test "x$GCC" = xyes ; then
     CWARNFLAGS="-Wall -Wpointer-arith -Wstrict-prototypes -Wmissing-prototypes \
 -Wmissing-declarations -Wnested-externs -fno-strict-aliasing \
@@ -890,6 +908,10 @@ else
 	CWARNFLAGS="-v"
     fi
 fi
+
+# Add strict cflags from xorg_strict_option which are also warning flags
+CWARNFLAGS="$CWARNFLAGS $STRICT_CFLAGS"
+
 AC_SUBST(CWARNFLAGS)
 ]) # XORG_CWARNFLAGS
 
@@ -898,10 +920,11 @@ AC_SUBST(CWARNFLAGS)
 # Minimum version: 1.3.0
 #
 # Add configure option to enable strict compilation
+# STRICT_CFLAGS is included in deprecated CWARNFLAGS and PROJECT_WARN_CFLAGS
+# It cannot (and never could) be invoked directly from configure.ac
 AC_DEFUN([XORG_STRICT_OPTION], [
 AC_REQUIRE([AC_PROG_CC])
 AC_REQUIRE([AC_PROG_CC_C99])
-AC_REQUIRE([XORG_CWARNFLAGS])
 
 AC_ARG_ENABLE(strict-compilation,
 			  AS_HELP_STRING([--enable-strict-compilation],
@@ -918,8 +941,6 @@ if test "x$STRICT_COMPILE" = "xyes"; then
 		STRICT_CFLAGS="-Werror"
 	fi
 fi
-CWARNFLAGS="$CWARNFLAGS $STRICT_CFLAGS"
-AC_SUBST([CWARNFLAGS])
 ]) # XORG_STRICT_OPTION
 
 # XORG_DEFAULT_OPTIONS
@@ -929,8 +950,11 @@ AC_SUBST([CWARNFLAGS])
 # Defines default options for X.Org modules.
 #
 AC_DEFUN([XORG_DEFAULT_OPTIONS], [
-XORG_CWARNFLAGS
 XORG_STRICT_OPTION
+XORG_CWARNFLAGS
+XORG_PROJECT_WARN_CFLAGS
+XORG_PROJECT_OPTIMIZE_CFLAGS
+XORG_PROJECT_ALL_CFLAGS
 XORG_RELEASE_VERSION
 XORG_CHANGELOG
 XORG_INSTALL
@@ -955,3 +979,138 @@ mv \$(top_srcdir)/.INSTALL.tmp \$(top_srcdir)/INSTALL) \
 echo 'util-macros \"pkgdatadir\" from xorg-macros.pc not found: installing possibly empty INSTALL.' >&2)"
 AC_SUBST([INSTALL_CMD])
 ]) # XORG_INSTALL
+
+# XORG_PROJECT_ALL_CFLAGS
+# -----------------------
+# Minimum version: 1.7.0
+#
+# Defines Automake PROJECT_ALL_CFLAGS variable.
+#
+# This macro is defined as containing a set of required compiler options for
+# all X.Org modules, including xserver, libraries, drivers, fonts and apps.
+# Additional compiler options are added locally by the each module.
+#
+# These options are set in each module makefile like this:
+# AM_CFLAGS = $(PROJECT_ALL_CFLAGS) ...
+# See Automake 27.6 Flag Variables Ordering.
+#
+# All Makefile.am should have it for all C code targets for the following reasons:
+#  - Provides a hook for an emergency system fix due to compiler behavior change
+#  - Allow for an easy way to experiment different compiler options on the system
+#    on a private local build
+#  - Implement project wide policies such as warning flags
+#
+# As an organizing principle, this macro does not contain discrete compiler options
+# but rather aggregates macros containing options based on their categories.
+#
+# Backward compatibility: the variable CWARNFLAGS is still available for older
+# modules using it. Modules requesting version 1.7.0 or higher should not use it.
+#
+AC_DEFUN([XORG_PROJECT_ALL_CFLAGS], [
+AC_REQUIRE([XORG_PROJECT_WARN_CFLAGS])
+AC_REQUIRE([XORG_PROJECT_OPTIMIZE_CFLAGS])
+# m4_errprintn([PROJECT_ALL_CFLAGS: requested version: ]xorg_macros_needed)
+
+PROJECT_ALL_CFLAGS="$PROJECT_WARN_CFLAGS $PROJECT_OPTIMIZE_CFLAGS"
+
+# Other compiler categories that may be created as needed in the future
+# PROJECT_DEBUG_CFLAGS
+# PROJECT_LINKER_CFLAGS
+# PROJECT_DIALECT_CFLAGS
+# and so on...
+AC_SUBST(PROJECT_ALL_CFLAGS)
+]) # XORG_PROJECT_ALL_CFLAGS
+
+# XORG_PROJECT_WARN_CFLAGS
+# ------------------------
+# Minimum version: 1.7.0
+#
+# Defines PROJECT_WARN_CFLAGS to enable C compiler warnings.
+# This macro is mandatory for all X.Org C code
+# It should only contain options in the "warning category"
+# It implements a project policy to improve general code quality
+# Note that XORG_STRICT_OPTION provides additional warning flags to it
+#
+AC_DEFUN([XORG_PROJECT_WARN_CFLAGS], [
+AC_REQUIRE([XORG_STRICT_OPTION])
+# m4_errprintn([PROJECT_WARN_CFLAGS: requested version: ]xorg_macros_needed)
+
+_XORG_PROJECT_WARN_CFLAGS_V1
+
+# Add strict cflags from xorg_strict_option which are also warning flags
+PROJECT_WARN_CFLAGS="$PROJECT_WARN_CFLAGS $STRICT_CFLAGS"
+
+# If a subsequent version of warning flags is not backward compatible,
+# e.g. a flag must be removed, use the following test.
+# The util-macros package 'major' version number should then be bumped to 2
+#m4_if(m4_version_compare(xorg_macros_needed,[2.0]),[-1],
+#  [_XORG_PROJECT_WARN_CFLAGS_V1],
+#  [_XORG_PROJECT_WARN_CFLAGS_V2]
+#)
+]) # XORG_PROJECT_WARN_CFLAGS
+
+# _XORG_PROJECT_WARN_CFLAGS_V1
+# ----------------------------
+# Minimum version: 1.7.0
+#
+# Private implementation of version 1.7.0.x of PROJECT_WARN_CFLAGS
+# It should not be called directly from configure.ac
+#
+AC_DEFUN([_XORG_PROJECT_WARN_CFLAGS_V1], [
+if test "x$GCC" = xyes ; then
+    PROJECT_WARN_CFLAGS="-Wall -Wpointer-arith -Wstrict-prototypes -Wmissing-prototypes \
+-Wmissing-declarations -Wnested-externs -Wbad-function-cast -Wformat=2 -Wstrict-aliasing"
+    case `$CC -dumpversion` in
+    3.4.* | 4.*)
+	PROJECT_WARN_CFLAGS="$PROJECT_WARN_CFLAGS -Wold-style-definition -Wdeclaration-after-statement"
+	;;
+    esac
+else
+    AC_CHECK_DECL([__SUNPRO_C], [SUNCC="yes"], [SUNCC="no"])
+    if test "x$SUNCC" = "xyes"; then
+	PROJECT_WARN_CFLAGS="-v"
+    fi
+fi
+AC_SUBST(PROJECT_WARN_CFLAGS)
+]) # _XORG_PROJECT_WARN_CFLAGS_V1
+
+# XORG_PROJECT_OPTIMIZE_CFLAGS
+# ----------------------------
+# Minimum version: 1.7.0
+#
+# Defines PROJECT_OPTIMIZE_CFLAGS.
+# This macro is mandatory for all X.Org C code
+# It should only contain options in the "optimization category"
+#
+# The main motivation for this option is to preserve old code behavior
+# following a controversial change in the compiler. Refer to xorg-devel
+# list for related discussions.
+#
+AC_DEFUN([XORG_PROJECT_OPTIMIZE_CFLAGS], [
+AC_REQUIRE([AC_PROG_CC])
+# m4_errprintn([PROJECT_OPTIMIZE_CFLAGS: requested version: ]xorg_macros_needed)
+
+_XORG_PROJECT_OPTIMIZE_CFLAGS_V1
+
+# If a subsequent version of warning flags is not backward compatible,
+# e.g. a flag must be removed, use the following test.
+# The util-macros package 'major' version number should then be bumped to 2
+#m4_if(m4_version_compare(xorg_macros_needed,[2.0]),[-1],
+#  [_XORG_PROJECT_OPTIMIZE_CFLAGS_V1],
+#  [_XORG_PROJECT_OPTIMIZE_CFLAGS_V2]
+#)
+]) # XORG_PROJECT_OPTIMIZE_CFLAGS
+
+# _XORG_PROJECT_OPTIMIZE_CFLAGS_V1
+# --------------------------------
+# Minimum version: 1.7.0
+#
+# Private implementation of version 1.7.0.x of XORG_PROJECT_OPTIMIZE_CFLAGS
+# It should not be called directly from configure.ac
+#
+AC_DEFUN([_XORG_PROJECT_OPTIMIZE_CFLAGS_V1], [
+if  test "x$GCC" = xyes ; then
+    PROJECT_OPTIMIZE_CFLAGS="-fno-strict-aliasing"
+fi
+AC_SUBST(PROJECT_OPTIMIZE_CFLAGS)
+]) # _XORG_PROJECT_OPTIMIZE_CFLAGS_V1
-- 
1.6.0.4



More information about the xorg-devel mailing list