SHELL := /bin/bash

# The targets made here are individual code-level demos.
# Some produce LaTeX fragments.  All are being checked for the code being valid.
# None are being built from *.tex toward *.pdf.  Use the top-level makefile for that.


BuildBase = ../../build
Build = ${BuildBase}/string

# (plg2 has gem)
# gem install --user-install liquid 
# gem install --user-install liquid-cli
Liquid = ~/.gem/ruby/2.7.0/bin/liquid

CFA = ../../../../../../build/driver/cfa

DEMOS = ${addsuffix -demo, \
	sharing \
}

EZDEMOS = ${addsuffix -ezdemo, \
	sharectx \
}


all: $(DEMOS) $(EZDEMOS)

# removing the echo rule body means the rule doesn't fire
%-demo: $(Build)/%-demo.tex %-demo-runok | $(Build) 
	@echo target $@ made

%-ezdemo: %-ezdemo-runok | $(Build) 
	@echo target $@ made

%-demo-runok: $(Build)/%-demo | $(Build)
	$<

%-ezdemo-runok: $(Build)/%-ezdemo | $(Build)
	$<

$(Build)/%-demo.tex: %-demo.json %-demo.tex.liquid | $(Build)
	$(Liquid) "$$(< $<)" < $(word 2,$^) > $@ 
#	echo will run $(Liquid)
#	echo will get JSON from $<
#	echo will get template from $(word 2,$^)

$(Build)/%-demo: $(Build)/%-demo.cfa
	$(CFA) $< -o $@

$(Build)/%-demo.cfa: %-demo.json %-demo.cfa.liquid | $(Build)
	$(Liquid) "$$(< $<)" < $(word 2,$^) > $@ 

$(Build)/%-ezdemo: %-demo.cfa
	$(CFA) $< -o $@




${Build}:
	mkdir -p $@

.PHONY : all %-demo %-demo %-runok
.PRECIOUS : $(Build)/%-demo.tex $(Build)/%-demo.cfa $(Build)/%-demo
