This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re-enable warnings for libcpp (build maintainer review requested)


When cpplib got moved to its own directory, it also stopped being
compiled with all the warnings flags we use for the gcc directory.
This patch restores most of them.  I cannot turn -Werror back on for
two reasons.  First, since it's been awhile since cpplib was built
with warnings enabled, there are some regressions, which I will fix in
a subsequent patch.  Second, the bootstrap compiler may generate false
positives, so we want some threshold version check in configure.  I'm
not sure how to do that.  The gcc subdir's policy is to only enable
warnings in stage 2, unless --enable-werror-always; which would be
fine by me, but I'm not sure how to do that in the context of a
toplevel bootstrap (obviously that doesn't help a gcc-subdir-only
bootstrap).  The macros defined in warnings.m4 are intended to be
useful for other directories - libiberty, intl, and libdata if I ever
get round to finishing that.

Tangentially, I decided to figure out some way of getting the
-DLOCALEDIR="/long/path/name" off the command line for every .c file
in cpplib.  It turns out to be impossible to put this definition into
config.h because the value is only determined at 'make' time, so I
create a single-definition header instead; this works well.  I am
tempted to convert the gcc subdirectory to this style as well, so that
we don't have to rebuild several files if we tweak the Makefile.
Comments on this appreciated.

I'd like a build system maintainer to review this, especially the
refactoring done to the gcc Makefile and configure script.  It has
bootstrapped successfully on i686-linux, with all the warning flags
being passed when they were supposed to be passed and not otherwise.

zw

config:
        * warnings.m4: New file; logic lifted from gcc/configure.ac.
gcc:
        * aclocal.m4: Include ../config/warnings.m4.
        * configure.ac: Use macros defined by warnings.m4.
        * configure: Regenerate.
        * Makefile.in (STRICT_WARN, WARN_CFLAGS): Update definition
        to match changes to configure.
        (STRICT2_WARN): Include -Werror unconditionally.
        (POSTSTAGE1_FLAGS_TO_PASS): Remove redundant setting of CFLAGS.
        (STAGE2_FLAGS_TO_PASS): Remove unnecessary setting of WERROR.
libcpp:
        * configure.ac: Use macros defined by warnings.m4 to find out
        whether compiler warnings can be enabled.  Move two AC_PROG_* 
        macros to the proper cluster of checks.
        * aclocal.m4, configure: Regenerate.
        * Makefile.in (WARN_CFLAGS, GCC_WARN_CFLAGS, ALL_CFLAGS): New vars.
        (DEFS): Delete.
        (localedir.h, localedir.hs): New rules.
        (clean): Use rm -rf, as autom4te.cache is a directory.
        (distclean): Also delete localedir.h and localedir.hs.
        (.c.o): Use ALL_CFLAGS.
        (init.o): Update dependencies.
        * init.c: Include localedir.h.

