• Ævar Arnfjörð Bjarmason's avatar
    Makefile: allow for combining DEVELOPER=1 and CFLAGS="..." · 6d5d4b4e
    Ævar Arnfjörð Bjarmason authored
    Ever since the DEVELOPER=1 facility introduced there's been no way to
    have custom CFLAGS (e.g. CFLAGS="-O0 -g -ggdb3") while still
    benefiting from the set of warnings and assertions DEVELOPER=1
    This is because the semantics of variables in the Makefile are such
    that the user setting CFLAGS overrides anything we set, including what
    we're doing in config.mak.dev[1].
    So let's introduce a "DEVELOPER_CFLAGS" variable in config.mak.dev and
    add it to ALL_CFLAGS. Before this the ALL_CFLAGS variable
    would (basically, there's some nuance we won't go into) be set to:
        $(CPPFLAGS) [$(CFLAGS) *or* $(CFLAGS) in config.mak.dev] $(BASIC_CFLAGS) $(EXTRA_CPPFLAGS)
    But will now be:
    The reason for putting DEVELOPER_CFLAGS first is to allow for
    selectively overriding something DEVELOPER=1 brings in. On both GCC
    and Clang later settings override earlier ones. E.g. "-Wextra
    -Wno-extra" will enable no "extra" warnings, but not if those two
    arguments are reversed.
    Examples of things that weren't possible before, but are now:
        # Use -O0 instead of -O2 for less painful debuggng
        DEVELOPER=1 CFLAGS="-O0 -g"
        # DEVELOPER=1 plus -Wextra, but disable some of the warnings
        DEVELOPER=1 DEVOPTS="no-error extra-all" CFLAGS="-O0 -g -Wno-unused-parameter"
    The reason for the patches leading up to this one re-arranged the
    various *FLAGS assignments and includes is just for readability. The
    Makefile supports assignments out of order, e.g.:
        $ cat Makefile
        X = $(A) $(B) $(C)
        A = A
        B = B
        include c.mak
                @echo $(X)
        $ cat c.mak
        $ make
        A B C
    So we could have gotten away with the much smaller change of changing
    "CFLAGS" in config.mak.dev to "DEVELOPER_CFLAGS" and adding that to
    ALL_CFLAGS earlier in the Makefile "before" the config.mak.*
    includes. But I think it's more readable to use variables "after"
    they're included.
    1. https://www.gnu.org/software/make/manual/html_node/Overriding.htmlSigned-off-by: Ævar Arnfjörð Bjarmason's avatarÆvar Arnfjörð Bjarmason <avarab@gmail.com>
    Signed-off-by: 's avatarJunio C Hamano <gitster@pobox.com>
config.mak.dev 1.61 KB