erlang.mk 18 KB

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