===================================================================
Index: config/warnings.m4
--- config/warnings.m4	1 Jan 1970 00:00:00 -0000
+++ config/warnings.m4	13 Sep 2004 19:12:24 -0000
@@ -0,0 +1,93 @@
+# Autoconf include file defining macros related to compile-time warnings.
+
+# Copyright 2004 Free Software Foundation, Inc.
+
+#This file is part of GCC.
+
+#GCC is free software; you can redistribute it and/or modify it under
+#the terms of the GNU General Public License as published by the Free
+#Software Foundation; either version 2, or (at your option) any later
+#version.
+
+#GCC is distributed in the hope that it will be useful, but WITHOUT
+#ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+#FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+#for more details.
+
+#You should have received a copy of the GNU General Public License
+#along with GCC; see the file COPYING.  If not, write to the Free
+#Software Foundation, 59 Temple Place - Suite 330, Boston, MA
+#02111-1307, USA.
+
+# Set WARN_CFLAGS to "$(GCC_WARN_CFLAGS)" if CC is GCC, and to nothing
+# if it isn't.  This prevents passing GCC's warning flags to compilers
+# which don't understand them.
+AC_DEFUN([GCC_CC_WARN_ENABLE],
+[AC_REQUIRE([AC_PROG_CC])dnl
+WARN_CFLAGS=  AC_SUBST([WARN_CFLAGS])
+if test "x$GCC" = "xyes"; then
+  WARN_CFLAGS='$(GCC_WARN_CFLAGS)'
+fi])
+
+# We want to use -pedantic, but we don't want warnings about
+# * 'long long'
+# * variadic macros
+# So, we only use -pedantic if we can disable those warnings.
+AC_DEFUN([GCC_CC_WARN_PEDANTIC],
+[AC_REQUIRE([AC_PROG_CC])dnl
+AC_CACHE_CHECK(
+  [whether ${CC} accepts -Wno-long-long],
+  [ac_cv_prog_cc_w_no_long_long],
+  [save_CFLAGS="$CFLAGS"
+  CFLAGS="-Wno-long-long"
+  AC_COMPILE_IFELSE([AC_LANG_SOURCE([[]])],
+                    [ac_cv_prog_cc_w_no_long_long=yes],
+                    [ac_cv_prog_cc_w_no_long_long=no])
+  CFLAGS="$save_CFLAGS"
+  ])
+AC_CACHE_CHECK(
+  [whether ${CC} accepts -Wno-variadic-macros],
+  [ac_cv_prog_cc_w_no_variadic_macros],
+  [save_CFLAGS="$CFLAGS"
+  CFLAGS="-Wno-variadic-macros"
+  AC_COMPILE_IFELSE([AC_LANG_SOURCE([[]])],
+                    [ac_cv_prog_cc_w_no_variadic_macros=yes],
+                    [ac_cv_prog_cc_w_no_variadic_macros=no])
+  CFLAGS="$save_CFLAGS"
+  ])
+WARN_PEDANTIC= AC_SUBST(WARN_PEDANTIC)
+if test $ac_cv_prog_cc_w_no_long_long = yes \
+   && test $ac_cv_prog_cc_w_no_variadic_macros = yes ; then
+  WARN_PEDANTIC="-pedantic -Wno-long-long -Wno-variadic-macros"
+fi])
+
+AC_DEFUN([GCC_CC_WARN_OSD],
+[AC_REQUIRE([AC_PROG_CC])dnl
+AC_CACHE_CHECK(
+  [whether ${CC} accepts -Wold-style-definition],
+  [ac_cv_prog_cc_w_old_style_definition],
+  [save_CFLAGS="$CFLAGS"
+  CFLAGS="-Wold-style-definition"
+  AC_COMPILE_IFELSE([AC_LANG_SOURCE([[]])],
+                    [ac_cv_prog_cc_w_old_style_definition=yes],
+                    [ac_cv_prog_cc_w_old_style_definition=no])
+  CFLAGS="$save_CFLAGS"
+  ])
+WARN_OSD=  AC_SUBST(WARN_OSD)
+if test $ac_cv_prog_cc_w_old_style_definition = yes ; then
+  WARN_OSD="-Wold-style-definition"
+fi])
+
+# We need a way of deciding at configure time whether it is safe to
+# enable -Werror.  The GCC makefile just turns it on in stage 2, but
+# that's not going to work for libcpp etc.  For now, just do the
+# --enable thing.
+AC_DEFUN([GCC_CC_WARN_WERROR],
+[AC_REQUIRE([AC_PROG_CC])dnl
+AC_ARG_ENABLE(werror_always, 
+[  --enable-werror-always         enable -Werror always], [],
+[enable_werror_always=no])
+WERROR=  AC_SUBST(WERROR)
+if test x${enable_werror_always} = xyes ; then
+  WERROR=-Werror
+fi])
===================================================================
Index: gcc/Makefile.in
--- gcc/Makefile.in	11 Sep 2004 04:22:14 -0000	1.1384
+++ gcc/Makefile.in	13 Sep 2004 19:12:24 -0000
@@ -164,9 +164,9 @@ coverageexts = .{gcda,gcno}
 # stage1, as not all versions of gcc understand -Wno-long-long or
 # -Wno-variadic-macros.
 LOOSE_WARN = -W -Wall -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes
-STRICT_WARN = @strict1_warn@
+STRICT_WARN = @WARN_PEDANTIC@ @WARN_OSD@ @WERROR@
 STRICT2_WARN = -pedantic -Wno-long-long -Wno-variadic-macros \
-  -Wold-style-definition @WERROR@
+  -Wold-style-definition -Werror
 
 # This is set by --enable-checking.  The idea is to catch forgotten
 # "extern" tags in header files.
