Search code examples
pythonconditional-statementsautoconfautomake

Makefile conditional with automake/autoconf


can anybody tell me if there is a way to insert a conditional block to Makefile.am so that it will be passed further to a Makfile created by autotools?

Here is an example:

ifeq "$(SOMEVAR)" ""
SOMEVAR="default_value"
endif

This seems to be a usual Makefile way of doing conditional things. Automake cuts endif line off and make fails eventually with a message like this:

Makefile:390: * missing `endif'. Stop.

any thoughts?


Solution

  • Since it's tagged as Autoconf also, I suggest putting the condition in configure.ac, if that is possible. Similar to so:

    AM_CONDITIONAL([CONDITION_NAME], [test x"${SOMEVAR}" != x])
    

    Then, your Makefile.am would contain

    if CONDITION_NAME
    <conditional code>
    else
    <else :)>
    endif
    

    Update

    The problem has to do with

    python setup.py --root=$(DESTDIR) --prefix=$(DESTDIR)$(prefix)
    

    being called from somewhere. If DESTDIR is empty, the prefix may expand to a relative path, which is not what you want. You have confirmed it is being called from your Makefile.am. Then there's two things you can do.

    1. Change the above command to python setup.py --root=${DESTDIR}/// --prefix=${DESTDIR}///$(prefix). Triple slashes may be necessary since, AFAIK, POSIX allows for double slashes to have a special meaning, but not for three or more consecutive slashes.

    2. Change the above command to DESTDIR=${DESTDIR:-///} && python setup.py --root=${DESTDIR} --prefix=${DESTDIR}$(prefix)

    It may be noteworthy that, in my opinion and limited understanding of the whole picture, none of that should be necessary. Since the original caller of configure was able to specify exactly which prefix he really wanted to use. If none is specified, Autoconf already defaults to an absolute path (/usr/local). So, I guess, I don't quite understand why you run into your problem.