> > Unfortunately $(shell ...) is stripping out the newlines and
> > making the multiple assignments - one per line - into one single
> > assignment with a very long right-hand side.
>
> I have done something similar by replacing the spaces with an unused
> character and then substituting back the space. I am retyping the
>
> ...
>
> $(foreach var $(shell branding_vars),$(eval $(subst @,${space},${var})))
Brilliant! Willingly letting $(shell ...) change newlines to spaces,
accepting that space now means newline - having first changed spaces
to something else so there is no ambiguity! Brilliant!
In fact I refined your idea a bit so the external script remains
writing *pure* Make assigments and the single line does both
the escaping ( $(shell ...)'s own conversion of newline to space
and using sed to convert space to '@') and the unescaping ( $(subst
...) to unescape the spaces and $(foreach ...) to effectively unescape
newlines by passing assigments one by one to $(eval ...)).
Here's the generator:
graces$ cat get-vars
#!/bin/sh
echo "FRUITS = apple banana"
echo "VEGETABLES = asparagus beetroot"
graces$
Here's the Makefile (with some long variable names for clarity):
graces$ cat Makefile
COLONED_ASSIGNMENT_ONLY_TO_FORCE_IMMEDIATE_EXECUTION := $(foreach
PACKED_ASSIGNMENT,$(shell get-vars | sed 's/ /@/g'),$(eval $(subst @,
,$(PACKED_ASSIGNMENT))))
default:
@echo FRUITS = $(FRUITS)
@echo VEGETABLES = $(VEGETABLES)
graces$
And here's it working:
graces$ make
FRUITS = apple banana
VEGETABLES = asparagus beetroot
graces$
Brilliant!
John Graham-Cumming <[EMAIL PROTECTED]>'s solution looked fine too, but
I forgot to mention one thing which makes the above solution more
suitable; namely:
The whole purpose of what I'm trying to do is abstract a lot of
Makefile intelligence into an external script (a script rather than
a Makefile because the former can be found in the $PATH without the
user needing to have to set any additional environment variables) and
therefore it makes sense that whatever loads the abstracted content
should be below a certain level of complexity - ideally one line -
otherwise I'm tempted to say "This is so complex I should abstract it
in to an include-able Makefile (whose purpose is to load other complex
stuff I already abstracted in to another include-able Makefile)"
Many thanks for the quick an extremely helpful responses!
Alexis
_______________________________________________
Help-make mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/help-make