erlang.mk 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164
  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 erlang-mk
  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 [-jNUM] [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. "Parallel execution is supported through the -j Make flag."
  51. # Core functions.
  52. ifeq ($(shell which wget 2>/dev/null | wc -l), 1)
  53. define core_http_get
  54. wget --no-check-certificate -O $(1) $(2)|| rm $(1)
  55. endef
  56. else
  57. define core_http_get
  58. erl -noshell -eval 'ssl:start(), inets:start(), case httpc:request(get, {"$(2)", []}, [{autoredirect, true}], []) of {ok, {{_, 200, _}, _, Body}} -> case file:write_file("$(1)", Body) of ok -> ok; {error, R1} -> halt(R1) end; {error, R2} -> halt(R2) end, halt(0).'
  59. endef
  60. endif
  61. # Automated update.
  62. ERLANG_MK_BUILD_CONFIG ?= build.config
  63. ERLANG_MK_BUILD_DIR ?= .erlang.mk.build
  64. erlang-mk:
  65. git clone https://github.com/ninenines/erlang.mk $(ERLANG_MK_BUILD_DIR)
  66. if [ -f $(ERLANG_MK_BUILD_CONFIG) ]; then cp $(ERLANG_MK_BUILD_CONFIG) $(ERLANG_MK_BUILD_DIR); fi
  67. cd $(ERLANG_MK_BUILD_DIR) && make
  68. cp $(ERLANG_MK_BUILD_DIR)/erlang.mk ./erlang.mk
  69. rm -rf $(ERLANG_MK_BUILD_DIR)
  70. # Copyright (c) 2013-2014, Loïc Hoguin <essen@ninenines.eu>
  71. # This file is part of erlang.mk and subject to the terms of the ISC License.
  72. .PHONY: distclean-deps distclean-pkg pkg-list pkg-search
  73. # Configuration.
  74. DEPS_DIR ?= $(CURDIR)/deps
  75. export DEPS_DIR
  76. REBAR_DEPS_DIR = $(DEPS_DIR)
  77. export REBAR_DEPS_DIR
  78. ALL_DEPS_DIRS = $(addprefix $(DEPS_DIR)/,$(DEPS))
  79. ifeq ($(filter $(DEPS_DIR),$(subst :, ,$(ERL_LIBS))),)
  80. ifeq ($(ERL_LIBS),)
  81. ERL_LIBS = $(DEPS_DIR)
  82. else
  83. ERL_LIBS := $(ERL_LIBS):$(DEPS_DIR)
  84. endif
  85. endif
  86. export ERL_LIBS
  87. PKG_FILE2 ?= $(CURDIR)/.erlang.mk.packages.v2
  88. export PKG_FILE2
  89. PKG_FILE_URL ?= https://raw.githubusercontent.com/ninenines/erlang.mk/master/packages.v2.tsv
  90. # Core targets.
  91. deps:: $(ALL_DEPS_DIRS)
  92. @for dep in $(ALL_DEPS_DIRS) ; do \
  93. if [ -f $$dep/GNUmakefile ] || [ -f $$dep/makefile ] || [ -f $$dep/Makefile ] ; then \
  94. $(MAKE) -C $$dep ; \
  95. else \
  96. echo "include $(CURDIR)/erlang.mk" | ERLC_OPTS=+debug_info $(MAKE) -f - -C $$dep ; \
  97. fi ; \
  98. done
  99. distclean:: distclean-deps distclean-pkg
  100. # Deps related targets.
  101. define dep_fetch
  102. if [ "$$$$VS" = "git" ]; then \
  103. git clone -n -- $$$$REPO $(DEPS_DIR)/$(1); \
  104. cd $(DEPS_DIR)/$(1) && git checkout -q $$$$COMMIT; \
  105. elif [ "$$$$VS" = "hg" ]; then \
  106. hg clone -U $$$$REPO $(DEPS_DIR)/$(1); \
  107. cd $(DEPS_DIR)/$(1) && hg update -q $$$$COMMIT; \
  108. elif [ "$$$$VS" = "svn" ]; then \
  109. svn checkout $$$$REPO $(DEPS_DIR)/$(1); \
  110. else \
  111. echo "Unknown or invalid dependency: $(1). Please consult the erlang.mk README for instructions." >&2; \
  112. exit 78; \
  113. fi
  114. endef
  115. define dep_target
  116. $(DEPS_DIR)/$(1):
  117. @mkdir -p $(DEPS_DIR)
  118. ifeq (,$(dep_$(1)))
  119. @if [ ! -f $(PKG_FILE2) ]; then $(call core_http_get,$(PKG_FILE2),$(PKG_FILE_URL)); fi
  120. @DEPPKG=$$$$(awk 'BEGIN { FS = "\t" }; $$$$1 == "$(1)" { print $$$$2 " " $$$$3 " " $$$$4 }' $(PKG_FILE2);); \
  121. VS=$$$$(echo $$$$DEPPKG | cut -d " " -f1); \
  122. REPO=$$$$(echo $$$$DEPPKG | cut -d " " -f2); \
  123. COMMIT=$$$$(echo $$$$DEPPKG | cut -d " " -f3); \
  124. $(call dep_fetch,$(1))
  125. else
  126. @VS=$(word 1,$(dep_$(1))); \
  127. REPO=$(word 2,$(dep_$(1))); \
  128. COMMIT=$(word 3,$(dep_$(1))); \
  129. $(call dep_fetch,$(1))
  130. endif
  131. endef
  132. $(foreach dep,$(DEPS),$(eval $(call dep_target,$(dep))))
  133. distclean-deps:
  134. $(gen_verbose) rm -rf $(DEPS_DIR)
  135. # Packages related targets.
  136. $(PKG_FILE2):
  137. @$(call core_http_get,$(PKG_FILE2),$(PKG_FILE_URL))
  138. pkg-list: $(PKG_FILE2)
  139. @cat $(PKG_FILE2) | awk 'BEGIN { FS = "\t" }; { print \
  140. "Name:\t\t" $$1 "\n" \
  141. "Repository:\t" $$3 "\n" \
  142. "Website:\t" $$5 "\n" \
  143. "Description:\t" $$6 "\n" }'
  144. ifdef q
  145. pkg-search: $(PKG_FILE2)
  146. @cat $(PKG_FILE2) | grep -i ${q} | awk 'BEGIN { FS = "\t" }; { print \
  147. "Name:\t\t" $$1 "\n" \
  148. "Repository:\t" $$3 "\n" \
  149. "Website:\t" $$5 "\n" \
  150. "Description:\t" $$6 "\n" }'
  151. else
  152. pkg-search:
  153. $(error Usage: make pkg-search q=STRING)
  154. endif
  155. ifeq ($(PKG_FILE2),$(CURDIR)/.erlang.mk.packages.v2)
  156. distclean-pkg:
  157. $(gen_verbose) rm -f $(PKG_FILE2)
  158. endif
  159. help::
  160. @printf "%s\n" "" \
  161. "Package-related targets:" \
  162. " pkg-list List all known packages" \
  163. " pkg-search q=STRING Search for STRING in the package index"
  164. # Copyright (c) 2013-2014, Loïc Hoguin <essen@ninenines.eu>
  165. # This file is part of erlang.mk and subject to the terms of the ISC License.
  166. .PHONY: clean-app
  167. # Configuration.
  168. ERLC_OPTS ?= -Werror +debug_info +warn_export_vars +warn_shadow_vars \
  169. +warn_obsolete_guard # +bin_opt_info +warn_export_all +warn_missing_spec
  170. COMPILE_FIRST ?=
  171. COMPILE_FIRST_PATHS = $(addprefix src/,$(addsuffix .erl,$(COMPILE_FIRST)))
  172. ERLC_EXCLUDE ?=
  173. ERLC_EXCLUDE_PATHS = $(addprefix src/,$(addsuffix .erl,$(ERLC_EXCLUDE)))
  174. ERLC_MIB_OPTS ?=
  175. COMPILE_MIB_FIRST ?=
  176. COMPILE_MIB_FIRST_PATHS = $(addprefix mibs/,$(addsuffix .mib,$(COMPILE_MIB_FIRST)))
  177. # Verbosity.
  178. appsrc_verbose_0 = @echo " APP " $(PROJECT).app.src;
  179. appsrc_verbose = $(appsrc_verbose_$(V))
  180. erlc_verbose_0 = @echo " ERLC " $(filter-out $(patsubst %,%.erl,$(ERLC_EXCLUDE)),\
  181. $(filter %.erl %.core,$(?F)));
  182. erlc_verbose = $(erlc_verbose_$(V))
  183. xyrl_verbose_0 = @echo " XYRL " $(filter %.xrl %.yrl,$(?F));
  184. xyrl_verbose = $(xyrl_verbose_$(V))
  185. mib_verbose_0 = @echo " MIB " $(filter %.bin %.mib,$(?F));
  186. mib_verbose = $(mib_verbose_$(V))
  187. # Core targets.
  188. app:: erlc-include ebin/$(PROJECT).app
  189. $(eval MODULES := $(shell find ebin -type f -name \*.beam \
  190. | sed "s/ebin\//'/;s/\.beam/',/" | sed '$$s/.$$//'))
  191. @if [ -z "$$(grep -E '^[^%]*{modules,' src/$(PROJECT).app.src)" ]; then \
  192. echo "Empty modules entry not found in $(PROJECT).app.src. Please consult the erlang.mk README for instructions." >&2; \
  193. exit 1; \
  194. fi
  195. $(eval GITDESCRIBE := $(shell git describe --dirty --abbrev=7 --tags --always --first-parent 2>/dev/null || true))
  196. $(appsrc_verbose) cat src/$(PROJECT).app.src \
  197. | sed "s/{modules,[[:space:]]*\[\]}/{modules, \[$(MODULES)\]}/" \
  198. | sed "s/{id,[[:space:]]*\"git\"}/{id, \"$(GITDESCRIBE)\"}/" \
  199. > ebin/$(PROJECT).app
  200. define compile_erl
  201. $(erlc_verbose) erlc -v $(ERLC_OPTS) -o ebin/ \
  202. -pa ebin/ -I include/ $(filter-out $(ERLC_EXCLUDE_PATHS),\
  203. $(COMPILE_FIRST_PATHS) $(1))
  204. endef
  205. define compile_xyrl
  206. $(xyrl_verbose) erlc -v -o ebin/ $(1)
  207. $(xyrl_verbose) erlc $(ERLC_OPTS) -o ebin/ ebin/*.erl
  208. @rm ebin/*.erl
  209. endef
  210. define compile_mib
  211. $(mib_verbose) erlc -v $(ERLC_MIB_OPTS) -o priv/mibs/ \
  212. -I priv/mibs/ $(COMPILE_MIB_FIRST_PATHS) $(1)
  213. $(mib_verbose) erlc -o include/ -- priv/mibs/*.bin
  214. endef
  215. ifneq ($(wildcard src/),)
  216. ebin/$(PROJECT).app::
  217. @mkdir -p ebin/
  218. ifneq ($(wildcard mibs/),)
  219. ebin/$(PROJECT).app:: $(shell find mibs -type f -name \*.mib)
  220. @mkdir -p priv/mibs/ include
  221. $(if $(strip $?),$(call compile_mib,$?))
  222. endif
  223. ebin/$(PROJECT).app:: $(shell find src -type f -name \*.erl) \
  224. $(shell find src -type f -name \*.core) | deps
  225. $(if $(strip $?),$(call compile_erl,$?))
  226. ebin/$(PROJECT).app:: $(shell find src -type f -name \*.xrl) \
  227. $(shell find src -type f -name \*.yrl) | deps
  228. $(if $(strip $?),$(call compile_xyrl,$?))
  229. endif
  230. clean:: clean-app
  231. # Extra targets.
  232. erlc-include:
  233. -@if [ -d ebin/ ]; then \
  234. find include/ src/ -type f -name \*.hrl -newer ebin -exec touch $(shell find src/ -type f -name "*.erl") \; 2>/dev/null || printf ''; \
  235. fi
  236. clean-app:
  237. $(gen_verbose) rm -rf ebin/ priv/mibs/ \
  238. $(addprefix include/,$(addsuffix .hrl,$(notdir $(basename $(wildcard mibs/*.mib)))))
  239. # Copyright (c) 2014, Loïc Hoguin <essen@ninenines.eu>
  240. # This file is part of erlang.mk and subject to the terms of the ISC License.
  241. .PHONY: bootstrap bootstrap-lib bootstrap-rel new list-templates
  242. # Core targets.
  243. help::
  244. @printf "%s\n" "" \
  245. "Bootstrap targets:" \
  246. " bootstrap Generate a skeleton of an OTP application" \
  247. " bootstrap-lib Generate a skeleton of an OTP library" \
  248. " bootstrap-rel Generate the files needed to build a release" \
  249. " new t=TPL n=NAME Generate a module NAME based on the template TPL" \
  250. " list-templates List available templates"
  251. # Bootstrap templates.
  252. bs_appsrc = "{application, $(PROJECT), [" \
  253. " {description, \"\"}," \
  254. " {vsn, \"0.1.0\"}," \
  255. " {id, \"git\"}," \
  256. " {modules, []}," \
  257. " {registered, []}," \
  258. " {applications, [" \
  259. " kernel," \
  260. " stdlib" \
  261. " ]}," \
  262. " {mod, {$(PROJECT)_app, []}}," \
  263. " {env, []}" \
  264. "]}."
  265. bs_appsrc_lib = "{application, $(PROJECT), [" \
  266. " {description, \"\"}," \
  267. " {vsn, \"0.1.0\"}," \
  268. " {id, \"git\"}," \
  269. " {modules, []}," \
  270. " {registered, []}," \
  271. " {applications, [" \
  272. " kernel," \
  273. " stdlib" \
  274. " ]}" \
  275. "]}."
  276. bs_Makefile = "PROJECT = $(PROJECT)" \
  277. "include erlang.mk"
  278. bs_app = "-module($(PROJECT)_app)." \
  279. "-behaviour(application)." \
  280. "" \
  281. "-export([start/2])." \
  282. "-export([stop/1])." \
  283. "" \
  284. "start(_Type, _Args) ->" \
  285. " $(PROJECT)_sup:start_link()." \
  286. "" \
  287. "stop(_State) ->" \
  288. " ok."
  289. bs_relx_config = "{release, {$(PROJECT)_release, \"1\"}, [$(PROJECT)]}." \
  290. "{extended_start_script, true}." \
  291. "{sys_config, \"rel/sys.config\"}." \
  292. "{vm_args, \"rel/vm.args\"}."
  293. bs_sys_config = "[" \
  294. "]."
  295. bs_vm_args = "-name $(PROJECT)@127.0.0.1" \
  296. "-setcookie $(PROJECT)" \
  297. "-heart"
  298. # Normal templates.
  299. tpl_supervisor = "-module($(n))." \
  300. "-behaviour(supervisor)." \
  301. "" \
  302. "-export([start_link/0])." \
  303. "-export([init/1])." \
  304. "" \
  305. "start_link() ->" \
  306. " supervisor:start_link({local, ?MODULE}, ?MODULE, [])." \
  307. "" \
  308. "init([]) ->" \
  309. " Procs = []," \
  310. " {ok, {{one_for_one, 1, 5}, Procs}}."
  311. tpl_gen_server = "-module($(n))." \
  312. "-behaviour(gen_server)." \
  313. "" \
  314. "%% API." \
  315. "-export([start_link/0])." \
  316. "" \
  317. "%% gen_server." \
  318. "-export([init/1])." \
  319. "-export([handle_call/3])." \
  320. "-export([handle_cast/2])." \
  321. "-export([handle_info/2])." \
  322. "-export([terminate/2])." \
  323. "-export([code_change/3])." \
  324. "" \
  325. "-record(state, {" \
  326. "})." \
  327. "" \
  328. "%% API." \
  329. "" \
  330. "-spec start_link() -> {ok, pid()}." \
  331. "start_link() ->" \
  332. " gen_server:start_link(?MODULE, [], [])." \
  333. "" \
  334. "%% gen_server." \
  335. "" \
  336. "init([]) ->" \
  337. " {ok, \#state{}}." \
  338. "" \
  339. "handle_call(_Request, _From, State) ->" \
  340. " {reply, ignored, State}." \
  341. "" \
  342. "handle_cast(_Msg, State) ->" \
  343. " {noreply, State}." \
  344. "" \
  345. "handle_info(_Info, State) ->" \
  346. " {noreply, State}." \
  347. "" \
  348. "terminate(_Reason, _State) ->" \
  349. " ok." \
  350. "" \
  351. "code_change(_OldVsn, State, _Extra) ->" \
  352. " {ok, State}."
  353. tpl_gen_fsm = "-module($(n))." \
  354. "-behaviour(gen_fsm)." \
  355. "" \
  356. "%% API." \
  357. "-export([start_link/0])." \
  358. "" \
  359. "%% gen_fsm." \
  360. "-export([init/1])." \
  361. "-export([state_name/2])." \
  362. "-export([handle_event/3])." \
  363. "-export([state_name/3])." \
  364. "-export([handle_sync_event/4])." \
  365. "-export([handle_info/3])." \
  366. "-export([terminate/3])." \
  367. "-export([code_change/4])." \
  368. "" \
  369. "-record(state, {" \
  370. "})." \
  371. "" \
  372. "%% API." \
  373. "" \
  374. "-spec start_link() -> {ok, pid()}." \
  375. "start_link() ->" \
  376. " gen_fsm:start_link(?MODULE, [], [])." \
  377. "" \
  378. "%% gen_fsm." \
  379. "" \
  380. "init([]) ->" \
  381. " {ok, state_name, \#state{}}." \
  382. "" \
  383. "state_name(_Event, StateData) ->" \
  384. " {next_state, state_name, StateData}." \
  385. "" \
  386. "handle_event(_Event, StateName, StateData) ->" \
  387. " {next_state, StateName, StateData}." \
  388. "" \
  389. "state_name(_Event, _From, StateData) ->" \
  390. " {reply, ignored, state_name, StateData}." \
  391. "" \
  392. "handle_sync_event(_Event, _From, StateName, StateData) ->" \
  393. " {reply, ignored, StateName, StateData}." \
  394. "" \
  395. "handle_info(_Info, StateName, StateData) ->" \
  396. " {next_state, StateName, StateData}." \
  397. "" \
  398. "terminate(_Reason, _StateName, _StateData) ->" \
  399. " ok." \
  400. "" \
  401. "code_change(_OldVsn, StateName, StateData, _Extra) ->" \
  402. " {ok, StateName, StateData}."
  403. tpl_cowboy_http = "-module($(n))." \
  404. "-behaviour(cowboy_http_handler)." \
  405. "" \
  406. "-export([init/3])." \
  407. "-export([handle/2])." \
  408. "-export([terminate/3])." \
  409. "" \
  410. "-record(state, {" \
  411. "})." \
  412. "" \
  413. "init(_, Req, _Opts) ->" \
  414. " {ok, Req, \#state{}}." \
  415. "" \
  416. "handle(Req, State=\#state{}) ->" \
  417. " {ok, Req2} = cowboy_req:reply(200, Req)," \
  418. " {ok, Req2, State}." \
  419. "" \
  420. "terminate(_Reason, _Req, _State) ->" \
  421. " ok."
  422. tpl_cowboy_loop = "-module($(n))." \
  423. "-behaviour(cowboy_loop_handler)." \
  424. "" \
  425. "-export([init/3])." \
  426. "-export([info/3])." \
  427. "-export([terminate/3])." \
  428. "" \
  429. "-record(state, {" \
  430. "})." \
  431. "" \
  432. "init(_, Req, _Opts) ->" \
  433. " {loop, Req, \#state{}, 5000, hibernate}." \
  434. "" \
  435. "info(_Info, Req, State) ->" \
  436. " {loop, Req, State, hibernate}." \
  437. "" \
  438. "terminate(_Reason, _Req, _State) ->" \
  439. " ok."
  440. tpl_cowboy_rest = "-module($(n))." \
  441. "" \
  442. "-export([init/3])." \
  443. "-export([content_types_provided/2])." \
  444. "-export([get_html/2])." \
  445. "" \
  446. "init(_, _Req, _Opts) ->" \
  447. " {upgrade, protocol, cowboy_rest}." \
  448. "" \
  449. "content_types_provided(Req, State) ->" \
  450. " {[{{<<\"text\">>, <<\"html\">>, '*'}, get_html}], Req, State}." \
  451. "" \
  452. "get_html(Req, State) ->" \
  453. " {<<\"<html><body>This is REST!</body></html>\">>, Req, State}."
  454. tpl_cowboy_ws = "-module($(n))." \
  455. "-behaviour(cowboy_websocket_handler)." \
  456. "" \
  457. "-export([init/3])." \
  458. "-export([websocket_init/3])." \
  459. "-export([websocket_handle/3])." \
  460. "-export([websocket_info/3])." \
  461. "-export([websocket_terminate/3])." \
  462. "" \
  463. "-record(state, {" \
  464. "})." \
  465. "" \
  466. "init(_, _, _) ->" \
  467. " {upgrade, protocol, cowboy_websocket}." \
  468. "" \
  469. "websocket_init(_, Req, _Opts) ->" \
  470. " Req2 = cowboy_req:compact(Req)," \
  471. " {ok, Req2, \#state{}}." \
  472. "" \
  473. "websocket_handle({text, Data}, Req, State) ->" \
  474. " {reply, {text, Data}, Req, State};" \
  475. "websocket_handle({binary, Data}, Req, State) ->" \
  476. " {reply, {binary, Data}, Req, State};" \
  477. "websocket_handle(_Frame, Req, State) ->" \
  478. " {ok, Req, State}." \
  479. "" \
  480. "websocket_info(_Info, Req, State) ->" \
  481. " {ok, Req, State}." \
  482. "" \
  483. "websocket_terminate(_Reason, _Req, _State) ->" \
  484. " ok."
  485. tpl_ranch_protocol = "-module($(n))." \
  486. "-behaviour(ranch_protocol)." \
  487. "" \
  488. "-export([start_link/4])." \
  489. "-export([init/4])." \
  490. "" \
  491. "-type opts() :: []." \
  492. "-export_type([opts/0])." \
  493. "" \
  494. "-record(state, {" \
  495. " socket :: inet:socket()," \
  496. " transport :: module()" \
  497. "})." \
  498. "" \
  499. "start_link(Ref, Socket, Transport, Opts) ->" \
  500. " Pid = spawn_link(?MODULE, init, [Ref, Socket, Transport, Opts])," \
  501. " {ok, Pid}." \
  502. "" \
  503. "-spec init(ranch:ref(), inet:socket(), module(), opts()) -> ok." \
  504. "init(Ref, Socket, Transport, _Opts) ->" \
  505. " ok = ranch:accept_ack(Ref)," \
  506. " loop(\#state{socket=Socket, transport=Transport})." \
  507. "" \
  508. "loop(State) ->" \
  509. " loop(State)."
  510. # Plugin-specific targets.
  511. bootstrap:
  512. ifneq ($(wildcard src/),)
  513. $(error Error: src/ directory already exists)
  514. endif
  515. @printf "%s\n" $(bs_Makefile) > Makefile
  516. @mkdir src/
  517. @printf "%s\n" $(bs_appsrc) > src/$(PROJECT).app.src
  518. @printf "%s\n" $(bs_app) > src/$(PROJECT)_app.erl
  519. $(eval n := $(PROJECT)_sup)
  520. @printf "%s\n" $(tpl_supervisor) > src/$(PROJECT)_sup.erl
  521. bootstrap-lib:
  522. ifneq ($(wildcard src/),)
  523. $(error Error: src/ directory already exists)
  524. endif
  525. @printf "%s\n" $(bs_Makefile) > Makefile
  526. @mkdir src/
  527. @printf "%s\n" $(bs_appsrc_lib) > src/$(PROJECT).app.src
  528. bootstrap-rel:
  529. ifneq ($(wildcard relx.config),)
  530. $(error Error: relx.config already exists)
  531. endif
  532. ifneq ($(wildcard rel/),)
  533. $(error Error: rel/ directory already exists)
  534. endif
  535. @printf "%s\n" $(bs_relx_config) > relx.config
  536. @mkdir rel/
  537. @printf "%s\n" $(bs_sys_config) > rel/sys.config
  538. @printf "%s\n" $(bs_vm_args) > rel/vm.args
  539. new:
  540. ifeq ($(wildcard src/),)
  541. $(error Error: src/ directory does not exist)
  542. endif
  543. ifndef t
  544. $(error Usage: make new t=TEMPLATE n=NAME)
  545. endif
  546. ifndef tpl_$(t)
  547. $(error Unknown template)
  548. endif
  549. ifndef n
  550. $(error Usage: make new t=TEMPLATE n=NAME)
  551. endif
  552. @printf "%s\n" $(tpl_$(t)) > src/$(n).erl
  553. list-templates:
  554. @echo Available templates: $(sort $(patsubst tpl_%,%,$(filter tpl_%,$(.VARIABLES))))
  555. # Copyright (c) 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: clean-c_src distclean-c_src-env
  558. # todo
  559. # Configuration.
  560. C_SRC_DIR = $(CURDIR)/c_src
  561. C_SRC_ENV ?= $(C_SRC_DIR)/env.mk
  562. C_SRC_OUTPUT ?= $(CURDIR)/priv/$(PROJECT).so
  563. # System type and C compiler/flags.
  564. UNAME_SYS := $(shell uname -s)
  565. ifeq ($(UNAME_SYS), Darwin)
  566. CC ?= cc
  567. CFLAGS ?= -O3 -std=c99 -arch x86_64 -finline-functions -Wall -Wmissing-prototypes
  568. CXXFLAGS ?= -O3 -arch x86_64 -finline-functions -Wall
  569. LDFLAGS ?= -arch x86_64 -flat_namespace -undefined suppress
  570. else ifeq ($(UNAME_SYS), FreeBSD)
  571. CC ?= cc
  572. CFLAGS ?= -O3 -std=c99 -finline-functions -Wall -Wmissing-prototypes
  573. CXXFLAGS ?= -O3 -finline-functions -Wall
  574. else ifeq ($(UNAME_SYS), Linux)
  575. CC ?= gcc
  576. CFLAGS ?= -O3 -std=c99 -finline-functions -Wall -Wmissing-prototypes
  577. CXXFLAGS ?= -O3 -finline-functions -Wall
  578. endif
  579. CFLAGS += -fPIC -I $(ERTS_INCLUDE_DIR) -I $(ERL_INTERFACE_INCLUDE_DIR)
  580. CXXFLAGS += -fPIC -I $(ERTS_INCLUDE_DIR) -I $(ERL_INTERFACE_INCLUDE_DIR)
  581. LDLIBS += -L $(ERL_INTERFACE_LIB_DIR) -lerl_interface -lei
  582. LDFLAGS += -shared
  583. # Verbosity.
  584. c_verbose_0 = @echo " C " $(?F);
  585. c_verbose = $(c_verbose_$(V))
  586. cpp_verbose_0 = @echo " CPP " $(?F);
  587. cpp_verbose = $(cpp_verbose_$(V))
  588. link_verbose_0 = @echo " LD " $(@F);
  589. link_verbose = $(link_verbose_$(V))
  590. # Targets.
  591. ifeq ($(wildcard $(C_SRC_DIR)),)
  592. else ifneq ($(wildcard $(C_SRC_DIR)/Makefile),)
  593. app::
  594. $(MAKE) -C $(C_SRC_DIR)
  595. clean::
  596. $(MAKE) -C $(C_SRC_DIR) clean
  597. else
  598. SOURCES := $(shell find $(C_SRC_DIR) -type f \( -name "*.c" -o -name "*.C" -o -name "*.cc" -o -name "*.cpp" \))
  599. OBJECTS = $(addsuffix .o, $(basename $(SOURCES)))
  600. COMPILE_C = $(c_verbose) $(CC) $(CFLAGS) $(CPPFLAGS) -c
  601. COMPILE_CPP = $(cpp_verbose) $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c
  602. app:: $(C_SRC_ENV) $(C_SRC_OUTPUT)
  603. $(C_SRC_OUTPUT): $(OBJECTS)
  604. @mkdir -p priv/
  605. $(link_verbose) $(CC) $(OBJECTS) $(LDFLAGS) $(LDLIBS) -o $(C_SRC_OUTPUT)
  606. %.o: %.c
  607. $(COMPILE_C) $(OUTPUT_OPTION) $<
  608. %.o: %.cc
  609. $(COMPILE_CPP) $(OUTPUT_OPTION) $<
  610. %.o: %.C
  611. $(COMPILE_CPP) $(OUTPUT_OPTION) $<
  612. %.o: %.cpp
  613. $(COMPILE_CPP) $(OUTPUT_OPTION) $<
  614. $(C_SRC_ENV):
  615. @erl -noshell -noinput -eval "file:write_file(\"$(C_SRC_ENV)\", \
  616. io_lib:format( \
  617. \"ERTS_INCLUDE_DIR ?= ~s/erts-~s/include/~n\" \
  618. \"ERL_INTERFACE_INCLUDE_DIR ?= ~s~n\" \
  619. \"ERL_INTERFACE_LIB_DIR ?= ~s~n\", \
  620. [code:root_dir(), erlang:system_info(version), \
  621. code:lib_dir(erl_interface, include), \
  622. code:lib_dir(erl_interface, lib)])), \
  623. erlang:halt()."
  624. clean:: clean-c_src
  625. clean-c_src:
  626. $(gen_verbose) rm -f $(C_SRC_OUTPUT) $(OBJECTS)
  627. distclean:: distclean-c_src-env
  628. distclean-c_src-env:
  629. $(gen_verbose) rm -f $(C_SRC_ENV)
  630. -include $(C_SRC_ENV)
  631. endif
  632. # Copyright (c) 2013-2014, Loïc Hoguin <essen@ninenines.eu>
  633. # This file is part of erlang.mk and subject to the terms of the ISC License.
  634. .PHONY: build-ct-deps build-ct-suites tests-ct clean-ct distclean-ct
  635. # Configuration.
  636. CT_OPTS ?=
  637. ifneq ($(wildcard test/),)
  638. CT_SUITES ?= $(sort $(subst _SUITE.erl,,$(shell find test -type f -name \*_SUITE.erl -exec basename {} \;)))
  639. else
  640. CT_SUITES ?=
  641. endif
  642. TEST_ERLC_OPTS ?= +debug_info +warn_export_vars +warn_shadow_vars +warn_obsolete_guard
  643. TEST_ERLC_OPTS += -DTEST=1 -DEXTRA=1 +'{parse_transform, eunit_autoexport}'
  644. # Core targets.
  645. tests:: tests-ct
  646. clean:: clean-ct
  647. distclean:: distclean-ct
  648. help::
  649. @printf "%s\n" "" \
  650. "All your common_test suites have their associated targets." \
  651. "A suite named http_SUITE can be ran using the ct-http target."
  652. # Plugin-specific targets.
  653. ALL_TEST_DEPS_DIRS = $(addprefix $(DEPS_DIR)/,$(TEST_DEPS))
  654. CT_RUN = ct_run \
  655. -no_auto_compile \
  656. -noshell \
  657. -pa $(realpath ebin) $(DEPS_DIR)/*/ebin \
  658. -dir test \
  659. -logdir logs
  660. $(foreach dep,$(TEST_DEPS),$(eval $(call dep_target,$(dep))))
  661. build-ct-deps: $(ALL_TEST_DEPS_DIRS)
  662. @for dep in $(ALL_TEST_DEPS_DIRS) ; do $(MAKE) -C $$dep; done
  663. build-ct-suites: build-ct-deps
  664. $(gen_verbose) erlc -v $(TEST_ERLC_OPTS) -I include/ -o test/ \
  665. $(wildcard test/*.erl test/*/*.erl) -pa ebin/
  666. tests-ct: ERLC_OPTS = $(TEST_ERLC_OPTS)
  667. tests-ct: clean deps app build-ct-suites
  668. @if [ -d "test" ] ; \
  669. then \
  670. mkdir -p logs/ ; \
  671. $(CT_RUN) -suite $(addsuffix _SUITE,$(CT_SUITES)) $(CT_OPTS) ; \
  672. fi
  673. $(gen_verbose) rm -f test/*.beam
  674. define ct_suite_target
  675. ct-$(1): ERLC_OPTS = $(TEST_ERLC_OPTS)
  676. ct-$(1): clean deps app build-ct-suites
  677. @if [ -d "test" ] ; \
  678. then \
  679. mkdir -p logs/ ; \
  680. $(CT_RUN) -suite $(addsuffix _SUITE,$(1)) $(CT_OPTS) ; \
  681. fi
  682. $(gen_verbose) rm -f test/*.beam
  683. endef
  684. $(foreach test,$(CT_SUITES),$(eval $(call ct_suite_target,$(test))))
  685. clean-ct:
  686. $(gen_verbose) rm -rf test/*.beam
  687. distclean-ct:
  688. $(gen_verbose) rm -rf logs/
  689. # Copyright (c) 2013-2014, Loïc Hoguin <essen@ninenines.eu>
  690. # This file is part of erlang.mk and subject to the terms of the ISC License.
  691. .PHONY: plt distclean-plt dialyze
  692. # Configuration.
  693. DIALYZER_PLT ?= $(CURDIR)/.$(PROJECT).plt
  694. export DIALYZER_PLT
  695. PLT_APPS ?=
  696. DIALYZER_DIRS ?= --src -r src
  697. DIALYZER_OPTS ?= -Werror_handling -Wrace_conditions \
  698. -Wunmatched_returns # -Wunderspecs
  699. # Core targets.
  700. distclean:: distclean-plt
  701. help::
  702. @printf "%s\n" "" \
  703. "Dialyzer targets:" \
  704. " plt Build a PLT file for this project" \
  705. " dialyze Analyze the project using Dialyzer"
  706. # Plugin-specific targets.
  707. $(DIALYZER_PLT): deps app
  708. @dialyzer --build_plt --apps erts kernel stdlib $(PLT_APPS) $(ALL_DEPS_DIRS)
  709. plt: $(DIALYZER_PLT)
  710. distclean-plt:
  711. $(gen_verbose) rm -f $(DIALYZER_PLT)
  712. ifneq ($(wildcard $(DIALYZER_PLT)),)
  713. dialyze:
  714. else
  715. dialyze: $(DIALYZER_PLT)
  716. endif
  717. @dialyzer --no_native $(DIALYZER_DIRS) $(DIALYZER_OPTS)
  718. # Copyright (c) 2013-2014, Loïc Hoguin <essen@ninenines.eu>
  719. # This file is part of erlang.mk and subject to the terms of the ISC License.
  720. .PHONY: distclean-edoc
  721. # Configuration.
  722. EDOC_OPTS ?=
  723. # Core targets.
  724. docs:: distclean-edoc
  725. $(gen_verbose) erl -noshell \
  726. -eval 'edoc:application($(PROJECT), ".", [$(EDOC_OPTS)]), init:stop().'
  727. distclean:: distclean-edoc
  728. # Plugin-specific targets.
  729. distclean-edoc:
  730. $(gen_verbose) rm -f doc/*.css doc/*.html doc/*.png doc/edoc-info
  731. # Copyright (c) 2014, Juan Facorro <juan@inaka.net>
  732. # This file is part of erlang.mk and subject to the terms of the ISC License.
  733. .PHONY: elvis distclean-elvis
  734. # Configuration.
  735. ELVIS_CONFIG ?= $(CURDIR)/elvis.config
  736. ELVIS ?= $(CURDIR)/elvis
  737. export ELVIS
  738. ELVIS_URL ?= https://github.com/inaka/elvis/releases/download/0.2.3/elvis
  739. ELVIS_CONFIG_URL ?= https://github.com/inaka/elvis/releases/download/0.2.3/elvis.config
  740. ELVIS_OPTS ?=
  741. # Core targets.
  742. help::
  743. @printf "%s\n" "" \
  744. "Elvis targets:" \
  745. " elvis Run Elvis using the local elvis.config or download the default otherwise"
  746. ifneq ($(wildcard $(ELVIS_CONFIG)),)
  747. rel:: distclean-elvis
  748. endif
  749. distclean:: distclean-elvis
  750. # Plugin-specific targets.
  751. $(ELVIS):
  752. @$(call core_http_get,$(ELVIS_CONFIG),$(ELVIS_CONFIG_URL))
  753. @$(call core_http_get,$(ELVIS),$(ELVIS_URL))
  754. @chmod +x $(ELVIS)
  755. elvis: $(ELVIS)
  756. @$(ELVIS) rock -c $(ELVIS_CONFIG) $(ELVIS_OPTS)
  757. distclean-elvis:
  758. $(gen_verbose) rm -rf $(ELVIS)
  759. # Copyright (c) 2013-2014, Loïc Hoguin <essen@ninenines.eu>
  760. # This file is part of erlang.mk and subject to the terms of the ISC License.
  761. # Configuration.
  762. DTL_FULL_PATH ?= 0
  763. # Verbosity.
  764. dtl_verbose_0 = @echo " DTL " $(filter %.dtl,$(?F));
  765. dtl_verbose = $(dtl_verbose_$(V))
  766. # Core targets.
  767. define compile_erlydtl
  768. $(dtl_verbose) erl -noshell -pa ebin/ $(DEPS_DIR)/erlydtl/ebin/ -eval ' \
  769. Compile = fun(F) -> \
  770. S = fun (1) -> re:replace(filename:rootname(string:sub_string(F, 11), ".dtl"), "/", "_", [{return, list}, global]); \
  771. (0) -> filename:basename(F, ".dtl") \
  772. end, \
  773. Module = list_to_atom(string:to_lower(S($(DTL_FULL_PATH))) ++ "_dtl"), \
  774. {ok, _} = erlydtl:compile(F, Module, [{out_dir, "ebin/"}, return_errors, {doc_root, "templates"}]) \
  775. end, \
  776. _ = [Compile(F) || F <- string:tokens("$(1)", " ")], \
  777. init:stop()'
  778. endef
  779. ifneq ($(wildcard src/),)
  780. ebin/$(PROJECT).app:: $(shell find templates -type f -name \*.dtl 2>/dev/null)
  781. $(if $(strip $?),$(call compile_erlydtl,$?))
  782. endif
  783. # Copyright (c) 2014 Dave Cottlehuber <dch@skunkwerks.at>
  784. # This file is part of erlang.mk and subject to the terms of the ISC License.
  785. .PHONY: distclean-escript escript
  786. # Configuration.
  787. ESCRIPT_NAME ?= $(PROJECT)
  788. ESCRIPT_COMMENT ?= This is an -*- erlang -*- file
  789. ESCRIPT_BEAMS ?= "ebin/*", "deps/*/ebin/*"
  790. ESCRIPT_SYS_CONFIG ?= "rel/sys.config"
  791. ESCRIPT_EMU_ARGS ?= -pa . \
  792. -noshell -noinput \
  793. -sasl errlog_type error \
  794. -escript main $(ESCRIPT_NAME)
  795. ESCRIPT_SHEBANG ?= /usr/bin/env escript
  796. ESCRIPT_STATIC ?= "deps/*/priv/**", "priv/**"
  797. # Core targets.
  798. distclean:: distclean-escript
  799. help::
  800. @printf "%s\n" "" \
  801. "Escript targets:" \
  802. " escript Build an executable escript archive" \
  803. # Plugin-specific targets.
  804. # Based on https://github.com/synrc/mad/blob/master/src/mad_bundle.erl
  805. # Copyright (c) 2013 Maxim Sokhatsky, Synrc Research Center
  806. # Modified MIT License, https://github.com/synrc/mad/blob/master/LICENSE :
  807. # Software may only be used for the great good and the true happiness of all
  808. # sentient beings.
  809. define ESCRIPT_RAW
  810. 'Read = fun(F) -> {ok, B} = file:read_file(filename:absname(F)), B end,'\
  811. 'Files = fun(L) -> A = lists:concat([filelib:wildcard(X)||X<- L ]),'\
  812. ' [F || F <- A, not filelib:is_dir(F) ] end,'\
  813. 'Squash = fun(L) -> [{filename:basename(F), Read(F) } || F <- L ] end,'\
  814. 'Zip = fun(A, L) -> {ok,{_,Z}} = zip:create(A, L, [{compress,all},memory]), Z end,'\
  815. 'Ez = fun(Escript) ->'\
  816. ' Static = Files([$(ESCRIPT_STATIC)]),'\
  817. ' Beams = Squash(Files([$(ESCRIPT_BEAMS), $(ESCRIPT_SYS_CONFIG)])),'\
  818. ' Archive = Beams ++ [{ "static.gz", Zip("static.gz", Static)}],'\
  819. ' escript:create(Escript, [ $(ESCRIPT_OPTIONS)'\
  820. ' {archive, Archive, [memory]},'\
  821. ' {shebang, "$(ESCRIPT_SHEBANG)"},'\
  822. ' {comment, "$(ESCRIPT_COMMENT)"},'\
  823. ' {emu_args, " $(ESCRIPT_EMU_ARGS)"}'\
  824. ' ]),'\
  825. ' file:change_mode(Escript, 8#755)'\
  826. 'end,'\
  827. 'Ez("$(ESCRIPT_NAME)").'
  828. endef
  829. ESCRIPT_COMMAND = $(subst ' ',,$(ESCRIPT_RAW))
  830. escript:: distclean-escript deps app
  831. $(gen_verbose) erl -noshell -eval $(ESCRIPT_COMMAND) -s init stop
  832. distclean-escript:
  833. $(gen_verbose) rm -f $(ESCRIPT_NAME)
  834. # Copyright (c) 2014, Enrique Fernandez <enrique.fernandez@erlang-solutions.com>
  835. # This file is contributed to erlang.mk and subject to the terms of the ISC License.
  836. .PHONY: help-eunit build-eunit eunit distclean-eunit
  837. # Configuration
  838. EUNIT_ERLC_OPTS ?= +debug_info +warn_export_vars +warn_shadow_vars +warn_obsolete_guard -DTEST=1 -DEXTRA=1
  839. EUNIT_DIR ?=
  840. EUNIT_DIRS = $(sort $(EUNIT_DIR) ebin)
  841. ifeq ($(strip $(EUNIT_DIR)),)
  842. TAGGED_EUNIT_TESTS = {dir,"ebin"}
  843. else
  844. # All modules in EUNIT_DIR
  845. EUNIT_DIR_MODS = $(notdir $(basename $(shell find $(EUNIT_DIR) -type f -name *.beam)))
  846. # All modules in 'ebin'
  847. EUNIT_EBIN_MODS = $(notdir $(basename $(shell find ebin -type f -name *.beam)))
  848. # Only those modules in EUNIT_DIR with no matching module in 'ebin'.
  849. # This is done to avoid some tests being executed twice.
  850. EUNIT_MODS = $(filter-out $(patsubst %,%_tests,$(EUNIT_EBIN_MODS)),$(EUNIT_DIR_MODS))
  851. TAGGED_EUNIT_TESTS = {dir,"ebin"} $(foreach mod,$(EUNIT_MODS),$(shell echo $(mod) | sed -e 's/\(.*\)/{module,\1}/g'))
  852. endif
  853. EUNIT_OPTS ?= verbose
  854. # Utility functions
  855. define str-join
  856. $(shell echo '$(strip $(1))' | sed -e "s/ /,/g")
  857. endef
  858. # Core targets.
  859. help:: help-eunit
  860. tests:: eunit
  861. clean:: clean-eunit
  862. # Plugin-specific targets.
  863. EUNIT_RUN = erl \
  864. -no_auto_compile \
  865. -noshell \
  866. -pa $(realpath $(EUNIT_DIR)) $(DEPS_DIR)/*/ebin \
  867. -pz $(realpath ebin) \
  868. -eval 'case eunit:test([$(call str-join,$(TAGGED_EUNIT_TESTS))], [$(EUNIT_OPTS)]) of ok -> erlang:halt(0); error -> erlang:halt(1) end.'
  869. help-eunit:
  870. @printf "%s\n" "" \
  871. "EUnit targets:" \
  872. " eunit Run all the EUnit tests for this project"
  873. ifeq ($(strip $(EUNIT_DIR)),)
  874. build-eunit:
  875. else ifeq ($(strip $(EUNIT_DIR)),ebin)
  876. build-eunit:
  877. else
  878. build-eunit:
  879. $(gen_verbose) erlc -v $(EUNIT_ERLC_OPTS) -I include/ -o $(EUNIT_DIR) \
  880. $(wildcard $(EUNIT_DIR)/*.erl $(EUNIT_DIR)/*/*.erl) -pa ebin/
  881. endif
  882. eunit: ERLC_OPTS = $(EUNIT_ERLC_OPTS)
  883. eunit: clean deps app build-eunit
  884. $(gen_verbose) $(EUNIT_RUN)
  885. clean-eunit:
  886. $(gen_verbose) $(foreach dir,$(EUNIT_DIRS),rm -rf $(dir)/*.beam)
  887. # Copyright (c) 2013-2014, Loïc Hoguin <essen@ninenines.eu>
  888. # This file is part of erlang.mk and subject to the terms of the ISC License.
  889. .PHONY: relx-rel distclean-relx-rel distclean-relx
  890. # Configuration.
  891. RELX_CONFIG ?= $(CURDIR)/relx.config
  892. RELX ?= $(CURDIR)/relx
  893. export RELX
  894. RELX_URL ?= https://github.com/erlware/relx/releases/download/v1.1.0/relx
  895. RELX_OPTS ?=
  896. RELX_OUTPUT_DIR ?= _rel
  897. ifeq ($(firstword $(RELX_OPTS)),-o)
  898. RELX_OUTPUT_DIR = $(word 2,$(RELX_OPTS))
  899. else
  900. RELX_OPTS += -o $(RELX_OUTPUT_DIR)
  901. endif
  902. # Core targets.
  903. ifneq ($(wildcard $(RELX_CONFIG)),)
  904. rel:: distclean-relx-rel relx-rel
  905. endif
  906. distclean:: distclean-relx-rel distclean-relx
  907. # Plugin-specific targets.
  908. define relx_fetch
  909. $(call core_http_get,$(RELX),$(RELX_URL))
  910. chmod +x $(RELX)
  911. endef
  912. $(RELX):
  913. @$(call relx_fetch)
  914. relx-rel: $(RELX) | deps app
  915. @$(RELX) -c $(RELX_CONFIG) $(RELX_OPTS)
  916. distclean-relx-rel:
  917. $(gen_verbose) rm -rf $(RELX_OUTPUT_DIR)
  918. distclean-relx:
  919. $(gen_verbose) rm -rf $(RELX)
  920. # Copyright (c) 2014, M Robert Martin <rob@version2beta.com>
  921. # This file is contributed to erlang.mk and subject to the terms of the ISC License.
  922. .PHONY: shell
  923. # Configuration.
  924. SHELL_PATH ?= -pa $(CURDIR)/ebin $(DEPS_DIR)/*/ebin
  925. SHELL_OPTS ?=
  926. ALL_SHELL_DEPS_DIRS = $(addprefix $(DEPS_DIR)/,$(SHELL_DEPS))
  927. # Core targets
  928. help::
  929. @printf "%s\n" "" \
  930. "Shell targets:" \
  931. " shell Run an erlang shell with SHELL_OPTS or reasonable default"
  932. # Plugin-specific targets.
  933. $(foreach dep,$(SHELL_DEPS),$(eval $(call dep_target,$(dep))))
  934. build-shell-deps: $(ALL_SHELL_DEPS_DIRS)
  935. @for dep in $(ALL_SHELL_DEPS_DIRS) ; do $(MAKE) -C $$dep ; done
  936. shell: build-shell-deps
  937. $(gen_verbose) erl $(SHELL_PATH) $(SHELL_OPTS)