I'm using GNU Make with Guile. How do I pass Make variables to Guile?
%.txt:
@echo $* $(guile (string-upcase $*))
What I want to see is this:
$ make foo.txt
foo FOO
What I get is an error, Unbound variable: foo
. My Guile invocation expands to (string-upcase foo)
, and foo
is unbound. I can put quotes around the variable and then I get the result I'm looking for:
$(guile (string-upcase "$*"))
This feels wrong. What if the string contains double quotes? It feels like there would be a more formal mechanism for passing values into Guile.
https://www.gnu.org/software/make/manual/html_node/Guile-Types.html goes into some detail about passing values from Guile to to Make, but I can't immediately see anything about passing them in.
You can use gmk-expand
to expand $*
more safely, like this:
%.txt:
@echo $* $(guile (string-upcase (gmk-expand "$$*")))
Or you can use the following technique to bind unary functions so that they can be invoked with $(call)
:
define _init :=
(define (gmk-bind1 proc)
(let ((name (symbol->string (procedure-name proc))))
(gmk-eval (string-append
name "=$$(guile ("
name " (gmk-expand \"$$$$1\")))"))))
(gmk-bind1 string-upcase)
endef
$(guile $(_init))
%.txt:
echo $* $(call string-upcase,$*)