diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/core.mk | 2 | ||||
-rw-r--r-- | core/deps.mk | 128 | ||||
-rw-r--r-- | core/erlc.mk | 6 |
3 files changed, 77 insertions, 59 deletions
diff --git a/core/core.mk b/core/core.mk index 75a3706..dd66bec 100644 --- a/core/core.mk +++ b/core/core.mk @@ -124,7 +124,7 @@ endef # Adding erlang.mk to make Erlang scripts who call init:get_plain_arguments() happy. define erlang -$(ERL) -pa $(ERLANG_MK_TMP)/ebin -eval "$(subst $(newline),,$(subst ",\",$(1)))" -- erlang.mk +$(ERL) -pa $(ERLANG_MK_TMP)/rebar/ebin -eval "$(subst $(newline),,$(subst ",\",$(1)))" -- erlang.mk endef ifeq ($(shell which wget 2>/dev/null | wc -l), 1) diff --git a/core/deps.mk b/core/deps.mk index d032fbb..9a5fa9a 100644 --- a/core/deps.mk +++ b/core/deps.mk @@ -66,7 +66,12 @@ define dep_autopatch elif [ 0 != `find $(DEPS_DIR)/$(1)/ -type f -name \*.mk -not -name erlang.mk | xargs grep -ci rebar` ]; then \ $(call dep_autopatch2,$(1)); \ else \ - $(call dep_autopatch_erlang_mk,$(1)); \ + if [ -f $(DEPS_DIR)/$(1)/erlang.mk ]; then \ + $(call erlang,$(call dep_autopatch_appsrc.erl,$(1))); \ + $(call dep_autopatch_erlang_mk,$(1)); \ + else \ + $(call erlang,$(call dep_autopatch_app.erl,$(1))); \ + fi \ fi \ else \ if [ ! -d $(DEPS_DIR)/$(1)/src/ ]; then \ @@ -78,8 +83,9 @@ define dep_autopatch endef define dep_autopatch2 + $(call erlang,$(call dep_autopatch_appsrc.erl,$(1))); \ if [ -f $(DEPS_DIR)/$(1)/rebar.config -o -f $(DEPS_DIR)/$(1)/rebar.config.script ]; then \ - $(call dep_autopatch_rebar_utils); \ + $(call dep_autopatch_fetch_rebar); \ $(call dep_autopatch_rebar,$(1)); \ else \ $(call dep_autopatch_gen,$(1)); \ @@ -94,38 +100,28 @@ endef ifeq ($(NO_AUTOPATCH_ERLANG_MK),) define dep_autopatch_erlang_mk rm -f $(DEPS_DIR)/$(1)/erlang.mk; \ - cd $(DEPS_DIR)/$(1)/ && ln -s ../../erlang.mk; \ - $(call erlang,$(call dep_autopatch_appsrc.erl,$(1))) + cd $(DEPS_DIR)/$(1)/ && ln -s ../../erlang.mk endef else define dep_autopatch_erlang_mk - $(call erlang,$(call dep_autopatch_appsrc.erl,$(1))) + echo -n endef endif define dep_autopatch_gen printf "%s\n" \ "ERLC_OPTS = +debug_info" \ - "include ../../erlang.mk" > $(DEPS_DIR)/$(1)/Makefile; \ - $(call erlang,$(call dep_autopatch_appsrc.erl,$(1))) + "include ../../erlang.mk" > $(DEPS_DIR)/$(1)/Makefile endef -define dep_autopatch_rebar_utils - mkdir -p $(ERLANG_MK_TMP)/ebin; \ - if [ ! -f $(ERLANG_MK_TMP)/rebar.hrl ]; then \ - $(call core_http_get,$(ERLANG_MK_TMP)/rebar.hrl,https://raw.githubusercontent.com/rebar/rebar/791db716b5a3a7671e0b351f95ddf24b848ee173/include/rebar.hrl); \ - fi; \ - if [ ! -f $(ERLANG_MK_TMP)/rebar_utils.erl ]; then \ - $(call core_http_get,$(ERLANG_MK_TMP)/rebar_utils.erl,https://raw.githubusercontent.com/rebar/rebar/791db716b5a3a7671e0b351f95ddf24b848ee173/src/rebar_utils.erl); \ - fi; \ - if [ ! -f $(ERLANG_MK_TMP)/ebin/rebar_utils.beam ]; then \ - erlc -o $(ERLANG_MK_TMP)/ebin $(ERLANG_MK_TMP)/rebar_utils.erl; \ - fi; \ - if [ ! -f $(ERLANG_MK_TMP)/rebar_log.erl ]; then \ - $(call core_http_get,$(ERLANG_MK_TMP)/rebar_log.erl,https://raw.githubusercontent.com/rebar/rebar/791db716b5a3a7671e0b351f95ddf24b848ee173/src/rebar_log.erl); \ - fi; \ - if [ ! -f $(ERLANG_MK_TMP)/ebin/rebar_log.beam ]; then \ - erlc -o $(ERLANG_MK_TMP)/ebin $(ERLANG_MK_TMP)/rebar_log.erl; \ +define dep_autopatch_fetch_rebar + mkdir -p $(ERLANG_MK_TMP); \ + if [ ! -d $(ERLANG_MK_TMP)/rebar ]; then \ + git clone -q -n -- https://github.com/rebar/rebar $(ERLANG_MK_TMP)/rebar; \ + cd $(ERLANG_MK_TMP)/rebar; \ + git checkout -q 791db716b5a3a7671e0b351f95ddf24b848ee173; \ + make; \ + cd -; \ fi endef @@ -133,8 +129,7 @@ define dep_autopatch_rebar 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))) + $(call erlang,$(call dep_autopatch_rebar.erl,$(1))) endef define dep_autopatch_rebar.erl @@ -167,13 +162,15 @@ define dep_autopatch_rebar.erl Write("DRV_CFLAGS = -fPIC\nexport DRV_CFLAGS\n"), Write(["ERLANG_ARCH = ", rebar_utils:wordsize(), "\nexport ERLANG_ARCH\n"]), fun() -> - Write("ERLC_OPTS = +debug_info\n"), + Write("ERLC_OPTS = +debug_info\nexport ERLC_OPTS\n"), case lists:keyfind(erl_opts, 1, Conf) of false -> ok; {_, ErlOpts} -> lists:foreach(fun ({d, D}) -> Write("ERLC_OPTS += -D" ++ atom_to_list(D) ++ "=1\n"); + ({i, I}) -> + Write(["ERLC_OPTS += -I ", I, "\n"]); ({platform_define, Regex, D}) -> case rebar_utils:is_arch(Regex) of true -> Write("ERLC_OPTS += -D" ++ atom_to_list(D) ++ "=1\n"); @@ -209,16 +206,25 @@ define dep_autopatch_rebar.erl end end(), fun() -> - First = case lists:keyfind(erl_first_files, 1, Conf) of false -> []; {_, Files} -> - Names = [[" ", begin "lre." ++ Elif = lists:reverse(F), lists:reverse(Elif) end] - || "src/" ++ F <- Files], - Write(io_lib:format("COMPILE_FIRST +=~s\n", [Names])) + case lists:keyfind(erl_first_files, 1, Conf) of + false -> ok; + {_, Files} -> + Names = [[" ", case lists:reverse(F) of + "lre." ++ Elif -> lists:reverse(Elif); + Elif -> lists:reverse(Elif) + end] || "src/" ++ F <- Files], + Write(io_lib:format("COMPILE_FIRST +=~s\n", [Names])) end end(), FindFirst = fun(F, Fd) -> case io:parse_erl_form(Fd, undefined) of - {ok, {attribute, _,compile, {parse_transform, PT}}, _} -> + {ok, {attribute, _, compile, {parse_transform, PT}}, _} -> [PT, F(F, Fd)]; + {ok, {attribute, _, compile, CompileOpts}, _} when is_list(CompileOpts) -> + case proplists:get_value(parse_transform, CompileOpts) of + undefined -> [F(F, Fd)]; + PT -> [PT, F(F, Fd)] + end; {ok, {attribute, _, include, Hrl}, _} -> case file:open("$(DEPS_DIR)/$(1)/include/" ++ Hrl, [read]) of {ok, HrlFd} -> [F(F, HrlFd), F(F, Fd)]; @@ -231,6 +237,11 @@ define dep_autopatch_rebar.erl {ok, {attribute, _, include_lib, "$(1)/include/" ++ Hrl}, _} -> {ok, HrlFd} = file:open("$(DEPS_DIR)/$(1)/include/" ++ Hrl, [read]), [F(F, HrlFd), F(F, Fd)]; + {ok, {attribute, _, include_lib, Hrl}, _} -> + case file:open("$(DEPS_DIR)/$(1)/include/" ++ Hrl, [read]) of + {ok, HrlFd} -> [F(F, HrlFd), F(F, Fd)]; + _ -> [F(F, Fd)] + end; {ok, {attribute, _, import, {Imp, _}}, _} -> case file:open("$(DEPS_DIR)/$(1)/src/" ++ atom_to_list(Imp) ++ ".erl", [read]) of {ok, ImpFd} -> [Imp, F(F, ImpFd), F(F, Fd)]; @@ -277,10 +288,10 @@ define dep_autopatch_rebar.erl {'get-deps', Cmd} -> Write("\npre-deps::\n\t" ++ PatchHook(Cmd) ++ "\n"); {compile, Cmd} -> - Write("\npre-app::\n\t" ++ PatchHook(Cmd) ++ "\n"); + Write("\npre-app::\n\tCC=$$$$\(CC) " ++ PatchHook(Cmd) ++ "\n"); {Regex, compile, Cmd} -> case rebar_utils:is_arch(Regex) of - true -> Write("\npre-app::\n\t" ++ PatchHook(Cmd) ++ "\n"); + true -> Write("\npre-app::\n\tCC=$$$$\(CC) " ++ PatchHook(Cmd) ++ "\n"); false -> ok end; _ -> ok @@ -288,7 +299,8 @@ define dep_autopatch_rebar.erl end end(), ShellToMk = fun(V) -> - re:replace(V, "(\\\\$$$$)(\\\\w*)", "\\\\1(\\\\2)", [{return, list}, global]) + re:replace(re:replace(V, "(\\\\$$$$)(\\\\w*)", "\\\\1(\\\\2)", [global]), + "-Werror\\\\b", "", [{return, list}, global]) end, PortSpecs = fun() -> case lists:keyfind(port_specs, 1, Conf) of @@ -354,6 +366,10 @@ define dep_autopatch_rebar.erl Input = [[" ", I] || I <- Input0], PortSpecWrite([ [["\n", K, " = ", ShellToMk(V)] || {K, V} <- lists:reverse(MergeEnv(PortEnv))], + case $(PLATFORM) of + darwin -> "\n\nLDFLAGS += -flat_namespace -undefined suppress"; + _ -> "" + end, "\n\nall:: ", Output, "\n\n", "%.o: %.c\n\t$$$$\(CC) -c -o $$$$\@ $$$$\< $$$$\(CFLAGS) $$$$\(ERL_CFLAGS) $$$$\(DRV_CFLAGS) $$$$\(EXE_CFLAGS)\n\n", "%.o: %.C\n\t$$$$\(CXX) -c -o $$$$\@ $$$$\< $$$$\(CXXFLAGS) $$$$\(ERL_CFLAGS) $$$$\(DRV_CFLAGS) $$$$\(EXE_CFLAGS)\n\n", @@ -371,22 +387,13 @@ define dep_autopatch_rebar.erl [PortSpec(S) || S <- PortSpecs] end, Write("\ninclude ../../erlang.mk"), - PatchPlugin = fun(ErlFile) -> - {ok, F0} = file:read_file(ErlFile), - case re:replace(F0, "rebar_config:", "rebar_config_", [global]) of - F0 -> ok; - F -> - ok = file:write_file(ErlFile, [F, - "\nrebar_config_get(_, current_command, _) -> compile.\n" - ]) - end - end, RunPlugin = fun(Plugin, Step) -> case erlang:function_exported(Plugin, Step, 2) of false -> ok; true -> c:cd("$(DEPS_DIR)/$(1)/"), - Ret = Plugin:Step(Conf, undefined), + Ret = Plugin:Step({config, "", Conf, dict:new(), dict:new(), dict:new(), + dict:store(base_dir, "", dict:new())}, undefined), io:format("rebar plugin ~p step ~p ret ~p~n", [Plugin, Step, Ret]) end end, @@ -415,7 +422,6 @@ define dep_autopatch_rebar.erl false -> ok; {_, PluginsDir} -> ErlFile = "$(DEPS_DIR)/$(1)/" ++ PluginsDir ++ "/" ++ atom_to_list(P) ++ ".erl", - PatchPlugin(ErlFile), {ok, P, Bin} = compile:file(ErlFile, [binary]), {module, P} = code:load_binary(P, ErlFile, Bin) end @@ -427,18 +433,32 @@ define dep_autopatch_rebar.erl halt() endef +define dep_autopatch_app.erl + UpdateModules = fun(App) -> + case filelib:is_regular(App) of + false -> ok; + true -> + {ok, [{application, $(1), L0}]} = file:consult(App), + Mods = filelib:fold_files("$(DEPS_DIR)/$(1)/src", "\\\\.erl$$$$", true, + fun (F, Acc) -> [list_to_atom(filename:rootname(filename:basename(F)))|Acc] end, []), + L = lists:keystore(modules, 1, L0, {modules, Mods}), + ok = file:write_file(App, io_lib:format("~p.~n", [{application, $(1), L}])) + end + end, + UpdateModules("$(DEPS_DIR)/$(1)/ebin/$(1).app"), + halt() +endef + define dep_autopatch_appsrc.erl AppSrcOut = "$(DEPS_DIR)/$(1)/src/$(1).app.src", AppSrcIn = case filelib:is_regular(AppSrcOut) of false -> "$(DEPS_DIR)/$(1)/ebin/$(1).app"; true -> AppSrcOut end, case filelib:is_regular(AppSrcIn) of false -> ok; true -> - fun() -> - {ok, [{application, $(1), L}]} = file:consult(AppSrcIn), - L2 = lists:keystore(modules, 1, L, {modules, []}), - L3 = case lists:keyfind(vsn, 1, L2) of {vsn, git} -> lists:keyreplace(vsn, 1, L2, {vsn, "git"}); _ -> L2 end, - ok = file:write_file(AppSrcOut, io_lib:format("~p.~n", [{application, $(1), L3}])) - end(), + {ok, [{application, $(1), L0}]} = file:consult(AppSrcIn), + L1 = lists:keystore(modules, 1, L0, {modules, []}), + L2 = case lists:keyfind(vsn, 1, L1) of {vsn, git} -> lists:keyreplace(vsn, 1, L1, {vsn, "git"}); _ -> L1 end, + ok = file:write_file(AppSrcOut, io_lib:format("~p.~n", [{application, $(1), L2}])), case AppSrcOut of AppSrcIn -> ok; _ -> ok = file:delete(AppSrcIn) end end, halt() @@ -491,9 +511,9 @@ else endif endif endif - @if [ -f $(DEPS_DIR)/$(1)/configure.ac ]; then \ + @if [ -f $(DEPS_DIR)/$(1)/configure.ac -o -f $(DEPS_DIR)/$(1)/configure.in ]; then \ echo " AUTO " $(1); \ - cd $(DEPS_DIR)/$(1) && autoreconf -vif; \ + cd $(DEPS_DIR)/$(1) && autoreconf -Wall -vif -I m4; \ fi -@if [ -f $(DEPS_DIR)/$(1)/configure ]; then \ echo " CONF " $(1); \ diff --git a/core/erlc.mk b/core/erlc.mk index 6790cab..a646984 100644 --- a/core/erlc.mk +++ b/core/erlc.mk @@ -101,12 +101,10 @@ ebin/$(PROJECT).app:: $(shell find mibs -type f -name \*.mib) $(if $(strip $?),$(call compile_mib,$?)) endif -ebin/$(PROJECT).app:: $(shell find src -type f -name \*.erl) \ - $(shell find src -type f -name \*.core) +ebin/$(PROJECT).app:: $(shell find src -type f -name \*.erl -o -name \*.core) $(if $(strip $?),$(call compile_erl,$?)) -ebin/$(PROJECT).app:: $(shell find src -type f -name \*.xrl) \ - $(shell find src -type f -name \*.yrl) +ebin/$(PROJECT).app:: $(shell find src -type f -name \*.xrl -o -name \*.yrl) $(if $(strip $?),$(call compile_xyrl,$?)) endif |