damsel/Makefile
2016-03-31 18:45:12 +03:00

69 lines
1.2 KiB
Makefile

THRIFT_EXEC = thrift
THRIFT_LANGUAGES = erlang go java
THRIFT_OPTIONS_html = standalone
FILES = $(wildcard proto/*.thrift)
DESTDIR = _gen
define generate
$(THRIFT_EXEC) -r -strict --gen $(1):$(THRIFT_OPTIONS_$(1)) -out $(2) $(3)
endef
define targets
$(patsubst %, $(DESTDIR)/$(1)/%, $(FILES))
endef
CUTLINE = $(shell printf '=%.0s' $$(seq 1 80))
.PHONY: all clean doc
LANGUAGE_TARGETS = $(foreach lang, $(THRIFT_LANGUAGES), verify-$(lang))
all: $(LANGUAGE_TARGETS)
@echo "Ok"
verify-%: $(DESTDIR)
@echo "Verifying '$*' ..."
@echo $(CUTLINE)
@$(MAKE) LANGUAGE=$* $(call targets,$*)
@echo
$(DESTDIR):
@mkdir -p $@
clean::
@rm -rfv $(DESTDIR)
TARGETS = $(call targets,$(LANGUAGE))
$(TARGETS):: $(DESTDIR)/$(LANGUAGE)/%: %
mkdir -p $@
$(call generate,$(LANGUAGE),$@,$<)
# Docs
DOCDIR = doc
DOCTARGETS = $(patsubst %.thrift, $(DOCDIR)/%.html, $(FILES))
doc: $(DOCTARGETS)
$(DOCTARGETS): $(DOCDIR)/%.html: %.thrift
mkdir -p $(dir $@)
$(call generate,html,$(dir $@),$<)
clean::
@rm -rfv $(DOCDIR)
# Erlang
ERLC ?= erlc
ifeq ($(LANGUAGE), erlang)
ifneq ($(shell which $(ERLC)),)
$(TARGETS):: $(DESTDIR)/$(LANGUAGE)/%: %
$(ERLC) -v -I$@ -o$@ $(shell find $@ -name "*.erl")
endif
endif