erlang.mk 31 KB

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