deps.mk 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539
  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"),
  143. Write("C_SRC_DIR = /path/do/not/exist\n"),
  144. Write("DRV_CFLAGS = -fPIC\nexport DRV_CFLAGS\n"),
  145. Write(["ERLANG_ARCH = ", rebar_utils:wordsize(), "\nexport ERLANG_ARCH\n"]),
  146. fun() ->
  147. Write("ERLC_OPTS = +debug_info\n"),
  148. case lists:keyfind(erl_opts, 1, Conf) of
  149. false -> ok;
  150. {_, ErlOpts} ->
  151. lists:foreach(fun
  152. ({d, D}) ->
  153. Write("ERLC_OPTS += -D" ++ atom_to_list(D) ++ "=1\n");
  154. ({platform_define, Regex, D}) ->
  155. case rebar_utils:is_arch(Regex) of
  156. true -> Write("ERLC_OPTS += -D" ++ atom_to_list(D) ++ "=1\n");
  157. false -> ok
  158. end;
  159. ({parse_transform, PT}) ->
  160. Write("ERLC_OPTS += +'{parse_transform, " ++ atom_to_list(PT) ++ "}'\n");
  161. (_) -> ok
  162. end, ErlOpts)
  163. end,
  164. Write("\n")
  165. end(),
  166. fun() ->
  167. File = case lists:keyfind(deps, 1, Conf) of
  168. false -> [];
  169. {_, Deps} ->
  170. [begin
  171. Name = element(1, Dep),
  172. {Method, Repo, Commit} = case element(3, Dep) of
  173. {git, R} -> {git, R, master};
  174. {M, R, {branch, C}} -> {M, R, C};
  175. {M, R, {tag, C}} -> {M, R, C};
  176. {M, R, C} -> {M, R, C}
  177. end,
  178. Write(io_lib:format("DEPS += ~s\ndep_~s = ~s ~s ~s~n", [Name, Name, Method, Repo, Commit]))
  179. end || Dep <- Deps, tuple_size(Dep) > 2]
  180. end
  181. end(),
  182. fun() ->
  183. First = case lists:keyfind(erl_first_files, 1, Conf) of false -> []; {_, Files} ->
  184. Names = [[" ", begin "lre." ++ Elif = lists:reverse(F), lists:reverse(Elif) end]
  185. || "src/" ++ F <- Files],
  186. Write(io_lib:format("COMPILE_FIRST +=~s\n", [Names]))
  187. end
  188. end(),
  189. FindFirst = fun(F, Fd) ->
  190. case io:parse_erl_form(Fd, undefined) of
  191. {ok, {attribute, _,compile, {parse_transform, PT}}, _} ->
  192. [PT, F(F, Fd)];
  193. {ok, {attribute, _, include, Hrl}, _} ->
  194. case file:open("$(DEPS_DIR)/$(1)/include/" ++ Hrl, [read]) of
  195. {ok, HrlFd} -> [F(F, HrlFd), F(F, Fd)];
  196. _ ->
  197. case file:open("$(DEPS_DIR)/$(1)/src/" ++ Hrl, [read]) of
  198. {ok, HrlFd} -> [F(F, HrlFd), F(F, Fd)];
  199. _ -> [F(F, Fd)]
  200. end
  201. end;
  202. {ok, {attribute, _, include_lib, "$(1)/include/" ++ Hrl}, _} ->
  203. {ok, HrlFd} = file:open("$(DEPS_DIR)/$(1)/include/" ++ Hrl, [read]),
  204. [F(F, HrlFd), F(F, Fd)];
  205. {ok, {attribute, _, import, {Imp, _}}, _} ->
  206. case file:open("$(DEPS_DIR)/$(1)/src/" ++ atom_to_list(Imp) ++ ".erl", [read]) of
  207. {ok, ImpFd} -> [Imp, F(F, ImpFd), F(F, Fd)];
  208. _ -> [F(F, Fd)]
  209. end;
  210. {eof, _} ->
  211. file:close(Fd),
  212. [];
  213. _ ->
  214. F(F, Fd)
  215. end
  216. end,
  217. fun() ->
  218. ErlFiles = filelib:wildcard("$(DEPS_DIR)/$(1)/src/*.erl"),
  219. First0 = lists:usort(lists:flatten([begin
  220. {ok, Fd} = file:open(F, [read]),
  221. FindFirst(FindFirst, Fd)
  222. end || F <- ErlFiles])),
  223. First = lists:flatten([begin
  224. {ok, Fd} = file:open("$(DEPS_DIR)/$(1)/src/" ++ atom_to_list(M) ++ ".erl", [read]),
  225. FindFirst(FindFirst, Fd)
  226. end || M <- First0, lists:member("$(DEPS_DIR)/$(1)/src/" ++ atom_to_list(M) ++ ".erl", ErlFiles)]) ++ First0,
  227. Write(["COMPILE_FIRST +=", [[" ", atom_to_list(M)] || M <- First,
  228. lists:member("$(DEPS_DIR)/$(1)/src/" ++ atom_to_list(M) ++ ".erl", ErlFiles)], "\n"])
  229. end(),
  230. Write("\n\nrebar_dep: preprocess pre-deps deps pre-app app\n"),
  231. Write("\npreprocess::\n"),
  232. Write("\npre-deps::\n"),
  233. Write("\npre-app::\n"),
  234. PatchHook = fun(Cmd) ->
  235. case Cmd of
  236. "make -C" ++ _ -> Escape(Cmd);
  237. "gmake -C" ++ _ -> Escape(Cmd);
  238. "make " ++ Cmd1 -> "make -f Makefile.orig.mk " ++ Escape(Cmd1);
  239. "gmake " ++ Cmd1 -> "gmake -f Makefile.orig.mk " ++ Escape(Cmd1);
  240. _ -> Escape(Cmd)
  241. end
  242. end,
  243. fun() ->
  244. case lists:keyfind(pre_hooks, 1, Conf) of
  245. false -> ok;
  246. {_, Hooks} ->
  247. [case H of
  248. {'get-deps', Cmd} ->
  249. Write("\npre-deps::\n\t" ++ PatchHook(Cmd) ++ "\n");
  250. {compile, Cmd} ->
  251. Write("\npre-app::\n\t" ++ PatchHook(Cmd) ++ "\n");
  252. {Regex, compile, Cmd} ->
  253. case rebar_utils:is_arch(Regex) of
  254. true -> Write("\npre-app::\n\t" ++ PatchHook(Cmd) ++ "\n");
  255. false -> ok
  256. end;
  257. _ -> ok
  258. end || H <- Hooks]
  259. end
  260. end(),
  261. ShellToMk = fun(V) ->
  262. re:replace(V, "(\\\\$$$$)(\\\\w*)", "\\\\1(\\\\2)", [{return, list}, global])
  263. end,
  264. PortSpecs = fun() ->
  265. case lists:keyfind(port_specs, 1, Conf) of
  266. false ->
  267. case filelib:is_dir("$(DEPS_DIR)/$(1)/c_src") of
  268. false -> [];
  269. true ->
  270. [{"priv/" ++ proplists:get_value(so_name, Conf, "$(1)_drv.so"),
  271. proplists:get_value(port_sources, Conf, ["c_src/*.c"]), []}]
  272. end;
  273. {_, Specs} ->
  274. lists:flatten([case S of
  275. {Output, Input} -> {ShellToMk(Output), Input, []};
  276. {Regex, Output, Input} ->
  277. case rebar_utils:is_arch(Regex) of
  278. true -> {ShellToMk(Output), Input, []};
  279. false -> []
  280. end;
  281. {Regex, Output, Input, [{env, Env}]} ->
  282. case rebar_utils:is_arch(Regex) of
  283. true -> {ShellToMk(Output), Input, Env};
  284. false -> []
  285. end
  286. end || S <- Specs])
  287. end
  288. end(),
  289. PortSpecWrite = fun (Text) ->
  290. file:write_file("$(DEPS_DIR)/$(1)/c_src/Makefile.erlang.mk", Text, [append])
  291. end,
  292. case PortSpecs of
  293. [] -> ok;
  294. _ ->
  295. Write("\npre-app::\n\t$$$$\(MAKE) -f c_src/Makefile.erlang.mk\n"),
  296. PortSpecWrite(io_lib:format("ERL_CFLAGS = -finline-functions -Wall -fPIC -I ~s/erts-~s/include -I ~s\n",
  297. [code:root_dir(), erlang:system_info(version), code:lib_dir(erl_interface, include)])),
  298. PortSpecWrite(io_lib:format("ERL_LDFLAGS = -L ~s -lerl_interface -lei\n",
  299. [code:lib_dir(erl_interface, lib)])),
  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. case re:replace(F0, "rebar_config:", "rebar_config_", [global]) of
  348. F0 -> ok;
  349. F ->
  350. ok = file:write_file(ErlFile, [F,
  351. "\nrebar_config_get(_, current_command, _) -> compile.\n"
  352. ])
  353. end
  354. end,
  355. RunPlugin = fun(Plugin, Step) ->
  356. case erlang:function_exported(Plugin, Step, 2) of
  357. false -> ok;
  358. true ->
  359. c:cd("$(DEPS_DIR)/$(1)/"),
  360. Ret = Plugin:Step(Conf, undefined),
  361. io:format("rebar plugin ~p step ~p ret ~p~n", [Plugin, Step, Ret])
  362. end
  363. end,
  364. fun() ->
  365. case lists:keyfind(plugins, 1, Conf) of
  366. false -> ok;
  367. {_, Plugins} ->
  368. [begin
  369. case lists:keyfind(deps, 1, Conf) of
  370. false -> ok;
  371. {_, Deps} ->
  372. case lists:keyfind(P, 1, Deps) of
  373. false -> ok;
  374. _ ->
  375. Path = "$(DEPS_DIR)/" ++ atom_to_list(P),
  376. io:format("~s", [os:cmd("$(MAKE) -C $(DEPS_DIR)/$(1) " ++ Path)]),
  377. io:format("~s", [os:cmd("$(MAKE) -C " ++ Path ++ " IS_DEP=1")]),
  378. code:add_patha(Path ++ "/ebin")
  379. end
  380. end
  381. end || P <- Plugins],
  382. [case code:load_file(P) of
  383. {module, P} -> ok;
  384. _ ->
  385. case lists:keyfind(plugin_dir, 1, Conf) of
  386. false -> ok;
  387. {_, PluginsDir} ->
  388. ErlFile = "$(DEPS_DIR)/$(1)/" ++ PluginsDir ++ "/" ++ atom_to_list(P) ++ ".erl",
  389. PatchPlugin(ErlFile),
  390. {ok, P, Bin} = compile:file(ErlFile, [binary]),
  391. {module, P} = code:load_binary(P, ErlFile, Bin)
  392. end
  393. end || P <- Plugins],
  394. [RunPlugin(P, preprocess) || P <- Plugins],
  395. [RunPlugin(P, pre_compile) || P <- Plugins]
  396. end
  397. end(),
  398. halt()
  399. endef
  400. define dep_autopatch_appsrc.erl
  401. AppSrcOut = "$(DEPS_DIR)/$(1)/src/$(1).app.src",
  402. AppSrcIn = case filelib:is_regular(AppSrcOut) of false -> "$(DEPS_DIR)/$(1)/ebin/$(1).app"; true -> AppSrcOut end,
  403. case filelib:is_regular(AppSrcIn) of
  404. false -> ok;
  405. true ->
  406. fun() ->
  407. {ok, [{application, $(1), L}]} = file:consult(AppSrcIn),
  408. L2 = lists:keystore(modules, 1, L, {modules, []}),
  409. L3 = case lists:keyfind(vsn, 1, L2) of {vsn, git} -> lists:keyreplace(vsn, 1, L2, {vsn, "git"}); _ -> L2 end,
  410. ok = file:write_file(AppSrcOut, io_lib:format("~p.~n", [{application, $(1), L3}]))
  411. end(),
  412. case AppSrcOut of AppSrcIn -> ok; _ -> ok = file:delete(AppSrcIn) end
  413. end,
  414. halt()
  415. endef
  416. define dep_fetch
  417. if [ "$$$$VS" = "git" ]; then \
  418. git clone -q -n -- $$$$REPO $(DEPS_DIR)/$(1); \
  419. cd $(DEPS_DIR)/$(1) && git checkout -q $$$$COMMIT; \
  420. elif [ "$$$$VS" = "hg" ]; then \
  421. hg clone -q -U $$$$REPO $(DEPS_DIR)/$(1); \
  422. cd $(DEPS_DIR)/$(1) && hg update -q $$$$COMMIT; \
  423. elif [ "$$$$VS" = "svn" ]; then \
  424. svn checkout -q $$$$REPO $(DEPS_DIR)/$(1); \
  425. elif [ "$$$$VS" = "cp" ]; then \
  426. cp -R $$$$REPO $(DEPS_DIR)/$(1); \
  427. else \
  428. echo "Unknown or invalid dependency: $(1). Please consult the erlang.mk README for instructions." >&2; \
  429. exit 78; \
  430. fi
  431. endef
  432. define dep_target
  433. $(DEPS_DIR)/$(1):
  434. @mkdir -p $(DEPS_DIR)
  435. ifeq (,$(dep_$(1)))
  436. @if [ ! -f $(PKG_FILE2) ]; then $(call core_http_get,$(PKG_FILE2),$(PKG_FILE_URL)); fi
  437. $(dep_verbose) DEPPKG=$$$$(awk 'BEGIN { FS = "\t" }; $$$$1 == "$(1)" { print $$$$2 " " $$$$3 " " $$$$4 }' $(PKG_FILE2);); \
  438. VS=$$$$(echo $$$$DEPPKG | cut -d " " -f1); \
  439. REPO=$$$$(echo $$$$DEPPKG | cut -d " " -f2); \
  440. COMMIT=$$$$(echo $$$$DEPPKG | cut -d " " -f3); \
  441. $(call dep_fetch,$(1))
  442. else
  443. ifeq (1,$(words $(dep_$(1))))
  444. $(dep_verbose) VS=git; \
  445. REPO=$(dep_$(1)); \
  446. COMMIT=master; \
  447. $(call dep_fetch,$(1))
  448. else
  449. ifeq (2,$(words $(dep_$(1))))
  450. $(dep_verbose) VS=git; \
  451. REPO=$(word 1,$(dep_$(1))); \
  452. COMMIT=$(word 2,$(dep_$(1))); \
  453. $(call dep_fetch,$(1))
  454. else
  455. $(dep_verbose) VS=$(word 1,$(dep_$(1))); \
  456. REPO=$(word 2,$(dep_$(1))); \
  457. COMMIT=$(word 3,$(dep_$(1))); \
  458. $(call dep_fetch,$(1))
  459. endif
  460. endif
  461. endif
  462. @if [ -f $(DEPS_DIR)/$(1)/configure.ac ]; then \
  463. echo " AUTO " $(1); \
  464. cd $(DEPS_DIR)/$(1) && autoreconf -vif; \
  465. fi
  466. -@if [ -f $(DEPS_DIR)/$(1)/configure ]; then \
  467. echo " CONF " $(1); \
  468. cd $(DEPS_DIR)/$(1) && ./configure; \
  469. fi
  470. ifeq ($(filter $(1),$(NO_AUTOPATCH)),)
  471. @$(call dep_autopatch,$(1))
  472. endif
  473. endef
  474. $(foreach dep,$(DEPS),$(eval $(call dep_target,$(dep))))
  475. distclean-deps:
  476. $(gen_verbose) rm -rf $(DEPS_DIR)
  477. # Packages related targets.
  478. $(PKG_FILE2):
  479. @$(call core_http_get,$(PKG_FILE2),$(PKG_FILE_URL))
  480. pkg-list: $(PKG_FILE2)
  481. @cat $(PKG_FILE2) | awk 'BEGIN { FS = "\t" }; { print \
  482. "Name:\t\t" $$1 "\n" \
  483. "Repository:\t" $$3 "\n" \
  484. "Website:\t" $$5 "\n" \
  485. "Description:\t" $$6 "\n" }'
  486. ifdef q
  487. pkg-search: $(PKG_FILE2)
  488. @cat $(PKG_FILE2) | grep -i ${q} | awk 'BEGIN { FS = "\t" }; { print \
  489. "Name:\t\t" $$1 "\n" \
  490. "Repository:\t" $$3 "\n" \
  491. "Website:\t" $$5 "\n" \
  492. "Description:\t" $$6 "\n" }'
  493. else
  494. pkg-search:
  495. $(error Usage: $(MAKE) pkg-search q=STRING)
  496. endif
  497. ifeq ($(PKG_FILE2),$(CURDIR)/.erlang.mk.packages.v2)
  498. distclean-pkg:
  499. $(gen_verbose) rm -f $(PKG_FILE2)
  500. endif
  501. help::
  502. @printf "%s\n" "" \
  503. "Package-related targets:" \
  504. " pkg-list List all known packages" \
  505. " pkg-search q=STRING Search for STRING in the package index"