@@ -204,7 +204,7 @@ reload1.o-warn = -Wno-error
 # All warnings have to be shut off in stage1 if the compiler used then
 # isn't gcc; configure determines that.  WARN_CFLAGS will be either
 # $(GCC_WARN_CFLAGS), or nothing.
-WARN_CFLAGS = @warn_cflags@
+WARN_CFLAGS = @WARN_CFLAGS@
 
 CPPFLAGS = @CPPFLAGS@
 
@@ -3603,7 +3603,6 @@ VOL_FILES=`echo $(BACKEND) $(OBJS) $(C_O
 
 POSTSTAGE1_FLAGS_TO_PASS = \
 	ADAFLAGS="$(BOOT_ADAFLAGS)" \
-	CFLAGS="$(BOOT_CFLAGS)" \
 	LDFLAGS="$(BOOT_LDFLAGS)" \
 	WARN_CFLAGS="\$$(GCC_WARN_CFLAGS)" \
 	STRICT_WARN="$(STRICT2_WARN)" \
@@ -3615,8 +3614,7 @@ POSTSTAGE1_FLAGS_TO_PASS = \
 	OUTPUT_OPTION="-o \$$@"
 
 STAGE2_FLAGS_TO_PASS = \
-	CFLAGS="$(BOOT_CFLAGS)" \
-	WERROR="@WERROR@" \
+	CFLAGS="$(BOOT_CFLAGS)"
 
 STAGEPROFILE_FLAGS_TO_PASS = \
 	CFLAGS="$(BOOT_CFLAGS) -fprofile-generate"
===================================================================
Index: gcc/aclocal.m4
--- gcc/aclocal.m4	3 Aug 2004 20:33:23 -0000	1.92
+++ gcc/aclocal.m4	13 Sep 2004 19:12:24 -0000
@@ -2,6 +2,7 @@ sinclude(../config/acx.m4)
 sinclude(../config/accross.m4)
 sinclude(../config/gettext.m4)
 sinclude(../config/progtest.m4)
+sinclude(../config/warnings.m4)
 
 dnl See whether we need a declaration for a function.
 dnl The result is highly dependent on the INCLUDES passed in, so make sure
===================================================================
Index: gcc/configure.ac
--- gcc/configure.ac	11 Sep 2004 04:26:36 -0000	2.65
+++ gcc/configure.ac	13 Sep 2004 19:12:24 -0000
@@ -304,88 +304,13 @@ fi
 # Warnings and checking
 # ---------------------
 
-# Check $CC warning features (if it's GCC).
-# We want to use -pedantic, but we don't want warnings about
-# * 'long long'
-# * variadic macros
-# So, we only use -pedantic if we can disable those warnings.
-
-AC_CACHE_CHECK(
-  [whether ${CC} accepts -Wno-long-long],
-  [ac_cv_prog_cc_w_no_long_long],
-  [save_CFLAGS="$CFLAGS"
-  CFLAGS="-Wno-long-long"
-  AC_COMPILE_IFELSE([AC_LANG_SOURCE([[]])],
-                    [ac_cv_prog_cc_w_no_long_long=yes],
-                    [ac_cv_prog_cc_w_no_long_long=no])
-  CFLAGS="$save_CFLAGS"
-  ])
-
-AC_CACHE_CHECK(
-  [whether ${CC} accepts -Wno-variadic-macros],
-  [ac_cv_prog_cc_w_no_variadic_macros],
-  [save_CFLAGS="$CFLAGS"
-  CFLAGS="-Wno-variadic-macros"
-  AC_COMPILE_IFELSE([AC_LANG_SOURCE([[]])],
-                    [ac_cv_prog_cc_w_no_variadic_macros=yes],
-                    [ac_cv_prog_cc_w_no_variadic_macros=no])
-  CFLAGS="$save_CFLAGS"
-  ])
-
-strict1_warn=
-if test $ac_cv_prog_cc_w_no_long_long = yes \
-   && test $ac_cv_prog_cc_w_no_variadic_macros = yes ; then
-  strict1_warn="-pedantic -Wno-long-long -Wno-variadic-macros"
-fi
-AC_SUBST(strict1_warn)
-
-# Add -Wold-style-definition if it's accepted
-AC_CACHE_CHECK(
-  [whether ${CC} accepts -Wold-style-definition],
-  [ac_cv_prog_cc_w_old_style_definition],
-  [save_CFLAGS="$CFLAGS"
-  CFLAGS="-Wold-style-definition"
-  AC_COMPILE_IFELSE([AC_LANG_SOURCE([[]])],
-                    [ac_cv_prog_cc_w_old_style_definition=yes],
-                    [ac_cv_prog_cc_w_old_style_definition=no])
-  CFLAGS="$save_CFLAGS"
-  ])
-if test $ac_cv_prog_cc_w_old_style_definition = yes ; then
-  strict1_warn="${strict1_warn} -Wold-style-definition"
-fi
-
-# Enable -Werror, period.
-AC_ARG_ENABLE(werror_always, 
-[  --enable-werror-always         enable -Werror always], [],
-[enable_werror_always=no])
-if test x${enable_werror_always} = xyes ; then
-  strict1_warn="${strict1_warn} -Werror"
-  WERROR=-Werror
-fi
-
-# If the native compiler is GCC, we can enable warnings even in stage1.  
-# That's useful for people building cross-compilers, or just running a
-# quick `make'.
-warn_cflags=
-if test "x$GCC" = "xyes"; then
-  warn_cflags='$(GCC_WARN_CFLAGS)'
-fi
-AC_SUBST(warn_cflags)
-
-# Enable -Werror in bootstrap stage2 and later.
-AC_ARG_ENABLE(werror, 
-[  --enable-werror         enable -Werror in bootstrap stage2 and later], [],
-[if test x$is_release = x ; then
-  # Default to "yes" on development branches.
-  enable_werror=yes
-else
-  # Default to "no" on release branches.
-  enable_werror=no
-fi])
-if test x$enable_werror = xyes ; then
-  WERROR=-Werror
-fi
-AC_SUBST(WERROR)
+# Figure out what compiler warnings we can enable.
+# See config/warnings.m4 for details.
+
+GCC_CC_WARN_ENABLE
+GCC_CC_WARN_PEDANTIC
+GCC_CC_WARN_OSD
+GCC_CC_WARN_WERROR
 
 # Enable expensive internal checks
 AC_ARG_ENABLE(checking,
===================================================================
Index: libcpp/Makefile.in
--- libcpp/Makefile.in	25 Aug 2004 12:57:05 -0000	1.9
+++ libcpp/Makefile.in	13 Sep 2004 19:12:25 -0000
@@ -59,10 +59,22 @@ prefix = @prefix@
 
 MSGMERGE = msgmerge
 mkinstalldirs = $(SHELL) $(srcdir)/../mkinstalldirs
-DEFS = -DLOCALEDIR="\"$(localedir)\""
 INCLUDES = -I$(srcdir) -I. -I$(srcdir)/../include @INCINTL@ \
 	-I$(srcdir)/include
 
+# Warning control.  This is somewhat hairy.
+# All warnings have to be shut off in stage1 if the compiler used then
+# isn't gcc; configure determines that.  WARN_CFLAGS will be either
+# $(GCC_WARN_CFLAGS), or nothing.
+WARN_CFLAGS = @WARN_CFLAGS@
+
+# The actual set of warnings to enable is itself partially determined by
+# configure.
+GCC_WARN_CFLAGS = -W -Wall -Wwrite-strings -Wstrict-prototypes \
+  -Wmissing-prototypes @WARN_PEDANTIC@ @WARN_OSD@ @WERROR@
+
+ALL_CFLAGS = $(CFLAGS) $(WARN_CFLAGS) $(INCLUDES) $(CPPFLAGS)
+
 libcpp_a_OBJS = charset.o directives.o errors.o expr.o files.o \
 	identifiers.o init.o lex.o line-map.o macro.o mkdeps.o \
 	pch.o symtab.o traditional.o
@@ -113,7 +125,15 @@ stamp-h1: $(srcdir)/config.in config.sta
 $(srcdir)/config.in: @MAINT@ $(srcdir)/configure
 	cd $(srcdir) && $(AUTOHEADER)
 	-rm -f stamp-h1
-	
+
+# It is not possible to get LOCALEDIR defined in config.h because
+# the value it needs to be defined to is only determined in the
+# Makefile.  Hence we do this instead.
+localedir.h: localedir.hs; @true
+localedir.hs: Makefile
+	echo "#define LOCALEDIR \"$(localedir)\"" > localedir.new
+	$(srcdir)/../move-if-change localedir.new localedir.h
+	echo timestamp > localedir.hs
 
 # Installation rules and other phony targets
 
@@ -147,11 +167,12 @@ mostlyclean:
 	-rm -f *.o
 
 clean: mostlyclean
-	-rm -f makedepend$(EXEEXT) libcpp.a $(srcdir)/autom4te.cache
+	-rm -rf makedepend$(EXEEXT) libcpp.a $(srcdir)/autom4te.cache
 
 distclean: clean
 	-rm -f config.h stamp-h1 config.status config.cache config.log \
-	  configure.lineno configure.status.lineno Makefile
+	  configure.lineno configure.status.lineno Makefile localedir.h \
+	  localedir.hs
 
 maintainer-clean: distclean
 	@echo "This command is intended for maintainers to use"
@@ -175,7 +196,7 @@ update-po: $(CATALOGS:.gmo=.pox)
 # Implicit rules and I18N
 
 .c.o:
-	$(CC) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS) -c $<
+	$(CC) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(ALL_CFLAGS) -c $<
 
 # N.B. We do not attempt to copy these into $(srcdir).
 .po.gmo:
