erlang.mk 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773
  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. 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 2,$(dep_$(1))); \
  106. COMMIT=$(word 3,$(dep_$(1))); \
  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. " list-templates List available templates"
  197. # Bootstrap templates.
  198. define bs_appsrc
  199. {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. endef
  212. define bs_appsrc_lib
  213. {application, $(PROJECT), [
  214. {description, ""},
  215. {vsn, "0.1.0"},
  216. {modules, []},
  217. {registered, []},
  218. {applications, [
  219. kernel,
  220. stdlib
  221. ]}
  222. ]}.
  223. endef
  224. define bs_Makefile
  225. PROJECT = $(PROJECT)
  226. include erlang.mk
  227. endef
  228. define bs_app
  229. -module($(PROJECT)_app).
  230. -behaviour(application).
  231. -export([start/2]).
  232. -export([stop/1]).
  233. start(_Type, _Args) ->
  234. $(PROJECT)_sup:start_link().
  235. stop(_State) ->
  236. ok.
  237. endef
  238. define bs_relx_config
  239. {release, {$(PROJECT)_release, "1"}, [$(PROJECT)]}.
  240. {extended_start_script, true}.
  241. {sys_config, "rel/sys.config"}.
  242. {vm_args, "rel/vm.args"}.
  243. endef
  244. define bs_sys_config
  245. [
  246. ].
  247. endef
  248. define bs_vm_args
  249. -name $(PROJECT)@127.0.0.1
  250. -setcookie $(PROJECT)
  251. -heart
  252. endef
  253. # Normal templates.
  254. define tpl_supervisor
  255. -module($(n)).
  256. -behaviour(supervisor).
  257. -export([start_link/0]).
  258. -export([init/1]).
  259. start_link() ->
  260. supervisor:start_link({local, ?MODULE}, ?MODULE, []).
  261. init([]) ->
  262. Procs = [],
  263. {ok, {{one_for_one, 1, 5}, Procs}}.
  264. endef
  265. define tpl_gen_server
  266. -module($(n)).
  267. -behaviour(gen_server).
  268. %% API.
  269. -export([start_link/0]).
  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. -record(state, {
  278. }).
  279. %% API.
  280. -spec start_link() -> {ok, pid()}.
  281. start_link() ->
  282. gen_server:start_link(?MODULE, [], []).
  283. %% gen_server.
  284. init([]) ->
  285. {ok, #state{}}.
  286. handle_call(_Request, _From, State) ->
  287. {reply, ignored, State}.
  288. handle_cast(_Msg, State) ->
  289. {noreply, State}.
  290. handle_info(_Info, State) ->
  291. {noreply, State}.
  292. terminate(_Reason, _State) ->
  293. ok.
  294. code_change(_OldVsn, State, _Extra) ->
  295. {ok, State}.
  296. endef
  297. define tpl_cowboy_http
  298. -module($(n)).
  299. -behaviour(cowboy_http_handler).
  300. -export([init/3]).
  301. -export([handle/2]).
  302. -export([terminate/3]).
  303. -record(state, {
  304. }).
  305. init(_, Req, _Opts) ->
  306. {ok, Req, #state{}}.
  307. handle(Req, State=#state{}) ->
  308. {ok, Req2} = cowboy_req:reply(200, Req),
  309. {ok, Req2, State}.
  310. terminate(_Reason, _Req, _State) ->
  311. ok.
  312. endef
  313. define tpl_cowboy_loop
  314. -module($(n)).
  315. -behaviour(cowboy_loop_handler).
  316. -export([init/3]).
  317. -export([info/3]).
  318. -export([terminate/3]).
  319. -record(state, {
  320. }).
  321. init(_, Req, _Opts) ->
  322. {loop, Req, #state{}, 5000, hibernate}.
  323. info(_Info, Req, State) ->
  324. {loop, Req, State, hibernate}.
  325. terminate(_Reason, _Req, _State) ->
  326. ok.
  327. endef
  328. define tpl_cowboy_rest
  329. -module($(n)).
  330. -export([init/3]).
  331. -export([content_types_provided/2]).
  332. -export([get_html/2]).
  333. init(_, _Req, _Opts) ->
  334. {upgrade, protocol, cowboy_rest}.
  335. content_types_provided(Req, State) ->
  336. {[{{<<"text">>, <<"html">>, '_'}, get_html}], Req, State}.
  337. get_html(Req, State) ->
  338. {<<"<html><body>This is REST!</body></html>">>, Req, State}.
  339. endef
  340. define tpl_cowboy_ws
  341. -module($(n)).
  342. -behaviour(cowboy_websocket_handler).
  343. -export([init/3]).
  344. -export([websocket_init/3]).
  345. -export([websocket_handle/3]).
  346. -export([websocket_info/3]).
  347. -export([websocket_terminate/3]).
  348. -record(state, {
  349. }).
  350. init(_, _, _) ->
  351. {upgrade, protocol, cowboy_websocket}.
  352. websocket_init(_, Req, _Opts) ->
  353. Req2 = cowboy_req:compact(Req),
  354. {ok, Req2, #state{}}.
  355. websocket_handle({text, Data}, Req, State) ->
  356. {reply, {text, Data}, Req, State};
  357. websocket_handle({binary, Data}, Req, State) ->
  358. {reply, {binary, Data}, Req, State};
  359. websocket_handle(_Frame, Req, State) ->
  360. {ok, Req, State}.
  361. websocket_info(_Info, Req, State) ->
  362. {ok, Req, State}.
  363. websocket_terminate(_Reason, _Req, _State) ->
  364. ok.
  365. endef
  366. define tpl_ranch_protocol
  367. -module($(n)).
  368. -behaviour(ranch_protocol).
  369. -export([start_link/4]).
  370. -export([init/4]).
  371. -type opts() :: [].
  372. -export_type([opts/0]).
  373. -record(state, {
  374. socket :: inet:socket(),
  375. transport :: module()
  376. }).
  377. start_link(Ref, Socket, Transport, Opts) ->
  378. Pid = spawn_link(?MODULE, init, [Ref, Socket, Transport, Opts]),
  379. {ok, Pid}.
  380. -spec init(ranch:ref(), inet:socket(), module(), opts()) -> ok.
  381. init(Ref, Socket, Transport, _Opts) ->
  382. ok = ranch:accept_ack(Ref),
  383. loop(#state{socket=Socket, transport=Transport}).
  384. loop(State) ->
  385. loop(State).
  386. endef
  387. # Plugin-specific targets.
  388. define render_template
  389. @echo '$(subst $(newline),\n,${1})' > $(2)
  390. endef
  391. define newline
  392. endef
  393. bootstrap:
  394. ifneq ($(wildcard src/),)
  395. $(error Error: src/ directory already exists)
  396. endif
  397. $(call render_template,$(bs_Makefile),Makefile)
  398. @mkdir src/
  399. $(call render_template,$(bs_appsrc),src/$(PROJECT).app.src)
  400. $(call render_template,$(bs_app),src/$(PROJECT)_app.erl)
  401. $(eval n := $(PROJECT)_sup)
  402. $(call render_template,$(tpl_supervisor),src/$(PROJECT)_sup.erl)
  403. bootstrap-lib:
  404. ifneq ($(wildcard src/),)
  405. $(error Error: src/ directory already exists)
  406. endif
  407. $(call render_template,$(bs_Makefile),Makefile)
  408. @mkdir src/
  409. $(call render_template,$(bs_appsrc_lib),src/$(PROJECT).app.src)
  410. bootstrap-rel:
  411. ifneq ($(wildcard relx.config),)
  412. $(error Error: relx.config already exists)
  413. endif
  414. ifneq ($(wildcard rel/),)
  415. $(error Error: rel/ directory already exists)
  416. endif
  417. $(call render_template,$(bs_relx_config),relx.config)
  418. @mkdir rel/
  419. $(call render_template,$(bs_sys_config),rel/sys.config)
  420. $(call render_template,$(bs_vm_args),rel/vm.args)
  421. new:
  422. ifeq ($(wildcard src/),)
  423. $(error Error: src/ directory does not exist)
  424. endif
  425. ifndef t
  426. $(error Usage: make new t=TEMPLATE n=NAME)
  427. endif
  428. ifndef tpl_$(t)
  429. $(error Unknown template)
  430. endif
  431. ifndef n
  432. $(error Usage: make new t=TEMPLATE n=NAME)
  433. endif
  434. $(call render_template,$(tpl_$(t)),src/$(n).erl)
  435. list-templates:
  436. @echo Available templates: $(sort $(patsubst tpl_%,%,$(filter tpl_%,$(.VARIABLES))))
  437. # Copyright (c) 2013-2014, Loïc Hoguin <essen@ninenines.eu>
  438. # This file is part of erlang.mk and subject to the terms of the ISC License.
  439. .PHONY: build-ct-deps build-ct-suites tests-ct clean-ct distclean-ct
  440. # Configuration.
  441. CT_OPTS ?=
  442. ifneq ($(wildcard test/),)
  443. CT_SUITES ?= $(sort $(subst _SUITE.erl,,$(shell find test -type f -name \*_SUITE.erl -exec basename {} \;)))
  444. else
  445. CT_SUITES ?=
  446. endif
  447. TEST_ERLC_OPTS ?= +debug_info +warn_export_vars +warn_shadow_vars +warn_obsolete_guard
  448. TEST_ERLC_OPTS += -DTEST=1 -DEXTRA=1 +'{parse_transform, eunit_autoexport}'
  449. # Core targets.
  450. tests:: tests-ct
  451. clean:: clean-ct
  452. distclean:: distclean-ct
  453. help::
  454. @printf "%s\n" "" \
  455. "All your common_test suites have their associated targets." \
  456. "A suite named http_SUITE can be ran using the ct-http target."
  457. # Plugin-specific targets.
  458. ALL_TEST_DEPS_DIRS = $(addprefix $(DEPS_DIR)/,$(TEST_DEPS))
  459. CT_RUN = ct_run \
  460. -no_auto_compile \
  461. -noshell \
  462. -pa $(realpath ebin) $(DEPS_DIR)/*/ebin \
  463. -dir test \
  464. -logdir logs
  465. $(foreach dep,$(TEST_DEPS),$(eval $(call dep_target,$(dep))))
  466. build-ct-deps: $(ALL_TEST_DEPS_DIRS)
  467. @for dep in $(ALL_TEST_DEPS_DIRS) ; do $(MAKE) -C $$dep; done
  468. build-ct-suites: build-ct-deps
  469. $(gen_verbose) erlc -v $(TEST_ERLC_OPTS) -o test/ \
  470. $(wildcard test/*.erl test/*/*.erl) -pa ebin/
  471. tests-ct: ERLC_OPTS = $(TEST_ERLC_OPTS)
  472. tests-ct: clean deps app build-ct-suites
  473. @if [ -d "test" ] ; \
  474. then \
  475. mkdir -p logs/ ; \
  476. $(CT_RUN) -suite $(addsuffix _SUITE,$(CT_SUITES)) $(CT_OPTS) ; \
  477. fi
  478. $(gen_verbose) rm -f test/*.beam
  479. define ct_suite_target
  480. ct-$(1): ERLC_OPTS = $(TEST_ERLC_OPTS)
  481. ct-$(1): clean deps app build-ct-suites
  482. @if [ -d "test" ] ; \
  483. then \
  484. mkdir -p logs/ ; \
  485. $(CT_RUN) -suite $(addsuffix _SUITE,$(1)) $(CT_OPTS) ; \
  486. fi
  487. $(gen_verbose) rm -f test/*.beam
  488. endef
  489. $(foreach test,$(CT_SUITES),$(eval $(call ct_suite_target,$(test))))
  490. clean-ct:
  491. $(gen_verbose) rm -rf test/*.beam
  492. distclean-ct:
  493. $(gen_verbose) rm -rf logs/
  494. # Copyright (c) 2013-2014, Loïc Hoguin <essen@ninenines.eu>
  495. # This file is part of erlang.mk and subject to the terms of the ISC License.
  496. .PHONY: plt distclean-plt dialyze
  497. # Configuration.
  498. DIALYZER_PLT ?= $(CURDIR)/.$(PROJECT).plt
  499. export DIALYZER_PLT
  500. PLT_APPS ?=
  501. DIALYZER_OPTS ?= -Werror_handling -Wrace_conditions \
  502. -Wunmatched_returns # -Wunderspecs
  503. # Core targets.
  504. distclean:: distclean-plt
  505. help::
  506. @printf "%s\n" "" \
  507. "Dialyzer targets:" \
  508. " plt Build a PLT file for this project" \
  509. " dialyze Analyze the project using Dialyzer"
  510. # Plugin-specific targets.
  511. plt: deps app
  512. @dialyzer --build_plt --apps erts kernel stdlib $(PLT_APPS) $(ALL_DEPS_DIRS)
  513. distclean-plt:
  514. $(gen_verbose) rm -f $(DIALYZER_PLT)
  515. dialyze:
  516. @dialyzer --no_native --src -r src $(DIALYZER_OPTS)
  517. # Copyright (c) 2013-2014, Loïc Hoguin <essen@ninenines.eu>
  518. # This file is part of erlang.mk and subject to the terms of the ISC License.
  519. # Verbosity.
  520. dtl_verbose_0 = @echo " DTL " $(filter %.dtl,$(?F));
  521. dtl_verbose = $(dtl_verbose_$(V))
  522. # Core targets.
  523. define compile_erlydtl
  524. $(dtl_verbose) erl -noshell -pa ebin/ $(DEPS_DIR)/erlydtl/ebin/ -eval ' \
  525. Compile = fun(F) -> \
  526. Module = list_to_atom( \
  527. string:to_lower(filename:basename(F, ".dtl")) ++ "_dtl"), \
  528. erlydtl:compile(F, Module, [{out_dir, "ebin/"}]) \
  529. end, \
  530. _ = [Compile(F) || F <- string:tokens("$(1)", " ")], \
  531. init:stop()'
  532. endef
  533. ifneq ($(wildcard src/),)
  534. ebin/$(PROJECT).app:: $(shell find templates -type f -name \*.dtl 2>/dev/null)
  535. $(if $(strip $?),$(call compile_erlydtl,$?))
  536. endif
  537. # Copyright (c) 2013-2014, Loïc Hoguin <essen@ninenines.eu>
  538. # This file is part of erlang.mk and subject to the terms of the ISC License.
  539. .PHONY: distclean-edoc
  540. # Configuration.
  541. EDOC_OPTS ?=
  542. # Core targets.
  543. docs:: distclean-edoc
  544. $(gen_verbose) erl -noshell \
  545. -eval 'edoc:application($(PROJECT), ".", [$(EDOC_OPTS)]), init:stop().'
  546. distclean:: distclean-edoc
  547. # Plugin-specific targets.
  548. distclean-edoc:
  549. $(gen_verbose) rm -f doc/*.css doc/*.html doc/*.png doc/edoc-info
  550. # Copyright (c) 2013-2014, Loïc Hoguin <essen@ninenines.eu>
  551. # This file is part of erlang.mk and subject to the terms of the ISC License.
  552. .PHONY: distclean-rel
  553. # Configuration.
  554. RELX_CONFIG ?= $(CURDIR)/relx.config
  555. ifneq ($(wildcard $(RELX_CONFIG)),)
  556. RELX ?= $(CURDIR)/relx
  557. export RELX
  558. RELX_URL ?= https://github.com/erlware/relx/releases/download/v1.0.2/relx
  559. RELX_OPTS ?=
  560. RELX_OUTPUT_DIR ?= _rel
  561. ifeq ($(firstword $(RELX_OPTS)),-o)
  562. RELX_OUTPUT_DIR = $(word 2,$(RELX_OPTS))
  563. endif
  564. # Core targets.
  565. rel:: distclean-rel $(RELX)
  566. @$(RELX) -c $(RELX_CONFIG) $(RELX_OPTS)
  567. distclean:: distclean-rel distclean-relx
  568. # Plugin-specific targets.
  569. define relx_fetch
  570. $(call core_http_get,$(RELX),$(RELX_URL))
  571. chmod +x $(RELX)
  572. endef
  573. $(RELX):
  574. @$(call relx_fetch)
  575. distclean-rel:
  576. $(gen_verbose) rm -rf $(RELX_OUTPUT_DIR)
  577. distclean-relx:
  578. $(gen_verbose) rm -rf $(RELX)
  579. endif