vinc17
vinc17

Reputation: 3476

Automake and external conditional sources

How to properly define external conditional sources in a Makefile.am file?

As an example, in GNU MPFR, we currently have in src/Makefile.am:

if MINI_GMP
nodist_include_HEADERS += $(mini_gmp_path)/mini-gmp.h
noinst_LTLIBRARIES = libminigmp.la
nodist_libminigmp_la_SOURCES = $(mini_gmp_path)/mini-gmp.h $(mini_gmp_path)/mini-gmp.c
libmpfr_la_LIBADD += libminigmp.la
endif

where MINI_GMP is true when mini_gmp_path is defined. The goal is to optionally build MPFR against a libminigmp library (mini-gmp), which is itself built with the autotools machinery (same compiler, same options, etc. as MPFR).

Everything seems to work well, except when one does not want to build against mini-gmp. In this case, the generated configure script fails with:

configure: creating ./config.status
config.status: creating Makefile
config.status: creating mpfr.pc
config.status: creating doc/Makefile
config.status: creating src/Makefile
config.status: creating tests/Makefile
config.status: creating tune/Makefile
config.status: creating src/mparam.h
config.status: creating tools/bench/Makefile
config.status: executing depfiles commands
config.status: error: in `/home/vlefevre/software/mpfr':
config.status: error: Something went wrong bootstrapping makefile fragments
    for automatic dependency tracking.  Try re-running configure with the
    '--disable-dependency-tracking' option to at least be able to build
    the package (albeit without support for automatic dependency tracking).
See `config.log' for more details

and in the config.log file:

config.status:19572: executing depfiles commands
config.status:19647: cd src       && sed -e '/# am--include-marker/d' Makefile         | make -f - am--depfiles
/bin/mkdir: cannot create directory '/.deps': Permission denied
make: *** [/tmp/GmlvxQJQ:720: /.deps/mini-gmp.Plo] Error 1

The reason is that the generated src/Makefile file contains things like $(mini_gmp_path)/$(DEPDIR)/mini-gmp.Plo while mini_gmp_path is not defined. But since one does not want to build against mini-gmp, such information about mini-gmp.Plo is incorrect, i.e. mini-gmp files should completely be ignored for automatic dependency tracking when MINI_GMP is false.

As a workaround, we currently define mini_gmp_path to . in configure.ac when one does not build against mini-gmp, so that the $(mini_gmp_path)/$(DEPDIR) directory exists, avoiding a configure failure. But this is not a clean solution, which might interfere with mini-gmp.{c,h} files that could be added in the MPFR source tree. The solution should just get rid of mini-gmp.Plo entirely.

Upvotes: 0

Views: 2238

Answers (1)

John Bollinger
John Bollinger

Reputation: 181199

I don't think incorporating external sources into your build is a supported use case. It certainly does not make much sense to me. Nevertheless, possible alternatives include

  • Bundle the minigmp sources with your project (their use can still be optional). This has the additional advantage that you can be sure you provide a compatible version.
  • Add standard make rules to create the minigmp sources in some existing directory inside the project by copying them from $(mini_gmp_path). You may also want to list the minigmp sources (in the internal directory) among your BUILT_SOURCES.

    if MINI_GMP
      noinst_LTLIBRARIES = libminigmp.la
      libmpfr_la_LIBADD += libminigmp.la
    
      nodist_libminigmp_la_SOURCES = minigmp/mini-gmp.h minigmp/mini-gmp.c
      BUILT_SOURCES = $(nodist_libminigmp_la_SOURCES)
    
      # Are you want the mini-gmp header to be installed?
      nodist_include_HEADERS += minigmp/mini-gmp.h
    else
      noinst_LTLIBRARIES =
      BUILT_SOURCES =
    endif
    
    minigmp/mini-gmp.c: $(mini_gmp_path)/mini-gmp.c
        cp $< $@
    
    minigmp/mini-gmp.h: $(mini_gmp_path)/mini-gmp.h
        cp $< $@
    

    Automake should not subject such rules to the same level of analysis that it does the variables that are meaningful to it.

  • Put the onus on the project builder to build and install a compatible version of minigmp. Link against that.

Upvotes: 0

Related Questions