3
votes

I am searching for solution of my problem for a while and getting suspicion that I chose wrong approach, but it looked simple enough to be possible.

Basically I want to inform my application where some additional data will be installed. I am doing it by defining preprocessor variable during compilation. Unfortunately data installation and application compilation is defined in two separate Makefiles (genereted with autotools) and I don't know how to pass this installation path between them.

I extracted the problematic part from my project, so here is how it looks like:

/
|-- configure.ac
|-- Makefile.am
|-- info
|   \-- index.html
\-- src
    |-- Makefile.am
    \-- main.cpp

configure.ac

AC_INIT(foo, 1.0)
AC_CONFIG_SRCDIR(src/main.cpp)
AM_INIT_AUTOMAKE
AC_PROG_CXX
AC_OUTPUT(Makefile src/Makefile)

Makefile.am

infodir = $(datadir)/foo/
nobase_dist_info_DATA = info/index.html
SUBDIRS = . src

src/Makefile.am

bin_PROGRAMS = foo
foo_SOURCES = main.cpp
foo_CPPFLAGS = -DWEB_PATH=\"$(infodir)\"

After ./configure $(infodir) in src/Makefile is not defined. How can I tell src/Makefile.am to generate this variable with the value from top level Makefile? Or, if it is just wrong way to do it, how can I achive my goal in a right way?

1

1 Answers

0
votes

For this, you would be better off using non-recursive make.

However, if you really want to do it this way, then you can use includes. Put the definition of infodir in a file named something like Makefile-common.am.inc and then in each Makefile write

include $(top_srcdir)/Makefile-common.am.inc