diff options
Diffstat (limited to 'core/deps.mk')
-rw-r--r-- | core/deps.mk | 56 |
1 files changed, 44 insertions, 12 deletions
diff --git a/core/deps.mk b/core/deps.mk index bae195b..4a9c9ac 100644 --- a/core/deps.mk +++ b/core/deps.mk @@ -66,7 +66,11 @@ define dep_autopatch $(call dep_autopatch_erlang_mk,$(1)); \ fi \ else \ - $(call dep_autopatch2,$(1)); \ + if [ ! -d $(DEPS_DIR)/$(1)/src/ ]; then \ + $(call dep_autopatch_noop,$(1)); \ + else \ + $(call dep_autopatch2,$(1)); \ + fi \ fi endef @@ -78,6 +82,10 @@ define dep_autopatch2 fi endef +define dep_autopatch_noop + printf "noop:\n" > $(DEPS_DIR)/$(1)/Makefile +endef + # Overwrite erlang.mk with the current file by default. ifeq ($(NO_AUTOPATCH_ERLANG_MK),) define dep_autopatch_erlang_mk @@ -99,7 +107,9 @@ define dep_autopatch_gen endef define dep_autopatch_rebar - rm -f $(DEPS_DIR)/$(1)/Makefile; \ + if [ -f $(DEPS_DIR)/$(1)/Makefile ]; then \ + mv $(DEPS_DIR)/$(1)/Makefile $(DEPS_DIR)/$(1)/Makefile.orig.mk; \ + fi; \ $(call erlang,$(call dep_autopatch_rebar.erl,$(1))); \ $(call erlang,$(call dep_autopatch_appsrc.erl,$(1))) endef @@ -109,6 +119,9 @@ define dep_autopatch_rebar.erl Write = fun (Text) -> file:write_file("$(DEPS_DIR)/$(1)/Makefile", Text, [append]) end, + Escape = fun (Text) -> + re:replace(Text, "\\\\$$$$", "\$$$$$$$$", [global, {return, list}]) + end, Write("ERLC_OPTS = +debug_info\n\n"), fun() -> File = case lists:keyfind(deps, 1, Conf) of @@ -136,8 +149,7 @@ define dep_autopatch_rebar.erl fun() -> case lists:keyfind(port_env, 1, Conf) of {_, Vars} -> - [Write(K ++ " = $$$$\(shell echo " ++ re:replace(V, "\\\\$$$$", "\$$$$$$$$", [global, {return, list}]) ++ "\)\n") - || {K, V} <- Vars], + [Write(K ++ " = $$$$\(shell echo " ++ Escape(V) ++ "\)\n") || {K, V} <- Vars], Write("CFLAGS += $$$$\(DRV_CFLAGS\)\n"), Write("CXXFLAGS += $$$$\(DRV_CFLAGS\)\n"), Write("LDFLAGS += $$$$\(DRV_LDFLAGS\)\n"); @@ -145,23 +157,43 @@ define dep_autopatch_rebar.erl end end(), fun() -> + case filelib:is_dir("$(DEPS_DIR)/$(1)/c_src") of + false -> ok; + true -> + Sources = [[" ./c_src/", S] || S <- filelib:wildcard("*.{c,C,cc,cpp}", "$(DEPS_DIR)/$(1)/c_src")], + Write(io_lib:format("SOURCES := ~s\n", [Sources])) + end + end(), + Write("\n\nrebar_dep: pre-deps deps pre-app app\n"), + Write("\npre-deps::\n"), + Write("\npre-app::\n"), + fun() -> case lists:keyfind(pre_hooks, 1, Conf) of false -> ok; {_, Hooks} -> [case H of {'get-deps', Command} -> - Write("\npre::\n\t" ++ Command ++ "\n"); + Write("\npre-deps::\n\t" ++ Escape(Command) ++ "\n"); {compile, Command} -> - Write("\npre::\n\t" ++ Command ++ "\n"); + Write("\npre-app::\n\t" ++ Escape(Command) ++ "\n"); + {Regex, compile, Command0} -> + case re:run("$(PLATFORM)", Regex, [{capture, none}]) of + match -> + Command = case Command0 of + "make -C" ++ _ -> Escape(Command0); + "gmake -C" ++ _ -> Escape(Command0); + "make " ++ Command1 -> "make -f Makefile.orig.mk " ++ Escape(Command1); + "gmake " ++ Command1 -> "gmake -f Makefile.orig.mk " ++ Escape(Command1); + _ -> Command0 + end, + Write("\npre-app::\n\t" ++ Command ++ "\n"); + nomatch -> + ok + end; _ -> ok - end || H <- Hooks], - Write("\npre:: deps app\n\n") + end || H <- Hooks] end end(), - case $(1) of - proper -> Write("\n# Proper hack.\napp::\n\t./write_compile_flags include/compile_flags.hrl\n"); - _ -> ok - end, Write("\ninclude ../../erlang.mk"), halt() endef |