deps.mk 17 KB

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