Search code examples
variablesmakefileconfigureautotools

CPPFLAGS set from configure.ac are ignored in Makefile.am


I am trying to build TerraGear with self-made AutoTools files (configure script). TerraGear is split into several subprojects. For each, I create a different set of configure.ac and Makefile.am files, but they are all almost the same.

Consider the following two files:

configure.ac

AC_PREREQ([2.69])
AC_INIT([TerraGear libterragear], [2.1.0], [])
AC_CONFIG_SRCDIR([airport.cxx])
AC_CONFIG_FILES([Makefile])
AM_INIT_AUTOMAKE([foreign])

AC_PROG_CXX

PKG_CHECK_MODULES([ZLIB], [zlib])
PKG_CHECK_MODULES([GDAL], [gdal])

AC_ARG_WITH([simgear-dir], [AS_HELP_STRING(
    [--with-simgear-dir=prefix],
    [installation prefix of SimGear])],
    [
        SIMGEAR_CPPFLAGS="-I${withval}/include"
        SIMGEAR_LIBRARY="-L${withval}/lib"
    ]
)
AC_MSG_NOTICE([simgear cppflags : ${SIMGEAR_CPPFLAGS}])

AC_OUTPUT

Makefile.am

bin_PROGRAMS = genapts850

genapts850_SOURCES = airport.cxx \
    apt_math.cxx \
    closedpoly.cxx \
    debug.cxx \
    elevations.cxx \
    helipad.cxx \
    lights.cxx \
    linearfeature.cxx \
    linked_objects.cxx \
    main.cxx \
    object.cxx \
    output.cxx \
    parser.cxx \
    runway.cxx \
    rwy_simple.cxx \
    rwy_gen.cxx \
    scheduler.cxx \
    taxiway.cxx

genapts850_LDADD = -L$(top_srcdir)/../../Lib/terragear \
    $(SIMGEAR_LIBRARY) \
    -lSimGearCore \
    -lSimGearScene \
    -lterragear \
    $(ZLIB_LIBRARY) \
    $(GDAL_LIBRARY)

genapts850_CXXFLAGS = -I$(top_srcdir)/../../Lib \
    -I$(top_srcdir)/../../Lib/terragear \
    $(SIMGEAR_CPPFLAGS) \
    $(ZLIB_CFLAGS) \
    $(GDAL_CFLAGS)/gdal

I run autoreconf:

autoreconf -vfi
autoreconf: Entering directory `.'
autoreconf: configure.ac: not using Gettext
autoreconf: running: aclocal --force 
autoreconf: configure.ac: tracing
autoreconf: configure.ac: not using Libtool
autoreconf: running: /usr/bin/autoconf --force
autoreconf: configure.ac: not using Autoheader
autoreconf: running: automake --add-missing --copy --force-missing
autoreconf: Leaving directory `.'

then run the configure script:

./configure --with-simgear-dir=/path/to/simgear/installation/prefix
[...]
configure: simgear cppflags : -I/path/to/simgear/installation/prefix/include
[...]

then I run make:

make
g++ -DPACKAGE_NAME=\"TerraGear\ libterragear\" -DPACKAGE_TARNAME=\"terragear-libterragear\" -DPACKAGE_VERSION=\"2.1.0\" -DPACKAGE_STRING=\"TerraGear\ libterragear\ 2.1.0\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DPACKAGE=\"terragear-libterragear\" -DVERSION=\"2.1.0\" -I.    -I./../../Lib -I./../../Lib/terragear   -Ig++ -DPACKAGE_NAME=\"TerraGear\ libterragear\" -DPACKAGE_TARNAME=\"terragear-libterragear\" -DPACKAGE_VERSION=\"2.1.0\" -DPACKAGE_STRING=\"TerraGear\ libterragear\ 2.1.0\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DPACKAGE=\"terragear-libterragear\" -DVERSION=\"2.1.0\" -I.    -I./../../Lib -I./../../Lib/terragear   -I/path/to/simgear/installation/prefix/include/gdal -g -O2 -MT genapts850-airport.o -MD -MP -MF .deps/genapts850-airport.Tpo -c -o genapts850-airport.o `test -f 'airport.cxx' || echo './'`airport.cxx
airport.cxx:6:10: fatal error: simgear/compiler.h: Datei oder Verzeichnis nicht gefunden
    6 | #include <simgear/compiler.h>
      |          ^~~~~~~~~~~~~~~~~~~~
compilation terminated.
make: *** [Makefile:471: genapts850-airport.o] Fehler 1

(simgear/compiler.h resides inside /path/to/simgear/installation/prefix/include) What am I doing wrong ? I'm banging my head into the screen for three hours now without being able to figure out the problem. Please help …


Solution

  • Not all shell variables defined in configure are forwarded to output files. Generally speaking, you need to use AC_SUBST() to tell Autoconf that a shell variable should be an output variable:

    AC_SUBST([SIMGEAR_CPPFLAGS])
    AC_SUBST([SIMGEAR_LIBRARY])