deps.mk 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536
  1. # Copyright (c) 2013-2015, Loïc Hoguin <essen@ninenines.eu>
  2. # This file is part of erlang.mk and subject to the terms of the ISC License.
  3. .PHONY: distclean-deps distclean-pkg pkg-list pkg-search
  4. # Configuration.
  5. IGNORE_DEPS ?=
  6. DEPS_DIR ?= $(CURDIR)/deps
  7. export DEPS_DIR
  8. REBAR_DEPS_DIR = $(DEPS_DIR)
  9. export REBAR_DEPS_DIR
  10. ALL_DEPS_DIRS = $(addprefix $(DEPS_DIR)/,$(filter-out $(IGNORE_DEPS),$(DEPS)))
  11. ifeq ($(filter $(DEPS_DIR),$(subst :, ,$(ERL_LIBS))),)
  12. ifeq ($(ERL_LIBS),)
  13. ERL_LIBS = $(DEPS_DIR)
  14. else
  15. ERL_LIBS := $(ERL_LIBS):$(DEPS_DIR)
  16. endif
  17. endif
  18. export ERL_LIBS
  19. PKG_FILE2 ?= $(CURDIR)/.erlang.mk.packages.v2
  20. export PKG_FILE2
  21. PKG_FILE_URL ?= https://raw.githubusercontent.com/ninenines/erlang.mk/master/packages.v2.tsv
  22. # Verbosity.
  23. dep_verbose_0 = @echo " DEP " $(1);
  24. dep_verbose = $(dep_verbose_$(V))
  25. # Core targets.
  26. ifneq ($(SKIP_DEPS),)
  27. deps::
  28. else
  29. deps:: $(ALL_DEPS_DIRS)
  30. @for dep in $(ALL_DEPS_DIRS) ; do \
  31. if [ -f $$dep/GNUmakefile ] || [ -f $$dep/makefile ] || [ -f $$dep/Makefile ] ; then \
  32. $(MAKE) -C $$dep IS_DEP=1 || exit $$? ; \
  33. else \
  34. echo "ERROR: No Makefile to build dependency $$dep." ; \
  35. exit 1 ; \
  36. fi ; \
  37. done
  38. endif
  39. distclean:: distclean-deps distclean-pkg
  40. # Deps related targets.
  41. # @todo rename GNUmakefile and makefile into Makefile first, if they exist
  42. # While Makefile file could be GNUmakefile or makefile,
  43. # in practice only Makefile is needed so far.
  44. define dep_autopatch
  45. if [ -f $(DEPS_DIR)/$(1)/Makefile ]; then \
  46. if [ 0 != `grep -c "include ../\w*\.mk" $(DEPS_DIR)/$(1)/Makefile` ]; then \
  47. $(call dep_autopatch2,$(1)); \
  48. elif [ 0 != `grep -ci rebar $(DEPS_DIR)/$(1)/Makefile` ]; then \
  49. $(call dep_autopatch2,$(1)); \
  50. elif [ 0 != `find $(DEPS_DIR)/$(1)/ -type f -name \*.mk -not -name erlang.mk | xargs grep -ci rebar` ]; then \
  51. $(call dep_autopatch2,$(1)); \
  52. else \
  53. $(call dep_autopatch_erlang_mk,$(1)); \
  54. fi \
  55. else \
  56. if [ ! -d $(DEPS_DIR)/$(1)/src/ ]; then \
  57. $(call dep_autopatch_noop,$(1)); \
  58. else \
  59. $(call dep_autopatch2,$(1)); \
  60. fi \
  61. fi
  62. endef
  63. define dep_autopatch2
  64. if [ -f $(DEPS_DIR)/$(1)/rebar.config -o -f $(DEPS_DIR)/$(1)/rebar.config.script ]; then \
  65. $(call dep_autopatch_rebar_utils); \
  66. $(call dep_autopatch_rebar,$(1)); \
  67. else \
  68. $(call dep_autopatch_gen,$(1)); \
  69. fi
  70. endef
  71. define dep_autopatch_noop
  72. printf "noop:\n" > $(DEPS_DIR)/$(1)/Makefile
  73. endef
  74. # Overwrite erlang.mk with the current file by default.
  75. ifeq ($(NO_AUTOPATCH_ERLANG_MK),)
  76. define dep_autopatch_erlang_mk
  77. rm -f $(DEPS_DIR)/$(1)/erlang.mk; \
  78. cd $(DEPS_DIR)/$(1)/ && ln -s ../../erlang.mk; \
  79. $(call erlang,$(call dep_autopatch_appsrc.erl,$(1)))
  80. endef
  81. else
  82. define dep_autopatch_erlang_mk
  83. $(call erlang,$(call dep_autopatch_appsrc.erl,$(1)))
  84. endef
  85. endif
  86. define dep_autopatch_gen
  87. printf "%s\n" \
  88. "ERLC_OPTS = +debug_info" \
  89. "include ../../erlang.mk" > $(DEPS_DIR)/$(1)/Makefile; \
  90. $(call erlang,$(call dep_autopatch_appsrc.erl,$(1)))
  91. endef
  92. define dep_autopatch_rebar_utils
  93. mkdir -p $(ERLANG_MK_TMP)/ebin; \
  94. if [ ! -f $(ERLANG_MK_TMP)/rebar.hrl ]; then \
  95. $(call core_http_get,$(ERLANG_MK_TMP)/rebar.hrl,https://raw.githubusercontent.com/rebar/rebar/791db716b5a3a7671e0b351f95ddf24b848ee173/include/rebar.hrl); \
  96. fi; \
  97. if [ ! -f $(ERLANG_MK_TMP)/rebar_utils.erl ]; then \
  98. $(call core_http_get,$(ERLANG_MK_TMP)/rebar_utils.erl,https://raw.githubusercontent.com/rebar/rebar/791db716b5a3a7671e0b351f95ddf24b848ee173/src/rebar_utils.erl); \
  99. fi; \
  100. if [ ! -f $(ERLANG_MK_TMP)/ebin/rebar_utils.beam ]; then \
  101. erlc -o $(ERLANG_MK_TMP)/ebin $(ERLANG_MK_TMP)/rebar_utils.erl; \
  102. fi; \
  103. if [ ! -f $(ERLANG_MK_TMP)/rebar_log.erl ]; then \
  104. $(call core_http_get,$(ERLANG_MK_TMP)/rebar_log.erl,https://raw.githubusercontent.com/rebar/rebar/791db716b5a3a7671e0b351f95ddf24b848ee173/src/rebar_log.erl); \
  105. fi; \
  106. if [ ! -f $(ERLANG_MK_TMP)/ebin/rebar_log.beam ]; then \
  107. erlc -o $(ERLANG_MK_TMP)/ebin $(ERLANG_MK_TMP)/rebar_log.erl; \
  108. fi
  109. endef
  110. define dep_autopatch_rebar
  111. if [ -f $(DEPS_DIR)/$(1)/Makefile ]; then \
  112. mv $(DEPS_DIR)/$(1)/Makefile $(DEPS_DIR)/$(1)/Makefile.orig.mk; \
  113. fi; \
  114. $(call erlang,$(call dep_autopatch_rebar.erl,$(1))); \
  115. $(call erlang,$(call dep_autopatch_appsrc.erl,$(1)))
  116. endef
  117. define dep_autopatch_rebar.erl
  118. application:set_env(rebar, log_level, debug),
  119. Conf1 = case file:consult("$(DEPS_DIR)/$(1)/rebar.config") of
  120. {ok, Conf0} -> Conf0;
  121. _ -> []
  122. end,
  123. {Conf, OsEnv} = fun() ->
  124. case filelib:is_file("$(DEPS_DIR)/$(1)/rebar.config.script") of
  125. false -> {Conf1, []};
  126. true ->
  127. Bindings0 = erl_eval:new_bindings(),
  128. Bindings1 = erl_eval:add_binding('CONFIG', Conf1, Bindings0),
  129. Bindings = erl_eval:add_binding('SCRIPT', "$(DEPS_DIR)/$(1)/rebar.config.script", Bindings1),
  130. Before = os:getenv(),
  131. {ok, Conf2} = file:script("$(DEPS_DIR)/$(1)/rebar.config.script", Bindings),
  132. {Conf2, lists:foldl(fun(E, Acc) -> lists:delete(E, Acc) end, os:getenv(), Before)}
  133. end
  134. end(),
  135. Write = fun (Text) ->
  136. file:write_file("$(DEPS_DIR)/$(1)/Makefile", Text, [append])
  137. end,
  138. Escape = fun (Text) ->
  139. re:replace(Text, "\\\\$$$$", "\$$$$$$$$", [global, {return, list}])
  140. end,
  141. Write("IGNORE_DEPS = edown eper eunit_formatters meck node_package "
  142. "rebar_lock_deps_plugin rebar_vsn_plugin reltool_util\n\n"),
  143. Write("C_SRC_DIR = /path/do/not/exist\n\n"),
  144. Write("DRV_CFLAGS = -fPIC\nexport DRV_CFLAGS\n\n"),
  145. fun() ->
  146. Write("ERLC_OPTS = +debug_info\n"),
  147. case lists:keyfind(erl_opts, 1, Conf) of
  148. false -> ok;
  149. {_, ErlOpts} ->
  150. lists:foreach(fun
  151. ({d, D}) ->
  152. Write("ERLC_OPTS += -D" ++ atom_to_list(D) ++ "=1\n");
  153. ({platform_define, Regex, D}) ->
  154. case rebar_utils:is_arch(Regex) of
  155. true -> Write("ERLC_OPTS += -D" ++ atom_to_list(D) ++ "=1\n");
  156. false -> ok
  157. end;
  158. ({parse_transform, PT}) ->
  159. Write("ERLC_OPTS += +'{parse_transform, " ++ atom_to_list(PT) ++ "}'\n");
  160. (_) -> ok
  161. end, ErlOpts)
  162. end,
  163. Write("\n")
  164. end(),
  165. fun() ->
  166. File = case lists:keyfind(deps, 1, Conf) of
  167. false -> [];
  168. {_, Deps} ->
  169. [begin
  170. Name = element(1, Dep),
  171. {Method, Repo, Commit} = case element(3, Dep) of
  172. {git, R} -> {git, R, master};
  173. {M, R, {branch, C}} -> {M, R, C};
  174. {M, R, {tag, C}} -> {M, R, C};
  175. {M, R, C} -> {M, R, C}
  176. end,
  177. Write(io_lib:format("DEPS += ~s\ndep_~s = ~s ~s ~s~n", [Name, Name, Method, Repo, Commit]))
  178. end || Dep <- Deps, tuple_size(Dep) > 2]
  179. end
  180. end(),
  181. fun() ->
  182. First = case lists:keyfind(erl_first_files, 1, Conf) of false -> []; {_, Files} ->
  183. Names = [[" ", begin "lre." ++ Elif = lists:reverse(F), lists:reverse(Elif) end]
  184. || "src/" ++ F <- Files],
  185. Write(io_lib:format("COMPILE_FIRST +=~s\n", [Names]))
  186. end
  187. end(),
  188. FindFirst = fun(F, Fd) ->
  189. case io:parse_erl_form(Fd, undefined) of
  190. {ok, {attribute, _,compile, {parse_transform, PT}}, _} ->
  191. [PT, F(F, Fd)];
  192. {ok, {attribute, _, include, Hrl}, _} ->
  193. case file:open("$(DEPS_DIR)/$(1)/include/" ++ Hrl, [read]) of
  194. {ok, HrlFd} -> [F(F, HrlFd), F(F, Fd)];
  195. _ ->
  196. case file:open("$(DEPS_DIR)/$(1)/src/" ++ Hrl, [read]) of
  197. {ok, HrlFd} -> [F(F, HrlFd), F(F, Fd)];
  198. _ -> [F(F, Fd)]
  199. end
  200. end;
  201. {ok, {attribute, _, include_lib, "$(1)/include/" ++ Hrl}, _} ->
  202. {ok, HrlFd} = file:open("$(DEPS_DIR)/$(1)/include/" ++ Hrl, [read]),
  203. [F(F, HrlFd), F(F, Fd)];
  204. {ok, {attribute, _, import, {Imp, _}}, _} ->
  205. case file:open("$(DEPS_DIR)/$(1)/src/" ++ atom_to_list(Imp) ++ ".erl", [read]) of
  206. {ok, ImpFd} -> [Imp, F(F, ImpFd), F(F, Fd)];
  207. _ -> [F(F, Fd)]
  208. end;
  209. {eof, _} ->
  210. file:close(Fd),
  211. [];
  212. _ ->
  213. F(F, Fd)
  214. end
  215. end,
  216. fun() ->
  217. ErlFiles = filelib:wildcard("$(DEPS_DIR)/$(1)/src/*.erl"),
  218. First0 = lists:usort(lists:flatten([begin
  219. {ok, Fd} = file:open(F, [read]),
  220. FindFirst(FindFirst, Fd)
  221. end || F <- ErlFiles])),
  222. First = lists:flatten([begin
  223. {ok, Fd} = file:open("$(DEPS_DIR)/$(1)/src/" ++ atom_to_list(M) ++ ".erl", [read]),
  224. FindFirst(FindFirst, Fd)
  225. end || M <- First0, lists:member("$(DEPS_DIR)/$(1)/src/" ++ atom_to_list(M) ++ ".erl", ErlFiles)]) ++ First0,
  226. Write(["COMPILE_FIRST +=", [[" ", atom_to_list(M)] || M <- First,
  227. lists:member("$(DEPS_DIR)/$(1)/src/" ++ atom_to_list(M) ++ ".erl", ErlFiles)], "\n"])
  228. end(),
  229. Write("\n\nrebar_dep: preprocess pre-deps deps pre-app app\n"),
  230. Write("\npreprocess::\n"),
  231. Write("\npre-deps::\n"),
  232. Write("\npre-app::\n"),
  233. PatchHook = fun(Cmd) ->
  234. case Cmd of
  235. "make -C" ++ _ -> Escape(Cmd);
  236. "gmake -C" ++ _ -> Escape(Cmd);
  237. "make " ++ Cmd1 -> "make -f Makefile.orig.mk " ++ Escape(Cmd1);
  238. "gmake " ++ Cmd1 -> "gmake -f Makefile.orig.mk " ++ Escape(Cmd1);
  239. _ -> Escape(Cmd)
  240. end
  241. end,
  242. fun() ->
  243. case lists:keyfind(pre_hooks, 1, Conf) of
  244. false -> ok;
  245. {_, Hooks} ->
  246. [case H of
  247. {'get-deps', Cmd} ->
  248. Write("\npre-deps::\n\t" ++ PatchHook(Cmd) ++ "\n");
  249. {compile, Cmd} ->
  250. Write("\npre-app::\n\t" ++ PatchHook(Cmd) ++ "\n");
  251. {Regex, compile, Cmd} ->
  252. case rebar_utils:is_arch(Regex) of
  253. true -> Write("\npre-app::\n\t" ++ PatchHook(Cmd) ++ "\n");
  254. false -> ok
  255. end;
  256. _ -> ok
  257. end || H <- Hooks]
  258. end
  259. end(),
  260. ShellToMk = fun(V) ->
  261. re:replace(V, "(\\\\$$$$)(\\\\w*)", "\\\\1(\\\\2)", [{return, list}, global])
  262. end,
  263. PortSpecs = fun() ->
  264. case lists:keyfind(port_specs, 1, Conf) of
  265. false ->
  266. case filelib:is_dir("$(DEPS_DIR)/$(1)/c_src") of
  267. false -> [];
  268. true ->
  269. [{"priv/" ++ proplists:get_value(so_name, Conf, "$(1)_drv.so"),
  270. proplists:get_value(port_sources, Conf, ["c_src/*.c"]), []}]
  271. end;
  272. {_, Specs} ->
  273. lists:flatten([case S of
  274. {Output, Input} -> {ShellToMk(Output), Input, []};
  275. {Regex, Output, Input} ->
  276. case rebar_utils:is_arch(Regex) of
  277. true -> {ShellToMk(Output), Input, []};
  278. false -> []
  279. end;
  280. {Regex, Output, Input, [{env, Env}]} ->
  281. case rebar_utils:is_arch(Regex) of
  282. true -> {ShellToMk(Output), Input, Env};
  283. false -> []
  284. end
  285. end || S <- Specs])
  286. end
  287. end(),
  288. PortSpecWrite = fun (Text) ->
  289. file:write_file("$(DEPS_DIR)/$(1)/c_src/Makefile.erlang.mk", Text, [append])
  290. end,
  291. case PortSpecs of
  292. [] -> ok;
  293. _ ->
  294. Write("\npre-app::\n\t$$$$\(MAKE) -f c_src/Makefile.erlang.mk\n"),
  295. PortSpecWrite(io_lib:format("ERL_CFLAGS = -finline-functions -Wall -fPIC -I ~s/erts-~s/include -I ~s\n",
  296. [code:root_dir(), erlang:system_info(version), code:lib_dir(erl_interface, include)])),
  297. PortSpecWrite(io_lib:format("ERL_LDFLAGS = -L ~s -lerl_interface -lei\n",
  298. [code:lib_dir(erl_interface, lib)])),
  299. PortSpecWrite(["\nERLANG_ARCH = ", rebar_utils:wordsize(), "\n"]),
  300. [PortSpecWrite(["\n", E, "\n"]) || E <- OsEnv],
  301. FilterEnv = fun(Env) ->
  302. lists:flatten([case E of
  303. {_, _} -> E;
  304. {Regex, K, V} ->
  305. case rebar_utils:is_arch(Regex) of
  306. true -> {K, V};
  307. false -> []
  308. end
  309. end || E <- Env])
  310. end,
  311. MergeEnv = fun(Env) ->
  312. lists:foldl(fun ({K, V}, Acc) ->
  313. case lists:keyfind(K, 1, Acc) of
  314. false -> [{K, rebar_utils:expand_env_variable(V, K, "")}|Acc];
  315. {_, V0} -> [{K, rebar_utils:expand_env_variable(V, K, V0)}|Acc]
  316. end
  317. end, [], Env)
  318. end,
  319. PortEnv = case lists:keyfind(port_env, 1, Conf) of
  320. false -> [];
  321. {_, PortEnv0} -> FilterEnv(PortEnv0)
  322. end,
  323. PortSpec = fun ({Output, Input0, Env}) ->
  324. filelib:ensure_dir("$(DEPS_DIR)/$(1)/" ++ Output),
  325. Input = [[" ", I] || I <- Input0],
  326. PortSpecWrite([
  327. [["\n", K, " = ", ShellToMk(V)] || {K, V} <- lists:reverse(MergeEnv(PortEnv))],
  328. "\n\nall:: ", Output, "\n\n",
  329. "%.o: %.c\n\t$$$$\(CC) -c -o $$$$\@ $$$$\< $$$$\(CFLAGS) $$$$\(ERL_CFLAGS) $$$$\(DRV_CFLAGS) $$$$\(EXE_CFLAGS)\n\n",
  330. "%.o: %.C\n\t$$$$\(CXX) -c -o $$$$\@ $$$$\< $$$$\(CXXFLAGS) $$$$\(ERL_CFLAGS) $$$$\(DRV_CFLAGS) $$$$\(EXE_CFLAGS)\n\n",
  331. "%.o: %.cc\n\t$$$$\(CXX) -c -o $$$$\@ $$$$\< $$$$\(CXXFLAGS) $$$$\(ERL_CFLAGS) $$$$\(DRV_CFLAGS) $$$$\(EXE_CFLAGS)\n\n",
  332. "%.o: %.cpp\n\t$$$$\(CXX) -c -o $$$$\@ $$$$\< $$$$\(CXXFLAGS) $$$$\(ERL_CFLAGS) $$$$\(DRV_CFLAGS) $$$$\(EXE_CFLAGS)\n\n",
  333. [[Output, ": ", K, " = ", ShellToMk(V), "\n"] || {K, V} <- lists:reverse(MergeEnv(FilterEnv(Env)))],
  334. Output, ": $$$$\(foreach ext,.c .C .cc .cpp,",
  335. "$$$$\(patsubst %$$$$\(ext),%.o,$$$$\(filter %$$$$\(ext),$$$$\(wildcard", Input, "))))\n",
  336. "\t$$$$\(CC) -o $$$$\@ $$$$\? $$$$\(LDFLAGS) $$$$\(ERL_LDFLAGS) $$$$\(DRV_LDFLAGS) $$$$\(EXE_LDFLAGS)",
  337. case filename:extension(Output) of
  338. [] -> "\n";
  339. _ -> " -shared\n"
  340. end])
  341. end,
  342. [PortSpec(S) || S <- PortSpecs]
  343. end,
  344. Write("\ninclude ../../erlang.mk"),
  345. PatchPlugin = fun(ErlFile) ->
  346. {ok, F0} = file:read_file(ErlFile),
  347. F = re:replace(F0, "rebar_config:", "rebar_config_", [global]),
  348. ok = file:write_file(ErlFile, [F,
  349. "\nrebar_config_get(_, current_command, _) -> compile.\n"
  350. ])
  351. end,
  352. RunPlugin = fun(Plugin, Step) ->
  353. case erlang:function_exported(Plugin, Step, 2) of
  354. false -> ok;
  355. true ->
  356. c:cd("$(DEPS_DIR)/$(1)/"),
  357. Ret = Plugin:Step(Conf, undefined),
  358. io:format("rebar plugin ~p step ~p ret ~p~n", [Plugin, Step, Ret])
  359. end
  360. end,
  361. fun() ->
  362. case lists:keyfind(plugins, 1, Conf) of
  363. false -> ok;
  364. {_, Plugins} ->
  365. [begin
  366. case lists:keyfind(deps, 1, Conf) of
  367. false -> ok;
  368. {_, Deps} ->
  369. case lists:keyfind(P, 1, Deps) of
  370. false -> ok;
  371. _ ->
  372. Path = "$(DEPS_DIR)/" ++ atom_to_list(P),
  373. io:format("~s", [os:cmd("$(MAKE) -C $(DEPS_DIR)/$(1) " ++ Path)]),
  374. io:format("~s", [os:cmd("$(MAKE) -C " ++ Path ++ " IS_DEP=1")]),
  375. code:add_patha(Path ++ "/ebin")
  376. end
  377. end
  378. end || P <- Plugins],
  379. [case code:load_file(P) of
  380. {module, P} -> ok;
  381. _ ->
  382. case lists:keyfind(plugin_dir, 1, Conf) of
  383. false -> ok;
  384. {_, PluginsDir} ->
  385. ErlFile = "$(DEPS_DIR)/$(1)/" ++ PluginsDir ++ "/" ++ atom_to_list(P) ++ ".erl",
  386. PatchPlugin(ErlFile),
  387. {ok, P, Bin} = compile:file(ErlFile, [binary]),
  388. {module, P} = code:load_binary(P, ErlFile, Bin)
  389. end
  390. end || P <- Plugins],
  391. [RunPlugin(P, preprocess) || P <- Plugins],
  392. [RunPlugin(P, pre_compile) || P <- Plugins]
  393. end
  394. end(),
  395. halt()
  396. endef
  397. define dep_autopatch_appsrc.erl
  398. AppSrcOut = "$(DEPS_DIR)/$(1)/src/$(1).app.src",
  399. AppSrcIn = case filelib:is_regular(AppSrcOut) of false -> "$(DEPS_DIR)/$(1)/ebin/$(1).app"; true -> AppSrcOut end,
  400. case filelib:is_regular(AppSrcIn) of
  401. false -> ok;
  402. true ->
  403. fun() ->
  404. {ok, [{application, $(1), L}]} = file:consult(AppSrcIn),
  405. L2 = lists:keystore(modules, 1, L, {modules, []}),
  406. L3 = case lists:keyfind(vsn, 1, L2) of {vsn, git} -> lists:keyreplace(vsn, 1, L2, {vsn, "git"}); _ -> L2 end,
  407. ok = file:write_file(AppSrcOut, io_lib:format("~p.~n", [{application, $(1), L3}]))
  408. end(),
  409. case AppSrcOut of AppSrcIn -> ok; _ -> ok = file:delete(AppSrcIn) end
  410. end,
  411. halt()
  412. endef
  413. define dep_fetch
  414. if [ "$$$$VS" = "git" ]; then \
  415. git clone -q -n -- $$$$REPO $(DEPS_DIR)/$(1); \
  416. cd $(DEPS_DIR)/$(1) && git checkout -q $$$$COMMIT; \
  417. elif [ "$$$$VS" = "hg" ]; then \
  418. hg clone -q -U $$$$REPO $(DEPS_DIR)/$(1); \
  419. cd $(DEPS_DIR)/$(1) && hg update -q $$$$COMMIT; \
  420. elif [ "$$$$VS" = "svn" ]; then \
  421. svn checkout -q $$$$REPO $(DEPS_DIR)/$(1); \
  422. elif [ "$$$$VS" = "cp" ]; then \
  423. cp -R $$$$REPO $(DEPS_DIR)/$(1); \
  424. else \
  425. echo "Unknown or invalid dependency: $(1). Please consult the erlang.mk README for instructions." >&2; \
  426. exit 78; \
  427. fi
  428. endef
  429. define dep_target
  430. $(DEPS_DIR)/$(1):
  431. @mkdir -p $(DEPS_DIR)
  432. ifeq (,$(dep_$(1)))
  433. @if [ ! -f $(PKG_FILE2) ]; then $(call core_http_get,$(PKG_FILE2),$(PKG_FILE_URL)); fi
  434. $(dep_verbose) DEPPKG=$$$$(awk 'BEGIN { FS = "\t" }; $$$$1 == "$(1)" { print $$$$2 " " $$$$3 " " $$$$4 }' $(PKG_FILE2);); \
  435. VS=$$$$(echo $$$$DEPPKG | cut -d " " -f1); \
  436. REPO=$$$$(echo $$$$DEPPKG | cut -d " " -f2); \
  437. COMMIT=$$$$(echo $$$$DEPPKG | cut -d " " -f3); \
  438. $(call dep_fetch,$(1))
  439. else
  440. ifeq (1,$(words $(dep_$(1))))
  441. $(dep_verbose) VS=git; \
  442. REPO=$(dep_$(1)); \
  443. COMMIT=master; \
  444. $(call dep_fetch,$(1))
  445. else
  446. ifeq (2,$(words $(dep_$(1))))
  447. $(dep_verbose) VS=git; \
  448. REPO=$(word 1,$(dep_$(1))); \
  449. COMMIT=$(word 2,$(dep_$(1))); \
  450. $(call dep_fetch,$(1))
  451. else
  452. $(dep_verbose) VS=$(word 1,$(dep_$(1))); \
  453. REPO=$(word 2,$(dep_$(1))); \
  454. COMMIT=$(word 3,$(dep_$(1))); \
  455. $(call dep_fetch,$(1))
  456. endif
  457. endif
  458. endif
  459. @if [ -f $(DEPS_DIR)/$(1)/configure.ac ]; then \
  460. echo " AUTO " $(1); \
  461. cd $(DEPS_DIR)/$(1) && autoreconf -vif; \
  462. fi
  463. -@if [ -f $(DEPS_DIR)/$(1)/configure ]; then \
  464. echo " CONF " $(1); \
  465. cd $(DEPS_DIR)/$(1) && ./configure; \
  466. fi
  467. ifeq ($(filter $(1),$(NO_AUTOPATCH)),)
  468. @$(call dep_autopatch,$(1))
  469. endif
  470. endef
  471. $(foreach dep,$(DEPS),$(eval $(call dep_target,$(dep))))
  472. distclean-deps:
  473. $(gen_verbose) rm -rf $(DEPS_DIR)
  474. # Packages related targets.
  475. $(PKG_FILE2):
  476. @$(call core_http_get,$(PKG_FILE2),$(PKG_FILE_URL))
  477. pkg-list: $(PKG_FILE2)
  478. @cat $(PKG_FILE2) | awk 'BEGIN { FS = "\t" }; { print \
  479. "Name:\t\t" $$1 "\n" \
  480. "Repository:\t" $$3 "\n" \
  481. "Website:\t" $$5 "\n" \
  482. "Description:\t" $$6 "\n" }'
  483. ifdef q
  484. pkg-search: $(PKG_FILE2)
  485. @cat $(PKG_FILE2) | grep -i ${q} | awk 'BEGIN { FS = "\t" }; { print \
  486. "Name:\t\t" $$1 "\n" \
  487. "Repository:\t" $$3 "\n" \
  488. "Website:\t" $$5 "\n" \
  489. "Description:\t" $$6 "\n" }'
  490. else
  491. pkg-search:
  492. $(error Usage: $(MAKE) pkg-search q=STRING)
  493. endif
  494. ifeq ($(PKG_FILE2),$(CURDIR)/.erlang.mk.packages.v2)
  495. distclean-pkg:
  496. $(gen_verbose) rm -f $(PKG_FILE2)
  497. endif
  498. help::
  499. @printf "%s\n" "" \
  500. "Package-related targets:" \
  501. " pkg-list List all known packages" \
  502. " pkg-search q=STRING Search for STRING in the package index"