blippy
blippy

Reputation: 1540

So what "is" AM_(F)CFLAGS?

The autotools documentation is very confusing. I am writng Fortran, so the AM_CFLAGS equivalent is AM_FCFLAGS. The two work exactly the same way (presumably).

First off, what actually "is" AM_CFLAGS, conceptually? Clearly, the "CFLAGS" bit is to do with setting compiler flags. But what does the "AM_" part mean?

There seems to be conflicting advice as to how to use it. Some say don't put it in Makefile.am, and some say don't put it in configure.ac. Who is right?

Here is my current Makefile.am:

AM_FCFLAGS = -Wall -O0 -C -fbacktrace

.f90.o:
    $(FC) -c $(AM_FCFLAGS) $<

What I want to happen is to compile with "-Wall -O0 -C -fbacktrace" by default if I'm compiling with gfortran. However, a user might want to use a different compiler, eg FC=ifort, in which case they'll probably have to pass in FCFLAGS="whatever" and completely scrap AM_FCFLAGS

Can the user also override the default AM_FCFLAGS from the configure option if they're still using gfortran?

Basically, WTF?

Upvotes: 2

Views: 1253

Answers (2)

blippy
blippy

Reputation: 1540

In Makefile.am I had

AM_CFCFLAGS = -Wall -O0 -C -fbacktrace

Bad idea! It assumes that folks are using gfortran and/or won't want to override those defaults. So I deleted that line.

Instead, I now have the following lines in configure.ac:

AC_PROG_FC([gfortran], [Fortran 90]) # we need a Fortran 90 compiler
AS_IF([test x$FC = xgfortran -a x$ac_cv_env_FCFLAGS_set = x],
   AC_SUBST([FCFLAGS], ["-Wall -O0 -C -fbacktrace"])
   [Set some flags automatically if using gfortran])

AC_PROG_FC checks for gfortran that meets with Fortran 90 standards, and automatically sets FC and FCFLAGS.

The last 3 lines set sensible defaults if the user is using gfortran, but hasn't set FCFLAGS.

I discovered about ac_cv_env_FCFLAGS_set when I looked at config.log. It is set to "set" if the user sets their own FCFLAGS.

In Makefile.am I now have rules like:

.f90.o:
        $(FC) -c $(FCFLAGS) $<


datetime_module.mod : datetime.o
datetime.o :      datetime.f90 mod_clock.o mod_datetime.o mod_strftime.o mod_timedelta.o
mod_clock.o:     mod_clock.f90 mod_datetime.o mod_timedelta.o
mod_datetime.o:  mod_datetime.f90 mod_constants.o mod_strftime.o mod_timedelta.o
mod_timedelta.o: mod_timedelta.f90

It's starting to make sense now.

Upvotes: 1

Diego Elio Petten&#242;
Diego Elio Petten&#242;

Reputation: 3240

AM_FCFLAGS (and similarly AM_CFLAGS and similar) are designed to not be user-overridable, so you should not put those options there unless you want them to always be present.

Users can pass their own FCFLAGS as part of their ./configure call — what you can do, if you want to default to those rather than what autoconf will default by itself, is to change configure.ac and compare the default flags (which to be honest I don't know for Fortran) to the current FCFLAGS, and if they match, replace FCFLAGS with your defaults.

Upvotes: 3

Related Questions