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::
  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_CONFIG),$(ELVIS_CONFIG_URL))
  763. @$(call core_http_get,$(ELVIS),$(ELVIS_URL))
  764. @chmod +x $(ELVIS)
  765. elvis: $(ELVIS)
  766. @$(ELVIS) rock -c $(ELVIS_CONFIG) $(ELVIS_OPTS)
  767. distclean-elvis:
  768. $(gen_verbose) rm -rf $(ELVIS)
  769. # Copyright (c) 2013-2014, Loïc Hoguin <essen@ninenines.eu>
  770. # This file is part of erlang.mk and subject to the terms of the ISC License.
  771. # Configuration.
  772. DTL_FULL_PATH ?= 0
  773. # Verbosity.
  774. dtl_verbose_0 = @echo " DTL " $(filter %.dtl,$(?F));
  775. dtl_verbose = $(dtl_verbose_$(V))
  776. # Core targets.
  777. define compile_erlydtl
  778. $(dtl_verbose) $(ERL) -pa ebin/ $(DEPS_DIR)/erlydtl/ebin/ -eval ' \
  779. Compile = fun(F) -> \
  780. S = fun (1) -> re:replace(filename:rootname(string:sub_string(F, 11), ".dtl"), "/", "_", [{return, list}, global]); \
  781. (0) -> filename:basename(F, ".dtl") \
  782. end, \
  783. Module = list_to_atom(string:to_lower(S($(DTL_FULL_PATH))) ++ "_dtl"), \
  784. {ok, _} = erlydtl:compile(F, Module, [{out_dir, "ebin/"}, return_errors, {doc_root, "templates"}]) \
  785. end, \
  786. _ = [Compile(F) || F <- string:tokens("$(1)", " ")], \
  787. halt().'
  788. endef
  789. ifneq ($(wildcard src/),)
  790. ebin/$(PROJECT).app:: $(shell find templates -type f -name \*.dtl 2>/dev/null)
  791. $(if $(strip $?),$(call compile_erlydtl,$?))
  792. endif
  793. # Copyright (c) 2014 Dave Cottlehuber <dch@skunkwerks.at>
  794. # This file is part of erlang.mk and subject to the terms of the ISC License.
  795. .PHONY: distclean-escript escript
  796. # Configuration.
  797. ESCRIPT_NAME ?= $(PROJECT)
  798. ESCRIPT_COMMENT ?= This is an -*- erlang -*- file
  799. ESCRIPT_BEAMS ?= "ebin/*", "deps/*/ebin/*"
  800. ESCRIPT_SYS_CONFIG ?= "rel/sys.config"
  801. ESCRIPT_EMU_ARGS ?= -pa . \
  802. -sasl errlog_type error \
  803. -escript main $(ESCRIPT_NAME)
  804. ESCRIPT_SHEBANG ?= /usr/bin/env escript
  805. ESCRIPT_STATIC ?= "deps/*/priv/**", "priv/**"
  806. # Core targets.
  807. distclean:: distclean-escript
  808. help::
  809. @printf "%s\n" "" \
  810. "Escript targets:" \
  811. " escript Build an executable escript archive" \
  812. # Plugin-specific targets.
  813. # Based on https://github.com/synrc/mad/blob/master/src/mad_bundle.erl
  814. # Copyright (c) 2013 Maxim Sokhatsky, Synrc Research Center
  815. # Modified MIT License, https://github.com/synrc/mad/blob/master/LICENSE :
  816. # Software may only be used for the great good and the true happiness of all
  817. # sentient beings.
  818. define ESCRIPT_RAW
  819. 'Read = fun(F) -> {ok, B} = file:read_file(filename:absname(F)), B end,'\
  820. 'Files = fun(L) -> A = lists:concat([filelib:wildcard(X)||X<- L ]),'\
  821. ' [F || F <- A, not filelib:is_dir(F) ] end,'\
  822. 'Squash = fun(L) -> [{filename:basename(F), Read(F) } || F <- L ] end,'\
  823. 'Zip = fun(A, L) -> {ok,{_,Z}} = zip:create(A, L, [{compress,all},memory]), Z end,'\
  824. 'Ez = fun(Escript) ->'\
  825. ' Static = Files([$(ESCRIPT_STATIC)]),'\
  826. ' Beams = Squash(Files([$(ESCRIPT_BEAMS), $(ESCRIPT_SYS_CONFIG)])),'\
  827. ' Archive = Beams ++ [{ "static.gz", Zip("static.gz", Static)}],'\
  828. ' escript:create(Escript, [ $(ESCRIPT_OPTIONS)'\
  829. ' {archive, Archive, [memory]},'\
  830. ' {shebang, "$(ESCRIPT_SHEBANG)"},'\
  831. ' {comment, "$(ESCRIPT_COMMENT)"},'\
  832. ' {emu_args, " $(ESCRIPT_EMU_ARGS)"}'\
  833. ' ]),'\
  834. ' file:change_mode(Escript, 8#755)'\
  835. 'end,'\
  836. 'Ez("$(ESCRIPT_NAME)"),'\
  837. 'halt().'
  838. endef
  839. ESCRIPT_COMMAND = $(subst ' ',,$(ESCRIPT_RAW))
  840. escript:: distclean-escript deps app
  841. $(gen_verbose) $(ERL) -eval $(ESCRIPT_COMMAND)
  842. distclean-escript:
  843. $(gen_verbose) rm -f $(ESCRIPT_NAME)
  844. # Copyright (c) 2014, Enrique Fernandez <enrique.fernandez@erlang-solutions.com>
  845. # This file is contributed to erlang.mk and subject to the terms of the ISC License.
  846. .PHONY: help-eunit build-eunit eunit distclean-eunit
  847. # Configuration
  848. EUNIT_ERLC_OPTS ?= +debug_info +warn_export_vars +warn_shadow_vars +warn_obsolete_guard -DTEST=1 -DEXTRA=1
  849. EUNIT_DIR ?=
  850. EUNIT_DIRS = $(sort $(EUNIT_DIR) ebin)
  851. ifeq ($(strip $(EUNIT_DIR)),)
  852. TAGGED_EUNIT_TESTS = {dir,"ebin"}
  853. else
  854. # All modules in EUNIT_DIR
  855. EUNIT_DIR_MODS = $(notdir $(basename $(shell find $(EUNIT_DIR) -type f -name *.beam)))
  856. # All modules in 'ebin'
  857. EUNIT_EBIN_MODS = $(notdir $(basename $(shell find ebin -type f -name *.beam)))
  858. # Only those modules in EUNIT_DIR with no matching module in 'ebin'.
  859. # This is done to avoid some tests being executed twice.
  860. EUNIT_MODS = $(filter-out $(patsubst %,%_tests,$(EUNIT_EBIN_MODS)),$(EUNIT_DIR_MODS))
  861. TAGGED_EUNIT_TESTS = {dir,"ebin"} $(foreach mod,$(EUNIT_MODS),$(shell echo $(mod) | sed -e 's/\(.*\)/{module,\1}/g'))
  862. endif
  863. EUNIT_OPTS ?= verbose
  864. # Utility functions
  865. define str-join
  866. $(shell echo '$(strip $(1))' | sed -e "s/ /,/g")
  867. endef
  868. # Core targets.
  869. help:: help-eunit
  870. tests:: eunit
  871. clean:: clean-eunit
  872. # Plugin-specific targets.
  873. EUNIT_RUN = $(ERL) \
  874. -no_auto_compile \
  875. -pa $(realpath $(EUNIT_DIR)) $(DEPS_DIR)/*/ebin \
  876. -pz $(realpath ebin) \
  877. -eval 'case eunit:test([$(call str-join,$(TAGGED_EUNIT_TESTS))], [$(EUNIT_OPTS)]) of ok -> halt(0); error -> halt(1) end.'
  878. help-eunit:
  879. @printf "%s\n" "" \
  880. "EUnit targets:" \
  881. " eunit Run all the EUnit tests for this project"
  882. ifeq ($(strip $(EUNIT_DIR)),)
  883. build-eunit:
  884. else ifeq ($(strip $(EUNIT_DIR)),ebin)
  885. build-eunit:
  886. else
  887. build-eunit:
  888. $(gen_verbose) erlc -v $(EUNIT_ERLC_OPTS) -I include/ -o $(EUNIT_DIR) \
  889. $(wildcard $(EUNIT_DIR)/*.erl $(EUNIT_DIR)/*/*.erl) -pa ebin/
  890. endif
  891. eunit: ERLC_OPTS = $(EUNIT_ERLC_OPTS)
  892. eunit: clean deps app build-eunit
  893. $(gen_verbose) $(EUNIT_RUN)
  894. clean-eunit:
  895. $(gen_verbose) $(foreach dir,$(EUNIT_DIRS),rm -rf $(dir)/*.beam)
  896. # Copyright (c) 2013-2014, Loïc Hoguin <essen@ninenines.eu>
  897. # This file is part of erlang.mk and subject to the terms of the ISC License.
  898. .PHONY: relx-rel distclean-relx-rel distclean-relx
  899. # Configuration.
  900. RELX_CONFIG ?= $(CURDIR)/relx.config
  901. RELX ?= $(CURDIR)/relx
  902. export RELX
  903. RELX_URL ?= https://github.com/erlware/relx/releases/download/v1.1.0/relx
  904. RELX_OPTS ?=
  905. RELX_OUTPUT_DIR ?= _rel
  906. ifeq ($(firstword $(RELX_OPTS)),-o)
  907. RELX_OUTPUT_DIR = $(word 2,$(RELX_OPTS))
  908. else
  909. RELX_OPTS += -o $(RELX_OUTPUT_DIR)
  910. endif
  911. # Core targets.
  912. ifneq ($(wildcard $(RELX_CONFIG)),)
  913. rel:: distclean-relx-rel relx-rel
  914. endif
  915. distclean:: distclean-relx-rel distclean-relx
  916. # Plugin-specific targets.
  917. define relx_fetch
  918. $(call core_http_get,$(RELX),$(RELX_URL))
  919. chmod +x $(RELX)
  920. endef
  921. $(RELX):
  922. @$(call relx_fetch)
  923. relx-rel: $(RELX)
  924. @$(RELX) -c $(RELX_CONFIG) $(RELX_OPTS)
  925. distclean-relx-rel:
  926. $(gen_verbose) rm -rf $(RELX_OUTPUT_DIR)
  927. distclean-relx:
  928. $(gen_verbose) rm -rf $(RELX)
  929. # Copyright (c) 2014, M Robert Martin <rob@version2beta.com>
  930. # This file is contributed to erlang.mk and subject to the terms of the ISC License.
  931. .PHONY: shell
  932. # Configuration.
  933. SHELL_PATH ?= -pa $(CURDIR)/ebin $(DEPS_DIR)/*/ebin
  934. SHELL_OPTS ?=
  935. ALL_SHELL_DEPS_DIRS = $(addprefix $(DEPS_DIR)/,$(SHELL_DEPS))
  936. # Core targets
  937. help::
  938. @printf "%s\n" "" \
  939. "Shell targets:" \
  940. " shell Run an erlang shell with SHELL_OPTS or reasonable default"
  941. # Plugin-specific targets.
  942. $(foreach dep,$(SHELL_DEPS),$(eval $(call dep_target,$(dep))))
  943. build-shell-deps: $(ALL_SHELL_DEPS_DIRS)
  944. @for dep in $(ALL_SHELL_DEPS_DIRS) ; do $(MAKE) -C $$dep ; done
  945. shell: build-shell-deps
  946. $(gen_verbose) erl $(SHELL_PATH) $(SHELL_OPTS)