Is there a way to change the specs file so that it will pass -march=native if nothing is specified in command line?
Related things in the default specs file is:
*cc1:
%(cc1_cpu)
*cc1_cpu:
%{march=native:%>march=native %:local_cpu_detect(arch) %{!mtune=*:%>mtune=native %:local_cpu_detect(tune)}} %{mtune=native:%>mtune=native %:local_cpu_detect(tune)}
I am not sure how specs works. Simply specifying -march=native before or after %(cc1_cpu) doesn’t work. However, this line does take effect because GCC will report error if I put -something_wierd instead of -march=native.
Another thing I noticed is if I put %{march=i386:-something_wierd} before %(cc1_cpu), gcc reports error so looks like -march=i386 is always passed in if nothing is specified, so is there a way to distinguish between nothing specified and -march=i386 in specs file?
BTW, what does %> do? Seems like it is not specified in the documentation.
I am using MinGW’s gcc-4.6.2.
Referring to your last question: The gcc 4.6.1 sources (
gcc/gcc.c) contain the following comment on%>:For the sake of completeness following the comment for
%<form the same file:To answer the first question in short: yes, but ….
… the only generic solution I found has the significant drawback that the
-marchoption will be ignored, so every build is done as if-march=nativehad been specified. Anyhow there is a workaround to that.1 The solution (without workaround)
Create a specs-file called let’s say
specs.nativealwayscontaining:When using the specs-file (for example by invoking
gccwith the option-specs=specs.nativealways) the build will be done as if-march=nativewas specified (with the mentioned drawback that any occurrence of option-march=<arch>would have simply been ignored).2 The workaround
To still by able to override the newly configured default behavior one can use a modified version of the specs-file described above, introducing a new option called
-myarchusing the same syntax as-march(except for-myarch=native, which won’t work, which does not metter asnativenow is the default).The modfied specs-file looks like this:
PS: This has been tested with with gcc 4.6.2 on Linux, but should work on MinGW.