@@ -227,9 +248,8 @@ expr.o: $(srcdir)/expr.c $(COMMON_DEPS)
 
 files.o: $(srcdir)/files.c $(COMMON_DEPS) $(libcpp_incdir)/mkdeps.h \
    $(top_incdir)/hashtab.h $(top_incdir)/md5.h
-  
 identifiers.o: $(srcdir)/identifiers.c $(COMMON_DEPS)
-init.o: $(srcdir)/init.c $(COMMON_DEPS) $(libcpp_incdir)/mkdeps.h
+init.o: $(srcdir)/init.c $(COMMON_DEPS) $(libcpp_incdir)/mkdeps.h localedir.h
 lex.o: $(srcdir)/lex.c $(COMMON_DEPS)
 line-map.o: $(srcdir)/line-map.c $(COMMON_DEPS)
 macro.o: $(srcdir)/macro.c $(COMMON_DEPS)
===================================================================
Index: libcpp/configure.ac
--- libcpp/configure.ac	28 Aug 2004 18:04:17 -0000	1.6
+++ libcpp/configure.ac	13 Sep 2004 19:12:25 -0000
@@ -5,10 +5,10 @@ AC_PREREQ(2.59)
 AC_INIT(cpplib, [ ], gcc-bugs@gcc.gnu.org, cpplib)
 AC_CONFIG_SRCDIR(ucnid.h)
 AC_CANONICAL_SYSTEM
