Allowing users to override CFLAGS, CXXFLAGS and friends

后端 未结 4 2151
面向向阳花
面向向阳花 2021-01-19 10:40

Typical makefiles often use the built-in variables CFLAGS, CXXFLAGS, CPPFLAGS and so on1 to set the flags passed to the C,

4条回答
  •  失恋的感觉
    2021-01-19 10:41

    Just stumbled upon the same question while building an RPM with debuginfo package.

    The requirement for debuginfo generation is to pass -g in CFLAGS while preserving whatever CFLAGS the software has in its Makefile.

    So if you want to add some extra bits to CFLAGS, without overwriting the ones present in Makefile, you can simply use CFLAGS as an environment variable. But only as long as the Makefile in question uses CFLAGS += ... notation.

    Example, suppose that you have software with Makefile having:

    CFLAGS += $(ARCH) -O3 -std=gnu11 -Wall ...
    

    To have it build with all those flags and -g, you will do:

    CFLAGS='-g' make 
    

    Note that passing it as an argument to make won't work, as in: make CFLAGS='-g' is wrong, because it will overwrite internal CFLAGS.

    More on the solution to pass -g for building debuginfo packages properly

    Here's reference on make: appending to variables.

提交回复
热议问题