erlang.mk 19 KB

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