[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Automatic recompile when flags change

From: Basin Ilya
Subject: Re: Automatic recompile when flags change
Date: Thu, 20 Oct 2016 19:11:06 +0300
User-agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0

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/ $(CFLAGS))

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

The script ./build-aux/ 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.

On 20.10.2016 14:26, Pauli . wrote:
> 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 = $(address@hidden@)
> flags_verbose_ = $(address@hidden@)
> flags_verbose_0 = @echo "  CHK-FLAG $@";
> flags_verbose_1 =
> #Helper for variable lists
> varprefix=$(foreach V,$(2),$($(1)$(V)))
> 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)))

reply via email to

[Prev in Thread] Current Thread [Next in Thread]