7

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?

dennycrane
  • 2,301
  • 18
  • 15
autoconfer
  • 73
  • 1
  • 3

2 Answers2

5

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.

dennycrane
  • 2,301
  • 18
  • 15
  • Thanks! This is for configure. I'm talking about the conditional block during make (depending on environment settings). For example if you run make to be installed in a different location like this: "DESTDIR=/some/rpm/builds make install" so Makefile should check whether this variable is set and then generate a command option for installing – autoconfer Nov 23 '10 at 13:51
  • Could you elaborate more on what exectly you want to do? `DESTDIR=/some/rpm/builds make install` does what it does. Do you need to modify it or is extending it enough? It can be extended by both the `install-exec-local` and `install-data-local` targets. These might check whether `DESTDIR` is set or not. – dennycrane Nov 23 '10 at 14:00
  • Well perhaps i needed to be more specific on what i'm trying to do, sorry. The idea is the following. When someone did not provide that DESDDIR env variable, I have to write a conditional block like this ifeq "$(DESTDIR)" "" DESTDIR="/" endif install: python setup.py --root=$(DESTDIR) --prefix=$(DESTDIR)$(prefix) otherwise empty DESTDIR passed to --root option and python is trying to install to a directory starting without slash – autoconfer Nov 23 '10 at 14:03
  • of course I can do the whole thing in configure.ac the way you proposed but then this DESTDIR will be passed to configure script not to make. This is just another solution, isn't it? – autoconfer Nov 23 '10 at 14:09
  • Do you have control over the `python setup.py ...` command line? If so, I'd suggest putting three slashes (`///`) after `$(DESTDIR)`, which should portably do what you want. (Double slashes may have a special meaning in POSIX, AFAIK. But three or more slashes collapse to one slash). If this Python call is in your Makefile.am and I understood the problem correctly now, I'd probably try that. – dennycrane Nov 23 '10 at 14:13
  • 1
    Similarly, if the `python ...` command is located in your Makefile.am, you could do this instead: `DESTDIR="${DESTDIR:-/}" python setup.py ...` – dennycrane Nov 23 '10 at 14:16
  • Yep! This is exactly what i wanted to do! Bravo! – autoconfer Nov 23 '10 at 14:26
  • The second approach with DESTDIR="${DESTDIR:-/}" seems to be nicer, but it doesn't work ... produces empty DESTDIR= in all cases. – autoconfer Nov 23 '10 at 14:31
  • Apologies. That should have been `DESTDIR="${DESTDIR:-/}" && python ...` (note that `&&`). Also, you must change `$(DESTDIR)` to `${DESTDIR}` in the Python command. – dennycrane Nov 23 '10 at 14:36
  • same effect DESTDIR is just empty, so the command line looks like this when no DESTDIR is provided: DESTDIR="" && python setup.py install --root= --prefix=/normal/prefix and like this when destdir is provided: DESTDIR="" && python setup.py install --root=/destdir --prefix=/normal/prefix – autoconfer Nov 23 '10 at 14:54
  • That's odd. Could you please show the whole rule that exhibits this behaviour? `make` should invoke `/bin/sh` and have it execute the respective lines. Does the following /bin/sh command behave as expected? `DESTDIR=${DESTDIR:-/} && echo python setup.py install --root=${DESTDIR} --prefix=${DESTDIR}/usr/local` – dennycrane Nov 23 '10 at 14:59
  • 1
    Eventually I solved the problem other way around. I put a line above in Makefile.am: DESTDIR ?= / which means define a value if it's not set and then used it in python line. Have no idea why it didn't work with ${DESTDIR:-/} construction. I use gnu make and bash, can it be the case that it's not understood by my environment? – autoconfer Nov 24 '10 at 15:43
  • In the answer, the comment is made that $(DESTDIR)$(prefix) may expand to a relative path if DESTDIR is empty. That isn't true. Autoconf generated configure scripts require that prefix begin with a '/'. – William Pursell Dec 16 '10 at 12:46
  • 2
    Lots of pointless workaround, but is there a way to make that automake emit regular if/else/endif into a makefile?? – Pavel P Jun 13 '15 at 13:07
  • @PavelP See [this other question](https://stackoverflow.com/q/7437116/7233423) – xhienne Jun 25 '20 at 18:56
0

I propose another approach I found accidentally in Is there a way to tell automake not to interpret part of the automakefile?. But unfortunately it does not work with ifeq .. else .. endif conditionals.

domson
  • 205
  • 2
  • 8