Allowing users to override CFLAGS, CXXFLAGS and friends

后端 未结 4 2199
面向向阳花
面向向阳花 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条回答
  •  猫巷女王i
    2021-01-19 10:59

    I am faced with the same problem. For the time being my solution is to provide "non-standard" flags such as OPTIMS, WARNINGS, MODENV which will be appended to the "standard" CXXFLAGS internally.

    If the user defines CXXFLAGS from the command-line it is assumed that he wants to override it, and if that's what he wants, that's what he should get: an override. Ironically this means I'm not using override CXXFLAGS += ... in the Makefile.

    I don't want advanced users to pull their hairs out because I insist on appending/prepending my stuff to their flags, so in my opinion the final situation is like this:

    • GOOD: require advanced users to pass intricate custom flags
    • BAD: require advanced users to patch the Makefile

提交回复
热议问题