erlang.mk 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730
  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:: ebin/$(PROJECT).app
  158. $(eval MODULES := $(shell find ebin -type f -name \*.beam \
  159. | sed "s/ebin\//'/;s/\.beam/',/" | sed '$$s/.$$//'))
  160. $(appsrc_verbose) cat src/$(PROJECT).app.src \
  161. | sed "s/{modules,[[:space:]]*\[\]}/{modules, \[$(MODULES)\]}/" \
  162. > ebin/$(PROJECT).app
  163. define compile_erl
  164. $(erlc_verbose) erlc -v $(ERLC_OPTS) -o ebin/ \
  165. -pa ebin/ -I include/ $(COMPILE_FIRST_PATHS) $(1)
  166. endef
  167. define compile_xyrl
  168. $(xyrl_verbose) erlc -v -o ebin/ $(1)
  169. $(xyrl_verbose) erlc $(ERLC_OPTS) -o ebin/ ebin/*.erl
  170. @rm ebin/*.erl
  171. endef
  172. ifneq ($(wildcard src/),)
  173. ebin/$(PROJECT).app::
  174. @mkdir -p ebin/
  175. ebin/$(PROJECT).app:: $(shell find src -type f -name \*.erl) \
  176. $(shell find src -type f -name \*.core)
  177. $(if $(strip $?),$(call compile_erl,$?))
  178. ebin/$(PROJECT).app:: $(shell find src -type f -name \*.xrl) \
  179. $(shell find src -type f -name \*.yrl)
  180. $(if $(strip $?),$(call compile_xyrl,$?))
  181. endif
  182. clean:: clean-app
  183. # Extra targets.
  184. clean-app:
  185. $(gen_verbose) rm -rf ebin/
  186. # Copyright (c) 2014, Loïc Hoguin <essen@ninenines.eu>
  187. # This file is part of erlang.mk and subject to the terms of the ISC License.
  188. .PHONY: bootstrap bootstrap-lib bootstrap-rel new list-templates
  189. # Core targets.
  190. help::
  191. @printf "%s\n" "" \
  192. "Bootstrap targets:" \
  193. " bootstrap Generate a skeleton of an OTP application" \
  194. " bootstrap-lib Generate a skeleton of an OTP library" \
  195. " bootstrap-rel Generate the files needed to build a release" \
  196. " new t=TPL n=NAME Generate a module NAME based on the template TPL" \
  197. " list-templates List available templates"
  198. # Bootstrap templates.
  199. bs_appsrc = "{application, $(PROJECT), [" \
  200. " {description, \"\"}," \
  201. " {vsn, \"0.1.0\"}," \
  202. " {modules, []}," \
  203. " {registered, []}," \
  204. " {applications, [" \
  205. " kernel," \
  206. " stdlib" \
  207. " ]}," \
  208. " {mod, {$(PROJECT)_app, []}}," \
  209. " {env, []}" \
  210. "]}."
  211. bs_appsrc_lib = "{application, $(PROJECT), [" \
  212. " {description, \"\"}," \
  213. " {vsn, \"0.1.0\"}," \
  214. " {modules, []}," \
  215. " {registered, []}," \
  216. " {applications, [" \
  217. " kernel," \
  218. " stdlib" \
  219. " ]}" \
  220. "]}."
  221. bs_Makefile = "PROJECT = $(PROJECT)" \
  222. "include erlang.mk"
  223. bs_app = "-module($(PROJECT)_app)." \
  224. "-behaviour(application)." \
  225. "" \
  226. "-export([start/2])." \
  227. "-export([stop/1])." \
  228. "" \
  229. "start(_Type, _Args) ->" \
  230. " $(PROJECT)_sup:start_link()." \
  231. "" \
  232. "stop(_State) ->" \
  233. " ok."
  234. bs_relx_config = "{release, {$(PROJECT)_release, \"1\"}, [$(PROJECT)]}." \
  235. "{extended_start_script, true}." \
  236. "{sys_config, \"rel/sys.config\"}." \
  237. "{vm_args, \"rel/vm.args\"}."
  238. bs_sys_config = "[" \
  239. "]."
  240. bs_vm_args = "-name $(PROJECT)@127.0.0.1" \
  241. "-setcookie $(PROJECT)" \
  242. "-heart"
  243. # Normal templates.
  244. tpl_supervisor = "-module($(n))." \
  245. "-behaviour(supervisor)." \
  246. "" \
  247. "-export([start_link/0])." \
  248. "-export([init/1])." \
  249. "" \
  250. "start_link() ->" \
  251. " supervisor:start_link({local, ?MODULE}, ?MODULE, [])." \
  252. "" \
  253. "init([]) ->" \
  254. " Procs = []," \
  255. " {ok, {{one_for_one, 1, 5}, Procs}}."
  256. tpl_gen_server = "-module($(n))." \
  257. "-behaviour(gen_server)." \
  258. "" \
  259. "%% API." \
  260. "-export([start_link/0])." \
  261. "" \
  262. "%% gen_server." \
  263. "-export([init/1])." \
  264. "-export([handle_call/3])." \
  265. "-export([handle_cast/2])." \
  266. "-export([handle_info/2])." \
  267. "-export([terminate/2])." \
  268. "-export([code_change/3])." \
  269. "" \
  270. "-record(state, {" \
  271. "})." \
  272. "" \
  273. "%% API." \
  274. "" \
  275. "-spec start_link() -> {ok, pid()}." \
  276. "start_link() ->" \
  277. " gen_server:start_link(?MODULE, [], [])." \
  278. "" \
  279. "%% gen_server." \
  280. "" \
  281. "init([]) ->" \
  282. " {ok, \#state{}}." \
  283. "" \
  284. "handle_call(_Request, _From, State) ->" \
  285. " {reply, ignored, State}." \
  286. "" \
  287. "handle_cast(_Msg, State) ->" \
  288. " {noreply, State}." \
  289. "" \
  290. "handle_info(_Info, State) ->" \
  291. " {noreply, State}." \
  292. "" \
  293. "terminate(_Reason, _State) ->" \
  294. " ok." \
  295. "" \
  296. "code_change(_OldVsn, State, _Extra) ->" \
  297. " {ok, State}."
  298. tpl_cowboy_http = "-module($(n))." \
  299. "-behaviour(cowboy_http_handler)." \
  300. "" \
  301. "-export([init/3])." \
  302. "-export([handle/2])." \
  303. "-export([terminate/3])." \
  304. "" \
  305. "-record(state, {" \
  306. "})." \
  307. "" \
  308. "init(_, Req, _Opts) ->" \
  309. " {ok, Req, \#state{}}." \
  310. "" \
  311. "handle(Req, State=\#state{}) ->" \
  312. " {ok, Req2} = cowboy_req:reply(200, Req)," \
  313. " {ok, Req2, State}." \
  314. "" \
  315. "terminate(_Reason, _Req, _State) ->" \
  316. " ok."
  317. tpl_cowboy_loop = "-module($(n))." \
  318. "-behaviour(cowboy_loop_handler)." \
  319. "" \
  320. "-export([init/3])." \
  321. "-export([info/3])." \
  322. "-export([terminate/3])." \
  323. "" \
  324. "-record(state, {" \
  325. "})." \
  326. "" \
  327. "init(_, Req, _Opts) ->" \
  328. " {loop, Req, \#state{}, 5000, hibernate}." \
  329. "" \
  330. "info(_Info, Req, State) ->" \
  331. " {loop, Req, State, hibernate}." \
  332. "" \
  333. "terminate(_Reason, _Req, _State) ->" \
  334. " ok."
  335. tpl_cowboy_rest = "-module($(n))." \
  336. "" \
  337. "-export([init/3])." \
  338. "-export([content_types_provided/2])." \
  339. "-export([get_html/2])." \
  340. "" \
  341. "init(_, _Req, _Opts) ->" \
  342. " {upgrade, protocol, cowboy_rest}." \
  343. "" \
  344. "content_types_provided(Req, State) ->" \
  345. " {[{{<<\"text\">>, <<\"html\">>, '_'}, get_html}], Req, State}." \
  346. "" \
  347. "get_html(Req, State) ->" \
  348. " {<<\"<html><body>This is REST!</body></html>\">>, Req, State}."
  349. tpl_cowboy_ws = "-module($(n))." \
  350. "-behaviour(cowboy_websocket_handler)." \
  351. "" \
  352. "-export([init/3])." \
  353. "-export([websocket_init/3])." \
  354. "-export([websocket_handle/3])." \
  355. "-export([websocket_info/3])." \
  356. "-export([websocket_terminate/3])." \
  357. "" \
  358. "-record(state, {" \
  359. "})." \
  360. "" \
  361. "init(_, _, _) ->" \
  362. " {upgrade, protocol, cowboy_websocket}." \
  363. "" \
  364. "websocket_init(_, Req, _Opts) ->" \
  365. " Req2 = cowboy_req:compact(Req)," \
  366. " {ok, Req2, \#state{}}." \
  367. "" \
  368. "websocket_handle({text, Data}, Req, State) ->" \
  369. " {reply, {text, Data}, Req, State};" \
  370. "websocket_handle({binary, Data}, Req, State) ->" \
  371. " {reply, {binary, Data}, Req, State};" \
  372. "websocket_handle(_Frame, Req, State) ->" \
  373. " {ok, Req, State}." \
  374. "" \
  375. "websocket_info(_Info, Req, State) ->" \
  376. " {ok, Req, State}." \
  377. "" \
  378. "websocket_terminate(_Reason, _Req, _State) ->" \
  379. " ok."
  380. tpl_ranch_protocol = "-module($(n))." \
  381. "-behaviour(ranch_protocol)." \
  382. "" \
  383. "-export([start_link/4])." \
  384. "-export([init/4])." \
  385. "" \
  386. "-type opts() :: []." \
  387. "-export_type([opts/0])." \
  388. "" \
  389. "-record(state, {" \
  390. " socket :: inet:socket()," \
  391. " transport :: module()" \
  392. "})." \
  393. "" \
  394. "start_link(Ref, Socket, Transport, Opts) ->" \
  395. " Pid = spawn_link(?MODULE, init, [Ref, Socket, Transport, Opts])," \
  396. " {ok, Pid}." \
  397. "" \
  398. "-spec init(ranch:ref(), inet:socket(), module(), opts()) -> ok." \
  399. "init(Ref, Socket, Transport, _Opts) ->" \
  400. " ok = ranch:accept_ack(Ref)," \
  401. " loop(\#state{socket=Socket, transport=Transport})." \
  402. "" \
  403. "loop(State) ->" \
  404. " loop(State)."
  405. # Plugin-specific targets.
  406. bootstrap:
  407. ifneq ($(wildcard src/),)
  408. $(error Error: src/ directory already exists)
  409. endif
  410. @printf "%s\n" $(bs_Makefile) > Makefile
  411. @mkdir src/
  412. @printf "%s\n" $(bs_appsrc) > src/$(PROJECT).app.src
  413. @printf "%s\n" $(bs_app) > src/$(PROJECT)_app.erl
  414. $(eval n := $(PROJECT)_sup)
  415. @printf "%s\n" $(tpl_supervisor) > src/$(PROJECT)_sup.erl
  416. bootstrap-lib:
  417. ifneq ($(wildcard src/),)
  418. $(error Error: src/ directory already exists)
  419. endif
  420. @printf "%s\n" $(bs_Makefile) > Makefile
  421. @mkdir src/
  422. @printf "%s\n" $(bs_appsrc_lib) > src/$(PROJECT).app.src
  423. bootstrap-rel:
  424. ifneq ($(wildcard relx.config),)
  425. $(error Error: relx.config already exists)
  426. endif
  427. ifneq ($(wildcard rel/),)
  428. $(error Error: rel/ directory already exists)
  429. endif
  430. @printf "%s\n" $(bs_relx_config) > relx.config
  431. @mkdir rel/
  432. @printf "%s\n" $(bs_sys_config) > rel/sys.config
  433. @printf "%s\n" $(bs_vm_args) > rel/vm.args
  434. new:
  435. ifeq ($(wildcard src/),)
  436. $(error Error: src/ directory does not exist)
  437. endif
  438. ifndef t
  439. $(error Usage: make new t=TEMPLATE n=NAME)
  440. endif
  441. ifndef tpl_$(t)
  442. $(error Unknown template)
  443. endif
  444. ifndef n
  445. $(error Usage: make new t=TEMPLATE n=NAME)
  446. endif
  447. @printf "%s\n" $(tpl_$(t)) > src/$(n).erl
  448. list-templates:
  449. @echo Available templates: $(sort $(patsubst tpl_%,%,$(filter tpl_%,$(.VARIABLES))))
  450. # Copyright (c) 2013-2014, Loïc Hoguin <essen@ninenines.eu>
  451. # This file is part of erlang.mk and subject to the terms of the ISC License.
  452. .PHONY: build-ct-deps build-ct-suites tests-ct clean-ct distclean-ct
  453. # Configuration.
  454. CT_OPTS ?=
  455. ifneq ($(wildcard test/),)
  456. CT_SUITES ?= $(sort $(subst _SUITE.erl,,$(shell find test -type f -name \*_SUITE.erl -exec basename {} \;)))
  457. else
  458. CT_SUITES ?=
  459. endif
  460. TEST_ERLC_OPTS ?= +debug_info +warn_export_vars +warn_shadow_vars +warn_obsolete_guard
  461. TEST_ERLC_OPTS += -DTEST=1 -DEXTRA=1 +'{parse_transform, eunit_autoexport}'
  462. # Core targets.
  463. tests:: tests-ct
  464. clean:: clean-ct
  465. distclean:: distclean-ct
  466. help::
  467. @printf "%s\n" "" \
  468. "All your common_test suites have their associated targets." \
  469. "A suite named http_SUITE can be ran using the ct-http target."
  470. # Plugin-specific targets.
  471. ALL_TEST_DEPS_DIRS = $(addprefix $(DEPS_DIR)/,$(TEST_DEPS))
  472. CT_RUN = ct_run \
  473. -no_auto_compile \
  474. -noshell \
  475. -pa $(realpath ebin) $(DEPS_DIR)/*/ebin \
  476. -dir test \
  477. -logdir logs
  478. $(foreach dep,$(TEST_DEPS),$(eval $(call dep_target,$(dep))))
  479. build-ct-deps: $(ALL_TEST_DEPS_DIRS)
  480. @for dep in $(ALL_TEST_DEPS_DIRS) ; do $(MAKE) -C $$dep; done
  481. build-ct-suites: build-ct-deps
  482. $(gen_verbose) erlc -v $(TEST_ERLC_OPTS) -o test/ \
  483. $(wildcard test/*.erl test/*/*.erl) -pa ebin/
  484. tests-ct: ERLC_OPTS = $(TEST_ERLC_OPTS)
  485. tests-ct: clean deps app build-ct-suites
  486. @if [ -d "test" ] ; \
  487. then \
  488. mkdir -p logs/ ; \
  489. $(CT_RUN) -suite $(addsuffix _SUITE,$(CT_SUITES)) $(CT_OPTS) ; \
  490. fi
  491. $(gen_verbose) rm -f test/*.beam
  492. define ct_suite_target
  493. ct-$(1): ERLC_OPTS = $(TEST_ERLC_OPTS)
  494. ct-$(1): clean deps app build-ct-suites
  495. @if [ -d "test" ] ; \
  496. then \
  497. mkdir -p logs/ ; \
  498. $(CT_RUN) -suite $(addsuffix _SUITE,$(1)) $(CT_OPTS) ; \
  499. fi
  500. $(gen_verbose) rm -f test/*.beam
  501. endef
  502. $(foreach test,$(CT_SUITES),$(eval $(call ct_suite_target,$(test))))
  503. clean-ct:
  504. $(gen_verbose) rm -rf test/*.beam
  505. distclean-ct:
  506. $(gen_verbose) rm -rf logs/
  507. # Copyright (c) 2013-2014, Loïc Hoguin <essen@ninenines.eu>
  508. # This file is part of erlang.mk and subject to the terms of the ISC License.
  509. .PHONY: plt distclean-plt dialyze
  510. # Configuration.
  511. DIALYZER_PLT ?= $(CURDIR)/.$(PROJECT).plt
  512. export DIALYZER_PLT
  513. PLT_APPS ?=
  514. DIALYZER_OPTS ?= -Werror_handling -Wrace_conditions \
  515. -Wunmatched_returns # -Wunderspecs
  516. # Core targets.
  517. distclean:: distclean-plt
  518. help::
  519. @printf "%s\n" "" \
  520. "Dialyzer targets:" \
  521. " plt Build a PLT file for this project" \
  522. " dialyze Analyze the project using Dialyzer"
  523. # Plugin-specific targets.
  524. $(DIALYZER_PLT): deps app
  525. @dialyzer --build_plt --apps erts kernel stdlib $(PLT_APPS) $(ALL_DEPS_DIRS)
  526. plt: $(DIALYZER_PLT)
  527. distclean-plt:
  528. $(gen_verbose) rm -f $(DIALYZER_PLT)
  529. ifneq ($(wildcard $(DIALYZER_PLT)),)
  530. dialyze:
  531. else
  532. dialyze: $(DIALYZER_PLT)
  533. endif
  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 distclean-relx
  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_OUTPUT_DIR)
  595. distclean-relx:
  596. $(gen_verbose) rm -rf $(RELX)
  597. endif