erlang.mk 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726
  1. # Copyright (c) 2013-2014, Loïc Hoguin <essen@ninenines.eu>
  2. #
  3. # Permission to use, copy, modify, and/or distribute this software for any
  4. # purpose with or without fee is hereby granted, provided that the above
  5. # copyright notice and this permission notice appear in all copies.
  6. #
  7. # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  8. # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  9. # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  10. # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  11. # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  12. # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  13. # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  14. .PHONY: all deps app rel docs tests clean distclean help
  15. ERLANG_MK_VERSION = 1
  16. # Core configuration.
  17. PROJECT ?= $(notdir $(CURDIR))
  18. PROJECT := $(strip $(PROJECT))
  19. # Verbosity.
  20. V ?= 0
  21. gen_verbose_0 = @echo " GEN " $@;
  22. gen_verbose = $(gen_verbose_$(V))
  23. # Core targets.
  24. all:: deps app rel
  25. clean::
  26. $(gen_verbose) rm -f erl_crash.dump
  27. distclean:: clean
  28. help::
  29. @printf "%s\n" \
  30. "erlang.mk (version $(ERLANG_MK_VERSION)) is distributed under the terms of the ISC License." \
  31. "Copyright (c) 2013-2014 Loïc Hoguin <essen@ninenines.eu>" \
  32. "" \
  33. "Usage: [V=1] make [target]" \
  34. "" \
  35. "Core targets:" \
  36. " all Run deps, app and rel targets in that order" \
  37. " deps Fetch dependencies (if needed) and compile them" \
  38. " app Compile the project" \
  39. " rel Build a release for this project, if applicable" \
  40. " docs Build the documentation for this project" \
  41. " tests Run the tests for this project" \
  42. " clean Delete temporary and output files from most targets" \
  43. " distclean Delete all temporary and output files" \
  44. " help Display this help and exit" \
  45. "" \
  46. "The target clean only removes files that are commonly removed." \
  47. "Dependencies and releases are left untouched." \
  48. "" \
  49. "Setting V=1 when calling make enables verbose mode."
  50. # Core functions.
  51. ifeq ($(shell which wget 2>/dev/null | wc -l), 1)
  52. define core_http_get
  53. wget --no-check-certificate -O $(1) $(2)|| rm $(1)
  54. endef
  55. else
  56. define core_http_get
  57. erl -noshell -eval ' ssl:start(), inets:start(), case httpc:request(get, {"$(2)", []}, [{autoredirect, true}], []) of {ok, {{_V, 200, _R}, _H, Body}} -> case file:write_file("$(1)", Body) of ok -> ok ; {error, R1} -> halt(R1) end ; {error, R2} -> halt(R2) end, halt(0). '
  58. endef
  59. endif
  60. # Copyright (c) 2013-2014, Loïc Hoguin <essen@ninenines.eu>
  61. # This file is part of erlang.mk and subject to the terms of the ISC License.
  62. .PHONY: distclean-deps distclean-pkg pkg-list pkg-search
  63. # Configuration.
  64. DEPS_DIR ?= $(CURDIR)/deps
  65. export DEPS_DIR
  66. REBAR_DEPS_DIR = $(DEPS_DIR)
  67. export REBAR_DEPS_DIR
  68. ALL_DEPS_DIRS = $(addprefix $(DEPS_DIR)/,$(DEPS))
  69. ifeq ($(filter $(DEPS_DIR),$(subst :, ,$(ERL_LIBS))),)
  70. ifeq ($(ERL_LIBS),)
  71. ERL_LIBS = $(DEPS_DIR)
  72. else
  73. ERL_LIBS := $(ERL_LIBS):$(DEPS_DIR)
  74. endif
  75. endif
  76. export ERL_LIBS
  77. PKG_FILE2 ?= $(CURDIR)/.erlang.mk.packages.v2
  78. export PKG_FILE2
  79. PKG_FILE_URL ?= https://raw.githubusercontent.com/ninenines/erlang.mk/master/packages.v2.tsv
  80. # Core targets.
  81. deps:: $(ALL_DEPS_DIRS)
  82. @for dep in $(ALL_DEPS_DIRS) ; do \
  83. if [ -f $$dep/GNUmakefile ] || [ -f $$dep/makefile ] || [ -f $$dep/Makefile ] ; then \
  84. $(MAKE) -C $$dep ; \
  85. else \
  86. echo "include $(CURDIR)/erlang.mk" | $(MAKE) -f - -C $$dep ; \
  87. fi ; \
  88. done
  89. distclean:: distclean-deps distclean-pkg
  90. # Deps related targets.
  91. define dep_fetch
  92. if [ "$$$$VS" = "git" ]; then \
  93. git clone -n -- $$$$REPO $(DEPS_DIR)/$(1); \
  94. cd $(DEPS_DIR)/$(1) && git checkout -q $$$$COMMIT; \
  95. else \
  96. exit 78; \
  97. fi
  98. endef
  99. define dep_target
  100. $(DEPS_DIR)/$(1):
  101. @mkdir -p $(DEPS_DIR)
  102. @if [ ! -f $(PKG_FILE2) ]; then $(call core_http_get,$(PKG_FILE2),$(PKG_FILE_URL)); fi
  103. ifeq (,$(dep_$(1)))
  104. DEPPKG=$$$$(awk 'BEGIN { FS = "\t" }; $$$$1 == "$(1)" { print $$$$2 " " $$$$3 " " $$$$4 }' $(PKG_FILE2);) \
  105. VS=$$$$(echo $$$$DEPPKG | cut -d " " -f1); \
  106. REPO=$$$$(echo $$$$DEPPKG | cut -d " " -f2); \
  107. COMMIT=$$$$(echo $$$$DEPPKG | cut -d " " -f3); \
  108. $(call dep_fetch,$(1))
  109. else
  110. VS=$(word 1,$(dep_$(1))); \
  111. REPO=$(word 2,$(dep_$(1))); \
  112. COMMIT=$(word 3,$(dep_$(1))); \
  113. $(call dep_fetch,$(1))
  114. endif
  115. endef
  116. $(foreach dep,$(DEPS),$(eval $(call dep_target,$(dep))))
  117. distclean-deps:
  118. $(gen_verbose) rm -rf $(DEPS_DIR)
  119. # Packages related targets.
  120. $(PKG_FILE2):
  121. $(call core_http_get,$(PKG_FILE2),$(PKG_FILE_URL))
  122. pkg-list: $(PKG_FILE2)
  123. @cat $(PKG_FILE2) | awk 'BEGIN { FS = "\t" }; { print \
  124. "Name:\t\t" $$1 "\n" \
  125. "Repository:\t" $$3 "\n" \
  126. "Website:\t" $$5 "\n" \
  127. "Description:\t" $$6 "\n" }'
  128. ifdef q
  129. pkg-search: $(PKG_FILE2)
  130. @cat $(PKG_FILE2) | grep -i ${q} | awk 'BEGIN { FS = "\t" }; { print \
  131. "Name:\t\t" $$1 "\n" \
  132. "Repository:\t" $$3 "\n" \
  133. "Website:\t" $$5 "\n" \
  134. "Description:\t" $$6 "\n" }'
  135. else
  136. pkg-search:
  137. $(error Usage: make pkg-search q=STRING)
  138. endif
  139. distclean-pkg:
  140. $(gen_verbose) rm -f $(PKG_FILE2)
  141. help::
  142. @printf "%s\n" "" \
  143. "Package-related targets:" \
  144. " pkg-list List all known packages" \
  145. " pkg-search q=STRING Search for STRING in the package index"
  146. # Copyright (c) 2013-2014, Loïc Hoguin <essen@ninenines.eu>
  147. # This file is part of erlang.mk and subject to the terms of the ISC License.
  148. .PHONY: clean-app
  149. # Configuration.
  150. ERLC_OPTS ?= -Werror +debug_info +warn_export_all +warn_export_vars \
  151. +warn_shadow_vars +warn_obsolete_guard # +bin_opt_info +warn_missing_spec
  152. COMPILE_FIRST ?=
  153. COMPILE_FIRST_PATHS = $(addprefix src/,$(addsuffix .erl,$(COMPILE_FIRST)))
  154. # Verbosity.
  155. appsrc_verbose_0 = @echo " APP " $(PROJECT).app.src;
  156. appsrc_verbose = $(appsrc_verbose_$(V))
  157. erlc_verbose_0 = @echo " ERLC " $(filter %.erl %.core,$(?F));
  158. erlc_verbose = $(erlc_verbose_$(V))
  159. xyrl_verbose_0 = @echo " XYRL " $(filter %.xrl %.yrl,$(?F));
  160. xyrl_verbose = $(xyrl_verbose_$(V))
  161. # Core targets.
  162. app:: ebin/$(PROJECT).app
  163. $(eval MODULES := $(shell find ebin -type f -name \*.beam \
  164. | sed "s/ebin\//'/;s/\.beam/',/" | sed '$$s/.$$//'))
  165. $(appsrc_verbose) cat src/$(PROJECT).app.src \
  166. | sed "s/{modules,[[:space:]]*\[\]}/{modules, \[$(MODULES)\]}/" \
  167. > ebin/$(PROJECT).app
  168. define compile_erl
  169. $(erlc_verbose) erlc -v $(ERLC_OPTS) -o ebin/ \
  170. -pa ebin/ -I include/ $(COMPILE_FIRST_PATHS) $(1)
  171. endef
  172. define compile_xyrl
  173. $(xyrl_verbose) erlc -v -o ebin/ $(1)
  174. $(xyrl_verbose) erlc $(ERLC_OPTS) -o ebin/ ebin/*.erl
  175. @rm ebin/*.erl
  176. endef
  177. ifneq ($(wildcard src/),)
  178. ebin/$(PROJECT).app::
  179. @mkdir -p ebin/
  180. ebin/$(PROJECT).app:: $(shell find src -type f -name \*.erl) \
  181. $(shell find src -type f -name \*.core)
  182. $(if $(strip $?),$(call compile_erl,$?))
  183. ebin/$(PROJECT).app:: $(shell find src -type f -name \*.xrl) \
  184. $(shell find src -type f -name \*.yrl)
  185. $(if $(strip $?),$(call compile_xyrl,$?))
  186. endif
  187. clean:: clean-app
  188. # Extra targets.
  189. clean-app:
  190. $(gen_verbose) rm -rf ebin/
  191. # Copyright (c) 2014, Loïc Hoguin <essen@ninenines.eu>
  192. # This file is part of erlang.mk and subject to the terms of the ISC License.
  193. .PHONY: bootstrap bootstrap-lib bootstrap-rel new list-templates
  194. # Core targets.
  195. help::
  196. @printf "%s\n" "" \
  197. "Bootstrap targets:" \
  198. " bootstrap Generate a skeleton of an OTP application" \
  199. " bootstrap-lib Generate a skeleton of an OTP library" \
  200. " bootstrap-rel Generate the files needed to build a release" \
  201. " new t=TPL n=NAME Generate a module NAME based on the template TPL" \
  202. " list-templates List available templates"
  203. # Bootstrap templates.
  204. bs_appsrc = "{application, $(PROJECT), [" \
  205. " {description, \"\"}," \
  206. " {vsn, \"0.1.0\"}," \
  207. " {modules, []}," \
  208. " {registered, []}," \
  209. " {applications, [" \
  210. " kernel," \
  211. " stdlib" \
  212. " ]}," \
  213. " {mod, {$(PROJECT)_app, []}}," \
  214. " {env, []}" \
  215. "]}."
  216. bs_appsrc_lib = "{application, $(PROJECT), [" \
  217. " {description, \"\"}," \
  218. " {vsn, \"0.1.0\"}," \
  219. " {modules, []}," \
  220. " {registered, []}," \
  221. " {applications, [" \
  222. " kernel," \
  223. " stdlib" \
  224. " ]}" \
  225. "]}."
  226. bs_Makefile = "PROJECT = $(PROJECT)" \
  227. "include erlang.mk"
  228. bs_app = "-module($(PROJECT)_app)." \
  229. "-behaviour(application)." \
  230. "" \
  231. "-export([start/2])." \
  232. "-export([stop/1])." \
  233. "" \
  234. "start(_Type, _Args) ->" \
  235. " $(PROJECT)_sup:start_link()." \
  236. "" \
  237. "stop(_State) ->" \
  238. " ok."
  239. bs_relx_config = "{release, {$(PROJECT)_release, \"1\"}, [$(PROJECT)]}." \
  240. "{extended_start_script, true}." \
  241. "{sys_config, \"rel/sys.config\"}." \
  242. "{vm_args, \"rel/vm.args\"}."
  243. bs_sys_config = "[" \
  244. "]."
  245. bs_vm_args = "-name $(PROJECT)@127.0.0.1" \
  246. "-setcookie $(PROJECT)" \
  247. "-heart"
  248. # Normal templates.
  249. tpl_supervisor = "-module($(n))." \
  250. "-behaviour(supervisor)." \
  251. "" \
  252. "-export([start_link/0])." \
  253. "-export([init/1])." \
  254. "" \
  255. "start_link() ->" \
  256. " supervisor:start_link({local, ?MODULE}, ?MODULE, [])." \
  257. "" \
  258. "init([]) ->" \
  259. " Procs = []," \
  260. " {ok, {{one_for_one, 1, 5}, Procs}}."
  261. tpl_gen_server = "-module($(n))." \
  262. "-behaviour(gen_server)." \
  263. "" \
  264. "%% API." \
  265. "-export([start_link/0])." \
  266. "" \
  267. "%% gen_server." \
  268. "-export([init/1])." \
  269. "-export([handle_call/3])." \
  270. "-export([handle_cast/2])." \
  271. "-export([handle_info/2])." \
  272. "-export([terminate/2])." \
  273. "-export([code_change/3])." \
  274. "" \
  275. "-record(state, {" \
  276. "})." \
  277. "" \
  278. "%% API." \
  279. "" \
  280. "-spec start_link() -> {ok, pid()}." \
  281. "start_link() ->" \
  282. " gen_server:start_link(?MODULE, [], [])." \
  283. "" \
  284. "%% gen_server." \
  285. "" \
  286. "init([]) ->" \
  287. " {ok, \#state{}}." \
  288. "" \
  289. "handle_call(_Request, _From, State) ->" \
  290. " {reply, ignored, State}." \
  291. "" \
  292. "handle_cast(_Msg, State) ->" \
  293. " {noreply, State}." \
  294. "" \
  295. "handle_info(_Info, State) ->" \
  296. " {noreply, State}." \
  297. "" \
  298. "terminate(_Reason, _State) ->" \
  299. " ok." \
  300. "" \
  301. "code_change(_OldVsn, State, _Extra) ->" \
  302. " {ok, State}."
  303. tpl_cowboy_http = "-module($(n))." \
  304. "-behaviour(cowboy_http_handler)." \
  305. "" \
  306. "-export([init/3])." \
  307. "-export([handle/2])." \
  308. "-export([terminate/3])." \
  309. "" \
  310. "-record(state, {" \
  311. "})." \
  312. "" \
  313. "init(_, Req, _Opts) ->" \
  314. " {ok, Req, \#state{}}." \
  315. "" \
  316. "handle(Req, State=\#state{}) ->" \
  317. " {ok, Req2} = cowboy_req:reply(200, Req)," \
  318. " {ok, Req2, State}." \
  319. "" \
  320. "terminate(_Reason, _Req, _State) ->" \
  321. " ok."
  322. tpl_cowboy_loop = "-module($(n))." \
  323. "-behaviour(cowboy_loop_handler)." \
  324. "" \
  325. "-export([init/3])." \
  326. "-export([info/3])." \
  327. "-export([terminate/3])." \
  328. "" \
  329. "-record(state, {" \
  330. "})." \
  331. "" \
  332. "init(_, Req, _Opts) ->" \
  333. " {loop, Req, \#state{}, 5000, hibernate}." \
  334. "" \
  335. "info(_Info, Req, State) ->" \
  336. " {loop, Req, State, hibernate}." \
  337. "" \
  338. "terminate(_Reason, _Req, _State) ->" \
  339. " ok."
  340. tpl_cowboy_rest = "-module($(n))." \
  341. "" \
  342. "-export([init/3])." \
  343. "-export([content_types_provided/2])." \
  344. "-export([get_html/2])." \
  345. "" \
  346. "init(_, _Req, _Opts) ->" \
  347. " {upgrade, protocol, cowboy_rest}." \
  348. "" \
  349. "content_types_provided(Req, State) ->" \
  350. " {[{{<<\"text\">>, <<\"html\">>, '_'}, get_html}], Req, State}." \
  351. "" \
  352. "get_html(Req, State) ->" \
  353. " {<<\"<html><body>This is REST!</body></html>\">>, Req, State}."
  354. tpl_cowboy_ws = "-module($(n))." \
  355. "-behaviour(cowboy_websocket_handler)." \
  356. "" \
  357. "-export([init/3])." \
  358. "-export([websocket_init/3])." \
  359. "-export([websocket_handle/3])." \
  360. "-export([websocket_info/3])." \
  361. "-export([websocket_terminate/3])." \
  362. "" \
  363. "-record(state, {" \
  364. "})." \
  365. "" \
  366. "init(_, _, _) ->" \
  367. " {upgrade, protocol, cowboy_websocket}." \
  368. "" \
  369. "websocket_init(_, Req, _Opts) ->" \
  370. " Req2 = cowboy_req:compact(Req)," \
  371. " {ok, Req2, \#state{}}." \
  372. "" \
  373. "websocket_handle({text, Data}, Req, State) ->" \
  374. " {reply, {text, Data}, Req, State};" \
  375. "websocket_handle({binary, Data}, Req, State) ->" \
  376. " {reply, {binary, Data}, Req, State};" \
  377. "websocket_handle(_Frame, Req, State) ->" \
  378. " {ok, Req, State}." \
  379. "" \
  380. "websocket_info(_Info, Req, State) ->" \
  381. " {ok, Req, State}." \
  382. "" \
  383. "websocket_terminate(_Reason, _Req, _State) ->" \
  384. " ok."
  385. tpl_ranch_protocol = "-module($(n))." \
  386. "-behaviour(ranch_protocol)." \
  387. "" \
  388. "-export([start_link/4])." \
  389. "-export([init/4])." \
  390. "" \
  391. "-type opts() :: []." \
  392. "-export_type([opts/0])." \
  393. "" \
  394. "-record(state, {" \
  395. " socket :: inet:socket()," \
  396. " transport :: module()" \
  397. "})." \
  398. "" \
  399. "start_link(Ref, Socket, Transport, Opts) ->" \
  400. " Pid = spawn_link(?MODULE, init, [Ref, Socket, Transport, Opts])," \
  401. " {ok, Pid}." \
  402. "" \
  403. "-spec init(ranch:ref(), inet:socket(), module(), opts()) -> ok." \
  404. "init(Ref, Socket, Transport, _Opts) ->" \
  405. " ok = ranch:accept_ack(Ref)," \
  406. " loop(\#state{socket=Socket, transport=Transport})." \
  407. "" \
  408. "loop(State) ->" \
  409. " loop(State)."
  410. # Plugin-specific targets.
  411. bootstrap:
  412. ifneq ($(wildcard src/),)
  413. $(error Error: src/ directory already exists)
  414. endif
  415. @printf "%s\n" $(bs_Makefile) > Makefile
  416. @mkdir src/
  417. @printf "%s\n" $(bs_appsrc) > src/$(PROJECT).app.src
  418. @printf "%s\n" $(bs_app) > src/$(PROJECT)_app.erl
  419. $(eval n := $(PROJECT)_sup)
  420. @printf "%s\n" $(tpl_supervisor) > src/$(PROJECT)_sup.erl
  421. bootstrap-lib:
  422. ifneq ($(wildcard src/),)
  423. $(error Error: src/ directory already exists)
  424. endif
  425. @printf "%s\n" $(bs_Makefile) > Makefile
  426. @mkdir src/
  427. @printf "%s\n" $(bs_appsrc_lib) > src/$(PROJECT).app.src
  428. bootstrap-rel:
  429. ifneq ($(wildcard relx.config),)
  430. $(error Error: relx.config already exists)
  431. endif
  432. ifneq ($(wildcard rel/),)
  433. $(error Error: rel/ directory already exists)
  434. endif
  435. @printf "%s\n" $(bs_relx_config) > relx.config
  436. @mkdir rel/
  437. @printf "%s\n" $(bs_sys_config) > rel/sys.config
  438. @printf "%s\n" $(bs_vm_args) > rel/vm.args
  439. new:
  440. ifeq ($(wildcard src/),)
  441. $(error Error: src/ directory does not exist)
  442. endif
  443. ifndef t
  444. $(error Usage: make new t=TEMPLATE n=NAME)
  445. endif
  446. ifndef tpl_$(t)
  447. $(error Unknown template)
  448. endif
  449. ifndef n
  450. $(error Usage: make new t=TEMPLATE n=NAME)
  451. endif
  452. @printf "%s\n" $(tpl_$(t)) > src/$(n).erl
  453. list-templates:
  454. @echo Available templates: $(sort $(patsubst tpl_%,%,$(filter tpl_%,$(.VARIABLES))))
  455. # Copyright (c) 2013-2014, Loïc Hoguin <essen@ninenines.eu>
  456. # This file is part of erlang.mk and subject to the terms of the ISC License.
  457. .PHONY: build-ct-deps build-ct-suites tests-ct clean-ct distclean-ct
  458. # Configuration.
  459. CT_OPTS ?=
  460. ifneq ($(wildcard test/),)
  461. CT_SUITES ?= $(sort $(subst _SUITE.erl,,$(shell find test -type f -name \*_SUITE.erl -exec basename {} \;)))
  462. else
  463. CT_SUITES ?=
  464. endif
  465. TEST_ERLC_OPTS ?= +debug_info +warn_export_vars +warn_shadow_vars +warn_obsolete_guard
  466. TEST_ERLC_OPTS += -DTEST=1 -DEXTRA=1 +'{parse_transform, eunit_autoexport}'
  467. # Core targets.
  468. tests:: tests-ct
  469. clean:: clean-ct
  470. distclean:: distclean-ct
  471. help::
  472. @printf "%s\n" "" \
  473. "All your common_test suites have their associated targets." \
  474. "A suite named http_SUITE can be ran using the ct-http target."
  475. # Plugin-specific targets.
  476. ALL_TEST_DEPS_DIRS = $(addprefix $(DEPS_DIR)/,$(TEST_DEPS))
  477. CT_RUN = ct_run \
  478. -no_auto_compile \
  479. -noshell \
  480. -pa $(realpath ebin) $(DEPS_DIR)/*/ebin \
  481. -dir test \
  482. -logdir logs
  483. $(foreach dep,$(TEST_DEPS),$(eval $(call dep_target,$(dep))))
  484. build-ct-deps: $(ALL_TEST_DEPS_DIRS)
  485. @for dep in $(ALL_TEST_DEPS_DIRS) ; do $(MAKE) -C $$dep; done
  486. build-ct-suites: build-ct-deps
  487. $(gen_verbose) erlc -v $(TEST_ERLC_OPTS) -o test/ \
  488. $(wildcard test/*.erl test/*/*.erl) -pa ebin/
  489. tests-ct: ERLC_OPTS = $(TEST_ERLC_OPTS)
  490. tests-ct: clean deps app build-ct-suites
  491. @if [ -d "test" ] ; \
  492. then \
  493. mkdir -p logs/ ; \
  494. $(CT_RUN) -suite $(addsuffix _SUITE,$(CT_SUITES)) $(CT_OPTS) ; \
  495. fi
  496. $(gen_verbose) rm -f test/*.beam
  497. define ct_suite_target
  498. ct-$(1): ERLC_OPTS = $(TEST_ERLC_OPTS)
  499. ct-$(1): clean deps app build-ct-suites
  500. @if [ -d "test" ] ; \
  501. then \
  502. mkdir -p logs/ ; \
  503. $(CT_RUN) -suite $(addsuffix _SUITE,$(1)) $(CT_OPTS) ; \
  504. fi
  505. $(gen_verbose) rm -f test/*.beam
  506. endef
  507. $(foreach test,$(CT_SUITES),$(eval $(call ct_suite_target,$(test))))
  508. clean-ct:
  509. $(gen_verbose) rm -rf test/*.beam
  510. distclean-ct:
  511. $(gen_verbose) rm -rf logs/
  512. # Copyright (c) 2013-2014, Loïc Hoguin <essen@ninenines.eu>
  513. # This file is part of erlang.mk and subject to the terms of the ISC License.
  514. .PHONY: plt distclean-plt dialyze
  515. # Configuration.
  516. DIALYZER_PLT ?= $(CURDIR)/.$(PROJECT).plt
  517. export DIALYZER_PLT
  518. PLT_APPS ?=
  519. DIALYZER_OPTS ?= -Werror_handling -Wrace_conditions \
  520. -Wunmatched_returns # -Wunderspecs
  521. # Core targets.
  522. distclean:: distclean-plt
  523. help::
  524. @printf "%s\n" "" \
  525. "Dialyzer targets:" \
  526. " plt Build a PLT file for this project" \
  527. " dialyze Analyze the project using Dialyzer"
  528. # Plugin-specific targets.
  529. plt: deps app
  530. @dialyzer --build_plt --apps erts kernel stdlib $(PLT_APPS) $(ALL_DEPS_DIRS)
  531. distclean-plt:
  532. $(gen_verbose) rm -f $(DIALYZER_PLT)
  533. dialyze:
  534. @dialyzer --no_native --src -r src $(DIALYZER_OPTS)
  535. # Copyright (c) 2013-2014, Loïc Hoguin <essen@ninenines.eu>
  536. # This file is part of erlang.mk and subject to the terms of the ISC License.
  537. # Verbosity.
  538. dtl_verbose_0 = @echo " DTL " $(filter %.dtl,$(?F));
  539. dtl_verbose = $(dtl_verbose_$(V))
  540. # Core targets.
  541. define compile_erlydtl
  542. $(dtl_verbose) erl -noshell -pa ebin/ $(DEPS_DIR)/erlydtl/ebin/ -eval ' \
  543. Compile = fun(F) -> \
  544. Module = list_to_atom( \
  545. string:to_lower(filename:basename(F, ".dtl")) ++ "_dtl"), \
  546. erlydtl:compile(F, Module, [{out_dir, "ebin/"}]) \
  547. end, \
  548. _ = [Compile(F) || F <- string:tokens("$(1)", " ")], \
  549. init:stop()'
  550. endef
  551. ifneq ($(wildcard src/),)
  552. ebin/$(PROJECT).app:: $(shell find templates -type f -name \*.dtl 2>/dev/null)
  553. $(if $(strip $?),$(call compile_erlydtl,$?))
  554. endif
  555. # Copyright (c) 2013-2014, Loïc Hoguin <essen@ninenines.eu>
  556. # This file is part of erlang.mk and subject to the terms of the ISC License.
  557. .PHONY: distclean-edoc
  558. # Configuration.
  559. EDOC_OPTS ?=
  560. # Core targets.
  561. docs:: distclean-edoc
  562. $(gen_verbose) erl -noshell \
  563. -eval 'edoc:application($(PROJECT), ".", [$(EDOC_OPTS)]), init:stop().'
  564. distclean:: distclean-edoc
  565. # Plugin-specific targets.
  566. distclean-edoc:
  567. $(gen_verbose) rm -f doc/*.css doc/*.html doc/*.png doc/edoc-info
  568. # Copyright (c) 2013-2014, Loïc Hoguin <essen@ninenines.eu>
  569. # This file is part of erlang.mk and subject to the terms of the ISC License.
  570. .PHONY: distclean-rel
  571. # Configuration.
  572. RELX_CONFIG ?= $(CURDIR)/relx.config
  573. ifneq ($(wildcard $(RELX_CONFIG)),)
  574. RELX ?= $(CURDIR)/relx
  575. export RELX
  576. RELX_URL ?= https://github.com/erlware/relx/releases/download/v1.0.2/relx
  577. RELX_OPTS ?=
  578. RELX_OUTPUT_DIR ?= _rel
  579. ifeq ($(firstword $(RELX_OPTS)),-o)
  580. RELX_OUTPUT_DIR = $(word 2,$(RELX_OPTS))
  581. endif
  582. # Core targets.
  583. rel:: distclean-rel $(RELX)
  584. @$(RELX) -c $(RELX_CONFIG) $(RELX_OPTS)
  585. distclean:: distclean-rel
  586. # Plugin-specific targets.
  587. define relx_fetch
  588. $(call core_http_get,$(RELX),$(RELX_URL))
  589. chmod +x $(RELX)
  590. endef
  591. $(RELX):
  592. @$(call relx_fetch)
  593. distclean-rel:
  594. $(gen_verbose) rm -rf $(RELX) $(RELX_OUTPUT_DIR)
  595. endif