Why variable `FOO' not defined even if not needed? What to do instead?

2010-01-21 Thread Steffen Dettmer
Hi,

in a include *.mak a file is created and added to `mydir_DATA'.
The including (super-/caller) Makefile should be able to change
the default of this file name. If the Makefile takes no action
(except directly or indirectly including this *.mak), the
defaults should be used.

To ease maintenance, the order of inclusion of *.mak should not
matter.

We came closet to this goal by using:
TO_BE_USED=$(firstword $(OVERWRITE) default)

Makefile.am:

---8===
LIST=$(firstword $(PREPEND) default)
test_DATA=$(LIST)
testdir=.
testlist:
@echo $(LIST)
===8---

automake fails:
test/Makefile.am:24: variable `PREPEND' not defined

but `make -f Makefile.am testlist' works:
default




This try fails:
---8===
LIST=2
LIST?=default
testlist:
@echo $(LIST)
===8---

automake: test/Makefile.am:30: bad macro name `LIST?'


but `make -f Makefile.am testlist' works:
2

This has also the disadvantage that because of ?= the value
depends on the include order of the *.mak helpers.
But in first inclusion order does not matter, even if PREPEND (or
OVERWRITE) is defined later than LIST, i.e. Make can do:

---8===
LIST=$(firstword $(PREPEND) default)
PREPEND=overwritten_later_but_works! (only firstword, so _ used :))
testlist:
@echo $(LIST)
===8---


# make -f Makefile.am testlist
overwritten_later_but_works!

This also works with automake as long as PREPEND is defined:

---8===
test_DATA=$(LIST)
testdir=.
LIST=$(firstword $(PREPEND) default)
PREPEND=overwritten_later_but_works! (only firstword, so _ used :))
testlist:
@echo $(LIST)
===8---

make: *** No rule to make target `overwritten_later_but_works!', needed by `all-
am'.  Stop.

so correctly tried to build overwritten_later_but_works!.

With if COND, configure.in must know about, even if COND isn't
used (i.e. not set), because of
`Makefile.am:31: COND does not appear in AM_CONDITIONAL')


Because I didn't know how to handle I added to all Makefile.am
with that problem a PREPEND= at the end, but I think there is a
better way to archive this?

Is there a way to archive the goal? What would be best to handle
this?


oki,

Steffen




Re: Why variable `FOO' not defined even if not needed? What to do instead?

2010-01-21 Thread Ralf Wildenhues
* Steffen Dettmer wrote on Thu, Jan 21, 2010 at 01:44:44PM CET:
 in a include *.mak a file is created and added to `mydir_DATA'.
 The including (super-/caller) Makefile should be able to change
 the default of this file name. If the Makefile takes no action
 (except directly or indirectly including this *.mak), the
 defaults should be used.

--- Makefile.am ---
mydir_DATA =
include fragment.mak
# here, you can append:
mydir_DATA += foo
# or override:
mydir_DATA = bar

-- fragment.mak ---
# here, you can append:
mydir_DATA += baz
# or override:
mydir_DATA = bla
# but the including Makefile.am might override you later.


Ordering of includes matters, both for automake and by consequence for
make, and there is little you can do about it.

If the above is not good enough for you, maybe you instead want
something like this in the fragment:

frag_variable = default-value
mydir_DATA = $(frag_variable)


and be able to override frag_variable later in Makefile.am?

The ?= operator is GNU make-specific, but I suppose automake could learn
about it.

$(firstword ...) is GNU make-specific.  Current automake ignores it, so
you might want to update.


Cheers,
Ralf