I need the xpi_hash variable to be assigned only when update target’s command is decided to execute. Then I’m using this variable as environment, exporting, etc..
If I put it outside of rule, it will be expanded firstly, before $(xpi) target is called, hence will not find that file.
substitute := perl -p -e 's/@([^@]+)@/$$ENV{$$1} bla bla...
export xpi_hash
.PHONY: dirs substitute update
update: $(xpi) $(target_update_rdf)
xpi_hash := $(shell sha1sum $(xpi) | grep -Eow '^[^ ]+')
@echo "Updating..."
$(target_update_rdf): $(update_rdf)
$(substitute) $< > $@
and above of course is not correct, because for command part the shell is represented. So maybe another way to put this question is – how to bring variable as command output?
I’m not sure exactly what you’re looking for here, how are you planning to use
xpi_hash? If you want to get the current hash every time you use the variable use=to assign the variable instead of:=, e.g.will print the hash of
xpiafter it has been updated.For variables in
make, see section 6.2 of the manual. Briefly ‘:=’ will expand variables on the right hand side, ‘=’ will leave them to be expanded later.The altered command in my comment (
substitute = xpi_hash="$(xpi_hash)" perl -p -e 's/@([^@]+)@/$$ENV{$$1}...') will expand to be equivalent toThe
xpi_hash="..."syntax is defining a variable in the bash subshell, rather than using the variable in make.