erlang.mk 31 KB

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