[m-dev.] Bootstrapping Mercury with custom CFLA

Julien Fischer jfischer at opturion.com
Sun Oct 1 00:11:14 AEST 2017


Hi Keri,

On Sat, 30 Sep 2017, Keri Harris wrote:

> Is there a recommended way to specify custom (GCC) compiler flags when 
> bootstrapping Mercury? Both CFLAGS and EXTRA_CFLAGS seem like obvious 
> choices, but passing in either of them leads to build errors:
>
> $ make CFLAGS="..."
>
> gmake[2]: Entering directory '/home/keri/mercury-srcdist-14.01.1/util'
> ../scripts/mgnuc --no-mercury-stdlib-dir \
>   	--grade hlc.gc    -- -march=native -O2 -pipe -frecord-gcc-switches -o
>   mkinit \
> 		mkinit.c mkinit_common.c
> mkinit.c:40:29: fatal error: mercury_conf.h: No such file or directory
> compilation terminated.
> mkinit_common.c:19:29: fatal error: mercury_conf.h: No such file or directory
> compilation terminated.
>
> $ make EXTRA_CFLAGS="..."
>
> gmake[2]: Entering directory '/home/keri/mercury-srcdist-14.01.1/robdd'
> ../scripts/mgnuc --no-mercury-stdlib-dir --grade hlc.gc.pregen       -- 
> -DNDEBUG -DNEW -DCLEAR_CACHES -DCOMPUTED_TABLE -DEQUAL_TEST 
> -DUSE_ITE_CONSTANT -DRESTRICT_SET    -march=native -O2 -pipe 
> -frecord-gcc-switches    -c bryant.c -o bryant.o
> bryant.c:107:25: fatal error: mercury_imp.h: No such file or directory
> compilation terminated.

The problem there is that you are setting CFLAGS and EXTRA_CFLAGS for
make *not* mmake.  As a consequence you have ended up overriding the
CFLAGS that mmake constructs with your CFLAGS.  (One of the things
passed via CFLAGS is the location of the runtime header files, hence the
error above.)

To do what you want add the variable definitions to a file named
Mmake.params at the top-level of the source tree; mmake will pick them
up from there and handle them appropriately.

For example, if Mmake.params contains

    EXTRA_CFLAGS = -O0

then mmake will append -O0 to every invocation of GCC.  (Note that GNU
make's '+=', ':=' will also apply with mmake.)

(For the stage2 and stage3 compilers the file should be named
Mmake.stage.params rather than Mmake.params.)

> My preference would be for the EXTRA_XXX flags (EXTRA_CFLAGS, EXTRA_LDFLAGS 
> etc) to always be reserved for the user. Patching robdd/Mmakefile to avoid 
> using EXTRA_CFLAGS would then allow the build to succeed; see attached patch 
> for one way to do this.

They are reserved for the user; in this case the user happens to be the
Mercury compiler itself.

Julien.


More information about the developers mailing list