[m-dev.] proposal: runtime detection of C compiler flags

Julien Fischer jfischer at opturion.com
Fri Oct 11 18:05:44 AEDT 2013


Hi all,

Consider a Mercury compiler configured against GCC 4.7 (executable: gcc-4.7).
If we also have GCC 4.8 installed on the same system (executable: gcc-4.8), and
wish to use that with the Mercury installation, the the following is unlikely
to currently work correctly without re-configuring the system:

     mmc --cc gcc-4.8 --c-compiler-type gcc_4_8_0

(Or the equivalent using the MERCURY_C_COMPILER etc environment variables).
The above of course applies to all C compilers, not just GCC.  The point of
what follows is that the above *should* work correctly and that it would
be useful if it did work correctly.

The reason the above does not necessarily work is because we currently
determine nearly all (but in fact, not all)  of the properties of the target C
compiler at configuration time and write them out into the Mercury.config file.
I propose that for mmc --make (and also just mmc invoked directly)  C compiler
flags should be determined at runtime based on the values of --c-compiler-type
and (where necessary) --fullarch options.  In particular, I am referring to the
values of the following options:

     --cflags-for-warnings
     --cflags-for-optimization
     --cflags-for-ansi
     --cflags-for-regs
     --cflags-for-gotos
     --cflags-for-threads
     --cflags-for-debug
     --cflags-for-pic

As a transitional measure we would only do runtime setting of these flags if
the values in Mercury.config were empty.  Note that the double maintenance
problem this seems entail already exists, this change would just shift it around
(Actually, the existing situation is worse since we already do some runtime setting
of C compiler flags in compiler/compile_target_code.m as well.)

Nothing I am proposing here will affect mmake or the C compiler flags used by
the mgnuc script (i.e. building Mercury itself won't change).

As part of this change, I suspect we will need to break up compiler_target_code
into smaller, target-language specific submodules.

Finally, I propose to change the name of --fullarch to --target-arch (leaving
--fullarch as a synonym) and add the environment variable MERCURY_TARGET_ARCH,
which can be used to override the default setting --fullarch.

Comments?

Cheers,
Julien.




More information about the developers mailing list