test.mk 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. # Copyright (c) 2015-2016, Loïc Hoguin <essen@ninenines.eu>
  2. # This file is part of erlang.mk and subject to the terms of the ISC License.
  3. .PHONY: test-deps test-dir test-build clean-test-dir
  4. # Configuration.
  5. TEST_DIR ?= $(CURDIR)/test
  6. ALL_TEST_DEPS_DIRS = $(addprefix $(DEPS_DIR)/,$(TEST_DEPS))
  7. TEST_ERLC_OPTS ?= +debug_info +warn_export_vars +warn_shadow_vars +warn_obsolete_guard
  8. TEST_ERLC_OPTS += -DTEST=1
  9. # Targets.
  10. $(foreach dep,$(TEST_DEPS),$(eval $(call dep_target,$(dep))))
  11. ifneq ($(SKIP_DEPS),)
  12. test-deps:
  13. else
  14. test-deps: $(ALL_TEST_DEPS_DIRS)
  15. $(verbose) set -e; for dep in $(ALL_TEST_DEPS_DIRS) ; do \
  16. if [ -z "$(strip $(FULL))" ] && [ ! -L $$dep ] && [ -f $$dep/ebin/dep_built ]; then \
  17. :; \
  18. else \
  19. $(MAKE) -C $$dep IS_DEP=1; \
  20. if [ ! -L $$dep ] && [ -d $$dep/ebin ]; then touch $$dep/ebin/dep_built; fi; \
  21. fi \
  22. done
  23. endif
  24. ifneq ($(wildcard $(TEST_DIR)),)
  25. test-dir:
  26. $(gen_verbose) erlc -v $(TEST_ERLC_OPTS) -o $(TEST_DIR) \
  27. -pa ebin/ -I include/ $(call core_find,$(TEST_DIR)/,*.erl)
  28. endif
  29. test-build:: IS_TEST=1
  30. test-build:: ERLC_OPTS=$(TEST_ERLC_OPTS)
  31. test-build:: $(if $(wildcard src),$(if $(wildcard ebin/test),,clean)) $(if $(IS_APP),,deps test-deps)
  32. # We already compiled everything when IS_APP=1.
  33. ifndef IS_APP
  34. ifneq ($(wildcard $(TEST_DIR)),)
  35. $(verbose) $(MAKE) --no-print-directory test-dir ERLC_OPTS="$(call escape_dquotes,$(TEST_ERLC_OPTS))"
  36. endif
  37. ifneq ($(wildcard src),)
  38. $(verbose) $(MAKE) --no-print-directory $(PROJECT).d ERLC_OPTS="$(call escape_dquotes,$(TEST_ERLC_OPTS))"
  39. $(verbose) $(MAKE) --no-print-directory app-build ERLC_OPTS="$(call escape_dquotes,$(TEST_ERLC_OPTS))"
  40. $(gen_verbose) touch ebin/test
  41. endif
  42. endif
  43. # Roughly the same as test-build, but when IS_APP=1.
  44. # We only care about compiling the current application.
  45. ifdef IS_APP
  46. test-build-app:: ERLC_OPTS=$(TEST_ERLC_OPTS)
  47. test-build-app:: test-deps
  48. ifneq ($(wildcard $(TEST_DIR)),)
  49. $(verbose) $(MAKE) --no-print-directory test-dir ERLC_OPTS="$(call escape_dquotes,$(TEST_ERLC_OPTS))"
  50. endif
  51. ifneq ($(wildcard src),)
  52. $(verbose) $(MAKE) --no-print-directory $(PROJECT).d ERLC_OPTS="$(call escape_dquotes,$(TEST_ERLC_OPTS))"
  53. $(verbose) $(MAKE) --no-print-directory app-build ERLC_OPTS="$(call escape_dquotes,$(TEST_ERLC_OPTS))"
  54. $(gen_verbose) touch ebin/test
  55. endif
  56. endif
  57. clean:: clean-test-dir
  58. clean-test-dir:
  59. ifneq ($(wildcard $(TEST_DIR)/*.beam),)
  60. $(gen_verbose) rm -f $(TEST_DIR)/*.beam
  61. endif