Skip to content

Instantly share code, notes, and snippets.

@melekes
Last active August 29, 2015 14:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save melekes/be1f74555aae66da69f2 to your computer and use it in GitHub Desktop.
Save melekes/be1f74555aae66da69f2 to your computer and use it in GitHub Desktop.
Makefile for erlang projects
.PHONY: all compile deps clean distclean test docs xref dialyzer \
cleanplt
REBAR = `which rebar || ./script/rebar`
all: deps compile
compile: deps
@$(REBAR) compile
deps:
test -d deps || @$(REBAR) get-deps
clean:
@$(REBAR) clean
distclean: clean
@$(REBAR) delete-deps
DIALYZER_APPS = kernel stdlib thrift
test: compile
@$(REBAR) eunit skip_deps=true
docs:
@$(REBAR) doc skip_deps=true
xref: compile
@$(REBAR) xref skip_deps=true
PLT ?= $(HOME)/.dialyzer_plt
LOCAL_PLT = .local_dialyzer_plt
DIALYZER_FLAGS ?= -Wunmatched_returns
${PLT}: compile
ifneq (,$(wildcard $(PLT)))
dialyzer --check_plt --plt $(PLT) --apps $(DIALYZER_APPS) && \
dialyzer --add_to_plt --plt $(PLT) --output_plt $(PLT) --apps $(DIALYZER_APPS) ; test $$? -ne 1
else
dialyzer --build_plt --output_plt $(PLT) --apps $(DIALYZER_APPS); test $$? -ne 1
endif
${LOCAL_PLT}: compile
ifneq (,$(wildcard deps/*))
ifneq (,$(wildcard $(LOCAL_PLT)))
dialyzer --check_plt --plt $(LOCAL_PLT) deps/*/ebin && \
dialyzer --add_to_plt --plt $(LOCAL_PLT) --output_plt $(LOCAL_PLT) deps/*/ebin ; test $$? -ne 1
else
dialyzer --build_plt --output_plt $(LOCAL_PLT) deps/*/ebin ; test $$? -ne 1
endif
endif
dialyzer: ${PLT} ${LOCAL_PLT}
@echo "==> $(shell basename $(shell pwd)) (dialyzer)"
@if [ -f $(LOCAL_PLT) ]; then \
dialyzer $(DIALYZER_FLAGS) --plts $(PLT) $(LOCAL_PLT) -c ebin; \
else \
dialyzer $(DIALYZER_FLAGS) --plts $(PLT) -c ebin; \
fi
cleanplt:
@echo
@echo "Are you sure? It takes several minutes to re-build."
@echo Deleting $(PLT) and $(LOCAL_PLT) in 5 seconds.
@echo
sleep 5
rm $(PLT)
rm $(LOCAL_PLT)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment