Search code examples
makefileautoconfautomake

Automake fails when trying to run platform-specific build


I am using autotools to build a project that I want to cross-compile for both Linus and Mac OSX. I am building two libraries, libevent.la and libaffinity.la. libevent should be build when automake is run on both platform. However, libaffinity.la should be build only if the platform is MACOSX. To this end, I have the following in my configure.ac file:

#Detect the target system
case "$host_os" in
    darwin*)
        build_darwin=yes
        ;;
esac

AM_CONDITIONAL([DARWIN], [test "$build_darwin" = "yes"])

The variableDARWIN will be set if the proejct is being build on Mac OS. And in the Makefile.am I have following:

extlibdir = $(libdir)/guile/$(GUILE_EFFECTIVE_VERSION)/extensions
extlib_LTLIBRARIES = libevent.la
AM_CFLAGS = -I$(srcdir) $(WARN_CFLAGS) $(DEBUG_CFLAGS) 
libevent_la_SOURCES = libevent.c
libevent_la_CFLAGS = $(AM_CFLAGS) $(GUILE_CFLAGS) -Wno-error -Wno-nullability-completeness -Wno-expansion-to-defined
libevent_la_LIBADD = $(GUILE_LIBS)
libevent_la_LDFLAGS = -export-dynamic -module
$(GOBJECTS): libevent.la

if DARWIN
    extlib_LTLIBRARIES += libaffinity.la
    affinity_la_SOURCES = affinity.c
    affinity_la_CFLAGS = $(AM_CFLAGS) $(GUILE_CFLAGS) -Wno-error -Wno-nullability-completeness -Wno-expansion-to-defined
    affinity_la_LIBADD = $(GUILE_LIBS)
    affinity_la_LDFLAGS = -export-dynamic -module
    $(GOBJECTS) += libaffinity.la
endif

When I run make, it fails with the following error:

extlib_LTLIBRARIES += affinity.la

make[1]: extlib_LTLIBRARIES: No such file or directory

make: *** [all] Error 2

However, as you can see, extlib_LTLIBRARIES is defined above the if statement.

How can I fix this? Or is there a better way to do this so that I can selectively build libaffinity.la based on the platform?


Solution

  • The main problem turns out to have been that the lines in the conditional section were indented with tabs. These are not particularly significant to Automake, but they will have been carried through to its generated Makefile.in, and, from there, to the Makefile generated by configure. Tabs are significant to make: a leading tab is how make recognizes the lines of a rule's recipe. (Only a tab will do; spaces do not have the same significance.)

    The effect, then, was that make interpreted extlib_LTLIBRARIES += libaffinity.la as one of the commands in the recipe for some rule, so that when it tried to apply the rule, it wanted to execute a system command named extlib_LTLIBRARIES. There being no such executable command found in the path, the shell failed and reported "No such file or directory", which message make forwarded on to its own output.

    The fix is to avoid indenting with tabs in your Makefile.am (spaces are ok), except where you actually intend to write a recipe for a make rule (for which an initial tab is obligatory).