Rack: Compiler Flags Helper Variables

Created on 16 Oct 2019  路  3Comments  路  Source: VCVRack/Rack

Summary

This proposal could make the build process more developer-oriented for the framework, by adding these variables, you might have the ability to override flags assigned to the compiler by the plugin's makefile or make command.

for example you could use a similar command
make EXTRA_CFLAGS='-O0' EXTRA_CXXFLAGS='-O0 -std=c++17' install
to override some already set flags set by design or for compatibility reason.

Proposed design

image

add this extra variables:

$(EXTRA_CFLAGS)
$(EXTRA_CXXFLAGS)

to the compile.mk file here
https://github.com/VCVRack/Rack/blob/de76887320eeba2fc2d3b64adf2254aca72ec9d3/compile.mk#L40-L41
to this:

CFLAGS += $(FLAGS) $(EXTRA_CFLAGS)
CXXFLAGS += $(FLAGS) $(EXTRA_CXXFLAGS)

Most helpful comment

My first attempt was to append environment variables to Makefile variables, so that CXXFLAGS=-std=c++17 would result in a final value of -std=c++11 -std=c++17, i.e. flags defined in Makefile + environment variables.

However, after finding no straightforward solution in the Make manual (although I do think it's possible with hacks like temporarily redefining the variables), I realized that users actually do expect their environment to be prepended to the final flags because this is the behavior everywhere else. It doesn't seem that EXTRA_* is precisely the de-facto standard, but at least it's common enough for me to see it elsewhere.

Added EXTRA_FLAGS, EXTRA_CFLAGS, EXTRA_CXXFLAGS, EXTRA_LDFLAGS in 043401c.

In summary, define an environment variable CXXFLAGS=whatever make to prepend C++ compiler flags. Use EXTRA_CXXFLAGS=whatever make to append C++ compiler flags. Don't use make variables make CXXFLAGS=whatever as that redefines variables, not prepends them.

All 3 comments

ok, after some deep search on the community, I found this but it is only work from makefile and not from command arguments.
https://community.vcvrack.com/t/newest-c-standard-allowed-for-inclusion-in-plugin-library/5970/4

You can of course define CFLAGS, CXXFLAGS, LDFLAGS, etc and they will be prepended to the Makefile variables. Is your feature request to be able to append flags to redefine compile settings like -std=c++11 -std=c++17?

My first attempt was to append environment variables to Makefile variables, so that CXXFLAGS=-std=c++17 would result in a final value of -std=c++11 -std=c++17, i.e. flags defined in Makefile + environment variables.

However, after finding no straightforward solution in the Make manual (although I do think it's possible with hacks like temporarily redefining the variables), I realized that users actually do expect their environment to be prepended to the final flags because this is the behavior everywhere else. It doesn't seem that EXTRA_* is precisely the de-facto standard, but at least it's common enough for me to see it elsewhere.

Added EXTRA_FLAGS, EXTRA_CFLAGS, EXTRA_CXXFLAGS, EXTRA_LDFLAGS in 043401c.

In summary, define an environment variable CXXFLAGS=whatever make to prepend C++ compiler flags. Use EXTRA_CXXFLAGS=whatever make to append C++ compiler flags. Don't use make variables make CXXFLAGS=whatever as that redefines variables, not prepends them.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Euphorbium picture Euphorbium  路  8Comments

ShofB picture ShofB  路  4Comments

synthi picture synthi  路  4Comments

vogelscheiss picture vogelscheiss  路  5Comments

jonheal picture jonheal  路  4Comments