Workaround a bug in GNU make when reloading generated makefiles

The problem was discovered testing parallel builds.
The configuration rules depend on generated pkg-config.mk files.
However, experimentally, variables set in these files are not
correctly reloaded in rules declared in other variables.

Specifically, $(CFLAGS_PKGCONFIG) was not re-expanded after being
modified, which led to configuration builds to lack the required
flags, causing false configuration step failures.

The flags are now explicitly listed using $(shell cat...), which
is a little bit more expensive during the configuration step, but
ensures that the flags are correctly seen. Note that at that stage,
the dependency ensures that all the files were built correctly.
This commit is contained in:
Christophe de Dinechin 2017-11-24 10:43:30 +01:00
parent cb38305bb6
commit 24eff2112b
2 changed files with 24 additions and 14 deletions

View File

@ -113,11 +113,13 @@ CFG_TEST= \
CFG_UNDEF0= \
| sed -e 's|^\#define \(.*\) 0$$|/* \#undef \1 */|g' > "$@"; \
[ -f "$<".out ] && cat >> "$@" "$<".out; true
CFG_CFLAGS= $(CFLAGS) $(shell cat $(PKG_CFLAGS) $(PKG_LDFLAGS) /dev/null)
CFG_CXXFLAGS= $(CXXFLAGS) $(shell cat $(PKG_CFLAGS) $(PKG_LDFLAGS) /dev/null)
CFG_CC_CMD= $$($(CC) $(CFLAGS) $(CFLAGS_CONFIG_$*) $(LDFLAGS) $(CFG_TEST))
CFG_CXX_CMD= $$($(CXX) $(CXXFLAGS) $(CXXFLAGS_CONFIG_$*) $(LDFLAGS) $(CFG_TEST))
CFG_LIB_CMD= $$($(CC) $(CFLAGS) $(CFLAGS_CONFIG_$*) $(LDFLAGS) -l$* $(CFG_TEST))
CFG_FN_CMD= $$($(CC) $(CFLAGS) $(CFLAGS_CONFIG_$*) $(LDFLAGS) $(CFG_TEST))
CFG_CC_CMD= `$(CC) $(CFG_CFLAGS) $(CFLAGS_CONFIG_$*) $(CFG_TEST)`
CFG_CXX_CMD= `$(CXX) $(CFG_CXXFLAGS) $(CXXFLAGS_CONFIG_$*) $(CFG_TEST)`
CFG_LIB_CMD= `$(CC) $(CFG_CFLAGS) $(CFLAGS_CONFIG_$*) -l$* $(CFG_TEST)`
CFG_FN_CMD= `$(CC) $(CFG_CFLAGS) $(CFLAGS_CONFIG_$*) $(CFG_TEST)`
CC_CONFIG= $(CFG_DEF) HAVE_$(CFG_UPPER)_H $(CFG_CC_CMD) $(CFG_UNDEF0)
CXX_CONFIG= $(CFG_DEF) HAVE_$(CFG_UPPER) $(CFG_CXX_CMD) $(CFG_UNDEF0)

View File

@ -94,9 +94,6 @@ BUILD_COUNT:= $(words $(SOURCES))
GIT_REVISION:= $(shell git rev-parse --short HEAD 2> /dev/null || echo "unknown")
PROFILE_OUTPUT:=$(subst $(EXE_EXT),,$(OBJROOT_EXE))_prof_$(GIT_REVISION).vsp
-include $(PKGCONFIGS:%=$(OBJROOT)/%.pkg-config.mk)
#------------------------------------------------------------------------------
# User targets
#------------------------------------------------------------------------------
@ -182,7 +179,6 @@ objects:$(OBJDIR:%=%/.mkdir) $(OBJECTS)
# "Hooks" for pre and post build steps
config: $(VARIANTS:%=%.variant)
config: $(PKGCONFIGS:%=$(OBJROOT)/%.pkg-config.mk)
config: $(CONFIG:%=config.h)
prebuild: config
postbuild:
@ -209,11 +205,6 @@ product.test: product .ALWAYS
%.install_hdr: $(PREFIX_HDR).mkdir
$(PRINT_INSTALL) $(INSTALL) $* $(PREFIX_HDR)
# Check pkg-config
$(OBJROOT)/%.pkg-config.mk: $(MAKEFILE_DEPS) $(OBJROOT)/.mkdir
$(PRINT_PKGCONFIG) pkg-config $*
$(PRINT_COMMAND) (echo CFLAGS_PKGCONFIG+=`pkg-config --cflags $*` && echo LDFLAGS_PKGCONFIG+=`pkg-config --libs $*`) > $@
# Benchmarking (always done with profile target)
benchmark: $(BENCHMARK:%=%.benchmark) $(BENCHMARKS:%=%.benchmark)
product.benchmark: product .ALWAYS
@ -391,6 +382,23 @@ ifeq ($(MAKECMDGOALS),build)
endif
#------------------------------------------------------------------------------
# Package configuration
#------------------------------------------------------------------------------
# Package configuration file
PKG_CFLAGS=$(PKGCONFIGS:%=$(OBJROOT)/%.pkg-config.cflags)
PKG_LDFLAGS=$(PKGCONFIGS:%=$(OBJROOT)/%.pkg-config.ldflags)
$(OBJROOT)/pkg-config.mk: $(PKG_CFLAGS) $(PKG_LDFLAGS)
$(PRINT_COMMAND) (echo CFLAGS_PKGCONFIG=`cat $(PKG_CFLAGS)`; echo LDFLAGS_PKGCONFIG=`cat $(PKG_LDFLAGS)`) > $@
-include $(PKGCONFIGS:%=$(OBJROOT)/pkg-config.mk)
$(OBJROOT)/%.pkg-config.cflags: $(MAKEFILE_DEPS) $(OBJROOT)/.mkdir
$(PRINT_PKGCONFIG) pkg-config --cflags $* > $@
$(OBJROOT)/%.pkg-config.ldflags: $(MAKEFILE_DEPS) $(OBJROOT)/.mkdir
$(PRINT_COMMAND) pkg-config --libs $* > $@
#------------------------------------------------------------------------------
# Configuration rules
#------------------------------------------------------------------------------
@ -398,7 +406,7 @@ endif
NORM_CONFIG=$(subst <,.lt.,$(subst >,.gt.,$(subst /,.sl.,$(CONFIG))))
ORIG_TARGET=$(subst .lt.,<,$(subst .gt.,>,$(subst .sl.,/,$*)))
CONFIG_DEPS= $(MAKEFILE_DEPS) $(OBJDIR)/.mkdir \
$(PKGCONFIGS:%=$(OBJROOT)/%.pkg-config.mk)
$(PKGCONFIGS:%=$(OBJROOT)/pkg-config.mk)
config.h: $(NORM_CONFIG:%=$(OBJDIR)/CFG_HAVE_%.h)
$(PRINT_GENERATE) cat $^ > $@