erlang.mk 31 KB

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