Merge pull request #187 from basho/adt-dialyzer-mad-science

Rework how dialyzer PLTs are built and used
diff --git a/.gitignore b/.gitignore
index 3bde15b..d053947 100644
--- a/.gitignore
+++ b/.gitignore
@@ -7,3 +7,4 @@
 .project
 log
 deps
+.local_dialyzer_plt
diff --git a/Makefile b/Makefile
index 6b78d1a..4c61dd6 100644
--- a/Makefile
+++ b/Makefile
@@ -15,39 +15,6 @@
 distclean: clean
 	./rebar delete-deps
 
-test:
-	./rebar compile eunit
+DIALYZER_APPS = kernel stdlib erts sasl eunit syntax_tools compiler crypto
 
-##
-## Doc targets
-##
-docs:
-	./rebar doc
-
-APPS = kernel stdlib sasl erts ssl tools os_mon runtime_tools crypto inets \
-	xmerl webtool snmp public_key mnesia eunit
-PLT ?= $(HOME)/.riak_combo_dialyzer_plt
-
-check_plt: compile
-	dialyzer --check_plt --plt $(PLT) --apps $(APPS)
-
-build_plt: compile
-	dialyzer --build_plt --output_plt $(PLT) --apps $(APPS)
-
-dialyzer: compile
-	@echo
-	@echo Use "'make check_plt'" to check PLT prior to using this target.
-	@echo Use "'make build_plt'" to build PLT prior to using this target.
-	@echo
-	@sleep 1
-	dialyzer -Wunmatched_returns --plt $(PLT) ebin | \
-	    fgrep -v -f ./dialyzer.ignore-warnings
-
-cleanplt:
-	@echo 
-	@echo "Are you sure?  It takes about 1/2 hour to re-build."
-	@echo Deleting $(PLT) in 5 seconds.
-	@echo 
-	sleep 5
-	rm $(PLT)
-
+include tools.mk
diff --git a/tools.mk b/tools.mk
new file mode 100644
index 0000000..7e73423
--- /dev/null
+++ b/tools.mk
@@ -0,0 +1,39 @@
+test: compile
+	./rebar eunit skip_deps=true
+
+docs:
+	./rebar doc skip_deps=true
+
+PLT ?= $(HOME)/.riak_combo_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 $(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
+
+dialyzer: ${PLT} ${LOCAL_PLT}
+	@echo "==> $(shell basename $(shell pwd)) (dialyzer)"
+	dialyzer $(DIALYZER_FLAGS) --plts $(PLT) $(LOCAL_PLT) -c ebin
+
+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)
+