Advertisement
rockdrilla

propagating variables from GNU Make to files

Apr 7th, 2017
442
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Make 1.05 KB | None | 0 0
  1. ## how do I propagate variables from GNU Make to files?..
  2.  
  3. ## 1st version
  4. ## this is totally WRONG solution and given here just for your knowledge
  5.  
  6. FILES_TEMPLATED :=$(patsubst %.in,%,$(wildcard debian/*.in))
  7. $(FILES_TEMPLATED): %: %.in
  8.     @cp -f $(<) $(@)
  9.  
  10. .PHONY: process_templates
  11. process_templates: $(FILES_TEMPLATED)
  12.     $(foreach var,$(.VARIABLES),echo -n '$(var)' | grep -Eqe '^[a-zA-Z_][a-zA-Z0-9_]*$$' && grep -Fqe '%$(var)%' $(FILES_TEMPLATED) && sed -re 's/%$(var)%/$($(var))/g' -i $(FILES_TEMPLATED);)
  13.  
  14. ## 2nd version
  15.  
  16. X :=$(shell printf '\027')
  17.  
  18. FILES_TEMPLATED :=$(patsubst %.in,%,$(wildcard debian/*.in))
  19.  
  20. .PHONY: push_templates
  21. push_templates:
  22.     @$(foreach f,$(FILES_TEMPLATED),cp -f '$(f).in' '$(f)';)
  23.  
  24. .PHONY: process_templates
  25. process_templates: push_templates
  26.     @$(foreach var,$(.VARIABLES),$(if $(shell echo -n '$(var)' | grep -Eqe '^[a-zA-Z_][a-zA-Z0-9_]*$$' && echo ok || true),$(if $(shell grep -Fqe '%$(var)%' $(FILES_TEMPLATED) && echo ok || true),sed -re 's$(X)%$(var)%$(X)$($(var))$(X)g' -i $(FILES_TEMPLATED);)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement