erlang.mk 31 KB

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