* config.make.in: _set_ the initial value for $({C,CPP,LD}FLAGS). * Makeconf: alter $(FOOFLAGS) _after_ config.make has been included. * */Makefile: make sure $(FOOFLAGS) is modified after Makeconf has been included.
The current situation with {C,CPP,LD}FLAGS is this: - foo/Makefile may in principle set an initial value corresponding to the extra flags it needs; - Makeconf adds some stuff on top of this; - config.make, included by Makeconf, appends the configured value. The first problem with this is that the most specific options will end up at the beginning, where they run the risk of being overridden by the more generic ones. In practice, most Makefiles actually alter the value after they include Makeconf, maybe to avoid this. Furthermore, this approach is incompatible with the user overriding FOOFLAGS when running make. If we're lucky, they will do so on the command-line, and as a result the user-specified options will be merely prepended to the one we set. But a more problematic scenario can occur: the first "FOOFLAGS +=" will reference an undefined variable, so make will try to pull its value from the environment. If it succeeds, the variable will be marked as exported and its altered value will be passed downstream, resulting in a new copy of the whole thing being added when a sub-make is invoked. This patch makes sure that this doesn't happen and that the user can safely override the flags on the make command line. NB: the flag duplication which still happens when building the Debian package is the combined result of dpkg-buildpackage and cdbs and is not related to any of this. Signed-off-by: Jeremie Koenig <j...@jk.fr.eu.org> --- Makeconf | 13 ++++++------- config.make.in | 14 ++++++++------ configure.in | 1 + console-client/Makefile | 4 ++-- defpager/Makefile | 2 ++ libftpconn/Makefile | 4 ++-- mach-defpager/Makefile | 3 ++- 7 files changed, 23 insertions(+), 18 deletions(-) diff --git a/Makeconf b/Makeconf index 8c2bd0c..fd47ee0 100644 --- a/Makeconf +++ b/Makeconf @@ -55,18 +55,11 @@ top_srcdir = .. endif endif -# Generic compiler options, appended to whatever the particular makefile set. -# The config.make file will append the values chosed by configure. INCLUDES = -I. $(srcdirinc) ifneq (.,$(dir)) INCLUDES += -I.. $(top_srcdirinc) endif INCLUDES += -I$(..)include -I$(top_srcdir)/include -CPPFLAGS += $(INCLUDES) \ - -D_GNU_SOURCE -D_IO_MTSAFE_IO -D_FILE_OFFSET_BITS=64 \ - $($*-CPPFLAGS) -CFLAGS += -std=gnu99 $(gnu89-inline-CFLAGS) -Wall -g -O3 \ - $($*-CFLAGS) # Include the configure-generated file of parameters. # This sets up variables for build tools and installation directories. @@ -76,6 +69,12 @@ include $(..)config.make configured = yes endif +# Complement the configured values. +CFLAGS := -std=gnu99 $(gnu89-inline-CFLAGS) $(CFLAGS) $($*-CFLAGS) +CPPFLAGS += $(INCLUDES) \ + -D_GNU_SOURCE -D_IO_MTSAFE_IO -D_FILE_OFFSET_BITS=64 \ + $($*-CPPFLAGS) + # If we're not configured, don't do deps; then `make TAGS' and such can work. ifndef configured no_deps = t diff --git a/config.make.in b/config.make.in index 986ea2a..7876d47 100644 --- a/config.make.in +++ b/config.make.in @@ -45,14 +45,16 @@ MIG = @MIG@ MIGCOM = $(MIG) -cc cat - /dev/null AWK = @AWK@ -# Compilation flags. Append these to the definitions already made by -# the specific Makefile. -CPPFLAGS += @CPPFLAGS@ @DEFS@ -CFLAGS += @CFLAGS@ -LDFLAGS += @LDFLAGS@ - +# Compilation flags. +CFLAGS = @CFLAGS@ +CPPFLAGS = @CPPFLAGS@ +LDFLAGS = @LDFLAGS@ gnu89-inline-CFLAGS = @libc_cv_gnu89_inline@ +# Append the preprocessor definitions in a second pass; this way they will be +# included even if the user overrides CPPFLAGS on the make command line. +CPPFLAGS += @DEFS@ + # `yes' or `no' to indicate if ld --version-script is available. VERSIONING = @VERSIONING@ diff --git a/configure.in b/configure.in index 1cf4daa..a0994cb 100644 --- a/configure.in +++ b/configure.in @@ -83,6 +83,7 @@ INSTALL="$SHELL $(readlink -f "$ac_install_sh")"\ -C || unset INSTALL] AC_PROG_INSTALL AC_PROG_AWK +: ${CFLAGS="-Wall -g -O3"} AC_PROG_CC # Require GCC. if test x$GCC != xyes; then diff --git a/console-client/Makefile b/console-client/Makefile index 22a492a..64f056f 100644 --- a/console-client/Makefile +++ b/console-client/Makefile @@ -43,11 +43,11 @@ LDLIBS = -ldl module-dir = $(libdir)/hurd/console console-LDFLAGS = -Wl,-E +include ../Makeconf + # In seeking, thou shalt find it! CPPFLAGS += -DQUAERENDO_INVENIETIS -include ../Makeconf - driver-CPPFLAGS = -D'CONSOLE_DEFPATH="$(module-dir)\0"' \ -D'CONSOLE_SONAME_SUFFIX=".so.$(hurd-version)"' diff --git a/defpager/Makefile b/defpager/Makefile index 8f92dd7..9d54905 100644 --- a/defpager/Makefile +++ b/defpager/Makefile @@ -18,6 +18,8 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +# XXX this is broken + dir := defpager makemode := misc diff --git a/libftpconn/Makefile b/libftpconn/Makefile index 05f3ddf..4f5123e 100644 --- a/libftpconn/Makefile +++ b/libftpconn/Makefile @@ -29,6 +29,6 @@ LCLHDRS = ftpconn.h priv.h OBJS = $(SRCS:.c=.o) -CPPFLAGS += -DHAVE_HURD_HURD_TYPES_H -DHAVE_STAT_ST_AUTHOR - include ../Makeconf + +CPPFLAGS += -DHAVE_HURD_HURD_TYPES_H -DHAVE_STAT_ST_AUTHOR diff --git a/mach-defpager/Makefile b/mach-defpager/Makefile index 5ed8f11..e903954 100644 --- a/mach-defpager/Makefile +++ b/mach-defpager/Makefile @@ -29,10 +29,11 @@ OBJS := $(SRCS:.c=.o) \ default_pager_replyUser.o HURDLIBS:= threads -LDFLAGS += -static include ../Makeconf +LDFLAGS += -static + vpath %.c $(srcdir)/../serverboot CPPFLAGS += -I$(srcdir)/../serverboot -- 1.7.1