erlang.mk 31 KB

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