concrete.mk 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. # =============================================================================
  2. # Verify that the programs we need to run are installed on this system
  3. # =============================================================================
  4. ERL = $(shell which erl)
  5. ifeq ($(ERL),)
  6. $(error "Erlang not available on this system")
  7. endif
  8. # If building on travis, use the rebar in the current directory
  9. ifeq ($(TRAVIS),true)
  10. REBAR = $(CURDIR)/rebar
  11. endif
  12. # If there is a rebar in the current directory, use it
  13. ifeq ($(wildcard rebar),rebar)
  14. REBAR = $(CURDIR)/rebar
  15. endif
  16. # Fallback to rebar on PATH
  17. REBAR ?= $(shell which rebar)
  18. # And finally, prep to download rebar if all else fails
  19. ifeq ($(REBAR),)
  20. REBAR = $(CURDIR)/rebar
  21. endif
  22. # If we have a rebar.config.lock file, use it!
  23. ifeq ($(wildcard rebar.config.lock),rebar.config.lock)
  24. REBAR_CONFIG = rebar.config.lock
  25. else
  26. REBAR_CONFIG = rebar.config
  27. endif
  28. # This is the variable to use to respect the lock file
  29. REBARC = $(REBAR) -C $(REBAR_CONFIG)
  30. # For use on Travis CI, skip dialyzer for R14 and R15. Newer versions
  31. # have a faster dialyzer that is less likely to cause a build timeout.
  32. DIALYZER = dialyzer
  33. R14 = $(findstring R14,$(TRAVIS_OTP_RELEASE))
  34. R15 = $(findstring R15,$(TRAVIS_OTP_RELEASE))
  35. ifneq ($(R14),)
  36. DIALYZER = echo "SKIPPING dialyzer"
  37. endif
  38. ifneq ($(R15),)
  39. DIALYZER = echo "SKIPPING dialyzer"
  40. endif
  41. ifneq ($(SKIP_DIALYZER),)
  42. DIALYZER = echo "SKIPPING dialyzer"
  43. endif
  44. REBAR_URL=https://github.com/rebar/rebar/wiki/rebar
  45. DEPS ?= $(CURDIR)/deps
  46. DIALYZER_OPTS ?=
  47. # Find all the deps the project has by searching the deps dir
  48. ALL_DEPS = $(notdir $(wildcard deps/*))
  49. # Create a list of deps that should be used by dialyzer by doing a
  50. # complement on the sets
  51. DEPS_LIST = $(filter-out $(DIALYZER_SKIP_DEPS), $(ALL_DEPS))
  52. # Create the path structure from the dep names
  53. # so dialyzer can find the .beam files in the ebin dir
  54. # This list is then used by dialyzer in creating the local PLT
  55. DIALYZER_DEPS = $(foreach dep,$(DEPS_LIST),deps/$(dep)/ebin)
  56. DEPS_PLT = deps.plt
  57. ERLANG_DIALYZER_APPS ?= asn1 \
  58. compiler \
  59. crypto \
  60. edoc \
  61. erts \
  62. inets \
  63. kernel \
  64. mnesia \
  65. public_key \
  66. ssl \
  67. stdlib \
  68. syntax_tools \
  69. tools \
  70. xmerl
  71. PROJ = $(notdir $(CURDIR))
  72. # Let's compute $(BASE_PLT_ID) that identifies the base PLT to use for this project
  73. # and depends on your `$(ERLANG_DIALYZER_APPS)' list and your erlang version
  74. ERLANG_VERSION := $(shell $(ERL) -eval 'io:format("~s~n", [erlang:system_info(otp_release)]), halt().' -noshell)
  75. MD5_BIN := $(shell which md5 || which md5sum)
  76. ifeq ($(MD5_BIN),)
  77. # neither md5 nor md5sum, we just take the project name
  78. BASE_PLT_ID := $(PROJ)
  79. else
  80. BASE_PLT_ID := $(word 1, $(shell echo $(ERLANG_DIALYZER_APPS) $(ERLANG_VERSION) | $(MD5_BIN)))
  81. endif
  82. BASE_PLT := ~/.concrete_dialyzer_plt_$(BASE_PLT_ID)_$(ERLANG_VERSION).plt
  83. all: all_but_dialyzer dialyzer
  84. all_but_dialyzer: .concrete/DEV_MODE compile eunit $(ALL_HOOK)
  85. $(REBAR):
  86. curl -Lo rebar $(REBAR_URL) || wget $(REBAR_URL)
  87. chmod a+x rebar
  88. get-rebar: $(REBAR)
  89. .concrete/DEV_MODE:
  90. @mkdir -p .concrete
  91. @touch $@
  92. # Clean ebin and .eunit of this project
  93. clean:
  94. @$(REBARC) clean skip_deps=true
  95. # Clean this project and all deps
  96. # Newer rebar requires -r to recursively clean
  97. allclean:
  98. @($(REBARC) --help 2>&1|grep -q recursive && $(REBARC) -r clean) || $(REBARC) clean
  99. compile: $(DEPS)
  100. @$(REBARC) compile
  101. $(DEPS):
  102. @$(REBARC) get-deps
  103. # Full clean and removal of all deps. Remove deps first to avoid
  104. # wasted effort of cleaning deps before nuking them.
  105. distclean:
  106. @rm -rf deps $(DEPS_PLT)
  107. @$(REBARC) clean
  108. eunit:
  109. @$(REBARC) skip_deps=true eunit
  110. test: eunit
  111. # Only include local PLT if we have deps that we are going to analyze
  112. ifeq ($(strip $(DIALYZER_DEPS)),)
  113. dialyzer: $(BASE_PLT)
  114. @$(DIALYZER) $(DIALYZER_OPTS) -r ebin
  115. else
  116. dialyzer: $(BASE_PLT) $(DEPS_PLT)
  117. @$(DIALYZER) $(DIALYZER_OPTS) --plts $(BASE_PLT) $(DEPS_PLT) -r ebin
  118. $(DEPS_PLT):
  119. @$(DIALYZER) --build_plt $(DIALYZER_DEPS) --output_plt $(DEPS_PLT)
  120. endif
  121. $(BASE_PLT):
  122. @echo "Missing $(BASE_PLT). Please wait while a new PLT is compiled."
  123. $(DIALYZER) --build_plt --apps $(ERLANG_DIALYZER_APPS) --output_plt $(BASE_PLT)
  124. @echo "now try your build again"
  125. doc:
  126. @$(REBARC) doc skip_deps=true
  127. shell:
  128. @$(ERL) -pa deps/*/ebin ebin .eunit
  129. tags:
  130. find src deps -name "*.[he]rl" -print | etags -
  131. # Releases via relx. we will install a local relx, as we do for rebar,
  132. # if we don't find one on PATH.
  133. RELX_CONFIG ?= $(CURDIR)/relx.config
  134. RELX = $(shell which relx)
  135. RELX_OPTS ?=
  136. RELX_OUTPUT_DIR ?= _rel
  137. ifeq ($(RELX),)
  138. RELX = $(CURDIR)/relx
  139. RELX_VERSION = 1.0.4
  140. else
  141. RELX_VERSION = $(shell relx --version)
  142. endif
  143. RELX_URL = https://github.com/erlware/relx/releases/download/v$(RELX_VERSION)/relx
  144. # relx introduced a breaking change in v1: the output doesn't have the same structure
  145. # see https://github.com/erlware/relx/releases/tag/v1.0.0
  146. ifeq ($(shell echo $(RELX_VERSION) | head -c 1), 0)
  147. RELX_RELEASE_DIR = $(RELX_OUTPUT_DIR)
  148. else
  149. RELX_RELEASE_DIR = $(RELX_OUTPUT_DIR)/$(PROJ)
  150. endif
  151. $(RELX):
  152. curl -Lo relx $(RELX_URL) || wget $(RELX_URL)
  153. chmod a+x relx
  154. rel: relclean all_but_dialyzer $(RELX)
  155. @$(RELX) -c $(RELX_CONFIG) -o $(RELX_OUTPUT_DIR) $(RELX_OPTS)
  156. devrel: rel
  157. devrel: lib_dir=$(wildcard $(RELX_RELEASE_DIR)/lib/$(PROJ)-* )
  158. devrel:
  159. @/bin/echo Symlinking deps and apps into release
  160. @rm -rf $(lib_dir); mkdir -p $(lib_dir)
  161. @ln -sf `pwd`/ebin $(lib_dir)
  162. @ln -sf `pwd`/priv $(lib_dir)
  163. @ln -sf `pwd`/src $(lib_dir)
  164. relclean:
  165. rm -rf $(RELX_OUTPUT_DIR)
  166. ## Release prep and dep locking. These recipes use $(REBAR), not
  167. ## $(REBARC) in order to NOT use the lock file since they are
  168. ## concerned with the task of updating the lock file.
  169. BUMP ?= patch
  170. prepare_release: distclean unlocked_deps unlocked_compile update_locked_config rel
  171. @echo 'release prepared, bumping version'
  172. @$(REBAR) bump-rel-version version=$(BUMP)
  173. unlocked_deps:
  174. @echo 'Fetching deps as: rebar -C rebar.config'
  175. @$(REBAR) -C rebar.config get-deps
  176. # When running the prepare_release target, we have to ensure that a
  177. # compile occurs using the unlocked rebar.config. If a dependency has
  178. # been removed, then using the locked version that contains the stale
  179. # dep will cause a compile error.
  180. unlocked_compile:
  181. @$(REBAR) -C rebar.config compile
  182. update_locked_config:
  183. @$(REBAR) lock-deps skip_deps=true
  184. .PHONY: all all_but_dialyzer compile eunit test dialyzer clean allclean relclean distclean doc tags get-rebar rel devrel