erlang.mk 57 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186
  1. # Copyright (c) 2013-2015, 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 install-docs tests check clean distclean help erlang-mk
  15. ERLANG_MK_VERSION = 1.2.0-511-g56f9388
  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. # Temporary files directory.
  24. ERLANG_MK_TMP ?= $(CURDIR)/.erlang.mk
  25. export ERLANG_MK_TMP
  26. # "erl" command.
  27. ERL = erl +A0 -noinput -boot start_clean
  28. # Platform detection.
  29. # @todo Add Windows/Cygwin detection eventually.
  30. ifeq ($(PLATFORM),)
  31. UNAME_S := $(shell uname -s)
  32. ifeq ($(UNAME_S),Linux)
  33. PLATFORM = linux
  34. else ifeq ($(UNAME_S),Darwin)
  35. PLATFORM = darwin
  36. else ifeq ($(UNAME_S),SunOS)
  37. PLATFORM = solaris
  38. else ifeq ($(UNAME_S),GNU)
  39. PLATFORM = gnu
  40. else ifeq ($(UNAME_S),FreeBSD)
  41. PLATFORM = freebsd
  42. else ifeq ($(UNAME_S),NetBSD)
  43. PLATFORM = netbsd
  44. else ifeq ($(UNAME_S),OpenBSD)
  45. PLATFORM = openbsd
  46. else
  47. $(error Unable to detect platform. Please open a ticket with the output of uname -a.)
  48. endif
  49. export PLATFORM
  50. endif
  51. # Core targets.
  52. ifneq ($(words $(MAKECMDGOALS)),1)
  53. .NOTPARALLEL:
  54. endif
  55. all:: deps
  56. @$(MAKE) --no-print-directory app
  57. @$(MAKE) --no-print-directory rel
  58. # Noop to avoid a Make warning when there's nothing to do.
  59. rel::
  60. @echo -n
  61. check:: clean app tests
  62. clean:: clean-crashdump
  63. clean-crashdump:
  64. ifneq ($(wildcard erl_crash.dump),)
  65. $(gen_verbose) rm -f erl_crash.dump
  66. endif
  67. distclean:: clean
  68. help::
  69. @printf "%s\n" \
  70. "erlang.mk (version $(ERLANG_MK_VERSION)) is distributed under the terms of the ISC License." \
  71. "Copyright (c) 2013-2014 Loïc Hoguin <essen@ninenines.eu>" \
  72. "" \
  73. "Usage: [V=1] $(MAKE) [-jNUM] [target]" \
  74. "" \
  75. "Core targets:" \
  76. " all Run deps, app and rel targets in that order" \
  77. " deps Fetch dependencies (if needed) and compile them" \
  78. " app Compile the project" \
  79. " rel Build a release for this project, if applicable" \
  80. " docs Build the documentation for this project" \
  81. " install-docs Install the man pages for this project" \
  82. " tests Run the tests for this project" \
  83. " check Compile and run all tests and analysis for this project" \
  84. " clean Delete temporary and output files from most targets" \
  85. " distclean Delete all temporary and output files" \
  86. " help Display this help and exit" \
  87. "" \
  88. "The target clean only removes files that are commonly removed." \
  89. "Dependencies and releases are left untouched." \
  90. "" \
  91. "Setting V=1 when calling $(MAKE) enables verbose mode." \
  92. "Parallel execution is supported through the -j $(MAKE) flag."
  93. # Core functions.
  94. define newline
  95. endef
  96. # Adding erlang.mk to make Erlang scripts who call init:get_plain_arguments() happy.
  97. define erlang
  98. $(ERL) -pa $(ERLANG_MK_TMP)/ebin -eval "$(subst $(newline),,$(subst ",\",$(1)))" -- erlang.mk
  99. endef
  100. ifeq ($(shell which wget 2>/dev/null | wc -l), 1)
  101. define core_http_get
  102. wget --no-check-certificate -O $(1) $(2)|| rm $(1)
  103. endef
  104. else
  105. define core_http_get.erl
  106. ssl:start(),
  107. inets:start(),
  108. case httpc:request(get, {"$(2)", []}, [{autoredirect, true}], []) of
  109. {ok, {{_, 200, _}, _, Body}} ->
  110. case file:write_file("$(1)", Body) of
  111. ok -> ok;
  112. {error, R1} -> halt(R1)
  113. end;
  114. {error, R2} ->
  115. halt(R2)
  116. end,
  117. halt(0).
  118. endef
  119. define core_http_get
  120. $(call erlang,$(call core_http_get.erl,$(1),$(2)))
  121. endef
  122. endif
  123. # Automated update.
  124. ERLANG_MK_BUILD_CONFIG ?= build.config
  125. ERLANG_MK_BUILD_DIR ?= .erlang.mk.build
  126. erlang-mk:
  127. git clone https://github.com/ninenines/erlang.mk $(ERLANG_MK_BUILD_DIR)
  128. if [ -f $(ERLANG_MK_BUILD_CONFIG) ]; then cp $(ERLANG_MK_BUILD_CONFIG) $(ERLANG_MK_BUILD_DIR); fi
  129. cd $(ERLANG_MK_BUILD_DIR) && $(MAKE)
  130. cp $(ERLANG_MK_BUILD_DIR)/erlang.mk ./erlang.mk
  131. rm -rf $(ERLANG_MK_BUILD_DIR)
  132. # Copyright (c) 2013-2015, Loïc Hoguin <essen@ninenines.eu>
  133. # This file is part of erlang.mk and subject to the terms of the ISC License.
  134. .PHONY: distclean-deps distclean-pkg pkg-list pkg-search
  135. # Configuration.
  136. IGNORE_DEPS ?=
  137. DEPS_DIR ?= $(CURDIR)/deps
  138. export DEPS_DIR
  139. REBAR_DEPS_DIR = $(DEPS_DIR)
  140. export REBAR_DEPS_DIR
  141. ALL_DEPS_DIRS = $(addprefix $(DEPS_DIR)/,$(filter-out $(IGNORE_DEPS),$(DEPS)))
  142. ifeq ($(filter $(DEPS_DIR),$(subst :, ,$(ERL_LIBS))),)
  143. ifeq ($(ERL_LIBS),)
  144. ERL_LIBS = $(DEPS_DIR)
  145. else
  146. ERL_LIBS := $(ERL_LIBS):$(DEPS_DIR)
  147. endif
  148. endif
  149. export ERL_LIBS
  150. PKG_FILE2 ?= $(CURDIR)/.erlang.mk.packages.v2
  151. export PKG_FILE2
  152. PKG_FILE_URL ?= https://raw.githubusercontent.com/ninenines/erlang.mk/master/packages.v2.tsv
  153. # Verbosity.
  154. dep_verbose_0 = @echo " DEP " $(1);
  155. dep_verbose = $(dep_verbose_$(V))
  156. # Core targets.
  157. ifneq ($(SKIP_DEPS),)
  158. deps::
  159. else
  160. deps:: $(ALL_DEPS_DIRS)
  161. @for dep in $(ALL_DEPS_DIRS) ; do \
  162. if [ -f $$dep/GNUmakefile ] || [ -f $$dep/makefile ] || [ -f $$dep/Makefile ] ; then \
  163. $(MAKE) -C $$dep IS_DEP=1 || exit $$? ; \
  164. else \
  165. echo "ERROR: No Makefile to build dependency $$dep." ; \
  166. exit 1 ; \
  167. fi ; \
  168. done
  169. endif
  170. distclean:: distclean-deps distclean-pkg
  171. # Deps related targets.
  172. # @todo rename GNUmakefile and makefile into Makefile first, if they exist
  173. # While Makefile file could be GNUmakefile or makefile,
  174. # in practice only Makefile is needed so far.
  175. define dep_autopatch
  176. if [ -f $(DEPS_DIR)/$(1)/Makefile ]; then \
  177. if [ 0 != `grep -c "include ../\w*\.mk" $(DEPS_DIR)/$(1)/Makefile` ]; then \
  178. $(call dep_autopatch2,$(1)); \
  179. elif [ 0 != `grep -ci rebar $(DEPS_DIR)/$(1)/Makefile` ]; then \
  180. $(call dep_autopatch2,$(1)); \
  181. elif [ 0 != `find $(DEPS_DIR)/$(1)/ -type f -name \*.mk -not -name erlang.mk | xargs grep -ci rebar` ]; then \
  182. $(call dep_autopatch2,$(1)); \
  183. else \
  184. $(call dep_autopatch_erlang_mk,$(1)); \
  185. fi \
  186. else \
  187. if [ ! -d $(DEPS_DIR)/$(1)/src/ ]; then \
  188. $(call dep_autopatch_noop,$(1)); \
  189. else \
  190. $(call dep_autopatch2,$(1)); \
  191. fi \
  192. fi
  193. endef
  194. define dep_autopatch2
  195. if [ -f $(DEPS_DIR)/$(1)/rebar.config -o -f $(DEPS_DIR)/$(1)/rebar.config.script ]; then \
  196. $(call dep_autopatch_rebar_utils); \
  197. $(call dep_autopatch_rebar,$(1)); \
  198. else \
  199. $(call dep_autopatch_gen,$(1)); \
  200. fi
  201. endef
  202. define dep_autopatch_noop
  203. printf "noop:\n" > $(DEPS_DIR)/$(1)/Makefile
  204. endef
  205. # Overwrite erlang.mk with the current file by default.
  206. ifeq ($(NO_AUTOPATCH_ERLANG_MK),)
  207. define dep_autopatch_erlang_mk
  208. rm -f $(DEPS_DIR)/$(1)/erlang.mk; \
  209. cd $(DEPS_DIR)/$(1)/ && ln -s ../../erlang.mk; \
  210. $(call erlang,$(call dep_autopatch_appsrc.erl,$(1)))
  211. endef
  212. else
  213. define dep_autopatch_erlang_mk
  214. $(call erlang,$(call dep_autopatch_appsrc.erl,$(1)))
  215. endef
  216. endif
  217. define dep_autopatch_gen
  218. printf "%s\n" \
  219. "ERLC_OPTS = +debug_info" \
  220. "include ../../erlang.mk" > $(DEPS_DIR)/$(1)/Makefile; \
  221. $(call erlang,$(call dep_autopatch_appsrc.erl,$(1)))
  222. endef
  223. define dep_autopatch_rebar_utils
  224. mkdir -p $(ERLANG_MK_TMP)/ebin; \
  225. if [ ! -f $(ERLANG_MK_TMP)/rebar.hrl ]; then \
  226. $(call core_http_get,$(ERLANG_MK_TMP)/rebar.hrl,https://raw.githubusercontent.com/rebar/rebar/791db716b5a3a7671e0b351f95ddf24b848ee173/include/rebar.hrl); \
  227. fi; \
  228. if [ ! -f $(ERLANG_MK_TMP)/rebar_utils.erl ]; then \
  229. $(call core_http_get,$(ERLANG_MK_TMP)/rebar_utils.erl,https://raw.githubusercontent.com/rebar/rebar/791db716b5a3a7671e0b351f95ddf24b848ee173/src/rebar_utils.erl); \
  230. fi; \
  231. if [ ! -f $(ERLANG_MK_TMP)/ebin/rebar_utils.beam ]; then \
  232. erlc -o $(ERLANG_MK_TMP)/ebin $(ERLANG_MK_TMP)/rebar_utils.erl; \
  233. fi; \
  234. if [ ! -f $(ERLANG_MK_TMP)/rebar_log.erl ]; then \
  235. $(call core_http_get,$(ERLANG_MK_TMP)/rebar_log.erl,https://raw.githubusercontent.com/rebar/rebar/791db716b5a3a7671e0b351f95ddf24b848ee173/src/rebar_log.erl); \
  236. fi; \
  237. if [ ! -f $(ERLANG_MK_TMP)/ebin/rebar_log.beam ]; then \
  238. erlc -o $(ERLANG_MK_TMP)/ebin $(ERLANG_MK_TMP)/rebar_log.erl; \
  239. fi
  240. endef
  241. define dep_autopatch_rebar
  242. if [ -f $(DEPS_DIR)/$(1)/Makefile ]; then \
  243. mv $(DEPS_DIR)/$(1)/Makefile $(DEPS_DIR)/$(1)/Makefile.orig.mk; \
  244. fi; \
  245. $(call erlang,$(call dep_autopatch_rebar.erl,$(1))); \
  246. $(call erlang,$(call dep_autopatch_appsrc.erl,$(1)))
  247. endef
  248. define dep_autopatch_rebar.erl
  249. application:set_env(rebar, log_level, debug),
  250. Conf1 = case file:consult("$(DEPS_DIR)/$(1)/rebar.config") of
  251. {ok, Conf0} -> Conf0;
  252. _ -> []
  253. end,
  254. {Conf, OsEnv} = fun() ->
  255. case filelib:is_file("$(DEPS_DIR)/$(1)/rebar.config.script") of
  256. false -> {Conf1, []};
  257. true ->
  258. Bindings0 = erl_eval:new_bindings(),
  259. Bindings1 = erl_eval:add_binding('CONFIG', Conf1, Bindings0),
  260. Bindings = erl_eval:add_binding('SCRIPT', "$(DEPS_DIR)/$(1)/rebar.config.script", Bindings1),
  261. Before = os:getenv(),
  262. {ok, Conf2} = file:script("$(DEPS_DIR)/$(1)/rebar.config.script", Bindings),
  263. {Conf2, lists:foldl(fun(E, Acc) -> lists:delete(E, Acc) end, os:getenv(), Before)}
  264. end
  265. end(),
  266. Write = fun (Text) ->
  267. file:write_file("$(DEPS_DIR)/$(1)/Makefile", Text, [append])
  268. end,
  269. Escape = fun (Text) ->
  270. re:replace(Text, "\\\\$$$$", "\$$$$$$$$", [global, {return, list}])
  271. end,
  272. Write("IGNORE_DEPS = edown eper eunit_formatters meck node_package "
  273. "rebar_lock_deps_plugin rebar_vsn_plugin reltool_util\n"),
  274. Write("C_SRC_DIR = /path/do/not/exist\n"),
  275. Write("DRV_CFLAGS = -fPIC\nexport DRV_CFLAGS\n"),
  276. Write(["ERLANG_ARCH = ", rebar_utils:wordsize(), "\nexport ERLANG_ARCH\n"]),
  277. fun() ->
  278. Write("ERLC_OPTS = +debug_info\n"),
  279. case lists:keyfind(erl_opts, 1, Conf) of
  280. false -> ok;
  281. {_, ErlOpts} ->
  282. lists:foreach(fun
  283. ({d, D}) ->
  284. Write("ERLC_OPTS += -D" ++ atom_to_list(D) ++ "=1\n");
  285. ({platform_define, Regex, D}) ->
  286. case rebar_utils:is_arch(Regex) of
  287. true -> Write("ERLC_OPTS += -D" ++ atom_to_list(D) ++ "=1\n");
  288. false -> ok
  289. end;
  290. ({parse_transform, PT}) ->
  291. Write("ERLC_OPTS += +'{parse_transform, " ++ atom_to_list(PT) ++ "}'\n");
  292. (_) -> ok
  293. end, ErlOpts)
  294. end,
  295. Write("\n")
  296. end(),
  297. fun() ->
  298. File = case lists:keyfind(deps, 1, Conf) of
  299. false -> [];
  300. {_, Deps} ->
  301. [begin case case Dep of
  302. {N, S} when is_tuple(S) -> {N, S};
  303. {N, _, S} -> {N, S};
  304. {N, _, S, _} -> {N, S};
  305. _ -> false
  306. end of
  307. false -> ok;
  308. {Name, Source} ->
  309. {Method, Repo, Commit} = case Source of
  310. {git, R} -> {git, R, master};
  311. {M, R, {branch, C}} -> {M, R, C};
  312. {M, R, {tag, C}} -> {M, R, C};
  313. {M, R, C} -> {M, R, C}
  314. end,
  315. Write(io_lib:format("DEPS += ~s\ndep_~s = ~s ~s ~s~n", [Name, Name, Method, Repo, Commit]))
  316. end end || Dep <- Deps]
  317. end
  318. end(),
  319. fun() ->
  320. First = case lists:keyfind(erl_first_files, 1, Conf) of false -> []; {_, Files} ->
  321. Names = [[" ", begin "lre." ++ Elif = lists:reverse(F), lists:reverse(Elif) end]
  322. || "src/" ++ F <- Files],
  323. Write(io_lib:format("COMPILE_FIRST +=~s\n", [Names]))
  324. end
  325. end(),
  326. FindFirst = fun(F, Fd) ->
  327. case io:parse_erl_form(Fd, undefined) of
  328. {ok, {attribute, _,compile, {parse_transform, PT}}, _} ->
  329. [PT, F(F, Fd)];
  330. {ok, {attribute, _, include, Hrl}, _} ->
  331. case file:open("$(DEPS_DIR)/$(1)/include/" ++ Hrl, [read]) of
  332. {ok, HrlFd} -> [F(F, HrlFd), F(F, Fd)];
  333. _ ->
  334. case file:open("$(DEPS_DIR)/$(1)/src/" ++ Hrl, [read]) of
  335. {ok, HrlFd} -> [F(F, HrlFd), F(F, Fd)];
  336. _ -> [F(F, Fd)]
  337. end
  338. end;
  339. {ok, {attribute, _, include_lib, "$(1)/include/" ++ Hrl}, _} ->
  340. {ok, HrlFd} = file:open("$(DEPS_DIR)/$(1)/include/" ++ Hrl, [read]),
  341. [F(F, HrlFd), F(F, Fd)];
  342. {ok, {attribute, _, import, {Imp, _}}, _} ->
  343. case file:open("$(DEPS_DIR)/$(1)/src/" ++ atom_to_list(Imp) ++ ".erl", [read]) of
  344. {ok, ImpFd} -> [Imp, F(F, ImpFd), F(F, Fd)];
  345. _ -> [F(F, Fd)]
  346. end;
  347. {eof, _} ->
  348. file:close(Fd),
  349. [];
  350. _ ->
  351. F(F, Fd)
  352. end
  353. end,
  354. fun() ->
  355. ErlFiles = filelib:wildcard("$(DEPS_DIR)/$(1)/src/*.erl"),
  356. First0 = lists:usort(lists:flatten([begin
  357. {ok, Fd} = file:open(F, [read]),
  358. FindFirst(FindFirst, Fd)
  359. end || F <- ErlFiles])),
  360. First = lists:flatten([begin
  361. {ok, Fd} = file:open("$(DEPS_DIR)/$(1)/src/" ++ atom_to_list(M) ++ ".erl", [read]),
  362. FindFirst(FindFirst, Fd)
  363. end || M <- First0, lists:member("$(DEPS_DIR)/$(1)/src/" ++ atom_to_list(M) ++ ".erl", ErlFiles)]) ++ First0,
  364. Write(["COMPILE_FIRST +=", [[" ", atom_to_list(M)] || M <- First,
  365. lists:member("$(DEPS_DIR)/$(1)/src/" ++ atom_to_list(M) ++ ".erl", ErlFiles)], "\n"])
  366. end(),
  367. Write("\n\nrebar_dep: preprocess pre-deps deps pre-app app\n"),
  368. Write("\npreprocess::\n"),
  369. Write("\npre-deps::\n"),
  370. Write("\npre-app::\n"),
  371. PatchHook = fun(Cmd) ->
  372. case Cmd of
  373. "make -C" ++ _ -> Escape(Cmd);
  374. "gmake -C" ++ _ -> Escape(Cmd);
  375. "make " ++ Cmd1 -> "make -f Makefile.orig.mk " ++ Escape(Cmd1);
  376. "gmake " ++ Cmd1 -> "gmake -f Makefile.orig.mk " ++ Escape(Cmd1);
  377. _ -> Escape(Cmd)
  378. end
  379. end,
  380. fun() ->
  381. case lists:keyfind(pre_hooks, 1, Conf) of
  382. false -> ok;
  383. {_, Hooks} ->
  384. [case H of
  385. {'get-deps', Cmd} ->
  386. Write("\npre-deps::\n\t" ++ PatchHook(Cmd) ++ "\n");
  387. {compile, Cmd} ->
  388. Write("\npre-app::\n\t" ++ PatchHook(Cmd) ++ "\n");
  389. {Regex, compile, Cmd} ->
  390. case rebar_utils:is_arch(Regex) of
  391. true -> Write("\npre-app::\n\t" ++ PatchHook(Cmd) ++ "\n");
  392. false -> ok
  393. end;
  394. _ -> ok
  395. end || H <- Hooks]
  396. end
  397. end(),
  398. ShellToMk = fun(V) ->
  399. re:replace(V, "(\\\\$$$$)(\\\\w*)", "\\\\1(\\\\2)", [{return, list}, global])
  400. end,
  401. PortSpecs = fun() ->
  402. case lists:keyfind(port_specs, 1, Conf) of
  403. false ->
  404. case filelib:is_dir("$(DEPS_DIR)/$(1)/c_src") of
  405. false -> [];
  406. true ->
  407. [{"priv/" ++ proplists:get_value(so_name, Conf, "$(1)_drv.so"),
  408. proplists:get_value(port_sources, Conf, ["c_src/*.c"]), []}]
  409. end;
  410. {_, Specs} ->
  411. lists:flatten([case S of
  412. {Output, Input} -> {ShellToMk(Output), Input, []};
  413. {Regex, Output, Input} ->
  414. case rebar_utils:is_arch(Regex) of
  415. true -> {ShellToMk(Output), Input, []};
  416. false -> []
  417. end;
  418. {Regex, Output, Input, [{env, Env}]} ->
  419. case rebar_utils:is_arch(Regex) of
  420. true -> {ShellToMk(Output), Input, Env};
  421. false -> []
  422. end
  423. end || S <- Specs])
  424. end
  425. end(),
  426. PortSpecWrite = fun (Text) ->
  427. file:write_file("$(DEPS_DIR)/$(1)/c_src/Makefile.erlang.mk", Text, [append])
  428. end,
  429. case PortSpecs of
  430. [] -> ok;
  431. _ ->
  432. Write("\npre-app::\n\t$$$$\(MAKE) -f c_src/Makefile.erlang.mk\n"),
  433. PortSpecWrite(io_lib:format("ERL_CFLAGS = -finline-functions -Wall -fPIC -I ~s/erts-~s/include -I ~s\n",
  434. [code:root_dir(), erlang:system_info(version), code:lib_dir(erl_interface, include)])),
  435. PortSpecWrite(io_lib:format("ERL_LDFLAGS = -L ~s -lerl_interface -lei\n",
  436. [code:lib_dir(erl_interface, lib)])),
  437. [PortSpecWrite(["\n", E, "\n"]) || E <- OsEnv],
  438. FilterEnv = fun(Env) ->
  439. lists:flatten([case E of
  440. {_, _} -> E;
  441. {Regex, K, V} ->
  442. case rebar_utils:is_arch(Regex) of
  443. true -> {K, V};
  444. false -> []
  445. end
  446. end || E <- Env])
  447. end,
  448. MergeEnv = fun(Env) ->
  449. lists:foldl(fun ({K, V}, Acc) ->
  450. case lists:keyfind(K, 1, Acc) of
  451. false -> [{K, rebar_utils:expand_env_variable(V, K, "")}|Acc];
  452. {_, V0} -> [{K, rebar_utils:expand_env_variable(V, K, V0)}|Acc]
  453. end
  454. end, [], Env)
  455. end,
  456. PortEnv = case lists:keyfind(port_env, 1, Conf) of
  457. false -> [];
  458. {_, PortEnv0} -> FilterEnv(PortEnv0)
  459. end,
  460. PortSpec = fun ({Output, Input0, Env}) ->
  461. filelib:ensure_dir("$(DEPS_DIR)/$(1)/" ++ Output),
  462. Input = [[" ", I] || I <- Input0],
  463. PortSpecWrite([
  464. [["\n", K, " = ", ShellToMk(V)] || {K, V} <- lists:reverse(MergeEnv(PortEnv))],
  465. "\n\nall:: ", Output, "\n\n",
  466. "%.o: %.c\n\t$$$$\(CC) -c -o $$$$\@ $$$$\< $$$$\(CFLAGS) $$$$\(ERL_CFLAGS) $$$$\(DRV_CFLAGS) $$$$\(EXE_CFLAGS)\n\n",
  467. "%.o: %.C\n\t$$$$\(CXX) -c -o $$$$\@ $$$$\< $$$$\(CXXFLAGS) $$$$\(ERL_CFLAGS) $$$$\(DRV_CFLAGS) $$$$\(EXE_CFLAGS)\n\n",
  468. "%.o: %.cc\n\t$$$$\(CXX) -c -o $$$$\@ $$$$\< $$$$\(CXXFLAGS) $$$$\(ERL_CFLAGS) $$$$\(DRV_CFLAGS) $$$$\(EXE_CFLAGS)\n\n",
  469. "%.o: %.cpp\n\t$$$$\(CXX) -c -o $$$$\@ $$$$\< $$$$\(CXXFLAGS) $$$$\(ERL_CFLAGS) $$$$\(DRV_CFLAGS) $$$$\(EXE_CFLAGS)\n\n",
  470. [[Output, ": ", K, " = ", ShellToMk(V), "\n"] || {K, V} <- lists:reverse(MergeEnv(FilterEnv(Env)))],
  471. Output, ": $$$$\(foreach ext,.c .C .cc .cpp,",
  472. "$$$$\(patsubst %$$$$\(ext),%.o,$$$$\(filter %$$$$\(ext),$$$$\(wildcard", Input, "))))\n",
  473. "\t$$$$\(CC) -o $$$$\@ $$$$\? $$$$\(LDFLAGS) $$$$\(ERL_LDFLAGS) $$$$\(DRV_LDFLAGS) $$$$\(EXE_LDFLAGS)",
  474. case filename:extension(Output) of
  475. [] -> "\n";
  476. _ -> " -shared\n"
  477. end])
  478. end,
  479. [PortSpec(S) || S <- PortSpecs]
  480. end,
  481. Write("\ninclude ../../erlang.mk"),
  482. PatchPlugin = fun(ErlFile) ->
  483. {ok, F0} = file:read_file(ErlFile),
  484. case re:replace(F0, "rebar_config:", "rebar_config_", [global]) of
  485. F0 -> ok;
  486. F ->
  487. ok = file:write_file(ErlFile, [F,
  488. "\nrebar_config_get(_, current_command, _) -> compile.\n"
  489. ])
  490. end
  491. end,
  492. RunPlugin = fun(Plugin, Step) ->
  493. case erlang:function_exported(Plugin, Step, 2) of
  494. false -> ok;
  495. true ->
  496. c:cd("$(DEPS_DIR)/$(1)/"),
  497. Ret = Plugin:Step(Conf, undefined),
  498. io:format("rebar plugin ~p step ~p ret ~p~n", [Plugin, Step, Ret])
  499. end
  500. end,
  501. fun() ->
  502. case lists:keyfind(plugins, 1, Conf) of
  503. false -> ok;
  504. {_, Plugins} ->
  505. [begin
  506. case lists:keyfind(deps, 1, Conf) of
  507. false -> ok;
  508. {_, Deps} ->
  509. case lists:keyfind(P, 1, Deps) of
  510. false -> ok;
  511. _ ->
  512. Path = "$(DEPS_DIR)/" ++ atom_to_list(P),
  513. io:format("~s", [os:cmd("$(MAKE) -C $(DEPS_DIR)/$(1) " ++ Path)]),
  514. io:format("~s", [os:cmd("$(MAKE) -C " ++ Path ++ " IS_DEP=1")]),
  515. code:add_patha(Path ++ "/ebin")
  516. end
  517. end
  518. end || P <- Plugins],
  519. [case code:load_file(P) of
  520. {module, P} -> ok;
  521. _ ->
  522. case lists:keyfind(plugin_dir, 1, Conf) of
  523. false -> ok;
  524. {_, PluginsDir} ->
  525. ErlFile = "$(DEPS_DIR)/$(1)/" ++ PluginsDir ++ "/" ++ atom_to_list(P) ++ ".erl",
  526. PatchPlugin(ErlFile),
  527. {ok, P, Bin} = compile:file(ErlFile, [binary]),
  528. {module, P} = code:load_binary(P, ErlFile, Bin)
  529. end
  530. end || P <- Plugins],
  531. [RunPlugin(P, preprocess) || P <- Plugins],
  532. [RunPlugin(P, pre_compile) || P <- Plugins]
  533. end
  534. end(),
  535. halt()
  536. endef
  537. define dep_autopatch_appsrc.erl
  538. AppSrcOut = "$(DEPS_DIR)/$(1)/src/$(1).app.src",
  539. AppSrcIn = case filelib:is_regular(AppSrcOut) of false -> "$(DEPS_DIR)/$(1)/ebin/$(1).app"; true -> AppSrcOut end,
  540. case filelib:is_regular(AppSrcIn) of
  541. false -> ok;
  542. true ->
  543. fun() ->
  544. {ok, [{application, $(1), L}]} = file:consult(AppSrcIn),
  545. L2 = lists:keystore(modules, 1, L, {modules, []}),
  546. L3 = case lists:keyfind(vsn, 1, L2) of {vsn, git} -> lists:keyreplace(vsn, 1, L2, {vsn, "git"}); _ -> L2 end,
  547. ok = file:write_file(AppSrcOut, io_lib:format("~p.~n", [{application, $(1), L3}]))
  548. end(),
  549. case AppSrcOut of AppSrcIn -> ok; _ -> ok = file:delete(AppSrcIn) end
  550. end,
  551. halt()
  552. endef
  553. define dep_fetch
  554. if [ "$$$$VS" = "git" ]; then \
  555. git clone -q -n -- $$$$REPO $(DEPS_DIR)/$(1); \
  556. cd $(DEPS_DIR)/$(1) && git checkout -q $$$$COMMIT; \
  557. elif [ "$$$$VS" = "hg" ]; then \
  558. hg clone -q -U $$$$REPO $(DEPS_DIR)/$(1); \
  559. cd $(DEPS_DIR)/$(1) && hg update -q $$$$COMMIT; \
  560. elif [ "$$$$VS" = "svn" ]; then \
  561. svn checkout -q $$$$REPO $(DEPS_DIR)/$(1); \
  562. elif [ "$$$$VS" = "cp" ]; then \
  563. cp -R $$$$REPO $(DEPS_DIR)/$(1); \
  564. else \
  565. echo "Unknown or invalid dependency: $(1). Please consult the erlang.mk README for instructions." >&2; \
  566. exit 78; \
  567. fi
  568. endef
  569. define dep_target
  570. $(DEPS_DIR)/$(1):
  571. @mkdir -p $(DEPS_DIR)
  572. ifeq (,$(dep_$(1)))
  573. @if [ ! -f $(PKG_FILE2) ]; then $(call core_http_get,$(PKG_FILE2),$(PKG_FILE_URL)); fi
  574. $(dep_verbose) DEPPKG=$$$$(awk 'BEGIN { FS = "\t" }; $$$$1 == "$(1)" { print $$$$2 " " $$$$3 " " $$$$4 }' $(PKG_FILE2);); \
  575. VS=$$$$(echo $$$$DEPPKG | cut -d " " -f1); \
  576. REPO=$$$$(echo $$$$DEPPKG | cut -d " " -f2); \
  577. COMMIT=$$$$(echo $$$$DEPPKG | cut -d " " -f3); \
  578. $(call dep_fetch,$(1))
  579. else
  580. ifeq (1,$(words $(dep_$(1))))
  581. $(dep_verbose) VS=git; \
  582. REPO=$(dep_$(1)); \
  583. COMMIT=master; \
  584. $(call dep_fetch,$(1))
  585. else
  586. ifeq (2,$(words $(dep_$(1))))
  587. $(dep_verbose) VS=git; \
  588. REPO=$(word 1,$(dep_$(1))); \
  589. COMMIT=$(word 2,$(dep_$(1))); \
  590. $(call dep_fetch,$(1))
  591. else
  592. $(dep_verbose) VS=$(word 1,$(dep_$(1))); \
  593. REPO=$(word 2,$(dep_$(1))); \
  594. COMMIT=$(word 3,$(dep_$(1))); \
  595. $(call dep_fetch,$(1))
  596. endif
  597. endif
  598. endif
  599. @if [ -f $(DEPS_DIR)/$(1)/configure.ac ]; then \
  600. echo " AUTO " $(1); \
  601. cd $(DEPS_DIR)/$(1) && autoreconf -vif; \
  602. fi
  603. -@if [ -f $(DEPS_DIR)/$(1)/configure ]; then \
  604. echo " CONF " $(1); \
  605. cd $(DEPS_DIR)/$(1) && ./configure; \
  606. fi
  607. ifeq ($(filter $(1),$(NO_AUTOPATCH)),)
  608. @$(call dep_autopatch,$(1))
  609. endif
  610. endef
  611. $(foreach dep,$(DEPS),$(eval $(call dep_target,$(dep))))
  612. distclean-deps:
  613. $(gen_verbose) rm -rf $(DEPS_DIR)
  614. # Packages related targets.
  615. $(PKG_FILE2):
  616. @$(call core_http_get,$(PKG_FILE2),$(PKG_FILE_URL))
  617. pkg-list: $(PKG_FILE2)
  618. @cat $(PKG_FILE2) | awk 'BEGIN { FS = "\t" }; { print \
  619. "Name:\t\t" $$1 "\n" \
  620. "Repository:\t" $$3 "\n" \
  621. "Website:\t" $$5 "\n" \
  622. "Description:\t" $$6 "\n" }'
  623. ifdef q
  624. pkg-search: $(PKG_FILE2)
  625. @cat $(PKG_FILE2) | grep -i ${q} | awk 'BEGIN { FS = "\t" }; { print \
  626. "Name:\t\t" $$1 "\n" \
  627. "Repository:\t" $$3 "\n" \
  628. "Website:\t" $$5 "\n" \
  629. "Description:\t" $$6 "\n" }'
  630. else
  631. pkg-search:
  632. $(error Usage: $(MAKE) pkg-search q=STRING)
  633. endif
  634. ifeq ($(PKG_FILE2),$(CURDIR)/.erlang.mk.packages.v2)
  635. distclean-pkg:
  636. $(gen_verbose) rm -f $(PKG_FILE2)
  637. endif
  638. help::
  639. @printf "%s\n" "" \
  640. "Package-related targets:" \
  641. " pkg-list List all known packages" \
  642. " pkg-search q=STRING Search for STRING in the package index"
  643. # Copyright (c) 2015, Loïc Hoguin <essen@ninenines.eu>
  644. # This file is part of erlang.mk and subject to the terms of the ISC License.
  645. # Verbosity.
  646. proto_verbose_0 = @echo " PROTO " $(filter %.proto,$(?F));
  647. proto_verbose = $(proto_verbose_$(V))
  648. # Core targets.
  649. define compile_proto
  650. @mkdir -p ebin/ include/
  651. $(proto_verbose) $(call erlang,$(call compile_proto.erl,$(1)))
  652. $(proto_verbose) erlc +debug_info -o ebin/ ebin/*.erl
  653. @rm ebin/*.erl
  654. endef
  655. define compile_proto.erl
  656. [begin
  657. Dir = filename:dirname(filename:dirname(F)),
  658. protobuffs_compile:generate_source(F,
  659. [{output_include_dir, Dir ++ "/include"},
  660. {output_src_dir, Dir ++ "/ebin"}])
  661. end || F <- string:tokens("$(1)", " ")],
  662. halt().
  663. endef
  664. ifneq ($(wildcard src/),)
  665. ebin/$(PROJECT).app:: $(shell find src -type f -name \*.proto 2>/dev/null)
  666. $(if $(strip $?),$(call compile_proto,$?))
  667. endif
  668. # Copyright (c) 2013-2015, Loïc Hoguin <essen@ninenines.eu>
  669. # This file is part of erlang.mk and subject to the terms of the ISC License.
  670. .PHONY: clean-app
  671. # Configuration.
  672. ERLC_OPTS ?= -Werror +debug_info +warn_export_vars +warn_shadow_vars \
  673. +warn_obsolete_guard # +bin_opt_info +warn_export_all +warn_missing_spec
  674. COMPILE_FIRST ?=
  675. COMPILE_FIRST_PATHS = $(addprefix src/,$(addsuffix .erl,$(COMPILE_FIRST)))
  676. ERLC_EXCLUDE ?=
  677. ERLC_EXCLUDE_PATHS = $(addprefix src/,$(addsuffix .erl,$(ERLC_EXCLUDE)))
  678. ERLC_MIB_OPTS ?=
  679. COMPILE_MIB_FIRST ?=
  680. COMPILE_MIB_FIRST_PATHS = $(addprefix mibs/,$(addsuffix .mib,$(COMPILE_MIB_FIRST)))
  681. # Verbosity.
  682. appsrc_verbose_0 = @echo " APP " $(PROJECT).app.src;
  683. appsrc_verbose = $(appsrc_verbose_$(V))
  684. erlc_verbose_0 = @echo " ERLC " $(filter-out $(patsubst %,%.erl,$(ERLC_EXCLUDE)),\
  685. $(filter %.erl %.core,$(?F)));
  686. erlc_verbose = $(erlc_verbose_$(V))
  687. xyrl_verbose_0 = @echo " XYRL " $(filter %.xrl %.yrl,$(?F));
  688. xyrl_verbose = $(xyrl_verbose_$(V))
  689. asn1_verbose_0 = @echo " ASN1 " $(filter %.asn1,$(?F));
  690. asn1_verbose = $(asn1_verbose_$(V))
  691. mib_verbose_0 = @echo " MIB " $(filter %.bin %.mib,$(?F));
  692. mib_verbose = $(mib_verbose_$(V))
  693. # Targets.
  694. ifeq ($(wildcard ebin/test),)
  695. app:: app-build
  696. else
  697. app:: clean app-build
  698. endif
  699. app-build: erlc-include ebin/$(PROJECT).app
  700. $(eval MODULES := $(shell find ebin -type f -name \*.beam \
  701. | sed "s/ebin\//'/;s/\.beam/',/" | sed '$$s/.$$//'))
  702. @if [ -z "$$(grep -E '^[^%]*{modules,' src/$(PROJECT).app.src)" ]; then \
  703. echo "Empty modules entry not found in $(PROJECT).app.src. Please consult the erlang.mk README for instructions." >&2; \
  704. exit 1; \
  705. fi
  706. $(eval GITDESCRIBE := $(shell git describe --dirty --abbrev=7 --tags --always --first-parent 2>/dev/null || true))
  707. $(appsrc_verbose) cat src/$(PROJECT).app.src \
  708. | sed "s/{modules,[[:space:]]*\[\]}/{modules, \[$(MODULES)\]}/" \
  709. | sed "s/{id,[[:space:]]*\"git\"}/{id, \"$(GITDESCRIBE)\"}/" \
  710. > ebin/$(PROJECT).app
  711. erlc-include:
  712. -@if [ -d ebin/ ]; then \
  713. find include/ src/ -type f -name \*.hrl -newer ebin -exec touch $(shell find src/ -type f -name "*.erl") \; 2>/dev/null || printf ''; \
  714. fi
  715. define compile_erl
  716. $(erlc_verbose) erlc -v $(ERLC_OPTS) -o ebin/ \
  717. -pa ebin/ -I include/ $(filter-out $(ERLC_EXCLUDE_PATHS),\
  718. $(COMPILE_FIRST_PATHS) $(1))
  719. endef
  720. define compile_xyrl
  721. $(xyrl_verbose) erlc -v -o ebin/ $(1)
  722. $(xyrl_verbose) erlc $(ERLC_OPTS) -o ebin/ ebin/*.erl
  723. @rm ebin/*.erl
  724. endef
  725. define compile_asn1
  726. $(asn1_verbose) erlc -v -I include/ -o ebin/ $(1)
  727. @mv ebin/*.hrl include/
  728. @mv ebin/*.asn1db include/
  729. @rm ebin/*.erl
  730. endef
  731. define compile_mib
  732. $(mib_verbose) erlc -v $(ERLC_MIB_OPTS) -o priv/mibs/ \
  733. -I priv/mibs/ $(COMPILE_MIB_FIRST_PATHS) $(1)
  734. $(mib_verbose) erlc -o include/ -- priv/mibs/*.bin
  735. endef
  736. ifneq ($(wildcard src/),)
  737. ebin/$(PROJECT).app::
  738. @mkdir -p ebin/
  739. ifneq ($(wildcard asn1/),)
  740. ebin/$(PROJECT).app:: $(shell find asn1 -type f -name \*.asn1)
  741. @mkdir -p include
  742. $(if $(strip $?),$(call compile_asn1,$?))
  743. endif
  744. ifneq ($(wildcard mibs/),)
  745. ebin/$(PROJECT).app:: $(shell find mibs -type f -name \*.mib)
  746. @mkdir -p priv/mibs/ include
  747. $(if $(strip $?),$(call compile_mib,$?))
  748. endif
  749. ebin/$(PROJECT).app:: $(shell find src -type f -name \*.erl) \
  750. $(shell find src -type f -name \*.core)
  751. $(if $(strip $?),$(call compile_erl,$?))
  752. ebin/$(PROJECT).app:: $(shell find src -type f -name \*.xrl) \
  753. $(shell find src -type f -name \*.yrl)
  754. $(if $(strip $?),$(call compile_xyrl,$?))
  755. endif
  756. clean:: clean-app
  757. clean-app:
  758. $(gen_verbose) rm -rf ebin/ priv/mibs/ \
  759. $(addprefix include/,$(addsuffix .hrl,$(notdir $(basename $(wildcard mibs/*.mib)))))
  760. # Copyright (c) 2015, Viktor Söderqvist <viktor@zuiderkwast.se>
  761. # This file is part of erlang.mk and subject to the terms of the ISC License.
  762. .PHONY: docs-deps
  763. # Configuration.
  764. ALL_DOC_DEPS_DIRS = $(addprefix $(DEPS_DIR)/,$(DOC_DEPS))
  765. # Targets.
  766. $(foreach dep,$(DOC_DEPS),$(eval $(call dep_target,$(dep))))
  767. ifneq ($(SKIP_DEPS),)
  768. doc-deps:
  769. else
  770. doc-deps: $(ALL_DOC_DEPS_DIRS)
  771. @for dep in $(ALL_DOC_DEPS_DIRS) ; do $(MAKE) -C $$dep; done
  772. endif
  773. # Copyright (c) 2015, Loïc Hoguin <essen@ninenines.eu>
  774. # This file is part of erlang.mk and subject to the terms of the ISC License.
  775. .PHONY: test-deps test-dir test-build clean-test-dir
  776. # Configuration.
  777. TEST_DIR ?= $(CURDIR)/test
  778. ALL_TEST_DEPS_DIRS = $(addprefix $(DEPS_DIR)/,$(TEST_DEPS))
  779. TEST_ERLC_OPTS ?= +debug_info +warn_export_vars +warn_shadow_vars +warn_obsolete_guard
  780. TEST_ERLC_OPTS += -DTEST=1
  781. # Targets.
  782. $(foreach dep,$(TEST_DEPS),$(eval $(call dep_target,$(dep))))
  783. ifneq ($(SKIP_DEPS),)
  784. test-deps:
  785. else
  786. test-deps: $(ALL_TEST_DEPS_DIRS)
  787. @for dep in $(ALL_TEST_DEPS_DIRS) ; do $(MAKE) -C $$dep; done
  788. endif
  789. ifneq ($(strip $(TEST_DIR)),)
  790. test-dir:
  791. $(gen_verbose) erlc -v $(TEST_ERLC_OPTS) -I include/ -o $(TEST_DIR) \
  792. $(wildcard $(TEST_DIR)/*.erl $(TEST_DIR)/*/*.erl) -pa ebin/
  793. endif
  794. ifeq ($(wildcard ebin/test),)
  795. test-build:: ERLC_OPTS=$(TEST_ERLC_OPTS)
  796. test-build:: clean deps test-deps
  797. @$(MAKE) --no-print-directory app-build test-dir ERLC_OPTS="$(TEST_ERLC_OPTS)"
  798. $(gen_verbose) touch ebin/test
  799. else
  800. test-build:: ERLC_OPTS=$(TEST_ERLC_OPTS)
  801. test-build:: deps test-deps
  802. @$(MAKE) --no-print-directory app-build test-dir ERLC_OPTS="$(TEST_ERLC_OPTS)"
  803. endif
  804. clean:: clean-test-dir
  805. clean-test-dir:
  806. ifneq ($(wildcard $(TEST_DIR)/*.beam),)
  807. $(gen_verbose) rm -f $(TEST_DIR)/*.beam
  808. endif
  809. # Copyright (c) 2015, Loïc Hoguin <essen@ninenines.eu>
  810. # This file is part of erlang.mk and subject to the terms of the ISC License.
  811. .PHONY: asciidoc asciidoc-guide asciidoc-manual install-asciidoc distclean-asciidoc
  812. MAN_INSTALL_PATH ?= /usr/local/share/man
  813. MAN_SECTIONS ?= 3 7
  814. docs:: asciidoc
  815. asciidoc: distclean-asciidoc doc-deps asciidoc-guide asciidoc-manual
  816. ifeq ($(wildcard doc/src/guide/book.asciidoc),)
  817. asciidoc-guide:
  818. else
  819. asciidoc-guide:
  820. a2x -v -f pdf doc/src/guide/book.asciidoc && mv doc/src/guide/book.pdf doc/guide.pdf
  821. a2x -v -f chunked doc/src/guide/book.asciidoc && mv doc/src/guide/book.chunked/ doc/html/
  822. endif
  823. ifeq ($(wildcard doc/src/manual/*.asciidoc),)
  824. asciidoc-manual:
  825. else
  826. asciidoc-manual:
  827. for f in doc/src/manual/*.asciidoc ; do \
  828. a2x -v -f manpage $$f ; \
  829. done
  830. for s in $(MAN_SECTIONS); do \
  831. mkdir -p doc/man$$s/ ; \
  832. mv doc/src/manual/*.$$s doc/man$$s/ ; \
  833. gzip doc/man$$s/*.$$s ; \
  834. done
  835. install-docs:: install-asciidoc
  836. install-asciidoc: asciidoc-manual
  837. for s in $(MAN_SECTIONS); do \
  838. mkdir -p $(MAN_INSTALL_PATH)/man$$s/ ; \
  839. install -g 0 -o 0 -m 0644 doc/man$$s/*.gz $(MAN_INSTALL_PATH)/man$$s/ ; \
  840. done
  841. endif
  842. distclean:: distclean-asciidoc
  843. distclean-asciidoc:
  844. $(gen_verbose) rm -rf doc/html/ doc/guide.pdf doc/man3/ doc/man7/
  845. # Copyright (c) 2014-2015, Loïc Hoguin <essen@ninenines.eu>
  846. # This file is part of erlang.mk and subject to the terms of the ISC License.
  847. .PHONY: bootstrap bootstrap-lib bootstrap-rel new list-templates
  848. # Core targets.
  849. help::
  850. @printf "%s\n" "" \
  851. "Bootstrap targets:" \
  852. " bootstrap Generate a skeleton of an OTP application" \
  853. " bootstrap-lib Generate a skeleton of an OTP library" \
  854. " bootstrap-rel Generate the files needed to build a release" \
  855. " new t=TPL n=NAME Generate a module NAME based on the template TPL" \
  856. " list-templates List available templates"
  857. # Bootstrap templates.
  858. define bs_appsrc
  859. {application, $(PROJECT), [
  860. {description, ""},
  861. {vsn, "0.1.0"},
  862. {id, "git"},
  863. {modules, []},
  864. {registered, []},
  865. {applications, [
  866. kernel,
  867. stdlib
  868. ]},
  869. {mod, {$(PROJECT)_app, []}},
  870. {env, []}
  871. ]}.
  872. endef
  873. define bs_appsrc_lib
  874. {application, $(PROJECT), [
  875. {description, ""},
  876. {vsn, "0.1.0"},
  877. {id, "git"},
  878. {modules, []},
  879. {registered, []},
  880. {applications, [
  881. kernel,
  882. stdlib
  883. ]}
  884. ]}.
  885. endef
  886. define bs_Makefile
  887. PROJECT = $(PROJECT)
  888. include erlang.mk
  889. endef
  890. define bs_app
  891. -module($(PROJECT)_app).
  892. -behaviour(application).
  893. -export([start/2]).
  894. -export([stop/1]).
  895. start(_Type, _Args) ->
  896. $(PROJECT)_sup:start_link().
  897. stop(_State) ->
  898. ok.
  899. endef
  900. define bs_relx_config
  901. {release, {$(PROJECT)_release, "1"}, [$(PROJECT)]}.
  902. {extended_start_script, true}.
  903. {sys_config, "rel/sys.config"}.
  904. {vm_args, "rel/vm.args"}.
  905. endef
  906. define bs_sys_config
  907. [
  908. ].
  909. endef
  910. define bs_vm_args
  911. -name $(PROJECT)@127.0.0.1
  912. -setcookie $(PROJECT)
  913. -heart
  914. endef
  915. # Normal templates.
  916. define tpl_supervisor
  917. -module($(n)).
  918. -behaviour(supervisor).
  919. -export([start_link/0]).
  920. -export([init/1]).
  921. start_link() ->
  922. supervisor:start_link({local, ?MODULE}, ?MODULE, []).
  923. init([]) ->
  924. Procs = [],
  925. {ok, {{one_for_one, 1, 5}, Procs}}.
  926. endef
  927. define tpl_gen_server
  928. -module($(n)).
  929. -behaviour(gen_server).
  930. %% API.
  931. -export([start_link/0]).
  932. %% gen_server.
  933. -export([init/1]).
  934. -export([handle_call/3]).
  935. -export([handle_cast/2]).
  936. -export([handle_info/2]).
  937. -export([terminate/2]).
  938. -export([code_change/3]).
  939. -record(state, {
  940. }).
  941. %% API.
  942. -spec start_link() -> {ok, pid()}.
  943. start_link() ->
  944. gen_server:start_link(?MODULE, [], []).
  945. %% gen_server.
  946. init([]) ->
  947. {ok, #state{}}.
  948. handle_call(_Request, _From, State) ->
  949. {reply, ignored, State}.
  950. handle_cast(_Msg, State) ->
  951. {noreply, State}.
  952. handle_info(_Info, State) ->
  953. {noreply, State}.
  954. terminate(_Reason, _State) ->
  955. ok.
  956. code_change(_OldVsn, State, _Extra) ->
  957. {ok, State}.
  958. endef
  959. define tpl_cowboy_http
  960. -module($(n)).
  961. -behaviour(cowboy_http_handler).
  962. -export([init/3]).
  963. -export([handle/2]).
  964. -export([terminate/3]).
  965. -record(state, {
  966. }).
  967. init(_, Req, _Opts) ->
  968. {ok, Req, #state{}}.
  969. handle(Req, State=#state{}) ->
  970. {ok, Req2} = cowboy_req:reply(200, Req),
  971. {ok, Req2, State}.
  972. terminate(_Reason, _Req, _State) ->
  973. ok.
  974. endef
  975. define tpl_gen_fsm
  976. -module($(n)).
  977. -behaviour(gen_fsm).
  978. %% API.
  979. -export([start_link/0]).
  980. %% gen_fsm.
  981. -export([init/1]).
  982. -export([state_name/2]).
  983. -export([handle_event/3]).
  984. -export([state_name/3]).
  985. -export([handle_sync_event/4]).
  986. -export([handle_info/3]).
  987. -export([terminate/3]).
  988. -export([code_change/4]).
  989. -record(state, {
  990. }).
  991. %% API.
  992. -spec start_link() -> {ok, pid()}.
  993. start_link() ->
  994. gen_fsm:start_link(?MODULE, [], []).
  995. %% gen_fsm.
  996. init([]) ->
  997. {ok, state_name, #state{}}.
  998. state_name(_Event, StateData) ->
  999. {next_state, state_name, StateData}.
  1000. handle_event(_Event, StateName, StateData) ->
  1001. {next_state, StateName, StateData}.
  1002. state_name(_Event, _From, StateData) ->
  1003. {reply, ignored, state_name, StateData}.
  1004. handle_sync_event(_Event, _From, StateName, StateData) ->
  1005. {reply, ignored, StateName, StateData}.
  1006. handle_info(_Info, StateName, StateData) ->
  1007. {next_state, StateName, StateData}.
  1008. terminate(_Reason, _StateName, _StateData) ->
  1009. ok.
  1010. code_change(_OldVsn, StateName, StateData, _Extra) ->
  1011. {ok, StateName, StateData}.
  1012. endef
  1013. define tpl_cowboy_loop
  1014. -module($(n)).
  1015. -behaviour(cowboy_loop_handler).
  1016. -export([init/3]).
  1017. -export([info/3]).
  1018. -export([terminate/3]).
  1019. -record(state, {
  1020. }).
  1021. init(_, Req, _Opts) ->
  1022. {loop, Req, #state{}, 5000, hibernate}.
  1023. info(_Info, Req, State) ->
  1024. {loop, Req, State, hibernate}.
  1025. terminate(_Reason, _Req, _State) ->
  1026. ok.
  1027. endef
  1028. define tpl_cowboy_rest
  1029. -module($(n)).
  1030. -export([init/3]).
  1031. -export([content_types_provided/2]).
  1032. -export([get_html/2]).
  1033. init(_, _Req, _Opts) ->
  1034. {upgrade, protocol, cowboy_rest}.
  1035. content_types_provided(Req, State) ->
  1036. {[{{<<"text">>, <<"html">>, '*'}, get_html}], Req, State}.
  1037. get_html(Req, State) ->
  1038. {<<"<html><body>This is REST!</body></html>">>, Req, State}.
  1039. endef
  1040. define tpl_cowboy_ws
  1041. -module($(n)).
  1042. -behaviour(cowboy_websocket_handler).
  1043. -export([init/3]).
  1044. -export([websocket_init/3]).
  1045. -export([websocket_handle/3]).
  1046. -export([websocket_info/3]).
  1047. -export([websocket_terminate/3]).
  1048. -record(state, {
  1049. }).
  1050. init(_, _, _) ->
  1051. {upgrade, protocol, cowboy_websocket}.
  1052. websocket_init(_, Req, _Opts) ->
  1053. Req2 = cowboy_req:compact(Req),
  1054. {ok, Req2, #state{}}.
  1055. websocket_handle({text, Data}, Req, State) ->
  1056. {reply, {text, Data}, Req, State};
  1057. websocket_handle({binary, Data}, Req, State) ->
  1058. {reply, {binary, Data}, Req, State};
  1059. websocket_handle(_Frame, Req, State) ->
  1060. {ok, Req, State}.
  1061. websocket_info(_Info, Req, State) ->
  1062. {ok, Req, State}.
  1063. websocket_terminate(_Reason, _Req, _State) ->
  1064. ok.
  1065. endef
  1066. define tpl_ranch_protocol
  1067. -module($(n)).
  1068. -behaviour(ranch_protocol).
  1069. -export([start_link/4]).
  1070. -export([init/4]).
  1071. -type opts() :: [].
  1072. -export_type([opts/0]).
  1073. -record(state, {
  1074. socket :: inet:socket(),
  1075. transport :: module()
  1076. }).
  1077. start_link(Ref, Socket, Transport, Opts) ->
  1078. Pid = spawn_link(?MODULE, init, [Ref, Socket, Transport, Opts]),
  1079. {ok, Pid}.
  1080. -spec init(ranch:ref(), inet:socket(), module(), opts()) -> ok.
  1081. init(Ref, Socket, Transport, _Opts) ->
  1082. ok = ranch:accept_ack(Ref),
  1083. loop(#state{socket=Socket, transport=Transport}).
  1084. loop(State) ->
  1085. loop(State).
  1086. endef
  1087. # Plugin-specific targets.
  1088. define render_template
  1089. @echo "$${$(1)}" > $(2)
  1090. endef
  1091. $(foreach template,$(filter bs_%,$(.VARIABLES)),$(eval export $(template)))
  1092. $(foreach template,$(filter tpl_%,$(.VARIABLES)),$(eval export $(template)))
  1093. bootstrap:
  1094. ifneq ($(wildcard src/),)
  1095. $(error Error: src/ directory already exists)
  1096. endif
  1097. $(call render_template,bs_Makefile,Makefile)
  1098. @mkdir src/
  1099. $(call render_template,bs_appsrc,src/$(PROJECT).app.src)
  1100. $(call render_template,bs_app,src/$(PROJECT)_app.erl)
  1101. $(eval n := $(PROJECT)_sup)
  1102. $(call render_template,tpl_supervisor,src/$(PROJECT)_sup.erl)
  1103. bootstrap-lib:
  1104. ifneq ($(wildcard src/),)
  1105. $(error Error: src/ directory already exists)
  1106. endif
  1107. $(call render_template,bs_Makefile,Makefile)
  1108. @mkdir src/
  1109. $(call render_template,bs_appsrc_lib,src/$(PROJECT).app.src)
  1110. bootstrap-rel:
  1111. ifneq ($(wildcard relx.config),)
  1112. $(error Error: relx.config already exists)
  1113. endif
  1114. ifneq ($(wildcard rel/),)
  1115. $(error Error: rel/ directory already exists)
  1116. endif
  1117. $(call render_template,bs_relx_config,relx.config)
  1118. @mkdir rel/
  1119. $(call render_template,bs_sys_config,rel/sys.config)
  1120. $(call render_template,bs_vm_args,rel/vm.args)
  1121. new:
  1122. ifeq ($(wildcard src/),)
  1123. $(error Error: src/ directory does not exist)
  1124. endif
  1125. ifndef t
  1126. $(error Usage: $(MAKE) new t=TEMPLATE n=NAME)
  1127. endif
  1128. ifndef tpl_$(t)
  1129. $(error Unknown template)
  1130. endif
  1131. ifndef n
  1132. $(error Usage: $(MAKE) new t=TEMPLATE n=NAME)
  1133. endif
  1134. $(call render_template,tpl_$(t),src/$(n).erl)
  1135. list-templates:
  1136. @echo Available templates: $(sort $(patsubst tpl_%,%,$(filter tpl_%,$(.VARIABLES))))
  1137. # Copyright (c) 2014-2015, Loïc Hoguin <essen@ninenines.eu>
  1138. # This file is part of erlang.mk and subject to the terms of the ISC License.
  1139. .PHONY: clean-c_src distclean-c_src-env
  1140. # Configuration.
  1141. C_SRC_DIR ?= $(CURDIR)/c_src
  1142. C_SRC_ENV ?= $(C_SRC_DIR)/env.mk
  1143. C_SRC_OUTPUT ?= $(CURDIR)/priv/$(PROJECT).so
  1144. C_SRC_TYPE ?= shared
  1145. # System type and C compiler/flags.
  1146. ifeq ($(PLATFORM),darwin)
  1147. CC ?= cc
  1148. CFLAGS ?= -O3 -std=c99 -arch x86_64 -finline-functions -Wall -Wmissing-prototypes
  1149. CXXFLAGS ?= -O3 -arch x86_64 -finline-functions -Wall
  1150. LDFLAGS ?= -arch x86_64 -flat_namespace -undefined suppress
  1151. else ifeq ($(PLATFORM),freebsd)
  1152. CC ?= cc
  1153. CFLAGS ?= -O3 -std=c99 -finline-functions -Wall -Wmissing-prototypes
  1154. CXXFLAGS ?= -O3 -finline-functions -Wall
  1155. else ifeq ($(PLATFORM),linux)
  1156. CC ?= gcc
  1157. CFLAGS ?= -O3 -std=c99 -finline-functions -Wall -Wmissing-prototypes
  1158. CXXFLAGS ?= -O3 -finline-functions -Wall
  1159. endif
  1160. CFLAGS += -fPIC -I $(ERTS_INCLUDE_DIR) -I $(ERL_INTERFACE_INCLUDE_DIR)
  1161. CXXFLAGS += -fPIC -I $(ERTS_INCLUDE_DIR) -I $(ERL_INTERFACE_INCLUDE_DIR)
  1162. LDLIBS += -L $(ERL_INTERFACE_LIB_DIR) -lerl_interface -lei
  1163. ifeq ($(C_SRC_TYPE),shared)
  1164. LDFLAGS += -shared
  1165. endif
  1166. # Verbosity.
  1167. c_verbose_0 = @echo " C " $(?F);
  1168. c_verbose = $(c_verbose_$(V))
  1169. cpp_verbose_0 = @echo " CPP " $(?F);
  1170. cpp_verbose = $(cpp_verbose_$(V))
  1171. link_verbose_0 = @echo " LD " $(@F);
  1172. link_verbose = $(link_verbose_$(V))
  1173. # Targets.
  1174. ifeq ($(wildcard $(C_SRC_DIR)),)
  1175. else ifneq ($(wildcard $(C_SRC_DIR)/Makefile),)
  1176. app:: app-c_src
  1177. test-build:: app-c_src
  1178. app-c_src:
  1179. $(MAKE) -C $(C_SRC_DIR)
  1180. clean::
  1181. $(MAKE) -C $(C_SRC_DIR) clean
  1182. else
  1183. ifeq ($(SOURCES),)
  1184. SOURCES := $(shell find $(C_SRC_DIR) -type f \( -name "*.c" -o -name "*.C" -o -name "*.cc" -o -name "*.cpp" \))
  1185. endif
  1186. OBJECTS = $(addsuffix .o, $(basename $(SOURCES)))
  1187. COMPILE_C = $(c_verbose) $(CC) $(CFLAGS) $(CPPFLAGS) -c
  1188. COMPILE_CPP = $(cpp_verbose) $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c
  1189. app:: $(C_SRC_ENV) $(C_SRC_OUTPUT)
  1190. test-build:: $(C_SRC_ENV) $(C_SRC_OUTPUT)
  1191. $(C_SRC_OUTPUT): $(OBJECTS)
  1192. @mkdir -p priv/
  1193. $(link_verbose) $(CC) $(OBJECTS) $(LDFLAGS) $(LDLIBS) -o $(C_SRC_OUTPUT)
  1194. %.o: %.c
  1195. $(COMPILE_C) $(OUTPUT_OPTION) $<
  1196. %.o: %.cc
  1197. $(COMPILE_CPP) $(OUTPUT_OPTION) $<
  1198. %.o: %.C
  1199. $(COMPILE_CPP) $(OUTPUT_OPTION) $<
  1200. %.o: %.cpp
  1201. $(COMPILE_CPP) $(OUTPUT_OPTION) $<
  1202. clean:: clean-c_src
  1203. clean-c_src:
  1204. $(gen_verbose) rm -f $(C_SRC_OUTPUT) $(OBJECTS)
  1205. endif
  1206. ifneq ($(wildcard $(C_SRC_DIR)),)
  1207. $(C_SRC_ENV):
  1208. @$(ERL) -eval "file:write_file(\"$(C_SRC_ENV)\", \
  1209. io_lib:format( \
  1210. \"ERTS_INCLUDE_DIR ?= ~s/erts-~s/include/~n\" \
  1211. \"ERL_INTERFACE_INCLUDE_DIR ?= ~s~n\" \
  1212. \"ERL_INTERFACE_LIB_DIR ?= ~s~n\", \
  1213. [code:root_dir(), erlang:system_info(version), \
  1214. code:lib_dir(erl_interface, include), \
  1215. code:lib_dir(erl_interface, lib)])), \
  1216. halt()."
  1217. distclean:: distclean-c_src-env
  1218. distclean-c_src-env:
  1219. $(gen_verbose) rm -f $(C_SRC_ENV)
  1220. -include $(C_SRC_ENV)
  1221. endif
  1222. # Copyright (c) 2015, Loïc Hoguin <essen@ninenines.eu>
  1223. # This file is part of erlang.mk and subject to the terms of the ISC License.
  1224. .PHONY: ci ci-setup distclean-kerl
  1225. KERL ?= $(CURDIR)/kerl
  1226. export KERL
  1227. KERL_URL ?= https://raw.githubusercontent.com/yrashk/kerl/master/kerl
  1228. OTP_GIT ?= https://github.com/erlang/otp
  1229. CI_INSTALL_DIR ?= $(HOME)/erlang
  1230. CI_OTP ?=
  1231. ifeq ($(strip $(CI_OTP)),)
  1232. ci::
  1233. else
  1234. ci:: $(KERL) $(addprefix ci-,$(CI_OTP))
  1235. ci-setup::
  1236. ci_verbose_0 = @echo " CI " $(1);
  1237. ci_verbose = $(ci_verbose_$(V))
  1238. define ci_target
  1239. ci-$(1): $(CI_INSTALL_DIR)/$(1)
  1240. -$(ci_verbose) \
  1241. PATH="$(CI_INSTALL_DIR)/$(1)/bin:$(PATH)" \
  1242. CI_OTP_RELEASE="$(1)" \
  1243. CT_OPTS="-label $(1)" \
  1244. $(MAKE) clean ci-setup tests
  1245. endef
  1246. $(foreach otp,$(CI_OTP),$(eval $(call ci_target,$(otp))))
  1247. define ci_otp_target
  1248. $(CI_INSTALL_DIR)/$(1):
  1249. $(KERL) build git $(OTP_GIT) $(1) $(1)
  1250. $(KERL) install $(1) $(CI_INSTALL_DIR)/$(1)
  1251. endef
  1252. $(foreach otp,$(CI_OTP),$(eval $(call ci_otp_target,$(otp))))
  1253. define kerl_fetch
  1254. $(call core_http_get,$(KERL),$(KERL_URL))
  1255. chmod +x $(KERL)
  1256. endef
  1257. $(KERL):
  1258. @$(call kerl_fetch)
  1259. help::
  1260. @printf "%s\n" "" \
  1261. "Continuous Integration targets:" \
  1262. " ci Run '$(MAKE) tests' on all configured Erlang versions." \
  1263. "" \
  1264. "The CI_OTP variable must be defined with the Erlang versions" \
  1265. "that must be tested. For example: CI_OTP = OTP-17.3.4 OTP-17.5.3"
  1266. distclean:: distclean-kerl
  1267. distclean-kerl:
  1268. $(gen_verbose) rm -rf $(KERL)
  1269. endif
  1270. # Copyright (c) 2013-2015, Loïc Hoguin <essen@ninenines.eu>
  1271. # This file is part of erlang.mk and subject to the terms of the ISC License.
  1272. .PHONY: ct distclean-ct
  1273. # Configuration.
  1274. CT_OPTS ?=
  1275. ifneq ($(wildcard $(TEST_DIR)),)
  1276. CT_SUITES ?= $(sort $(subst _SUITE.erl,,$(shell find $(TEST_DIR) -type f -name \*_SUITE.erl -exec basename {} \;)))
  1277. else
  1278. CT_SUITES ?=
  1279. endif
  1280. # Core targets.
  1281. tests:: ct
  1282. distclean:: distclean-ct
  1283. help::
  1284. @printf "%s\n" "" \
  1285. "Common_test targets:" \
  1286. " ct Run all the common_test suites for this project" \
  1287. "" \
  1288. "All your common_test suites have their associated targets." \
  1289. "A suite named http_SUITE can be ran using the ct-http target."
  1290. # Plugin-specific targets.
  1291. CT_RUN = ct_run \
  1292. -no_auto_compile \
  1293. -noinput \
  1294. -pa $(CURDIR)/ebin $(DEPS_DIR)/*/ebin $(TEST_DIR) \
  1295. -dir $(TEST_DIR) \
  1296. -logdir $(CURDIR)/logs
  1297. ifeq ($(CT_SUITES),)
  1298. ct:
  1299. else
  1300. ct: test-build
  1301. @mkdir -p $(CURDIR)/logs/
  1302. $(gen_verbose) $(CT_RUN) -suite $(addsuffix _SUITE,$(CT_SUITES)) $(CT_OPTS)
  1303. endif
  1304. define ct_suite_target
  1305. ct-$(1): test-build
  1306. @mkdir -p $(CURDIR)/logs/
  1307. $(gen_verbose) $(CT_RUN) -suite $(addsuffix _SUITE,$(1)) $(CT_OPTS)
  1308. endef
  1309. $(foreach test,$(CT_SUITES),$(eval $(call ct_suite_target,$(test))))
  1310. distclean-ct:
  1311. $(gen_verbose) rm -rf $(CURDIR)/logs/
  1312. # Copyright (c) 2013-2015, Loïc Hoguin <essen@ninenines.eu>
  1313. # This file is part of erlang.mk and subject to the terms of the ISC License.
  1314. .PHONY: plt distclean-plt dialyze
  1315. # Configuration.
  1316. DIALYZER_PLT ?= $(CURDIR)/.$(PROJECT).plt
  1317. export DIALYZER_PLT
  1318. PLT_APPS ?=
  1319. DIALYZER_DIRS ?= --src -r src
  1320. DIALYZER_OPTS ?= -Werror_handling -Wrace_conditions \
  1321. -Wunmatched_returns # -Wunderspecs
  1322. # Core targets.
  1323. check:: dialyze
  1324. distclean:: distclean-plt
  1325. help::
  1326. @printf "%s\n" "" \
  1327. "Dialyzer targets:" \
  1328. " plt Build a PLT file for this project" \
  1329. " dialyze Analyze the project using Dialyzer"
  1330. # Plugin-specific targets.
  1331. $(DIALYZER_PLT): deps app
  1332. @dialyzer --build_plt --apps erts kernel stdlib $(PLT_APPS) $(ALL_DEPS_DIRS)
  1333. plt: $(DIALYZER_PLT)
  1334. distclean-plt:
  1335. $(gen_verbose) rm -f $(DIALYZER_PLT)
  1336. ifneq ($(wildcard $(DIALYZER_PLT)),)
  1337. dialyze:
  1338. else
  1339. dialyze: $(DIALYZER_PLT)
  1340. endif
  1341. @dialyzer --no_native $(DIALYZER_DIRS) $(DIALYZER_OPTS)
  1342. # Copyright (c) 2013-2015, Loïc Hoguin <essen@ninenines.eu>
  1343. # This file is part of erlang.mk and subject to the terms of the ISC License.
  1344. .PHONY: distclean-edoc edoc
  1345. # Configuration.
  1346. EDOC_OPTS ?=
  1347. # Core targets.
  1348. docs:: distclean-edoc edoc
  1349. distclean:: distclean-edoc
  1350. # Plugin-specific targets.
  1351. edoc: doc-deps
  1352. $(gen_verbose) $(ERL) -eval 'edoc:application($(PROJECT), ".", [$(EDOC_OPTS)]), halt().'
  1353. distclean-edoc:
  1354. $(gen_verbose) rm -f doc/*.css doc/*.html doc/*.png doc/edoc-info
  1355. # Copyright (c) 2014, Juan Facorro <juan@inaka.net>
  1356. # This file is part of erlang.mk and subject to the terms of the ISC License.
  1357. .PHONY: elvis distclean-elvis
  1358. # Configuration.
  1359. ELVIS_CONFIG ?= $(CURDIR)/elvis.config
  1360. ELVIS ?= $(CURDIR)/elvis
  1361. export ELVIS
  1362. ELVIS_URL ?= https://github.com/inaka/elvis/releases/download/0.2.3/elvis
  1363. ELVIS_CONFIG_URL ?= https://github.com/inaka/elvis/releases/download/0.2.3/elvis.config
  1364. ELVIS_OPTS ?=
  1365. # Core targets.
  1366. help::
  1367. @printf "%s\n" "" \
  1368. "Elvis targets:" \
  1369. " elvis Run Elvis using the local elvis.config or download the default otherwise"
  1370. distclean:: distclean-elvis
  1371. # Plugin-specific targets.
  1372. $(ELVIS):
  1373. @$(call core_http_get,$(ELVIS),$(ELVIS_URL))
  1374. @chmod +x $(ELVIS)
  1375. $(ELVIS_CONFIG):
  1376. @$(call core_http_get,$(ELVIS_CONFIG),$(ELVIS_CONFIG_URL))
  1377. elvis: $(ELVIS) $(ELVIS_CONFIG)
  1378. @$(ELVIS) rock -c $(ELVIS_CONFIG) $(ELVIS_OPTS)
  1379. distclean-elvis:
  1380. $(gen_verbose) rm -rf $(ELVIS)
  1381. # Copyright (c) 2013-2015, Loïc Hoguin <essen@ninenines.eu>
  1382. # This file is part of erlang.mk and subject to the terms of the ISC License.
  1383. # Configuration.
  1384. DTL_FULL_PATH ?= 0
  1385. # Verbosity.
  1386. dtl_verbose_0 = @echo " DTL " $(filter %.dtl,$(?F));
  1387. dtl_verbose = $(dtl_verbose_$(V))
  1388. # Core targets.
  1389. define compile_erlydtl
  1390. $(dtl_verbose) $(ERL) -pa ebin/ $(DEPS_DIR)/erlydtl/ebin/ -eval ' \
  1391. Compile = fun(F) -> \
  1392. S = fun (1) -> re:replace(filename:rootname(string:sub_string(F, 11), ".dtl"), "/", "_", [{return, list}, global]); \
  1393. (0) -> filename:basename(F, ".dtl") \
  1394. end, \
  1395. Module = list_to_atom(string:to_lower(S($(DTL_FULL_PATH))) ++ "_dtl"), \
  1396. {ok, _} = erlydtl:compile(F, Module, [{out_dir, "ebin/"}, return_errors, {doc_root, "templates"}]) \
  1397. end, \
  1398. _ = [Compile(F) || F <- string:tokens("$(1)", " ")], \
  1399. halt().'
  1400. endef
  1401. ifneq ($(wildcard src/),)
  1402. ebin/$(PROJECT).app:: $(shell find templates -type f -name \*.dtl 2>/dev/null)
  1403. $(if $(strip $?),$(call compile_erlydtl,$?))
  1404. endif
  1405. # Copyright (c) 2014 Dave Cottlehuber <dch@skunkwerks.at>
  1406. # This file is part of erlang.mk and subject to the terms of the ISC License.
  1407. .PHONY: distclean-escript escript
  1408. # Configuration.
  1409. ESCRIPT_NAME ?= $(PROJECT)
  1410. ESCRIPT_COMMENT ?= This is an -*- erlang -*- file
  1411. ESCRIPT_BEAMS ?= "ebin/*", "deps/*/ebin/*"
  1412. ESCRIPT_SYS_CONFIG ?= "rel/sys.config"
  1413. ESCRIPT_EMU_ARGS ?= -pa . \
  1414. -sasl errlog_type error \
  1415. -escript main $(ESCRIPT_NAME)
  1416. ESCRIPT_SHEBANG ?= /usr/bin/env escript
  1417. ESCRIPT_STATIC ?= "deps/*/priv/**", "priv/**"
  1418. # Core targets.
  1419. distclean:: distclean-escript
  1420. help::
  1421. @printf "%s\n" "" \
  1422. "Escript targets:" \
  1423. " escript Build an executable escript archive" \
  1424. # Plugin-specific targets.
  1425. # Based on https://github.com/synrc/mad/blob/master/src/mad_bundle.erl
  1426. # Copyright (c) 2013 Maxim Sokhatsky, Synrc Research Center
  1427. # Modified MIT License, https://github.com/synrc/mad/blob/master/LICENSE :
  1428. # Software may only be used for the great good and the true happiness of all
  1429. # sentient beings.
  1430. define ESCRIPT_RAW
  1431. 'Read = fun(F) -> {ok, B} = file:read_file(filename:absname(F)), B end,'\
  1432. 'Files = fun(L) -> A = lists:concat([filelib:wildcard(X)||X<- L ]),'\
  1433. ' [F || F <- A, not filelib:is_dir(F) ] end,'\
  1434. 'Squash = fun(L) -> [{filename:basename(F), Read(F) } || F <- L ] end,'\
  1435. 'Zip = fun(A, L) -> {ok,{_,Z}} = zip:create(A, L, [{compress,all},memory]), Z end,'\
  1436. 'Ez = fun(Escript) ->'\
  1437. ' Static = Files([$(ESCRIPT_STATIC)]),'\
  1438. ' Beams = Squash(Files([$(ESCRIPT_BEAMS), $(ESCRIPT_SYS_CONFIG)])),'\
  1439. ' Archive = Beams ++ [{ "static.gz", Zip("static.gz", Static)}],'\
  1440. ' escript:create(Escript, [ $(ESCRIPT_OPTIONS)'\
  1441. ' {archive, Archive, [memory]},'\
  1442. ' {shebang, "$(ESCRIPT_SHEBANG)"},'\
  1443. ' {comment, "$(ESCRIPT_COMMENT)"},'\
  1444. ' {emu_args, " $(ESCRIPT_EMU_ARGS)"}'\
  1445. ' ]),'\
  1446. ' file:change_mode(Escript, 8#755)'\
  1447. 'end,'\
  1448. 'Ez("$(ESCRIPT_NAME)"),'\
  1449. 'halt().'
  1450. endef
  1451. ESCRIPT_COMMAND = $(subst ' ',,$(ESCRIPT_RAW))
  1452. escript:: distclean-escript deps app
  1453. $(gen_verbose) $(ERL) -eval $(ESCRIPT_COMMAND)
  1454. distclean-escript:
  1455. $(gen_verbose) rm -f $(ESCRIPT_NAME)
  1456. # Copyright (c) 2014, Enrique Fernandez <enrique.fernandez@erlang-solutions.com>
  1457. # Copyright (c) 2015, Loïc Hoguin <essen@ninenines.eu>
  1458. # This file is contributed to erlang.mk and subject to the terms of the ISC License.
  1459. .PHONY: eunit
  1460. # Configuration
  1461. # All modules in TEST_DIR
  1462. ifeq ($(strip $(TEST_DIR)),)
  1463. TEST_DIR_MODS =
  1464. else
  1465. TEST_DIR_MODS = $(notdir $(basename $(shell find $(TEST_DIR) -type f -name *.beam)))
  1466. endif
  1467. # All modules in 'ebin'
  1468. EUNIT_EBIN_MODS = $(notdir $(basename $(shell find ebin -type f -name *.beam)))
  1469. # Only those modules in TEST_DIR with no matching module in 'ebin'.
  1470. # This is done to avoid some tests being executed twice.
  1471. EUNIT_MODS = $(filter-out $(patsubst %,%_tests,$(EUNIT_EBIN_MODS)),$(TEST_DIR_MODS))
  1472. TAGGED_EUNIT_TESTS = $(foreach mod,$(EUNIT_EBIN_MODS) $(EUNIT_MODS),{module,$(mod)})
  1473. EUNIT_OPTS ?=
  1474. # Utility functions
  1475. define str-join
  1476. $(shell echo '$(strip $(1))' | sed -e "s/ /,/g")
  1477. endef
  1478. # Core targets.
  1479. tests:: eunit
  1480. help::
  1481. @printf "%s\n" "" \
  1482. "EUnit targets:" \
  1483. " eunit Run all the EUnit tests for this project"
  1484. # Plugin-specific targets.
  1485. EUNIT_RUN_BEFORE ?=
  1486. EUNIT_RUN_AFTER ?=
  1487. EUNIT_RUN = $(ERL) \
  1488. -pa $(TEST_DIR) $(DEPS_DIR)/*/ebin \
  1489. -pz ebin \
  1490. $(EUNIT_RUN_BEFORE) \
  1491. -eval 'case eunit:test([$(call str-join,$(TAGGED_EUNIT_TESTS))],\
  1492. [$(EUNIT_OPTS)]) of ok -> ok; error -> halt(1) end.' \
  1493. $(EUNIT_RUN_AFTER) \
  1494. -eval 'halt(0).'
  1495. eunit: test-build
  1496. $(gen_verbose) $(EUNIT_RUN)
  1497. # Copyright (c) 2013-2015, Loïc Hoguin <essen@ninenines.eu>
  1498. # This file is part of erlang.mk and subject to the terms of the ISC License.
  1499. .PHONY: relx-rel distclean-relx-rel distclean-relx run
  1500. # Configuration.
  1501. RELX_CONFIG ?= $(CURDIR)/relx.config
  1502. RELX ?= $(CURDIR)/relx
  1503. export RELX
  1504. RELX_URL ?= https://github.com/erlware/relx/releases/download/v2.0.0/relx
  1505. RELX_OPTS ?=
  1506. RELX_OUTPUT_DIR ?= _rel
  1507. ifeq ($(firstword $(RELX_OPTS)),-o)
  1508. RELX_OUTPUT_DIR = $(word 2,$(RELX_OPTS))
  1509. else
  1510. RELX_OPTS += -o $(RELX_OUTPUT_DIR)
  1511. endif
  1512. # Core targets.
  1513. ifeq ($(IS_DEP),)
  1514. ifneq ($(wildcard $(RELX_CONFIG)),)
  1515. rel:: distclean-relx-rel relx-rel
  1516. endif
  1517. endif
  1518. distclean:: distclean-relx-rel distclean-relx
  1519. # Plugin-specific targets.
  1520. define relx_fetch
  1521. $(call core_http_get,$(RELX),$(RELX_URL))
  1522. chmod +x $(RELX)
  1523. endef
  1524. $(RELX):
  1525. @$(call relx_fetch)
  1526. relx-rel: $(RELX)
  1527. @$(RELX) -c $(RELX_CONFIG) $(RELX_OPTS)
  1528. distclean-relx-rel:
  1529. $(gen_verbose) rm -rf $(RELX_OUTPUT_DIR)
  1530. distclean-relx:
  1531. $(gen_verbose) rm -rf $(RELX)
  1532. # Run target.
  1533. ifeq ($(wildcard $(RELX_CONFIG)),)
  1534. run:
  1535. else
  1536. define get_relx_release.erl
  1537. {ok, Config} = file:consult("$(RELX_CONFIG)"),
  1538. {release, {Name, _}, _} = lists:keyfind(release, 1, Config),
  1539. io:format("~s", [Name]),
  1540. halt(0).
  1541. endef
  1542. RELX_RELEASE = `$(call erlang,$(get_relx_release.erl))`
  1543. run: all
  1544. @$(RELX_OUTPUT_DIR)/$(RELX_RELEASE)/bin/$(RELX_RELEASE) console
  1545. help::
  1546. @printf "%s\n" "" \
  1547. "Relx targets:" \
  1548. " run Compile the project, build the release and run it"
  1549. endif
  1550. # Copyright (c) 2014, M Robert Martin <rob@version2beta.com>
  1551. # This file is contributed to erlang.mk and subject to the terms of the ISC License.
  1552. .PHONY: shell
  1553. # Configuration.
  1554. SHELL_PATH ?= -pa $(CURDIR)/ebin $(DEPS_DIR)/*/ebin
  1555. SHELL_OPTS ?=
  1556. ALL_SHELL_DEPS_DIRS = $(addprefix $(DEPS_DIR)/,$(SHELL_DEPS))
  1557. # Core targets
  1558. help::
  1559. @printf "%s\n" "" \
  1560. "Shell targets:" \
  1561. " shell Run an erlang shell with SHELL_OPTS or reasonable default"
  1562. # Plugin-specific targets.
  1563. $(foreach dep,$(SHELL_DEPS),$(eval $(call dep_target,$(dep))))
  1564. build-shell-deps: $(ALL_SHELL_DEPS_DIRS)
  1565. @for dep in $(ALL_SHELL_DEPS_DIRS) ; do $(MAKE) -C $$dep ; done
  1566. shell: build-shell-deps
  1567. $(gen_verbose) erl $(SHELL_PATH) $(SHELL_OPTS)
  1568. # Copyright (c) 2015, Loïc Hoguin <essen@ninenines.eu>
  1569. # This file is part of erlang.mk and subject to the terms of the ISC License.
  1570. ifneq ($(wildcard $(DEPS_DIR)/triq),)
  1571. .PHONY: triq
  1572. # Targets.
  1573. tests:: triq
  1574. define triq_check.erl
  1575. code:add_pathsa(["$(CURDIR)/ebin", "$(DEPS_DIR)/*/ebin"]),
  1576. try
  1577. case $(1) of
  1578. all -> [true] =:= lists:usort([triq:check(M) || M <- [$(MODULES)]]);
  1579. module -> triq:check($(2));
  1580. function -> triq:check($(2))
  1581. end
  1582. of
  1583. true -> halt(0);
  1584. _ -> halt(1)
  1585. catch error:undef ->
  1586. io:format("Undefined property or module~n"),
  1587. halt(0)
  1588. end.
  1589. endef
  1590. ifdef t
  1591. ifeq (,$(findstring :,$(t)))
  1592. triq: test-build
  1593. @$(call erlang,$(call triq_check.erl,module,$(t)))
  1594. else
  1595. triq: test-build
  1596. @echo Testing $(t)/0
  1597. @$(call erlang,$(call triq_check.erl,function,$(t)()))
  1598. endif
  1599. else
  1600. triq: test-build
  1601. $(eval MODULES := $(shell find ebin -type f -name \*.beam \
  1602. | sed "s/ebin\//'/;s/\.beam/',/" | sed '$$s/.$$//'))
  1603. $(gen_verbose) $(call erlang,$(call triq_check.erl,all,undefined))
  1604. endif
  1605. endif
  1606. # Copyright (c) 2015, Euen Lopez <euen@inakanetworks.com>
  1607. # This file is part of erlang.mk and subject to the terms of the ISC License.
  1608. .PHONY: xref distclean-xref
  1609. # Configuration.
  1610. ifeq ($(XREF_CONFIG),)
  1611. XREF_ARGS :=
  1612. else
  1613. XREF_ARGS := -c $(XREF_CONFIG)
  1614. endif
  1615. XREFR ?= $(CURDIR)/xrefr
  1616. export XREFR
  1617. XREFR_URL ?= https://github.com/inaka/xref_runner/releases/download/0.2.0/xrefr
  1618. # Core targets.
  1619. help::
  1620. @printf "%s\n" "" \
  1621. "Xref targets:" \
  1622. " xref Run Xrefr using $XREF_CONFIG as config file if defined"
  1623. distclean:: distclean-xref
  1624. # Plugin-specific targets.
  1625. $(XREFR):
  1626. @$(call core_http_get,$(XREFR),$(XREFR_URL))
  1627. @chmod +x $(XREFR)
  1628. xref: deps app $(XREFR)
  1629. $(gen_verbose) $(XREFR) $(XREFR_ARGS)
  1630. distclean-xref:
  1631. $(gen_verbose) rm -rf $(XREFR)
  1632. # Copyright 2015, Viktor Söderqvist <viktor@zuiderkwast.se>
  1633. # This file is part of erlang.mk and subject to the terms of the ISC License.
  1634. COVER_REPORT_DIR = cover
  1635. # utility variables for representing special symbols
  1636. empty :=
  1637. space := $(empty) $(empty)
  1638. comma := ,
  1639. # Hook in coverage to eunit
  1640. ifdef COVER
  1641. ifdef EUNIT_RUN
  1642. EUNIT_RUN_BEFORE += -eval \
  1643. 'case cover:compile_beam_directory("ebin") of \
  1644. {error, _} -> halt(1); \
  1645. _ -> ok \
  1646. end.'
  1647. EUNIT_RUN_AFTER += -eval 'cover:export("eunit.coverdata").'
  1648. endif
  1649. endif
  1650. # Hook in coverage to ct
  1651. ifdef COVER
  1652. ifdef CT_RUN
  1653. # All modules in 'ebin'
  1654. COVER_MODS = $(notdir $(basename $(shell echo ebin/*.beam)))
  1655. test-build:: $(TEST_DIR)/ct.cover.spec
  1656. $(TEST_DIR)/ct.cover.spec:
  1657. @echo Cover mods: $(COVER_MODS)
  1658. $(gen_verbose) printf "%s\n" \
  1659. '{incl_mods,[$(subst $(space),$(comma),$(COVER_MODS))]}.' \
  1660. '{export,"$(CURDIR)/ct.coverdata"}.' > $@
  1661. CT_RUN += -cover $(TEST_DIR)/ct.cover.spec
  1662. endif
  1663. endif
  1664. # Core targets
  1665. ifdef COVER
  1666. ifneq ($(COVER_REPORT_DIR),)
  1667. tests::
  1668. @$(MAKE) --no-print-directory cover-report
  1669. endif
  1670. endif
  1671. clean:: coverdata-clean
  1672. ifneq ($(COVER_REPORT_DIR),)
  1673. distclean:: cover-report-clean
  1674. endif
  1675. help::
  1676. @printf "%s\n" "" \
  1677. "Cover targets:" \
  1678. " cover-report Generate a HTML coverage report from previously collected" \
  1679. " cover data." \
  1680. " all.coverdata Merge {eunit,ct}.coverdata into one coverdata file." \
  1681. "" \
  1682. "If COVER=1 is set, coverage data is generated by the targets eunit and ct. The" \
  1683. "target tests additionally generates a HTML coverage report from the combined" \
  1684. "coverdata files from each of these testing tools. HTML reports can be disabled" \
  1685. "by setting COVER_REPORT_DIR to empty."
  1686. # Plugin specific targets
  1687. COVERDATA = $(filter-out all.coverdata,$(wildcard *.coverdata))
  1688. .PHONY: coverdata-clean
  1689. coverdata-clean:
  1690. $(gen_verbose) rm -f *.coverdata ct.cover.spec
  1691. # Merge all coverdata files into one.
  1692. all.coverdata: $(COVERDATA)
  1693. $(gen_verbose) $(ERL) -eval ' \
  1694. $(foreach f,$(COVERDATA),cover:import("$(f)") == ok orelse halt(1),) \
  1695. cover:export("$@"), halt(0).'
  1696. # These are only defined if COVER_REPORT_DIR is non-empty. Set COVER_REPORT_DIR to
  1697. # empty if you want the coverdata files but not the HTML report.
  1698. ifneq ($(COVER_REPORT_DIR),)
  1699. .PHONY: cover-report-clean cover-report
  1700. cover-report-clean:
  1701. $(gen_verbose) rm -rf $(COVER_REPORT_DIR)
  1702. ifeq ($(COVERDATA),)
  1703. cover-report:
  1704. else
  1705. # Modules which include eunit.hrl always contain one line without coverage
  1706. # because eunit defines test/0 which is never called. We compensate for this.
  1707. EUNIT_HRL_MODS = $(subst $(space),$(comma),$(shell \
  1708. grep -e '^\s*-include.*include/eunit\.hrl"' src/*.erl \
  1709. | sed "s/^src\/\(.*\)\.erl:.*/'\1'/" | uniq))
  1710. define cover_report.erl
  1711. $(foreach f,$(COVERDATA),cover:import("$(f)") == ok orelse halt(1),)
  1712. Ms = cover:imported_modules(),
  1713. [cover:analyse_to_file(M, "$(COVER_REPORT_DIR)/" ++ atom_to_list(M)
  1714. ++ ".COVER.html", [html]) || M <- Ms],
  1715. Report = [begin {ok, R} = cover:analyse(M, module), R end || M <- Ms],
  1716. EunitHrlMods = [$(EUNIT_HRL_MODS)],
  1717. Report1 = [{M, {Y, case lists:member(M, EunitHrlMods) of
  1718. true -> N - 1; false -> N end}} || {M, {Y, N}} <- Report],
  1719. TotalY = lists:sum([Y || {_, {Y, _}} <- Report1]),
  1720. TotalN = lists:sum([N || {_, {_, N}} <- Report1]),
  1721. TotalPerc = round(100 * TotalY / (TotalY + TotalN)),
  1722. {ok, F} = file:open("$(COVER_REPORT_DIR)/index.html", [write]),
  1723. io:format(F, "<!DOCTYPE html><html>~n"
  1724. "<head><meta charset=\"UTF-8\">~n"
  1725. "<title>Coverage report</title></head>~n"
  1726. "<body>~n", []),
  1727. io:format(F, "<h1>Coverage</h1>~n<p>Total: ~p%</p>~n", [TotalPerc]),
  1728. io:format(F, "<table><tr><th>Module</th><th>Coverage</th></tr>~n", []),
  1729. [io:format(F, "<tr><td><a href=\"~p.COVER.html\">~p</a></td>"
  1730. "<td>~p%</td></tr>~n",
  1731. [M, M, round(100 * Y / (Y + N))]) || {M, {Y, N}} <- Report1],
  1732. How = "$(subst $(space),$(comma)$(space),$(basename $(COVERDATA)))",
  1733. Date = "$(shell date -u "+%Y-%m-%dT%H:%M:%SZ")",
  1734. io:format(F, "</table>~n"
  1735. "<p>Generated using ~s and erlang.mk on ~s.</p>~n"
  1736. "</body></html>", [How, Date]),
  1737. halt().
  1738. endef
  1739. cover-report:
  1740. $(gen_verbose) mkdir -p $(COVER_REPORT_DIR)
  1741. $(gen_verbose) $(call erlang,$(cover_report.erl))
  1742. endif
  1743. endif # ifneq ($(COVER_REPORT_DIR),)