erlang.mk 31 KB

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