From: Nikolai Weibull Date: 2011-11-18T00:45:53+09:00 Subject: [ruby-core:41108] Re: mkmf sets CFLAGS to contain flags that it shouldn't be setting On Thu, Nov 17, 2011 at 14:46, Nobuyoshi Nakada wrote: > At Thu, 17 Nov 2011 16:27:27 +0900, > Nikolai Weibull wrote in [ruby-core:41094]: >> An example is that on my system, warnflags includes >> -Wdeclaration-after-statement. ��I don���t want this warning, as I use >> -std=c99, which allows such mixing of declarations and statements. >> (It does not matter if -Wdeclaration-after-statement comes before or >> after -std=c99, as I initially thought.) > How do you pass -std option to mkmf? ��If you do it in > extconf.rb, you could also override $warnflags together. Well, I perform a try_compile with the option, and if that passes I add it to $CFLAGS. You can read the code here: https://github.com/now/u/blob/master/ext/u/extconf.rb True, perhaps overriding $warnflags is better, but this needs to be backwards compatible with 1.8.7. That���s not hard to handle, I suppose, but still, it then still needs to be handled. And I still don���t believe Ruby should be telling me what optimizations to apply, as, for example, gcc may bomb with my code for -O3 but not with -O2. >>> It's convenient to change just optimizations, debugging, and >>> etc., on the compilation time. >> I don���t follow. ��Can you clarify? > > Sometimes I need to compile particular sources with different > options temporarily. I assume that you mean that you can run make as make optflags=-O2 if you don���t want to use the default value. I find it a lot more of an issue that I have to remember to run make as make cflags= every time (unless I remove '$(cflags)' from $CFLAGS in extconf.rb as I���ve done in the extconf.rb mentioned above). This issue seems to stem from the fact that mkmf is used for the bundled extensions and has been optimized for that use case. For the bundled extensions, having mkmf generate Makefiles with the same flags as for Ruby makes sense. For third-part extensions this, however, doesn���t hold true, at least not for the flags that we���re discussing here.