Discussion:
Automatic recompile when flags change
Pauli .
2016-10-20 11:26:35 UTC
Permalink
Hello

In many cases partial build with differing flags can results to hard
to debug runtime bugs. To avoid issues when compiler flags change
build system could automatically rebuild files when flags change. But
so far automake doesn't support flag change checking

I decided to try to implement checking my self. Following
implementation seems fairly simple but I think implementation depends
on gnu make specific features. It supports only c++ and seperation of
language specific flags is missing (to recompile only C files if
CFLAGS changes).

I'm wondering if this checking could be implemented in automake. I
don't want to attempt to implement this my self because I don't have
experience writing portable makefiles.

# Add compiler flags dependency to targets
flags_verbose = $(***@AM_V@)
flags_verbose_ = $(***@AM_DEFAULT_V@)
flags_verbose_0 = @echo " CHK-FLAG $@";
flags_verbose_1 =

#Helper for variable lists
varprefix=$(foreach V,$(2),$($(1)$(V)))

FD_VARS = CPPFLAGS CXXFLAGS LDFLAGS LDADD

FD_GLOBALS = $(call varprefix,AM_,$(FD_VARS)) $(call varprefix,,$(FD_VARS))

%.flags: %.tflags
$(flags_verbose)if ! cmp -s $< $@; then cp $< $@; fi; $(RM) $<

# Generate rules and dependencies for a target
# param 1: target filename
# param 2: target variable prefix
define flagsdep_single

$(1).tflags:
@echo "$$(FD_GLOBALS) $$(call varprefix,$(2)_,$$(FD_VARS))" > $$@;

$$(am_$(2)_OBJECTS): $(1).flags

$(1): $(1).flags

endef

# Callable variable to add flag dependency to targets
flagsdep=$(foreach T,$(1),$(call flagsdep_single,$(T),$(subst
.,_,$(subst $(EXEEXT),,$(T)))))

$(eval $(call flagsdep,$(LTLIBRARIES) $(PROGRAMS) $(check_PROGRAMS)))
Basin Ilya
2016-10-20 16:11:06 UTC
Permalink
Hi.
I think $(eval) is less portable than $(shell)

Instead of injecting a dependency to all targets you can generate
config.h with autoconf and include it at the beginning of all source
files. Automake plus gcc will make sure that the object files depend on it.

If you change your CFLAGS by running ./configure, you can save them to
config.h. If you plan to pass CFLAGS as make command line arguments,
then you must add a dependency to config.h:

$(top_srcdir)/config.h: $(shell
$(top_srcdir)/build-aux/check-cflags.sh $(CFLAGS))

.PHONY: cflags-changed
cflags-changed: # do nothing

The script ./build-aux/check-cflags.sh will check CFLAGS and if they
change, save them to a file for later comparison and print the PHONY
target name "cflags-changed".

You must also touch config.h in the script before saving CFLAGS in case
make is interrupted.
Post by Pauli .
Hello
In many cases partial build with differing flags can results to hard
to debug runtime bugs. To avoid issues when compiler flags change
build system could automatically rebuild files when flags change. But
so far automake doesn't support flag change checking
I decided to try to implement checking my self. Following
implementation seems fairly simple but I think implementation depends
on gnu make specific features. It supports only c++ and seperation of
language specific flags is missing (to recompile only C files if
CFLAGS changes).
I'm wondering if this checking could be implemented in automake. I
don't want to attempt to implement this my self because I don't have
experience writing portable makefiles.
# Add compiler flags dependency to targets
flags_verbose_1 =
#Helper for variable lists
varprefix=$(foreach V,$(2),$($(1)$(V)))
FD_VARS = CPPFLAGS CXXFLAGS LDFLAGS LDADD
FD_GLOBALS = $(call varprefix,AM_,$(FD_VARS)) $(call varprefix,,$(FD_VARS))
%.flags: %.tflags
# Generate rules and dependencies for a target
# param 1: target filename
# param 2: target variable prefix
define flagsdep_single
@echo "$$(FD_GLOBALS) $$(call varprefix,$(2)_,$$(FD_VARS))" > $$@;
$$(am_$(2)_OBJECTS): $(1).flags
$(1): $(1).flags
endef
# Callable variable to add flag dependency to targets
flagsdep=$(foreach T,$(1),$(call flagsdep_single,$(T),$(subst
.,_,$(subst $(EXEEXT),,$(T)))))
$(eval $(call flagsdep,$(LTLIBRARIES) $(PROGRAMS) $(check_PROGRAMS)))
Bob Friesenhahn
2016-10-20 17:33:50 UTC
Permalink
Post by Pauli .
In many cases partial build with differing flags can results to hard
to debug runtime bugs. To avoid issues when compiler flags change
build system could automatically rebuild files when flags change. But
so far automake doesn't support flag change checking
Why do compiler flags change? Did you re-run configure with different
CPPFLAGS/CFLAGS or are these flags induced on the make command line or
via environment variables?

Bob
--
Bob Friesenhahn
***@simple.dallas.tx.us, http://www.simplesystems.org/users/bfriesen/
GraphicsMagick Maintainer, http://www.GraphicsMagick.org/
Pauli .
2016-10-28 21:33:50 UTC
Permalink
On Thu, Oct 20, 2016 at 8:33 PM, Bob Friesenhahn
Post by Bob Friesenhahn
Post by Pauli .
In many cases partial build with differing flags can results to hard
to debug runtime bugs. To avoid issues when compiler flags change
build system could automatically rebuild files when flags change. But
so far automake doesn't support flag change checking
Why do compiler flags change? Did you re-run configure with different
CPPFLAGS/CFLAGS or are these flags induced on the make command line or via
environment variables?
It can happen for many reason but most likely to cause trouble for
developer is when configure.ac changes which leads to automatic
reconfigure with different flags.

Pauli

Loading...