-AC_PROG_MAKE_SET
-AC_PROG_INSTALL
 
 # Checks for programs.
+AC_PROG_MAKE_SET
+AC_PROG_INSTALL
 AC_PROG_CC
 AC_PROG_RANLIB
 
@@ -17,6 +17,14 @@ AC_CHECK_PROGS([ACLOCAL], [aclocal], [$M
 AC_CHECK_PROGS([AUTOCONF], [autoconf], [$MISSING autoconf])
 AC_CHECK_PROGS([AUTOHEADER], [autoheader], [$MISSING autoheader])
 
+# Figure out what compiler warnings we can enable.
+# See config/warnings.m4 for details.
+
+GCC_CC_WARN_ENABLE
+GCC_CC_WARN_PEDANTIC
+GCC_CC_WARN_OSD
+GCC_CC_WARN_WERROR
+
 # Checks for header files.
 AC_HEADER_TIME
 ACX_HEADER_STRING
===================================================================
Index: libcpp/init.c
--- libcpp/init.c	23 Jul 2004 07:00:57 -0000	1.4
+++ libcpp/init.c	13 Sep 2004 19:12:25 -0000
@@ -24,6 +24,7 @@ Foundation, 59 Temple Place - Suite 330,
 #include "cpplib.h"
 #include "internal.h"
 #include "mkdeps.h"
+#include "localedir.h"
 
 static void init_library (void);
 static void mark_named_operators (cpp_reader *);


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]