HTML_FILES := $(shell find web -name *.gohtml)
GO_FILES := $(shell find . -name *.go)
DEFAULT_DOMAIN = numerus
POT_FILE = po/$(DEFAULT_DOMAIN).pot
LINGUAS = ca es
MO_FILES = $(patsubst %,locales/%/LC_MESSAGES/$(DEFAULT_DOMAIN).mo,$(LINGUAS))
XGETTEXTFLAGS = --no-wrap --from-code=UTF-8 --package-name=numerus --msgid-bugs-address=jordi@tandem.blog

locales: $(MO_FILES)

locales/%/LC_MESSAGES/numerus.mo: po/%.po
	mkdir -p $(@D)
	msgfmt -o $@ $<

po/%.po: $(POT_FILE)
	msgmerge --no-wrap --update --backup=off $@ $<

$(POT_FILE): $(HTML_FILES) $(GO_FILES)
	xgettext $(XGETTEXTFLAGS) --language=Scheme --output=$@ --keyword=pgettext:1,2c $(HTML_FILES)
	xgettext $(XGETTEXTFLAGS) --language=C --output=$@ --join-existing $(GO_FILES)

test-deploy:
	sqitch deploy --db-name $(PGDATABASE)
	pg_prove test/*

.PHONY: locales test-db
