Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 32 additions & 9 deletions erlang.mk
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
ERLANG_MK_FILENAME := $(realpath $(lastword $(MAKEFILE_LIST)))
export ERLANG_MK_FILENAME

ERLANG_MK_VERSION = e13b4c7
ERLANG_MK_VERSION = 7cef74a
ERLANG_MK_WITHOUT =

# Make 3.81 and 3.82 are deprecated.
Expand Down Expand Up @@ -559,6 +559,14 @@ export ERL_LIBS

export NO_AUTOPATCH

# Elixir.

# Elixir is automatically enabled in all cases except when
# an Erlang project uses an Elixir dependency. In that case
# $(ELIXIR) must be set explicitly.
ELIXIR ?= $(if $(filter elixir,$(BUILD_DEPS) $(DEPS)),dep,$(if $(EX_FILES),system,disable))
export ELIXIR

# Verbosity.

dep_verbose_0 = @echo " DEP $1 ($(call query_version,$1))";
Expand Down Expand Up @@ -940,10 +948,11 @@ define dep_autopatch_rebar.erl
Write(io_lib:format("COMPILE_FIRST +=~s\n", [Names]))
end
end(),
Write("\n\nrebar_dep: preprocess pre-deps deps pre-app app\n"),
Write("\n\nrebar_dep: preprocess pre-deps deps pre-app app post-app\n"),
Write("\npreprocess::\n"),
Write("\npre-deps::\n"),
Write("\npre-app::\n"),
Write("\npost-app::\n"),
PatchHook = fun(Cmd) ->
Cmd2 = re:replace(Cmd, "^([g]?make)(.*)( -C.*)", "\\\\1\\\\3\\\\2", [{return, list}]),
case Cmd2 of
Expand Down Expand Up @@ -974,6 +983,24 @@ define dep_autopatch_rebar.erl
end || H <- Hooks]
end
end(),
fun() ->
case lists:keyfind(post_hooks, 1, Conf) of
false -> ok;
{_, Hooks} ->
[case H of
{compile, Cmd} ->
Write("\npost-app::\n\tCC=$$\(CC) " ++ PatchHook(Cmd) ++ "\n");
{{pc, compile}, Cmd} ->
Write("\npost-app::\n\tCC=$$\(CC) " ++ PatchHook(Cmd) ++ "\n");
{Regex, compile, Cmd} ->
case rebar_utils:is_arch(Regex) of
true -> Write("\npost-app::\n\tCC=$$\(CC) " ++ PatchHook(Cmd) ++ "\n");
false -> ok
end;
_ -> ok
end || H <- Hooks]
end
end(),
ShellToMk = fun(V0) ->
V1 = re:replace(V0, "[$$][(]", "$$\(shell ", [global]),
V = re:replace(V1, "([$$])(?![(])(\\\\w*)", "\\\\1(\\\\2)", [global]),
Expand Down Expand Up @@ -1778,12 +1805,6 @@ endif
# Copyright (c) 2024, Loïc Hoguin <[email protected]>
# This file is part of erlang.mk and subject to the terms of the ISC License.

# Elixir is automatically enabled in all cases except when
# an Erlang project uses an Elixir dependency. In that case
# $(ELIXIR) must be set explicitly.
ELIXIR ?= $(if $(filter elixir,$(BUILD_DEPS) $(DEPS)),dep,$(if $(EX_FILES),system,disable))
export ELIXIR

ifeq ($(ELIXIR),system)
# We expect 'elixir' to be on the path.
ELIXIR_BIN ?= $(shell readlink -f `which elixir`)
Expand Down Expand Up @@ -1952,7 +1973,8 @@ define dep_autopatch_mix.erl
endef

define dep_autopatch_mix
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; \
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; \
mv $(DEPS_DIR)/$(1)/mix.exs.new $(DEPS_DIR)/$(1)/mix.exs; \
$(MAKE) $(DEPS_DIR)/hex_core/ebin/dep_built; \
MIX_ENV="$(if $(MIX_ENV),$(strip $(MIX_ENV)),prod)" \
$(call erlang,$(call dep_autopatch_mix.erl,$1))
Expand All @@ -1964,6 +1986,7 @@ endef
define compile_ex.erl
{ok, _} = application:ensure_all_started(elixir),
{ok, _} = application:ensure_all_started(mix),
$(foreach dep,$(LOCAL_DEPS),_ = application:load($(dep)),)
ModCode = list_to_atom("Elixir.Code"),
ModCode:put_compiler_option(ignore_module_conflict, true),
ModComp = list_to_atom("Elixir.Kernel.ParallelCompiler"),
Expand Down