# Makefile to generate data:
#  template scripts -> final scripts
#  markdown files -> html files

CAPSMAN = $(wildcard *.capsman.rsc)
LOCAL = $(wildcard *.local.rsc)
WIFI = $(wildcard *.wifi.rsc)
WIFIWAVE2 = $(wildcard *.wifiwave2.rsc)

MARKDOWN = $(wildcard *.md doc/*.md doc/mod/*.md)
HTML = $(MARKDOWN:.md=.html)

all: $(CAPSMAN) $(LOCAL) $(WIFI) $(WIFIWAVE2) $(HTML)

%.html: %.md Makefile
	markdown $< | sed 's/href="\([-_\./[:alnum:]]*\)\.md"/href="\1.html"/g' > $@

%.capsman.rsc: %.template.rsc Makefile
	sed -e '/\/interface\/wifi\//d' -e '/\/interface\/wifiwave2\//d' -e '/\/interface\/wireless\//d' -e 's|%TEMPL%|.capsman|' \
		-e '/^# NOT \/caps-man\/ #$$/,/^# NOT \/caps-man\/ #$$/d' \
		-e '/^# !!/,/^# !!/c # !! Do not edit this file, it is generated from template!' \
		< $< > $@

%.local.rsc: %.template.rsc Makefile
	sed -e '/\/caps-man\//d' -e '/\/interface\/wifi\//d' -e '/\/interface\/wifiwave2\//d' -e 's|%TEMPL%|.local|' \
		-e '/^# NOT \/interface\/wireless\/ #$$/,/^# NOT \/interface\/wireless\/ #$$/d' \
		-e '/^# !!/,/^# !!/c # !! Do not edit this file, it is generated from template!' \
		< $< > $@

%.wifi.rsc: %.template.rsc Makefile
	sed -e '/\/caps-man\//d' -e '/\/interface\/wifiwave2\//d' -e '/\/interface\/wireless\//d' -e 's|%TEMPL%|.wifi|' \
		-e '/^# NOT \/interface\/wifi\/ #$$/,/^# NOT \/interface\/wifi\/ #$$/d' \
		-e '/^# !!/,/^# !!/c # !! Do not edit this file, it is generated from template!' \
		< $< > $@

%.wifiwave2.rsc: %.template.rsc Makefile
	sed -e '/\/caps-man\//d' -e '/\/interface\/wifi\//d' -e '/\/interface\/wireless\//d' -e 's|%TEMPL%|.wifiwave2|' \
		-e '/^# NOT \/interface\/wifiwave2\/ #$$/,/^# NOT \/interface\/wifiwave2\/ #$$/d' \
		-e '/^# !!/,/^# !!/c # !! Do not edit this file, it is generated from template!' \
		< $< > $@

clean:
	rm -f $(HTML)