Search code examples
makefileautotools

Symbols ($(bindir), $(sysconfdir),...) unknown in (sub) Makefiles


I'm working with autotools for the first time, for a tool that's written in perl (SQLTeX), so only installation is required, no compilation.

The toplevel contains a simple Makefile.am:

AUTOMAKE_OPTIONS = foreign
SUBDIRS = src man doc

EXTRA_DIST = README.md

.PHONY: all-am
all-am:
    @echo "Done!"

If I create Makefile.am files in the sub-directories too, nothing seems to happen there so I just stick to Makefile. A snippet from src/Makefile (EDIT: this file is now renamed to Makefile.am):

SQLTeX: SQLTeX.pl
    cat $^ | sed -e 's#{PERLDIR}#$(PL)#;s#{SYSCONFDIR}#$(sysconfdir)#' > $@
    @chmod +x $@

The symbol PL is set as expect (defined in the same makefile), but sysconfdir is empty, although it is defined in the top-level Makefile generated by ./configure.

What am I doing wrong?

Thanks in advance!


Solution

  • What am I doing wrong?

    Although the Autotools support, with some caveats, recursing into directories where you provide pre-built makefiles, you cannot expect those pre-built makefiles to be able to rely on autotools-provided variables such as the standard directory variables bindir and sysconfdir. Thus, although it is allowed to rely on hand-written makefiles in subdirectories, this is probably a false trail for you.

    I recommend going back to this:

    If I create Makefile.am files in the sub-directories too, nothing seems to happen there

    and working out what's wrong. The Autotools definitely support generating recursive build systems, and one Makefile.am per directory is part of the usual approach to that. If it didn't work for you then my first guess would be that you forgot to list the extra makefiles in your AC_CONFIG_FILES list.

    As an alternative, just because you have multiple directories does not mean that you need to use recursive make. It is quite possible to build such a project with the support of a single makefile, and the Autotools can help with such a makefile.