help-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: how to: write a rule which expands the contents of an arbitrary text


From: Cook, Malcolm
Subject: RE: how to: write a rule which expands the contents of an arbitrary text file?
Date: Fri, 14 May 2021 18:46:35 +0000

So I hit <send> too soon...

> I would to be able to expand Gnu make variables and macros appearing in a
> text file using values of .VARIABLES in the current execution environment.
> 
> This in effect is using Gnu make as a kind of [Template
> processor](https://en.wikipedia.org/wiki/Template_processor).
> 
> I find that this rule only copies the contents without expansion/interpolation
> 
> %.expanded: %
>       $(file >$@,$(file < $<))
> 
> However the following seems to do exactly what I desire:
> 
> define \n :=
> 
> 
> endef
> 
> %.expanded: %
>         $(file >$@,$(eval define .x:=${\n}$(file < $<)${\n}endef ${\n})${.x})

The problem with this approach is that, though it expands "correctly", it 
builds the target during the first phase of reading the makefile (c.f. [How 
make Reads a 
Makefile](https://www.gnu.org/software/make/manual/make.html#Reading-Makefiles))
 and thus standard dependency processing is precluded, which is decidedly 
unfavorable.

> 
> My question is whether this is the best/fastest way to do what I desire.

My question is changed and is now how to accomplish this in the second phase.

> 
> Thoughts?  Recommendations? Gothcas?




reply via email to

[Prev in Thread] Current Thread [Next in Thread]