.PHONY: all
all: bem-build xscript

.PHONY: bem-build
bem-build: b-smart-help.bembundle.bemdecl.js
	bem build -d $^ -n b-smart-help \
		-t ../i-loader/bem/techs/nodejs/bembundle.js \
		-l ../../blocks

	rm *.bundle-full.* *.bundle-pre.* \
		b-smart-help.bembundle.decl.xml \
		b-smart-help.bembundle.bemdecl.js \
		.b-smart-help.bundle-pre.raw.xml

b-smart-help.bundle-pre.raw.xml: FORCE
	@echo '<?xml version="1.0" encoding="utf-8"?>' > $@ ; \
	echo '<lego:declaration xmlns:lego="https://lego.yandex-team.ru">' >> $@ ; \
	echo '<lego:b-smart-help lego:loading="completed"><lego:content/></lego:b-smart-help>' >> $@ ; \
	echo '</lego:declaration>' >> $@

%.bemdecl.js: %.raw.xml
	xsltproc --xinclude ../../tools/convert2xml.xsl $^ > .$^
	xsltproc --xinclude ../../tools/raw2decl.xsl .$^ > $<.decl.xml
	xsltproc --stringparam output module ../../tools/declxml2decljson.xsl $<.decl.xml > $*.bemdecl.js

b-smart-help.bembundle.bemdecl.js: b-smart-help.bundle-pre.bemdecl.js
	bem build -d $^ -n b-smart-help.bundle-full -t ../../tools/bem/techs/nodejs/convert2xml.xsl.js -l ../../blocks
	xsltproc --xinclude b-smart-help.bundle-full.convert2xml.xsl .b-smart-help.bundle-pre.raw.xml > b-smart-help.bundle-full.raw.xml
	xsltproc --xinclude ../../tools/raw2decl.xsl b-smart-help.bundle-full.raw.xml > b-smart-help.bundle-full.decl.xml
	xsltproc decl2bembundledecl.xsl b-smart-help.bundle-full.decl.xml > b-smart-help.bembundle.decl.xml
	xsltproc --stringparam output module ../../tools/declxml2decljson.xsl b-smart-help.bembundle.decl.xml > b-smart-help.bembundle.bemdecl.js

.PHONY: xscript
xscript:
	$(MAKE) -C xscript

.PHONY: FORCE
