#!/usr/bin/make -f
ROOT_DIR   ?= ../
LEGO       ?= ${ROOT_DIR}lego
SERVICE_ID ?= rasp
LEGO_PATHS ?= ${LEGO}/bem-bl/blocks-common:${LEGO}/bem-bl/blocks-desktop:${LEGO}/blocks-common:${LEGO}/blocks-desktop:${ROOT_DIR}blocks-desktop
RAWS       ?= $(wildcard **/*.raw.xml)

%.xml: %.raw.xml
	${LEGO}/tools/rebuild --paths ${LEGO_PATHS} $<

%.html: %.xml
	xscript-proc --config=offline.conf $< > $@

xml: ${RAWS:%.raw.xml=%.xml}
html: ${RAWS:%.raw.xml=%.html}

${SERVICE_ID}.css ${SERVICE_ID}.ie.css: RULE = "@import url("$(1)");\n"
${SERVICE_ID}.js: RULE = "include('"$(1)"');\n"
${SERVICE_ID}.js: EXT = .js
${SERVICE_ID}.css: EXT = .css
${SERVICE_ID}.css: ${SERVICE_ID}.ie.css
${SERVICE_ID}.ie.css: EXT = .ie.css

${SERVICE_ID}.js ${SERVICE_ID}.css ${SERVICE_ID}.ie.css:
	@echo  $(foreach file, ${RAWS:%.raw.xml=%${EXT}},$(call RULE,$(strip ${file}))) > $@

.PHONY : clean clean-xml html xml
.DEFAULT : html
