Skip to content

Commit 514bcb2

Browse files
committed
Update Erlang.mk
1 parent 30a62a2 commit 514bcb2

File tree

1 file changed

+38
-9
lines changed

1 file changed

+38
-9
lines changed

erlang.mk

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
ERLANG_MK_FILENAME := $(realpath $(lastword $(MAKEFILE_LIST)))
1818
export ERLANG_MK_FILENAME
1919

20-
ERLANG_MK_VERSION = e13b4c7
20+
ERLANG_MK_VERSION = 2022.05.31-142-gba4dcff-dirty
2121
ERLANG_MK_WITHOUT =
2222

2323
# Make 3.81 and 3.82 are deprecated.
@@ -559,6 +559,14 @@ export ERL_LIBS
559559

560560
export NO_AUTOPATCH
561561

562+
# Elixir.
563+
564+
# Elixir is automatically enabled in all cases except when
565+
# an Erlang project uses an Elixir dependency. In that case
566+
# $(ELIXIR) must be set explicitly.
567+
ELIXIR ?= $(if $(filter elixir,$(BUILD_DEPS) $(DEPS)),dep,$(if $(EX_FILES),system,disable))
568+
export ELIXIR
569+
562570
# Verbosity.
563571

564572
dep_verbose_0 = @echo " DEP $1 ($(call query_version,$1))";
@@ -940,10 +948,11 @@ define dep_autopatch_rebar.erl
940948
Write(io_lib:format("COMPILE_FIRST +=~s\n", [Names]))
941949
end
942950
end(),
943-
Write("\n\nrebar_dep: preprocess pre-deps deps pre-app app\n"),
951+
Write("\n\nrebar_dep: preprocess pre-deps deps pre-app app post-app\n"),
944952
Write("\npreprocess::\n"),
945953
Write("\npre-deps::\n"),
946954
Write("\npre-app::\n"),
955+
Write("\npost-app::\n"),
947956
PatchHook = fun(Cmd) ->
948957
Cmd2 = re:replace(Cmd, "^([g]?make)(.*)( -C.*)", "\\\\1\\\\3\\\\2", [{return, list}]),
949958
case Cmd2 of
@@ -974,6 +983,24 @@ define dep_autopatch_rebar.erl
974983
end || H <- Hooks]
975984
end
976985
end(),
986+
fun() ->
987+
case lists:keyfind(post_hooks, 1, Conf) of
988+
false -> ok;
989+
{_, Hooks} ->
990+
[case H of
991+
{compile, Cmd} ->
992+
Write("\npost-app::\n\tCC=$$\(CC) " ++ PatchHook(Cmd) ++ "\n");
993+
{{pc, compile}, Cmd} ->
994+
Write("\npost-app::\n\tCC=$$\(CC) " ++ PatchHook(Cmd) ++ "\n");
995+
{Regex, compile, Cmd} ->
996+
case rebar_utils:is_arch(Regex) of
997+
true -> Write("\npost-app::\n\tCC=$$\(CC) " ++ PatchHook(Cmd) ++ "\n");
998+
false -> ok
999+
end;
1000+
_ -> ok
1001+
end || H <- Hooks]
1002+
end
1003+
end(),
9771004
ShellToMk = fun(V0) ->
9781005
V1 = re:replace(V0, "[$$][(]", "$$\(shell ", [global]),
9791006
V = re:replace(V1, "([$$])(?![(])(\\\\w*)", "\\\\1(\\\\2)", [global]),
@@ -1691,6 +1718,12 @@ endef
16911718

16921719
ifeq ($(if $(NO_MAKEDEP),$(wildcard $(PROJECT).d),),)
16931720
$(PROJECT).d:: $(ERL_FILES) $(EX_FILES) $(call core_find,include/,*.hrl) $(MAKEFILE_LIST)
1721+
# Rebuild everything when the .d file does not exist.
1722+
# We touch $@ to make sure the command doesn't fail in empty projects.
1723+
# The file will be generated with content immediately after.
1724+
$(verbose) if ! test -e $@; then \
1725+
touch $@ $(ERL_FILES) $(CORE_FILES) $(ASN1_FILES) $(MIB_FILES) $(XRL_FILES) $(YRL_FILES); \
1726+
fi
16941727
$(makedep_verbose) $(call erlang,$(call makedep.erl,$@))
16951728
endif
16961729

@@ -1778,12 +1811,6 @@ endif
17781811
# Copyright (c) 2024, Loïc Hoguin <essen@ninenines.eu>
17791812
# This file is part of erlang.mk and subject to the terms of the ISC License.
17801813

1781-
# Elixir is automatically enabled in all cases except when
1782-
# an Erlang project uses an Elixir dependency. In that case
1783-
# $(ELIXIR) must be set explicitly.
1784-
ELIXIR ?= $(if $(filter elixir,$(BUILD_DEPS) $(DEPS)),dep,$(if $(EX_FILES),system,disable))
1785-
export ELIXIR
1786-
17871814
ifeq ($(ELIXIR),system)
17881815
# We expect 'elixir' to be on the path.
17891816
ELIXIR_BIN ?= $(shell readlink -f `which elixir`)
@@ -1952,7 +1979,8 @@ define dep_autopatch_mix.erl
19521979
endef
19531980

19541981
define dep_autopatch_mix
1955-
sed 's|\(defmodule.*do\)|\1\n try do\n Code.compiler_options(on_undefined_variable: :warn)\n rescue _ -> :ok\n end\n|g' -i $(DEPS_DIR)/$(1)/mix.exs; \
1982+
sed 's|\(defmodule.*do\)|\1\n try do\n Code.compiler_options(on_undefined_variable: :warn)\n rescue _ -> :ok\n end\n|g' $(DEPS_DIR)/$(1)/mix.exs > $(DEPS_DIR)/$(1)/mix.exs.new; \
1983+
mv $(DEPS_DIR)/$(1)/mix.exs.new $(DEPS_DIR)/$(1)/mix.exs; \
19561984
$(MAKE) $(DEPS_DIR)/hex_core/ebin/dep_built; \
19571985
MIX_ENV="$(if $(MIX_ENV),$(strip $(MIX_ENV)),prod)" \
19581986
$(call erlang,$(call dep_autopatch_mix.erl,$1))
@@ -1964,6 +1992,7 @@ endef
19641992
define compile_ex.erl
19651993
{ok, _} = application:ensure_all_started(elixir),
19661994
{ok, _} = application:ensure_all_started(mix),
1995+
$(foreach dep,$(LOCAL_DEPS),_ = application:load($(dep)),)
19671996
ModCode = list_to_atom("Elixir.Code"),
19681997
ModCode:put_compiler_option(ignore_module_conflict, true),
19691998
ModComp = list_to_atom("Elixir.Kernel.ParallelCompiler"),

0 commit comments

Comments
 (0)