erlang.mk 19 KB

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