aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/beam-cache.mk42
-rw-r--r--core/compat.mk10
-rw-r--r--core/core.mk23
-rw-r--r--core/deps-tools.mk20
-rw-r--r--core/deps.mk507
-rw-r--r--core/elixir.mk201
-rw-r--r--core/erlc.mk58
-rw-r--r--core/index.mk8
-rw-r--r--core/kerl.mk31
-rw-r--r--core/test.mk9
10 files changed, 644 insertions, 265 deletions
diff --git a/core/beam-cache.mk b/core/beam-cache.mk
new file mode 100644
index 0000000..d0f1d3c
--- /dev/null
+++ b/core/beam-cache.mk
@@ -0,0 +1,42 @@
+# Copyright (c) 2024, Loïc Hoguin <[email protected]>
+# This file is part of erlang.mk and subject to the terms of the ISC License.
+
+.PHONY: beam-cache-restore-app beam-cache-restore-test clean-beam-cache distclean-beam-cache
+
+BEAM_CACHE_DIR ?= $(ERLANG_MK_TMP)/beam-cache
+PROJECT_BEAM_CACHE_DIR = $(BEAM_CACHE_DIR)/$(PROJECT)
+
+clean:: clean-beam-cache
+
+clean-beam-cache:
+ $(verbose) rm -rf $(PROJECT_BEAM_CACHE_DIR)
+
+distclean:: distclean-beam-cache
+
+$(PROJECT_BEAM_CACHE_DIR):
+ $(verbose) mkdir -p $(PROJECT_BEAM_CACHE_DIR)
+
+distclean-beam-cache:
+ $(gen_verbose) rm -rf $(BEAM_CACHE_DIR)
+
+beam-cache-restore-app: | $(PROJECT_BEAM_CACHE_DIR)
+ $(verbose) rm -rf $(PROJECT_BEAM_CACHE_DIR)/ebin-test
+ifneq ($(wildcard ebin/),)
+ $(verbose) mv ebin/ $(PROJECT_BEAM_CACHE_DIR)/ebin-test
+endif
+ifneq ($(wildcard $(PROJECT_BEAM_CACHE_DIR)/ebin-app),)
+ $(gen_verbose) mv $(PROJECT_BEAM_CACHE_DIR)/ebin-app ebin/
+else
+ $(verbose) $(MAKE) --no-print-directory clean-app
+endif
+
+beam-cache-restore-test: | $(PROJECT_BEAM_CACHE_DIR)
+ $(verbose) rm -rf $(PROJECT_BEAM_CACHE_DIR)/ebin-app
+ifneq ($(wildcard ebin/),)
+ $(verbose) mv ebin/ $(PROJECT_BEAM_CACHE_DIR)/ebin-app
+endif
+ifneq ($(wildcard $(PROJECT_BEAM_CACHE_DIR)/ebin-test),)
+ $(gen_verbose) mv $(PROJECT_BEAM_CACHE_DIR)/ebin-test ebin/
+else
+ $(verbose) $(MAKE) --no-print-directory clean-app
+endif
diff --git a/core/compat.mk b/core/compat.mk
index 906faac..f9dcfe7 100644
--- a/core/compat.mk
+++ b/core/compat.mk
@@ -3,6 +3,8 @@
.PHONY: rebar.config
+compat_ref = {$(shell (git -C $(DEPS_DIR)/$1 show-ref -q --verify "refs/heads/$2" && echo branch) || (git -C $(DEPS_DIR)/$1 show-ref -q --verify "refs/tags/$2" && echo tag) || echo ref),"$2"}
+
# We strip out -Werror because we don't want to fail due to
# warnings when used as a dependency.
@@ -21,12 +23,12 @@ endef
define compat_rebar_config
{deps, [
$(call comma_list,$(foreach d,$(DEPS),\
- $(if $(filter hex,$(call dep_fetch,$d)),\
- {$(call dep_name,$d)$(comma)"$(call dep_repo,$d)"},\
- {$(call dep_name,$d)$(comma)".*"$(comma){git,"$(call dep_repo,$d)"$(comma)"$(call dep_commit,$d)"}})))
+ $(if $(filter hex,$(call query_fetch_method,$d)),\
+ {$(call query_name,$d)$(comma)"$(call query_version_hex,$d)"},\
+ {$(call query_name,$d)$(comma)".*"$(comma){git,"$(call query_repo,$d)"$(comma)$(call compat_ref,$(call query_name,$d),$(call query_version,$d))}})))
]}.
{erl_opts, $(call compat_erlc_opts_to_list,$(ERLC_OPTS))}.
endef
-rebar.config:
+rebar.config: deps
$(gen_verbose) $(call core_render,compat_rebar_config,rebar.config)
diff --git a/core/core.mk b/core/core.mk
index 77adc2e..222faeb 100644
--- a/core/core.mk
+++ b/core/core.mk
@@ -36,7 +36,7 @@ PROJECT ?= $(notdir $(CURDIR))
PROJECT := $(strip $(PROJECT))
PROJECT_VERSION ?= rolling
-PROJECT_MOD ?= $(PROJECT)_app
+PROJECT_MOD ?=
PROJECT_ENV ?= []
# Verbosity.
@@ -47,7 +47,7 @@ verbose_0 = @
verbose_2 = set -x;
verbose = $(verbose_$(V))
-ifeq ($(V),3)
+ifeq ($V,3)
SHELL := $(SHELL) -x
endif
@@ -66,7 +66,7 @@ export ERLANG_MK_TMP
# "erl" command.
-ERL = erl +A1 -noinput -boot no_dot_erlang
+ERL = erl -noinput -boot no_dot_erlang -kernel start_distribution false +P 1024 +Q 1024
# Platform detection.
@@ -162,7 +162,7 @@ define newline
endef
define comma_list
-$(subst $(space),$(comma),$(strip $(1)))
+$(subst $(space),$(comma),$(strip $1))
endef
define escape_dquotes
@@ -171,7 +171,7 @@ endef
# Adding erlang.mk to make Erlang scripts who call init:get_plain_arguments() happy.
define erlang
-$(ERL) $2 -pz $(ERLANG_MK_TMP)/rebar/ebin -eval "$(subst $(newline),,$(call escape_dquotes,$1))" -- erlang.mk
+$(ERL) $2 -pz $(ERLANG_MK_TMP)/rebar3/_build/prod/lib/*/ebin/ -eval "$(subst $(newline),,$(call escape_dquotes,$1))" -- erlang.mk
endef
ifeq ($(PLATFORM),msys2)
@@ -180,22 +180,23 @@ else
core_native_path = $1
endif
-core_http_get = curl -Lf$(if $(filter-out 0,$(V)),,s)o $(call core_native_path,$1) $2
+core_http_get = curl -Lf$(if $(filter-out 0,$V),,s)o $(call core_native_path,$1) $2
-core_eq = $(and $(findstring $(1),$(2)),$(findstring $(2),$(1)))
+core_eq = $(and $(findstring $1,$2),$(findstring $2,$1))
# We skip files that contain spaces because they end up causing issues.
-core_find = $(if $(wildcard $1),$(shell find $(1:%/=%) \( -type l -o -type f \) -name $(subst *,\*,$2) | grep -v " "))
+# Files that begin with a dot are already ignored by the wildcard function.
+core_find = $(foreach f,$(wildcard $(1:%/=%)/*),$(if $(wildcard $f/.),$(call core_find,$f,$2),$(if $(filter $(subst *,%,$2),$f),$(if $(wildcard $f),$f))))
-core_lc = $(subst A,a,$(subst B,b,$(subst C,c,$(subst D,d,$(subst E,e,$(subst F,f,$(subst G,g,$(subst H,h,$(subst I,i,$(subst J,j,$(subst K,k,$(subst L,l,$(subst M,m,$(subst N,n,$(subst O,o,$(subst P,p,$(subst Q,q,$(subst R,r,$(subst S,s,$(subst T,t,$(subst U,u,$(subst V,v,$(subst W,w,$(subst X,x,$(subst Y,y,$(subst Z,z,$(1)))))))))))))))))))))))))))
+core_lc = $(subst A,a,$(subst B,b,$(subst C,c,$(subst D,d,$(subst E,e,$(subst F,f,$(subst G,g,$(subst H,h,$(subst I,i,$(subst J,j,$(subst K,k,$(subst L,l,$(subst M,m,$(subst N,n,$(subst O,o,$(subst P,p,$(subst Q,q,$(subst R,r,$(subst S,s,$(subst T,t,$(subst U,u,$(subst V,v,$(subst W,w,$(subst X,x,$(subst Y,y,$(subst Z,z,$1))))))))))))))))))))))))))
-core_ls = $(filter-out $(1),$(shell echo $(1)))
+core_ls = $(filter-out $1,$(shell echo $1))
# @todo Use a solution that does not require using perl.
core_relpath = $(shell perl -e 'use File::Spec; print File::Spec->abs2rel(@ARGV) . "\n"' $1 $2)
define core_render
- printf -- '$(subst $(newline),\n,$(subst %,%%,$(subst ','\'',$(subst $(tab),$(WS),$(call $(1))))))\n' > $(2)
+ printf -- '$(subst $(newline),\n,$(subst %,%%,$(subst ','\'',$(subst $(tab),$(WS),$(call $1)))))\n' > $2
endef
# Automated update.
diff --git a/core/deps-tools.mk b/core/deps-tools.mk
index 262d045..b29bf2a 100644
--- a/core/deps-tools.mk
+++ b/core/deps-tools.mk
@@ -78,9 +78,7 @@ endif
ifeq ($(IS_APP)$(IS_DEP),)
$(verbose) sort < $(ERLANG_MK_RECURSIVE_TMP_LIST) | \
uniq > $(ERLANG_MK_RECURSIVE_TMP_LIST).sorted
- $(verbose) cmp -s $(ERLANG_MK_RECURSIVE_TMP_LIST).sorted $@ \
- || mv $(ERLANG_MK_RECURSIVE_TMP_LIST).sorted $@
- $(verbose) rm -f $(ERLANG_MK_RECURSIVE_TMP_LIST).sorted
+ $(verbose) mv $(ERLANG_MK_RECURSIVE_TMP_LIST).sorted $@
$(verbose) rm $(ERLANG_MK_RECURSIVE_TMP_LIST)
endif
endif # ifneq ($(SKIP_DEPS),)
@@ -107,14 +105,14 @@ list-deps list-doc-deps list-rel-deps list-test-deps list-shell-deps:
QUERY ?= name fetch_method repo version
define query_target
-$(1): $(2) clean-tmp-query.log
+$1: $2 clean-tmp-query.log
ifeq ($(IS_APP)$(IS_DEP),)
- $(verbose) rm -f $(4)
+ $(verbose) rm -f $4
endif
- $(verbose) $(foreach dep,$(3),\
- echo $(PROJECT): $(foreach q,$(QUERY),$(call query_$(q),$(dep))) >> $(4) ;)
- $(if $(filter-out query-deps,$(1)),,\
- $(verbose) set -e; for dep in $(3) ; do \
+ $(verbose) $(foreach dep,$3,\
+ echo $(PROJECT): $(foreach q,$(QUERY),$(call query_$(q),$(dep))) >> $4 ;)
+ $(if $(filter-out query-deps,$1),,\
+ $(verbose) set -e; for dep in $3 ; do \
if grep -qs ^$$$$dep$$$$ $(ERLANG_MK_TMP)/query.log; then \
:; \
else \
@@ -123,8 +121,8 @@ endif
fi \
done)
ifeq ($(IS_APP)$(IS_DEP),)
- $(verbose) touch $(4)
- $(verbose) cat $(4)
+ $(verbose) touch $4
+ $(verbose) cat $4
endif
endef
diff --git a/core/deps.mk b/core/deps.mk
index 6d6623b..da7f7c4 100644
--- a/core/deps.mk
+++ b/core/deps.mk
@@ -21,19 +21,35 @@ export DEPS_DIR
REBAR_DEPS_DIR = $(DEPS_DIR)
export REBAR_DEPS_DIR
-REBAR_GIT ?= https://github.com/rebar/rebar
-REBAR_COMMIT ?= 576e12171ab8d69b048b827b92aa65d067deea01
+# When testing Erlang.mk and updating these, make sure
+# to delete test/test_rebar_git before running tests again.
+REBAR3_GIT ?= https://github.com/erlang/rebar3
+REBAR3_COMMIT ?= bde4b54248d16280b2c70a244aca3bb7566e2033 # 3.23.0
+
+CACHE_DEPS ?= 0
+
+CACHE_DIR ?= $(if $(XDG_CACHE_HOME),$(XDG_CACHE_HOME),$(HOME)/.cache)/erlang.mk
+export CACHE_DIR
+
+HEX_CONFIG ?=
+
+define hex_config.erl
+ begin
+ Config0 = hex_core:default_config(),
+ Config0$(HEX_CONFIG)
+ end
+endef
# External "early" plugins (see core/plugins.mk for regular plugins).
# They both use the core_dep_plugin macro.
define core_dep_plugin
-ifeq ($(2),$(PROJECT))
--include $$(patsubst $(PROJECT)/%,%,$(1))
+ifeq ($2,$(PROJECT))
+-include $$(patsubst $(PROJECT)/%,%,$1)
else
--include $(DEPS_DIR)/$(1)
+-include $(DEPS_DIR)/$1
-$(DEPS_DIR)/$(1): $(DEPS_DIR)/$(2) ;
+$(DEPS_DIR)/$1: $(DEPS_DIR)/$2 ;
endif
endef
@@ -46,44 +62,42 @@ $(foreach p,$(DEP_EARLY_PLUGINS),\
# Query functions.
-query_fetch_method = $(if $(dep_$(1)),$(call _qfm_dep,$(word 1,$(dep_$(1)))),$(call _qfm_pkg,$(1)))
-_qfm_dep = $(if $(dep_fetch_$(1)),$(1),$(if $(IS_DEP),legacy,fail))
+query_fetch_method = $(if $(dep_$(1)),$(call _qfm_dep,$(word 1,$(dep_$(1)))),$(call _qfm_pkg,$1))
+_qfm_dep = $(if $(dep_fetch_$(1)),$1,fail)
_qfm_pkg = $(if $(pkg_$(1)_fetch),$(pkg_$(1)_fetch),fail)
-query_name = $(if $(dep_$(1)),$(1),$(if $(pkg_$(1)_name),$(pkg_$(1)_name),$(1)))
+query_name = $(if $(dep_$(1)),$1,$(if $(pkg_$(1)_name),$(pkg_$(1)_name),$1))
-query_repo = $(call _qr,$(1),$(call query_fetch_method,$(1)))
-_qr = $(if $(query_repo_$(2)),$(call query_repo_$(2),$(1)),$(call dep_repo,$(1)))
+query_repo = $(call _qr,$1,$(call query_fetch_method,$1))
+_qr = $(if $(query_repo_$(2)),$(call query_repo_$(2),$1),$(call query_repo_git,$1))
query_repo_default = $(if $(dep_$(1)),$(word 2,$(dep_$(1))),$(pkg_$(1)_repo))
-query_repo_git = $(patsubst git://github.com/%,https://github.com/%,$(call query_repo_default,$(1)))
-query_repo_git-subfolder = $(call query_repo_git,$(1))
+query_repo_git = $(patsubst git://github.com/%,https://github.com/%,$(call query_repo_default,$1))
+query_repo_git-subfolder = $(call query_repo_git,$1)
query_repo_git-submodule = -
-query_repo_hg = $(call query_repo_default,$(1))
-query_repo_svn = $(call query_repo_default,$(1))
-query_repo_cp = $(call query_repo_default,$(1))
-query_repo_ln = $(call query_repo_default,$(1))
-query_repo_hex = https://hex.pm/packages/$(if $(word 3,$(dep_$(1))),$(word 3,$(dep_$(1))),$(1))
+query_repo_hg = $(call query_repo_default,$1)
+query_repo_svn = $(call query_repo_default,$1)
+query_repo_cp = $(call query_repo_default,$1)
+query_repo_ln = $(call query_repo_default,$1)
+query_repo_hex = https://hex.pm/packages/$(if $(word 3,$(dep_$(1))),$(word 3,$(dep_$(1))),$1)
query_repo_fail = -
-query_repo_legacy = -
-query_version = $(call _qv,$(1),$(call query_fetch_method,$(1)))
-_qv = $(if $(query_version_$(2)),$(call query_version_$(2),$(1)),$(call dep_commit,$(1)))
+query_version = $(call _qv,$1,$(call query_fetch_method,$1))
+_qv = $(if $(query_version_$(2)),$(call query_version_$(2),$1),$(call query_version_default,$1))
query_version_default = $(if $(dep_$(1)_commit),$(dep_$(1)_commit),$(if $(dep_$(1)),$(word 3,$(dep_$(1))),$(pkg_$(1)_commit)))
-query_version_git = $(call query_version_default,$(1))
-query_version_git-subfolder = $(call query_version_git,$(1))
+query_version_git = $(call query_version_default,$1)
+query_version_git-subfolder = $(call query_version_default,$1)
query_version_git-submodule = -
-query_version_hg = $(call query_version_default,$(1))
+query_version_hg = $(call query_version_default,$1)
query_version_svn = -
query_version_cp = -
query_version_ln = -
query_version_hex = $(if $(dep_$(1)_commit),$(dep_$(1)_commit),$(if $(dep_$(1)),$(word 2,$(dep_$(1))),$(pkg_$(1)_commit)))
query_version_fail = -
-query_version_legacy = -
-query_extra = $(call _qe,$(1),$(call query_fetch_method,$(1)))
-_qe = $(if $(query_extra_$(2)),$(call query_extra_$(2),$(1)),-)
+query_extra = $(call _qe,$1,$(call query_fetch_method,$1))
+_qe = $(if $(query_extra_$(2)),$(call query_extra_$(2),$1),-)
query_extra_git = -
query_extra_git-subfolder = $(if $(dep_$(1)),subfolder=$(word 4,$(dep_$(1))),-)
@@ -94,18 +108,19 @@ query_extra_cp = -
query_extra_ln = -
query_extra_hex = $(if $(dep_$(1)),package-name=$(word 3,$(dep_$(1))),-)
query_extra_fail = -
-query_extra_legacy = -
-query_absolute_path = $(addprefix $(DEPS_DIR)/,$(call query_name,$(1)))
+query_absolute_path = $(addprefix $(DEPS_DIR)/,$(call query_name,$1))
-# Deprecated legacy query functions.
-dep_fetch = $(call query_fetch_method,$(1))
+# Deprecated legacy query function. Used by RabbitMQ and its third party plugins.
+# Can be removed once RabbitMQ has been updated and enough time has passed.
dep_name = $(call query_name,$(1))
-dep_repo = $(call query_repo_git,$(1))
-dep_commit = $(if $(dep_$(1)_commit),$(dep_$(1)_commit),$(if $(dep_$(1)),$(if $(filter hex,$(word 1,$(dep_$(1)))),$(word 2,$(dep_$(1))),$(word 3,$(dep_$(1)))),$(pkg_$(1)_commit)))
-LOCAL_DEPS_DIRS = $(foreach a,$(LOCAL_DEPS),$(if $(wildcard $(APPS_DIR)/$(a)),$(APPS_DIR)/$(a)))
-ALL_DEPS_DIRS = $(addprefix $(DEPS_DIR)/,$(foreach dep,$(filter-out $(IGNORE_DEPS),$(BUILD_DEPS) $(DEPS)),$(call dep_name,$(dep))))
+# Application directories.
+
+LOCAL_DEPS_DIRS = $(foreach a,$(LOCAL_DEPS),$(if $(wildcard $(APPS_DIR)/$a),$(APPS_DIR)/$a))
+# Elixir is handled specially as it must be built before all other deps
+# when Mix autopatching is necessary.
+ALL_DEPS_DIRS = $(addprefix $(DEPS_DIR)/,$(foreach dep,$(filter-out $(IGNORE_DEPS),$(BUILD_DEPS) $(DEPS)),$(call query_name,$(dep))))
# When we are calling an app directly we don't want to include it here
# otherwise it'll be treated both as an apps and a top-level project.
@@ -127,9 +142,17 @@ 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 dep_commit,$1))";
+dep_verbose_0 = @echo " DEP $1 ($(call query_version,$1))";
dep_verbose_2 = set -x;
dep_verbose = $(dep_verbose_$(V))
@@ -197,15 +220,20 @@ endif
ifneq ($(SKIP_DEPS),)
deps::
else
-deps:: $(ALL_DEPS_DIRS) apps clean-tmp-deps.log | $(ERLANG_MK_TMP)
-ifneq ($(ALL_DEPS_DIRS),)
- $(verbose) set -e; for dep in $(ALL_DEPS_DIRS); do \
+ALL_DEPS_DIRS_TO_BUILD = $(if $(filter-out $(DEPS_DIR)/elixir,$(ALL_DEPS_DIRS)),$(filter-out $(DEPS_DIR)/elixir,$(ALL_DEPS_DIRS)),$(ALL_DEPS_DIRS))
+
+deps:: $(ALL_DEPS_DIRS_TO_BUILD) apps clean-tmp-deps.log | $(ERLANG_MK_TMP)
+ifneq ($(ALL_DEPS_DIRS_TO_BUILD),)
+ $(verbose) set -e; for dep in $(ALL_DEPS_DIRS_TO_BUILD); do \
if grep -qs ^$$dep$$ $(ERLANG_MK_TMP)/deps.log; then \
:; \
else \
echo $$dep >> $(ERLANG_MK_TMP)/deps.log; \
if [ -z "$(strip $(FULL))" ] $(if $(force_rebuild_dep),&& ! ($(call force_rebuild_dep,$$dep)),) && [ ! -L $$dep ] && [ -f $$dep/ebin/dep_built ]; then \
:; \
+ elif [ "$$dep" = "$(DEPS_DIR)/hut" -a "$(HUT_PATCH)" ]; then \
+ $(MAKE) -C $$dep app IS_DEP=1; \
+ if [ ! -L $$dep ] && [ -d $$dep/ebin ]; then touch $$dep/ebin/dep_built; fi; \
elif [ -f $$dep/GNUmakefile ] || [ -f $$dep/makefile ] || [ -f $$dep/Makefile ]; then \
$(MAKE) -C $$dep IS_DEP=1; \
if [ ! -L $$dep ] && [ -d $$dep/ebin ]; then touch $$dep/ebin/dep_built; fi; \
@@ -220,51 +248,80 @@ endif
# Deps related targets.
-# @todo rename GNUmakefile and makefile into Makefile first, if they exist
-# While Makefile file could be GNUmakefile or makefile,
-# in practice only Makefile is needed so far.
-define dep_autopatch
- if [ -f $(DEPS_DIR)/$(1)/erlang.mk ]; then \
- rm -rf $(DEPS_DIR)/$1/ebin/; \
- $(call erlang,$(call dep_autopatch_appsrc.erl,$(1))); \
- $(call dep_autopatch_erlang_mk,$(1)); \
- elif [ -f $(DEPS_DIR)/$(1)/Makefile ]; then \
- if [ -f $(DEPS_DIR)/$1/rebar.lock ]; then \
- $(call dep_autopatch2,$1); \
- elif [ 0 != `grep -c "include ../\w*\.mk" $(DEPS_DIR)/$(1)/Makefile` ]; then \
- $(call dep_autopatch2,$(1)); \
- elif [ 0 != `grep -ci "^[^#].*rebar" $(DEPS_DIR)/$(1)/Makefile` ]; then \
- $(call dep_autopatch2,$(1)); \
- elif [ -n "`find $(DEPS_DIR)/$(1)/ -type f -name \*.mk -not -name erlang.mk -exec grep -i "^[^#].*rebar" '{}' \;`" ]; then \
- $(call dep_autopatch2,$(1)); \
+autopatch_verbose_0 = @echo " PATCH " $(subst autopatch-,,$@) "(method: $(AUTOPATCH_METHOD))";
+autopatch_verbose_2 = set -x;
+autopatch_verbose = $(autopatch_verbose_$(V))
+
+define dep_autopatch_detect
+ if [ -f $(DEPS_DIR)/$1/erlang.mk ]; then \
+ echo erlang.mk; \
+ elif [ -f $(DEPS_DIR)/$1/mix.exs -a -d $(DEPS_DIR)/$1/lib ]; then \
+ if [ "$(ELIXIR)" != "disable" ]; then \
+ echo mix; \
+ elif [ -f $(DEPS_DIR)/$1/rebar.lock -o -f $(DEPS_DIR)/$1/rebar.config ]; then \
+ echo rebar3; \
+ elif [ -f $(DEPS_DIR)/$1/Makefile ]; then \
+ echo noop; \
+ else \
+ exit 99; \
fi \
- else \
- if [ ! -d $(DEPS_DIR)/$(1)/src/ ]; then \
- $(call dep_autopatch_noop,$(1)); \
+ elif [ -f $(DEPS_DIR)/$1/Makefile ]; then \
+ if [ -f $(DEPS_DIR)/$1/rebar.lock ]; then \
+ echo rebar3; \
+ elif [ 0 != \`grep -c "include ../\w*\.mk" $(DEPS_DIR)/$1/Makefile\` ]; then \
+ echo rebar3; \
+ elif [ 0 != \`grep -ci "^[^#].*rebar" $(DEPS_DIR)/$1/Makefile\` ]; then \
+ echo rebar3; \
+ elif [ -n "\`find $(DEPS_DIR)/$1/ -type f -name \*.mk -not -name erlang.mk -exec grep -i "^[^#].*rebar" '{}' \;\`" ]; then \
+ echo rebar3; \
else \
- $(call dep_autopatch2,$(1)); \
+ echo noop; \
fi \
+ elif [ ! -d $(DEPS_DIR)/$1/src/ ]; then \
+ echo noop; \
+ else \
+ echo rebar3; \
fi
endef
-define dep_autopatch2
+define dep_autopatch_for_erlang.mk
+ rm -rf $(DEPS_DIR)/$1/ebin/; \
+ $(call erlang,$(call dep_autopatch_appsrc.erl,$1)); \
+ $(call dep_autopatch_erlang_mk,$1)
+endef
+
+define dep_autopatch_for_rebar3
! test -f $(DEPS_DIR)/$1/ebin/$1.app || \
mv -n $(DEPS_DIR)/$1/ebin/$1.app $(DEPS_DIR)/$1/src/$1.app.src; \
rm -f $(DEPS_DIR)/$1/ebin/$1.app; \
if [ -f $(DEPS_DIR)/$1/src/$1.app.src.script ]; then \
- $(call erlang,$(call dep_autopatch_appsrc_script.erl,$(1))); \
+ $(call erlang,$(call dep_autopatch_appsrc_script.erl,$1)); \
fi; \
- $(call erlang,$(call dep_autopatch_appsrc.erl,$(1))); \
- if [ -f $(DEPS_DIR)/$(1)/rebar -o -f $(DEPS_DIR)/$(1)/rebar.config -o -f $(DEPS_DIR)/$(1)/rebar.config.script -o -f $(DEPS_DIR)/$1/rebar.lock ]; then \
+ $(call erlang,$(call dep_autopatch_appsrc.erl,$1)); \
+ if [ -f $(DEPS_DIR)/$1/rebar -o -f $(DEPS_DIR)/$1/rebar.config -o -f $(DEPS_DIR)/$1/rebar.config.script -o -f $(DEPS_DIR)/$1/rebar.lock ]; then \
$(call dep_autopatch_fetch_rebar); \
- $(call dep_autopatch_rebar,$(1)); \
+ $(call dep_autopatch_rebar,$1); \
else \
- $(call dep_autopatch_gen,$(1)); \
+ $(call dep_autopatch_gen,$1); \
fi
endef
-define dep_autopatch_noop
- printf "noop:\n" > $(DEPS_DIR)/$(1)/Makefile
+define dep_autopatch_for_mix
+ $(call dep_autopatch_mix,$1)
+endef
+
+define dep_autopatch_for_noop
+ test -f $(DEPS_DIR)/$1/Makefile || printf "noop:\n" > $(DEPS_DIR)/$1/Makefile
+endef
+
+define maybe_flock
+ if command -v flock >/dev/null; then \
+ flock $1 sh -c "$2"; \
+ elif command -v lockf >/dev/null; then \
+ lockf $1 sh -c "$2"; \
+ else \
+ $2; \
+ fi
endef
# Replace "include erlang.mk" with a line that will load the parent Erlang.mk
@@ -286,42 +343,36 @@ endif
define dep_autopatch_gen
printf "%s\n" \
"ERLC_OPTS = +debug_info" \
- "include ../../erlang.mk" > $(DEPS_DIR)/$(1)/Makefile
+ "include ../../erlang.mk" > $(DEPS_DIR)/$1/Makefile
endef
# We use flock/lockf when available to avoid concurrency issues.
define dep_autopatch_fetch_rebar
- if command -v flock >/dev/null; then \
- flock $(ERLANG_MK_TMP)/rebar.lock sh -c "$(call dep_autopatch_fetch_rebar2)"; \
- elif command -v lockf >/dev/null; then \
- lockf $(ERLANG_MK_TMP)/rebar.lock sh -c "$(call dep_autopatch_fetch_rebar2)"; \
- else \
- $(call dep_autopatch_fetch_rebar2); \
- fi
+ $(call maybe_flock,$(ERLANG_MK_TMP)/rebar.lock,$(call dep_autopatch_fetch_rebar2))
endef
define dep_autopatch_fetch_rebar2
- if [ ! -d $(ERLANG_MK_TMP)/rebar ]; then \
- git clone -q -n -- $(REBAR_GIT) $(ERLANG_MK_TMP)/rebar; \
- cd $(ERLANG_MK_TMP)/rebar; \
- git checkout -q $(REBAR_COMMIT); \
+ if [ ! -d $(ERLANG_MK_TMP)/rebar3 ]; then \
+ git clone -q -n -- $(REBAR3_GIT) $(ERLANG_MK_TMP)/rebar3; \
+ cd $(ERLANG_MK_TMP)/rebar3; \
+ git checkout -q $(REBAR3_COMMIT); \
./bootstrap; \
cd -; \
fi
endef
define dep_autopatch_rebar
- if [ -f $(DEPS_DIR)/$(1)/Makefile ]; then \
- mv $(DEPS_DIR)/$(1)/Makefile $(DEPS_DIR)/$(1)/Makefile.orig.mk; \
+ 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))); \
- rm -f $(DEPS_DIR)/$(1)/ebin/$(1).app
+ $(call erlang,$(call dep_autopatch_rebar.erl,$1)); \
+ rm -f $(DEPS_DIR)/$1/ebin/$1.app
endef
define dep_autopatch_rebar.erl
application:load(rebar),
application:set_env(rebar, log_level, debug),
- rmemo:start(),
+ {module, rebar3} = c:l(rebar3),
Conf1 = case file:consult("$(call core_native_path,$(DEPS_DIR)/$1/rebar.config)") of
{ok, Conf0} -> Conf0;
_ -> []
@@ -355,7 +406,7 @@ define dep_autopatch_rebar.erl
(V) when is_list(V) -> "'\\"" ++ V ++ "\\"'"
end,
fun() ->
- Write("ERLC_OPTS = +debug_info\nexport ERLC_OPTS\n"),
+ Write("ERLC_OPTS = +debug_info\n"),
case lists:keyfind(erl_opts, 1, Conf) of
false -> ok;
{_, ErlOpts} ->
@@ -378,78 +429,105 @@ define dep_autopatch_rebar.erl
end,
Write("\n")
end(),
- GetHexVsn = fun(N, NP) ->
+ GetHexVsn2 = fun(N, NP) ->
case file:consult("$(call core_native_path,$(DEPS_DIR)/$1/rebar.lock)") of
{ok, Lock} ->
- io:format("~p~n", [Lock]),
- case lists:keyfind("1.1.0", 1, Lock) of
- {_, LockPkgs} ->
- io:format("~p~n", [LockPkgs]),
+ LockPkgs = case lists:keyfind("1.2.0", 1, Lock) of
+ {_, LP} ->
+ LP;
+ _ ->
+ case lists:keyfind("1.1.0", 1, Lock) of
+ {_, LP} ->
+ LP;
+ _ ->
+ false
+ end
+ end,
+ if
+ is_list(LockPkgs) ->
case lists:keyfind(atom_to_binary(N, latin1), 1, LockPkgs) of
{_, {pkg, _, Vsn}, _} ->
- io:format("~p~n", [Vsn]),
{N, {hex, NP, binary_to_list(Vsn)}};
_ ->
false
end;
- _ ->
+ true ->
false
end;
_ ->
false
end
end,
- SemVsn = fun
- ("~>" ++ S0) ->
- S = case S0 of
- " " ++ S1 -> S1;
- _ -> S0
- end,
- case length([ok || $$. <- S]) of
- 0 -> S ++ ".0.0";
- 1 -> S ++ ".0";
- _ -> S
- end;
- (S) -> S
+ GetHexVsn3Common = fun(N, NP, S0) ->
+ case GetHexVsn2(N, NP) of
+ false ->
+ S2 = case S0 of
+ " " ++ S1 -> S1;
+ _ -> S0
+ end,
+ S = case length([ok || $$. <- S2]) of
+ 0 -> S2 ++ ".0.0";
+ 1 -> S2 ++ ".0";
+ _ -> S2
+ end,
+ {N, {hex, NP, S}};
+ NameSource ->
+ NameSource
+ end
+ end,
+ GetHexVsn3 = fun
+ (N, NP, "~>" ++ S0) ->
+ GetHexVsn3Common(N, NP, S0);
+ (N, NP, ">=" ++ S0) ->
+ GetHexVsn3Common(N, NP, S0);
+ (N, NP, S) -> {N, {hex, NP, S}}
+ end,
+ ConvertCommit = fun
+ ({branch, C}) -> C;
+ ({ref, C}) -> C;
+ ({tag, C}) -> C;
+ (C) -> C
end,
fun() ->
File = case lists:keyfind(deps, 1, Conf) of
false -> [];
{_, Deps} ->
[begin case case Dep of
- N when is_atom(N) -> GetHexVsn(N, N);
- {N, S} when is_atom(N), is_list(S) -> {N, {hex, N, SemVsn(S)}};
- {N, {pkg, NP}} when is_atom(N) -> GetHexVsn(N, NP);
- {N, S, {pkg, NP}} -> {N, {hex, NP, S}};
+ N when is_atom(N) -> GetHexVsn2(N, N);
+ {N, S} when is_atom(N), is_list(S) -> GetHexVsn3(N, N, S);
+ {N, {pkg, NP}} when is_atom(N) -> GetHexVsn2(N, NP);
+ {N, S, {pkg, NP}} -> GetHexVsn3(N, NP, S);
{N, S} when is_tuple(S) -> {N, S};
{N, _, S} -> {N, S};
{N, _, S, _} -> {N, S};
_ -> false
end of
false -> ok;
+ {Name, {git_subdir, Repo, Commit, SubDir}} ->
+ Write(io_lib:format("DEPS += ~s\ndep_~s = git-subfolder ~s ~s ~s~n", [Name, Name, Repo, ConvertCommit(Commit), SubDir]));
{Name, Source} ->
{Method, Repo, Commit} = case Source of
{hex, NPV, V} -> {hex, V, NPV};
{git, R} -> {git, R, master};
- {M, R, {branch, C}} -> {M, R, C};
- {M, R, {ref, C}} -> {M, R, C};
- {M, R, {tag, C}} -> {M, R, C};
{M, R, C} -> {M, R, C}
end,
- Write(io_lib:format("DEPS += ~s\ndep_~s = ~s ~s ~s~n", [Name, Name, Method, Repo, Commit]))
+ Write(io_lib:format("DEPS += ~s\ndep_~s = ~s ~s ~s~n", [Name, Name, Method, Repo, ConvertCommit(Commit)]))
end end || Dep <- Deps]
end
end(),
fun() ->
case lists:keyfind(erl_first_files, 1, Conf) of
false -> ok;
- {_, Files} ->
+ {_, Files0} ->
+ Files = [begin
+ hd(filelib:wildcard("$(call core_native_path,$(DEPS_DIR)/$1/src/)**/" ++ filename:rootname(F) ++ ".*rl"))
+ end || "src/" ++ F <- Files0],
Names = [[" ", case lists:reverse(F) of
"lre." ++ Elif -> lists:reverse(Elif);
"lrx." ++ Elif -> lists:reverse(Elif);
"lry." ++ Elif -> lists:reverse(Elif);
Elif -> lists:reverse(Elif)
- end] || "src/" ++ F <- Files],
+ end] || "$(call core_native_path,$(DEPS_DIR)/$1/src/)" ++ F <- Files],
Write(io_lib:format("COMPILE_FIRST +=~s\n", [Names]))
end
end(),
@@ -476,6 +554,8 @@ define dep_autopatch_rebar.erl
Write("\npre-deps::\n\t" ++ PatchHook(Cmd) ++ "\n");
{compile, Cmd} ->
Write("\npre-app::\n\tCC=$$\(CC) " ++ PatchHook(Cmd) ++ "\n");
+ {{pc, compile}, Cmd} ->
+ Write("\npre-app::\n\tCC=$$\(CC) " ++ PatchHook(Cmd) ++ "\n");
{Regex, compile, Cmd} ->
case rebar_utils:is_arch(Regex) of
true -> Write("\npre-app::\n\tCC=$$\(CC) " ++ PatchHook(Cmd) ++ "\n");
@@ -566,9 +646,11 @@ define dep_autopatch_rebar.erl
[[Output, ": ", K, " += ", ShellToMk(V), "\n"] || {K, V} <- lists:reverse(MergeEnv(FilterEnv(Env)))],
Output, ": $$\(foreach ext,.c .C .cc .cpp,",
"$$\(patsubst %$$\(ext),%.o,$$\(filter %$$\(ext),$$\(wildcard", Input, "))))\n",
- "\t$$\(CC) -o $$\@ $$\? $$\(LDFLAGS) $$\(ERL_LDFLAGS) $$\(DRV_LDFLAGS) $$\(EXE_LDFLAGS)",
+ "\t$$\(CC) -o $$\@ $$\? $$\(LDFLAGS) $$\(ERL_LDFLAGS) $$\(DRV_LDFLAGS) $$\(LDLIBS) $$\(EXE_LDFLAGS)",
case {filename:extension(Output), $(PLATFORM)} of
{[], _} -> "\n";
+ {".so", darwin} -> " -shared\n";
+ {".dylib", darwin} -> " -shared\n";
{_, darwin} -> "\n";
_ -> " -shared\n"
end])
@@ -638,9 +720,12 @@ endef
define dep_autopatch_appsrc_script.erl
AppSrc = "$(call core_native_path,$(DEPS_DIR)/$1/src/$1.app.src)",
AppSrcScript = AppSrc ++ ".script",
- {ok, Conf0} = file:consult(AppSrc),
+ Conf1 = case file:consult(AppSrc) of
+ {ok, Conf0} -> Conf0;
+ {error, enoent} -> []
+ end,
Bindings0 = erl_eval:new_bindings(),
- Bindings1 = erl_eval:add_binding('CONFIG', Conf0, Bindings0),
+ Bindings1 = erl_eval:add_binding('CONFIG', Conf1, Bindings0),
Bindings = erl_eval:add_binding('SCRIPT', AppSrcScript, Bindings1),
Conf = case file:script(AppSrcScript, Bindings) of
{ok, [C]} -> C;
@@ -656,7 +741,7 @@ define dep_autopatch_appsrc.erl
case filelib:is_regular(AppSrcIn) of
false -> ok;
true ->
- {ok, [{application, $(1), L0}]} = file:consult(AppSrcIn),
+ {ok, [{application, $1, L0}]} = file:consult(AppSrcIn),
L1 = lists:keystore(modules, 1, L0, {modules, []}),
L2 = case lists:keyfind(vsn, 1, L1) of
{_, git} -> lists:keyreplace(vsn, 1, L1, {vsn, lists:droplast(os:cmd("git -C $(DEPS_DIR)/$1 describe --dirty --tags --always"))});
@@ -664,116 +749,182 @@ define dep_autopatch_appsrc.erl
_ -> L1
end,
L3 = case lists:keyfind(registered, 1, L2) of false -> [{registered, []}|L2]; _ -> L2 end,
- ok = file:write_file(AppSrcOut, io_lib:format("~p.~n", [{application, $(1), L3}])),
+ ok = file:write_file(AppSrcOut, io_lib:format("~p.~n", [{application, $1, L3}])),
case AppSrcOut of AppSrcIn -> ok; _ -> ok = file:delete(AppSrcIn) end
end,
halt()
endef
+ifeq ($(CACHE_DEPS),1)
+
+define dep_cache_fetch_git
+ mkdir -p $(CACHE_DIR)/git; \
+ if test -d "$(join $(CACHE_DIR)/git/,$(call query_name,$1))"; then \
+ cd $(join $(CACHE_DIR)/git/,$(call query_name,$1)); \
+ if ! git checkout -q $(call query_version,$1); then \
+ git remote set-url origin $(call query_repo_git,$1) && \
+ git pull --all && \
+ git cat-file -e $(call query_version_git,$1) 2>/dev/null; \
+ fi; \
+ else \
+ git clone -q -n -- $(call query_repo_git,$1) $(join $(CACHE_DIR)/git/,$(call query_name,$1)); \
+ fi; \
+ git clone -q --single-branch -- $(join $(CACHE_DIR)/git/,$(call query_name,$1)) $2; \
+ cd $2 && git checkout -q $(call query_version_git,$1)
+endef
+
+define dep_fetch_git
+ $(call dep_cache_fetch_git,$1,$(DEPS_DIR)/$(call query_name,$1));
+endef
+
+define dep_fetch_git-subfolder
+ mkdir -p $(ERLANG_MK_TMP)/git-subfolder; \
+ $(call dep_cache_fetch_git,$1,$(ERLANG_MK_TMP)/git-subfolder/$(call query_name,$1)); \
+ ln -s $(ERLANG_MK_TMP)/git-subfolder/$(call query_name,$1)/$(word 4,$(dep_$1)) \
+ $(DEPS_DIR)/$(call query_name,$1);
+endef
+
+else
+
define dep_fetch_git
- git clone -q -n -- $(call dep_repo,$(1)) $(DEPS_DIR)/$(call dep_name,$(1)); \
- cd $(DEPS_DIR)/$(call dep_name,$(1)) && git checkout -q $(call dep_commit,$(1));
+ git clone -q -n -- $(call query_repo_git,$1) $(DEPS_DIR)/$(call query_name,$1); \
+ cd $(DEPS_DIR)/$(call query_name,$1) && git checkout -q $(call query_version_git,$1);
endef
define dep_fetch_git-subfolder
mkdir -p $(ERLANG_MK_TMP)/git-subfolder; \
- git clone -q -n -- $(call dep_repo,$1) \
- $(ERLANG_MK_TMP)/git-subfolder/$(call dep_name,$1); \
- cd $(ERLANG_MK_TMP)/git-subfolder/$(call dep_name,$1) \
- && git checkout -q $(call dep_commit,$1); \
- ln -s $(ERLANG_MK_TMP)/git-subfolder/$(call dep_name,$1)/$(word 4,$(dep_$(1))) \
- $(DEPS_DIR)/$(call dep_name,$1);
+ git clone -q -n -- $(call query_repo_git-subfolder,$1) \
+ $(ERLANG_MK_TMP)/git-subfolder/$(call query_name,$1); \
+ cd $(ERLANG_MK_TMP)/git-subfolder/$(call query_name,$1) \
+ && git checkout -q $(call query_version_git-subfolder,$1); \
+ ln -s $(ERLANG_MK_TMP)/git-subfolder/$(call query_name,$1)/$(word 4,$(dep_$1)) \
+ $(DEPS_DIR)/$(call query_name,$1);
endef
+endif
+
define dep_fetch_git-submodule
git submodule update --init -- $(DEPS_DIR)/$1;
endef
define dep_fetch_hg
- hg clone -q -U $(call dep_repo,$(1)) $(DEPS_DIR)/$(call dep_name,$(1)); \
- cd $(DEPS_DIR)/$(call dep_name,$(1)) && hg update -q $(call dep_commit,$(1));
+ hg clone -q -U $(call query_repo_hg,$1) $(DEPS_DIR)/$(call query_name,$1); \
+ cd $(DEPS_DIR)/$(call query_name,$1) && hg update -q $(call query_version_hg,$1);
endef
define dep_fetch_svn
- svn checkout -q $(call dep_repo,$(1)) $(DEPS_DIR)/$(call dep_name,$(1));
+ svn checkout -q $(call query_repo_svn,$1) $(DEPS_DIR)/$(call query_name,$1);
endef
define dep_fetch_cp
- cp -R $(call dep_repo,$(1)) $(DEPS_DIR)/$(call dep_name,$(1));
+ cp -R $(call query_repo_cp,$1) $(DEPS_DIR)/$(call query_name,$1);
endef
define dep_fetch_ln
- ln -s $(call dep_repo,$(1)) $(DEPS_DIR)/$(call dep_name,$(1));
+ ln -s $(call query_repo_ln,$1) $(DEPS_DIR)/$(call query_name,$1);
endef
+define hex_get_tarball.erl
+ {ok, _} = application:ensure_all_started(ssl),
+ {ok, _} = application:ensure_all_started(inets),
+ Config = $(hex_config.erl),
+ case hex_repo:get_tarball(Config, <<"$1">>, <<"$(strip $2)">>) of
+ {ok, {200, _, Tarball}} ->
+ ok = file:write_file("$(call core_native_path,$3)", Tarball),
+ halt(0);
+ {ok, {Status, _, Errors}} ->
+ io:format("Error ~b: ~0p~n", [Status, Errors]),
+ halt(79)
+ end
+endef
+
+ifeq ($(CACHE_DEPS),1)
+
+# Hex only has a package version. No need to look in the Erlang.mk packages.
+define dep_fetch_hex
+ mkdir -p $(CACHE_DIR)/hex $(DEPS_DIR)/$1; \
+ $(eval hex_pkg_name := $(if $(word 3,$(dep_$1)),$(word 3,$(dep_$1)),$1)) \
+ $(eval hex_tar_name := $(hex_pkg_name)-$(strip $(word 2,$(dep_$1))).tar) \
+ $(if $(wildcard $(CACHE_DIR)/hex/$(hex_tar_name)),,\
+ $(call erlang,$(call hex_get_tarball.erl,$(hex_pkg_name),$(word 2,$(dep_$1)),$(CACHE_DIR)/hex/$(hex_tar_name)));) \
+ tar -xOf $(CACHE_DIR)/hex/$(hex_tar_name) contents.tar.gz | tar -C $(DEPS_DIR)/$1 -xzf -;
+endef
+
+else
+
# Hex only has a package version. No need to look in the Erlang.mk packages.
define dep_fetch_hex
mkdir -p $(ERLANG_MK_TMP)/hex $(DEPS_DIR)/$1; \
- $(call core_http_get,$(ERLANG_MK_TMP)/hex/$1.tar,\
- https://repo.hex.pm/tarballs/$(if $(word 3,$(dep_$1)),$(word 3,$(dep_$1)),$1)-$(strip $(word 2,$(dep_$1))).tar); \
+ $(call erlang,$(call hex_get_tarball.erl,$(if $(word 3,$(dep_$1)),$(word 3,$(dep_$1)),$1),$(word 2,$(dep_$1)),$(ERLANG_MK_TMP)/hex/$1.tar)); \
tar -xOf $(ERLANG_MK_TMP)/hex/$1.tar contents.tar.gz | tar -C $(DEPS_DIR)/$1 -xzf -;
endef
+endif
+
define dep_fetch_fail
- echo "Error: Unknown or invalid dependency: $(1)." >&2; \
+ echo "Error: Unknown or invalid dependency: $1." >&2; \
exit 78;
endef
-# Kept for compatibility purposes with older Erlang.mk configuration.
-define dep_fetch_legacy
- $(warning WARNING: '$(1)' dependency configuration uses deprecated format.) \
- git clone -q -n -- $(word 1,$(dep_$(1))) $(DEPS_DIR)/$(1); \
- cd $(DEPS_DIR)/$(1) && git checkout -q $(if $(word 2,$(dep_$(1))),$(word 2,$(dep_$(1))),master);
-endef
-
define dep_target
-$(DEPS_DIR)/$(call dep_name,$1): | $(ERLANG_MK_TMP)
- $(eval DEP_NAME := $(call dep_name,$1))
+$(DEPS_DIR)/$(call query_name,$1): $(if $(filter elixir,$(BUILD_DEPS) $(DEPS)),$(if $(filter-out elixir,$1),$(DEPS_DIR)/elixir/ebin/dep_built)) $(if $(filter hex,$(call query_fetch_method,$1)),$(if $(wildcard $(DEPS_DIR)/$(call query_name,$1)),,$(DEPS_DIR)/hex_core/ebin/dep_built)) | $(ERLANG_MK_TMP)
+ $(eval DEP_NAME := $(call query_name,$1))
$(eval DEP_STR := $(if $(filter $1,$(DEP_NAME)),$1,"$1 ($(DEP_NAME))"))
$(verbose) if test -d $(APPS_DIR)/$(DEP_NAME); then \
echo "Error: Dependency" $(DEP_STR) "conflicts with application found in $(APPS_DIR)/$(DEP_NAME)." >&2; \
exit 17; \
fi
$(verbose) mkdir -p $(DEPS_DIR)
- $(dep_verbose) $(call dep_fetch_$(strip $(call dep_fetch,$(1))),$(1))
- $(verbose) if [ -f $(DEPS_DIR)/$(1)/configure.ac -o -f $(DEPS_DIR)/$(1)/configure.in ] \
- && [ ! -f $(DEPS_DIR)/$(1)/configure ]; then \
+ $(dep_verbose) $(call dep_fetch_$(strip $(call query_fetch_method,$1)),$1)
+ $(verbose) if [ -f $(DEPS_DIR)/$1/configure.ac -o -f $(DEPS_DIR)/$1/configure.in ] \
+ && [ ! -f $(DEPS_DIR)/$1/configure ]; then \
echo " AUTO " $(DEP_STR); \
- cd $(DEPS_DIR)/$(1) && autoreconf -Wall -vif -I m4; \
+ cd $(DEPS_DIR)/$1 && autoreconf -Wall -vif -I m4; \
fi
- $(verbose) if [ -f $(DEPS_DIR)/$(DEP_NAME)/configure ]; then \
echo " CONF " $(DEP_STR); \
cd $(DEPS_DIR)/$(DEP_NAME) && ./configure; \
fi
-ifeq ($(filter $(1),$(NO_AUTOPATCH)),)
- $(verbose) $$(MAKE) --no-print-directory autopatch-$(DEP_NAME)
+ifeq ($(filter $1,$(NO_AUTOPATCH)),)
+ $(verbose) AUTOPATCH_METHOD=`$(call dep_autopatch_detect,$1)`; \
+ if [ $$$$? -eq 99 ]; then \
+ echo "Elixir is currently disabled. Please set 'ELIXIR = system' in the Makefile to enable"; \
+ exit 99; \
+ fi; \
+ $$(MAKE) --no-print-directory autopatch-$(DEP_NAME) AUTOPATCH_METHOD=$$$$AUTOPATCH_METHOD
endif
-.PHONY: autopatch-$(call dep_name,$1)
+.PHONY: autopatch-$(call query_name,$1)
-autopatch-$(call dep_name,$1)::
- $(verbose) if [ "$(1)" = "amqp_client" -a "$(RABBITMQ_CLIENT_PATCH)" ]; then \
- if [ ! -d $(DEPS_DIR)/rabbitmq-codegen ]; then \
- echo " PATCH Downloading rabbitmq-codegen"; \
- git clone https://github.com/rabbitmq/rabbitmq-codegen.git $(DEPS_DIR)/rabbitmq-codegen; \
- fi; \
- if [ ! -d $(DEPS_DIR)/rabbitmq-server ]; then \
- echo " PATCH Downloading rabbitmq-server"; \
- git clone https://github.com/rabbitmq/rabbitmq-server.git $(DEPS_DIR)/rabbitmq-server; \
- fi; \
- ln -s $(DEPS_DIR)/amqp_client/deps/rabbit_common-0.0.0 $(DEPS_DIR)/rabbit_common; \
- elif [ "$(1)" = "rabbit" -a "$(RABBITMQ_SERVER_PATCH)" ]; then \
- if [ ! -d $(DEPS_DIR)/rabbitmq-codegen ]; then \
- echo " PATCH Downloading rabbitmq-codegen"; \
- git clone https://github.com/rabbitmq/rabbitmq-codegen.git $(DEPS_DIR)/rabbitmq-codegen; \
- fi \
- elif [ "$1" = "elixir" -a "$(ELIXIR_PATCH)" ]; then \
- ln -s lib/elixir/ebin $(DEPS_DIR)/elixir/; \
- else \
- $$(call dep_autopatch,$(call dep_name,$1)) \
- fi
+ifeq ($1,elixir)
+autopatch-elixir::
+ $$(verbose) ln -s lib/elixir/ebin $(DEPS_DIR)/elixir/
+else
+autopatch-$(call query_name,$1)::
+ $$(autopatch_verbose) $$(call dep_autopatch_for_$(AUTOPATCH_METHOD),$(call query_name,$1))
+endif
endef
+# We automatically depend on hex_core when the project isn't already.
+$(if $(filter hex_core,$(DEPS) $(BUILD_DEPS) $(DOC_DEPS) $(REL_DEPS) $(TEST_DEPS)),,\
+ $(eval $(call dep_target,hex_core)))
+
+$(DEPS_DIR)/hex_core/ebin/dep_built: | $(ERLANG_MK_TMP)
+ $(verbose) $(call maybe_flock,$(ERLANG_MK_TMP)/hex_core.lock,\
+ if [ ! -e $(DEPS_DIR)/hex_core/ebin/dep_built ]; then \
+ $(MAKE) $(DEPS_DIR)/hex_core; \
+ $(MAKE) -C $(DEPS_DIR)/hex_core IS_DEP=1; \
+ touch $(DEPS_DIR)/hex_core/ebin/dep_built; \
+ fi)
+
+$(DEPS_DIR)/elixir/ebin/dep_built: | $(ERLANG_MK_TMP)
+ $(verbose) $(call maybe_flock,$(ERLANG_MK_TMP)/elixir.lock,\
+ if [ ! -e $(DEPS_DIR)/elixir/ebin/dep_built ]; then \
+ $(MAKE) $(DEPS_DIR)/elixir; \
+ $(MAKE) -C $(DEPS_DIR)/elixir; \
+ touch $(DEPS_DIR)/elixir/ebin/dep_built; \
+ fi)
+
$(foreach dep,$(BUILD_DEPS) $(DEPS),$(eval $(call dep_target,$(dep))))
ifndef IS_APP
@@ -799,6 +950,16 @@ distclean-deps:
$(gen_verbose) rm -rf $(DEPS_DIR)
endif
+ifeq ($(CACHE_DEPS),1)
+cacheclean:: cacheclean-git cacheclean-hex
+
+cacheclean-git:
+ $(gen_verbose) rm -rf $(CACHE_DIR)/git
+
+cacheclean-hex:
+ $(gen_verbose) rm -rf $(CACHE_DIR)/hex
+endif
+
# Forward-declare variables used in core/deps-tools.mk. This is required
# in case plugins use them.
diff --git a/core/elixir.mk b/core/elixir.mk
new file mode 100644
index 0000000..7b6bdd8
--- /dev/null
+++ b/core/elixir.mk
@@ -0,0 +1,201 @@
+# Copyright (c) 2024, Tyler Hughes <[email protected]>
+# Copyright (c) 2024, Loïc Hoguin <[email protected]>
+# This file is part of erlang.mk and subject to the terms of the ISC License.
+
+ifeq ($(ELIXIR),system)
+# We expect 'elixir' to be on the path.
+ELIXIR_BIN ?= $(shell readlink -f `which elixir`)
+ELIXIR_LIBS ?= $(abspath $(dir $(ELIXIR_BIN))/../lib)
+# Fallback in case 'elixir' is a shim.
+ifeq ($(wildcard $(ELIXIR_LIBS)/elixir/),)
+ELIXIR_LIBS = $(abspath $(shell elixir -e 'IO.puts(:code.lib_dir(:elixir))')/../)
+endif
+ELIXIR_LIBS := $(ELIXIR_LIBS)
+export ELIXIR_LIBS
+ERL_LIBS := $(ERL_LIBS):$(ELIXIR_LIBS)
+else
+ifeq ($(ELIXIR),dep)
+ERL_LIBS := $(ERL_LIBS):$(DEPS_DIR)/elixir/lib/
+endif
+endif
+
+elixirc_verbose_0 = @echo " EXC $(words $(EX_FILES)) files";
+elixirc_verbose_2 = set -x;
+elixirc_verbose = $(elixirc_verbose_$(V))
+
+# Unfortunately this currently requires Elixir.
+# https://github.com/jelly-beam/verl is a good choice
+# for an Erlang implementation, but we already have to
+# pull hex_core and Rebar3 so adding yet another pull
+# is annoying, especially one that would be necessary
+# every time we autopatch Rebar projects. Wait and see.
+define hex_version_resolver.erl
+ HexVersionResolve = fun(Name, Req) ->
+ application:ensure_all_started(ssl),
+ application:ensure_all_started(inets),
+ Config = $(hex_config.erl),
+ case hex_repo:get_package(Config, atom_to_binary(Name)) of
+ {ok, {200, _RespHeaders, Package}} ->
+ #{releases := List} = Package,
+ {value, #{version := Version}} = lists:search(fun(#{version := Vsn}) ->
+ M = list_to_atom("Elixir.Version"),
+ F = list_to_atom("match?"),
+ M:F(Vsn, Req)
+ end, List),
+ {ok, Version};
+ {ok, {Status, _, Errors}} ->
+ {error, Status, Errors}
+ end
+ end,
+ HexVersionResolveAndPrint = fun(Name, Req) ->
+ case HexVersionResolve(Name, Req) of
+ {ok, Version} ->
+ io:format("~s", [Version]),
+ halt(0);
+ {error, Status, Errors} ->
+ io:format("Error ~b: ~0p~n", [Status, Errors]),
+ halt(77)
+ end
+ end
+endef
+
+define dep_autopatch_mix.erl
+ $(call hex_version_resolver.erl),
+ {ok, _} = application:ensure_all_started(elixir),
+ {ok, _} = application:ensure_all_started(mix),
+ MixFile = <<"$(call core_native_path,$(DEPS_DIR)/$1/mix.exs)">>,
+ {Mod, Bin} =
+ case elixir_compiler:file(MixFile, fun(_File, _LexerPid) -> ok end) of
+ [{T = {_, _}, _CheckerPid}] -> T;
+ [T = {_, _}] -> T
+ end,
+ {module, Mod} = code:load_binary(Mod, binary_to_list(MixFile), Bin),
+ Project = Mod:project(),
+ Application = try Mod:application() catch error:undef -> [] end,
+ StartMod = case lists:keyfind(mod, 1, Application) of
+ {mod, {StartMod0, _StartArgs}} ->
+ atom_to_list(StartMod0);
+ _ ->
+ ""
+ end,
+ Write = fun (Text) ->
+ file:write_file("$(call core_native_path,$(DEPS_DIR)/$1/Makefile)", Text, [append])
+ end,
+ Write([
+ "PROJECT = ", atom_to_list(proplists:get_value(app, Project)), "\n"
+ "PROJECT_DESCRIPTION = ", proplists:get_value(description, Project, ""), "\n"
+ "PROJECT_VERSION = ", proplists:get_value(version, Project, ""), "\n"
+ "PROJECT_MOD = ", StartMod, "\n"
+ "define PROJECT_ENV\n",
+ io_lib:format("~p", [proplists:get_value(env, Application, [])]), "\n"
+ "endef\n\n"]),
+ ExtraApps = lists:usort([eex, elixir, logger, mix] ++ proplists:get_value(extra_applications, Application, [])),
+ Write(["LOCAL_DEPS += ", lists:join(" ", [atom_to_list(App) || App <- ExtraApps]), "\n\n"]),
+ Deps = proplists:get_value(deps, Project, []) -- [elixir_make],
+ IsRequiredProdDep = fun(Opts) ->
+ (proplists:get_value(optional, Opts) =/= true)
+ andalso
+ case proplists:get_value(only, Opts, prod) of
+ prod -> true;
+ L when is_list(L) -> lists:member(prod, L);
+ _ -> false
+ end
+ end,
+ lists:foreach(fun
+ ({Name, Req}) when is_binary(Req) ->
+ {ok, Vsn} = HexVersionResolve(Name, Req),
+ Write(["DEPS += ", atom_to_list(Name), "\n"]),
+ Write(["dep_", atom_to_list(Name), " = hex ", Vsn, " ", atom_to_list(Name), "\n"]);
+ ({Name, Opts}) when is_list(Opts) ->
+ Path = proplists:get_value(path, Opts),
+ case IsRequiredProdDep(Opts) of
+ true when Path =/= undefined ->
+ Write(["DEPS += ", atom_to_list(Name), "\n"]),
+ Write(["dep_", atom_to_list(Name), " = ln ", Path, "\n"]);
+ true when Path =:= undefined ->
+ Write(["DEPS += ", atom_to_list(Name), "\n"]),
+ io:format(standard_error, "Warning: No version given for ~p.", [Name]);
+ false ->
+ ok
+ end;
+ ({Name, Req, Opts}) ->
+ case IsRequiredProdDep(Opts) of
+ true ->
+ {ok, Vsn} = HexVersionResolve(Name, Req),
+ Write(["DEPS += ", atom_to_list(Name), "\n"]),
+ Write(["dep_", atom_to_list(Name), " = hex ", Vsn, " ", atom_to_list(Name), "\n"]);
+ false ->
+ ok
+ end;
+ (_) ->
+ ok
+ end, Deps),
+ case lists:member(elixir_make, proplists:get_value(compilers, Project, [])) of
+ false ->
+ ok;
+ true ->
+ Write("# https://hexdocs.pm/elixir_make/Mix.Tasks.Compile.ElixirMake.html\n"),
+ MakeVal = fun(Key, Proplist, DefaultVal, DefaultReplacement) ->
+ case proplists:get_value(Key, Proplist, DefaultVal) of
+ DefaultVal -> DefaultReplacement;
+ Value -> Value
+ end
+ end,
+ MakeMakefile = binary_to_list(MakeVal(make_makefile, Project, default, <<"Makefile">>)),
+ MakeExe = MakeVal(make_executable, Project, default, "$$\(MAKE)"),
+ MakeCwd = MakeVal(make_cwd, Project, undefined, <<".">>),
+ MakeTargets = MakeVal(make_targets, Project, [], []),
+ MakeArgs = MakeVal(make_args, Project, undefined, []),
+ case file:rename("$(DEPS_DIR)/$1/" ++ MakeMakefile, "$(DEPS_DIR)/$1/elixir_make.mk") of
+ ok -> ok;
+ Err = {error, _} ->
+ io:format(standard_error, "Failed to copy Makefile with error ~p~n", [Err]),
+ halt(90)
+ end,
+ Write(["app::\n"
+ "\t", MakeExe, " -C ", MakeCwd, " -f $(DEPS_DIR)/$1/elixir_make.mk",
+ lists:join(" ", MakeTargets),
+ lists:join(" ", MakeArgs),
+ "\n\n"]),
+ case MakeVal(make_clean, Project, nil, undefined) of
+ undefined ->
+ ok;
+ Clean ->
+ Write(["clean::\n\t", Clean, "\n\n"])
+ end
+ end,
+ Write("ERLC_OPTS = +debug_info\n\n"),
+ Write("include $$\(if $$\(ERLANG_MK_FILENAME),$$\(ERLANG_MK_FILENAME),erlang.mk)"),
+ halt()
+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; \
+ $(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))
+endef
+
+# We change the group leader so the Elixir io:format output
+# isn't captured as we need to either print the modules on
+# success, or print _ERROR_ on failure.
+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"),
+ ModMixProject = list_to_atom("Elixir.Mix.Project"),
+ erlang:group_leader(whereis(standard_error), self()),
+ ModMixProject:in_project($(PROJECT), ".", [], fun(_MixFile) ->
+ case ModComp:compile_to_path([$(call comma_list,$(patsubst %,<<"%">>,$1))], <<"ebin/">>) of
+ {ok, Modules, _} ->
+ lists:foreach(fun(E) -> io:format(user, "~p ", [E]) end, Modules),
+ halt(0);
+ {error, _ErroredModules, _WarnedModules} ->
+ io:format(user, "_ERROR_", []),
+ halt(1)
+ end
+ end)
+endef
diff --git a/core/erlc.mk b/core/erlc.mk
index 71ba5b9..c956c4d 100644
--- a/core/erlc.mk
+++ b/core/erlc.mk
@@ -49,40 +49,29 @@ mib_verbose_0 = @echo " MIB " $(filter %.bin %.mib,$(?F));
mib_verbose_2 = set -x;
mib_verbose = $(mib_verbose_$(V))
-ifneq ($(wildcard src/),)
+ifneq ($(wildcard src/)$(wildcard lib/),)
# Targets.
-app:: $(if $(wildcard ebin/test),clean) deps
+app:: $(if $(wildcard ebin/test),beam-cache-restore-app) deps
$(verbose) $(MAKE) --no-print-directory $(PROJECT).d
$(verbose) $(MAKE) --no-print-directory app-build
-ifeq ($(wildcard src/$(PROJECT_MOD).erl),)
-define app_file
-{application, '$(PROJECT)', [
- {description, "$(PROJECT_DESCRIPTION)"},
- {vsn, "$(PROJECT_VERSION)"},$(if $(IS_DEP),
- {id$(comma)$(space)"$(1)"}$(comma))
- {modules, [$(call comma_list,$(2))]},
- {registered, []},
- {applications, [$(call comma_list,kernel stdlib $(OTP_DEPS) $(LOCAL_DEPS) $(foreach dep,$(DEPS),$(call dep_name,$(dep))))]},
- {env, $(subst \,\\,$(PROJECT_ENV))}$(if $(findstring {,$(PROJECT_APP_EXTRA_KEYS)),$(comma)$(newline)$(tab)$(subst \,\\,$(PROJECT_APP_EXTRA_KEYS)),)
-]}.
-endef
-else
+PROJECT_MOD := $(if $(PROJECT_MOD),$(PROJECT_MOD),$(if $(wildcard src/$(PROJECT)_app.erl),$(PROJECT)_app))
+
define app_file
{application, '$(PROJECT)', [
{description, "$(PROJECT_DESCRIPTION)"},
{vsn, "$(PROJECT_VERSION)"},$(if $(IS_DEP),
- {id$(comma)$(space)"$(1)"}$(comma))
- {modules, [$(call comma_list,$(2))]},
- {registered, [$(call comma_list,$(PROJECT)_sup $(PROJECT_REGISTERED))]},
- {applications, [$(call comma_list,kernel stdlib $(OTP_DEPS) $(LOCAL_DEPS) $(foreach dep,$(DEPS),$(call dep_name,$(dep))))]},
- {mod, {$(PROJECT_MOD), []}},
+ {id$(comma)$(space)"$1"}$(comma))
+ {modules, [$(call comma_list,$2)]},
+ {registered, [$(if $(PROJECT_MOD),$(call comma_list,$(if $(filter $(PROJECT_MOD),$(PROJECT)_app),$(PROJECT)_sup) $(PROJECT_REGISTERED)))]},
+ {applications, [$(call comma_list,kernel stdlib $(OTP_DEPS) $(LOCAL_DEPS) $(OPTIONAL_DEPS) $(foreach dep,$(DEPS),$(call query_name,$(dep))))]},
+ {optional_applications, [$(call comma_list,$(OPTIONAL_DEPS))]},$(if $(PROJECT_MOD),
+ {mod$(comma)$(space){$(patsubst %,'%',$(PROJECT_MOD))$(comma)$(space)[]}}$(comma))
{env, $(subst \,\\,$(PROJECT_ENV))}$(if $(findstring {,$(PROJECT_APP_EXTRA_KEYS)),$(comma)$(newline)$(tab)$(subst \,\\,$(PROJECT_APP_EXTRA_KEYS)),)
]}.
endef
-endif
app-build: ebin/$(PROJECT).app
$(verbose) :
@@ -94,6 +83,9 @@ ALL_SRC_FILES := $(sort $(call core_find,src/,*))
ERL_FILES := $(filter %.erl,$(ALL_SRC_FILES))
CORE_FILES := $(filter %.core,$(ALL_SRC_FILES))
+ALL_LIB_FILES := $(sort $(call core_find,lib/,*))
+EX_FILES := $(filter-out lib/mix/%,$(filter %.ex,$(ALL_SRC_FILES) $(ALL_LIB_FILES)))
+
# ASN.1 files.
ifneq ($(wildcard asn1/),)
@@ -102,7 +94,7 @@ ERL_FILES += $(addprefix src/,$(patsubst %.asn1,%.erl,$(notdir $(ASN1_FILES))))
define compile_asn1
$(verbose) mkdir -p include/
- $(asn1_verbose) erlc -v -I include/ -o asn1/ +noobj $(ERLC_ASN1_OPTS) $(1)
+ $(asn1_verbose) erlc -v -I include/ -o asn1/ +noobj $(ERLC_ASN1_OPTS) $1
$(verbose) mv asn1/*.erl src/
-$(verbose) mv asn1/*.hrl include/
$(verbose) mv asn1/*.asn1db include/
@@ -222,7 +214,6 @@ define makedep.erl
end,
MakeDepend = fun
(F, Fd, Mod, StartLocation) ->
- {ok, Filename} = file:pid2name(Fd),
case io:parse_erl_form(Fd, undefined, StartLocation) of
{ok, AbsData, EndLocation} ->
case AbsData of
@@ -265,26 +256,26 @@ define makedep.erl
[233] -> unicode:characters_to_binary(Output0);
_ -> Output0
end,
- ok = file:write_file("$(1)", Output),
+ ok = file:write_file("$1", Output),
halt()
endef
ifeq ($(if $(NO_MAKEDEP),$(wildcard $(PROJECT).d),),)
-$(PROJECT).d:: $(ERL_FILES) $(call core_find,include/,*.hrl) $(MAKEFILE_LIST)
+$(PROJECT).d:: $(ERL_FILES) $(EX_FILES) $(call core_find,include/,*.hrl) $(MAKEFILE_LIST)
$(makedep_verbose) $(call erlang,$(call makedep.erl,$@))
endif
ifeq ($(IS_APP)$(IS_DEP),)
-ifneq ($(words $(ERL_FILES) $(CORE_FILES) $(ASN1_FILES) $(MIB_FILES) $(XRL_FILES) $(YRL_FILES)),0)
+ifneq ($(words $(ERL_FILES) $(EX_FILES) $(CORE_FILES) $(ASN1_FILES) $(MIB_FILES) $(XRL_FILES) $(YRL_FILES) $(EX_FILES)),0)
# Rebuild everything when the Makefile changes.
$(ERLANG_MK_TMP)/last-makefile-change: $(MAKEFILE_LIST) | $(ERLANG_MK_TMP)
$(verbose) if test -f $@; then \
- touch $(ERL_FILES) $(CORE_FILES) $(ASN1_FILES) $(MIB_FILES) $(XRL_FILES) $(YRL_FILES); \
+ touch $(ERL_FILES) $(EX_FILES) $(CORE_FILES) $(ASN1_FILES) $(MIB_FILES) $(XRL_FILES) $(YRL_FILES) $(EX_FILES); \
touch -c $(PROJECT).d; \
fi
$(verbose) touch $@
-$(ERL_FILES) $(CORE_FILES) $(ASN1_FILES) $(MIB_FILES) $(XRL_FILES) $(YRL_FILES):: $(ERLANG_MK_TMP)/last-makefile-change
+$(ERL_FILES) $(EX_FILES) $(CORE_FILES) $(ASN1_FILES) $(MIB_FILES) $(XRL_FILES) $(YRL_FILES):: $(ERLANG_MK_TMP)/last-makefile-change
ebin/$(PROJECT).app:: $(ERLANG_MK_TMP)/last-makefile-change
endif
endif
@@ -301,7 +292,7 @@ ebin/:
define compile_erl
$(erlc_verbose) erlc -v $(if $(IS_DEP),$(filter-out -Werror,$(ERLC_OPTS)),$(ERLC_OPTS)) -o ebin/ \
- -pa ebin/ -I include/ $(filter-out $(ERLC_EXCLUDE_PATHS),$(COMPILE_FIRST_PATHS) $(1))
+ -pa ebin/ -I include/ $(filter-out $(ERLC_EXCLUDE_PATHS),$(COMPILE_FIRST_PATHS) $1)
endef
define validate_app_file
@@ -311,13 +302,16 @@ define validate_app_file
end
endef
-ebin/$(PROJECT).app:: $(ERL_FILES) $(CORE_FILES) $(wildcard src/$(PROJECT).app.src)
- $(eval FILES_TO_COMPILE := $(filter-out src/$(PROJECT).app.src,$?))
+ebin/$(PROJECT).app:: $(ERL_FILES) $(CORE_FILES) $(wildcard src/$(PROJECT).app.src) $(EX_FILES)
+ $(eval FILES_TO_COMPILE := $(filter-out $(EX_FILES) src/$(PROJECT).app.src,$?))
$(if $(strip $(FILES_TO_COMPILE)),$(call compile_erl,$(FILES_TO_COMPILE)))
+ $(if $(filter $(ELIXIR),disable),,$(if $(filter $?,$(EX_FILES)),$(elixirc_verbose) $(eval MODULES := $(shell $(call erlang,$(call compile_ex.erl,$(EX_FILES)))))))
+ $(eval ELIXIR_COMP_FAILED := $(if $(filter _ERROR_,$(firstword $(MODULES))),true,false))
# Older git versions do not have the --first-parent flag. Do without in that case.
+ $(verbose) if $(ELIXIR_COMP_FAILED); then exit 1; fi
$(eval GITDESCRIBE := $(shell git describe --dirty --abbrev=7 --tags --always --first-parent 2>/dev/null \
|| git describe --dirty --abbrev=7 --tags --always 2>/dev/null || true))
- $(eval MODULES := $(patsubst %,'%',$(sort $(notdir $(basename \
+ $(eval MODULES := $(MODULES) $(patsubst %,'%',$(sort $(notdir $(basename \
$(filter-out $(ERLC_EXCLUDE_PATHS),$(ERL_FILES) $(CORE_FILES) $(BEAM_FILES)))))))
ifeq ($(wildcard src/$(PROJECT).app.src),)
$(app_verbose) printf '$(subst %,%%,$(subst $(newline),\n,$(subst ','\'',$(call app_file,$(GITDESCRIBE),$(MODULES)))))' \
diff --git a/core/index.mk b/core/index.mk
index 0b75209..25c5e51 100644
--- a/core/index.mk
+++ b/core/index.mk
@@ -5,7 +5,7 @@
define pkg_print
$(verbose) printf "%s\n" \
- $(if $(call core_eq,$(1),$(pkg_$(1)_name)),,"Pkg name: $(1)") \
+ $(if $(call core_eq,$1,$(pkg_$(1)_name)),,"Pkg name: $1") \
"App name: $(pkg_$(1)_name)" \
"Description: $(pkg_$(1)_description)" \
"Home page: $(pkg_$(1)_homepage)" \
@@ -19,8 +19,8 @@ endef
search:
ifdef q
$(foreach p,$(PACKAGES), \
- $(if $(findstring $(call core_lc,$(q)),$(call core_lc,$(pkg_$(p)_name) $(pkg_$(p)_description))), \
- $(call pkg_print,$(p))))
+ $(if $(findstring $(call core_lc,$q),$(call core_lc,$(pkg_$(p)_name) $(pkg_$(p)_description))), \
+ $(call pkg_print,$p)))
else
- $(foreach p,$(PACKAGES),$(call pkg_print,$(p)))
+ $(foreach p,$(PACKAGES),$(call pkg_print,$p))
endif
diff --git a/core/kerl.mk b/core/kerl.mk
index eec0712..35ce1f3 100644
--- a/core/kerl.mk
+++ b/core/kerl.mk
@@ -21,19 +21,10 @@ KERL_MAKEFLAGS ?=
OTP_GIT ?= https://github.com/erlang/otp
define kerl_otp_target
-$(KERL_INSTALL_DIR)/$(1): $(KERL)
+$(KERL_INSTALL_DIR)/$1: $(KERL)
$(verbose) if [ ! -d $$@ ]; then \
- MAKEFLAGS="$(KERL_MAKEFLAGS)" $(KERL) build git $(OTP_GIT) $(1) $(1); \
- $(KERL) install $(1) $(KERL_INSTALL_DIR)/$(1); \
- fi
-endef
-
-define kerl_hipe_target
-$(KERL_INSTALL_DIR)/$1-native: $(KERL)
- $(verbose) if [ ! -d $$@ ]; then \
- KERL_CONFIGURE_OPTIONS=--enable-native-libs \
- MAKEFLAGS="$(KERL_MAKEFLAGS)" $(KERL) build git $(OTP_GIT) $1 $1-native; \
- $(KERL) install $1-native $(KERL_INSTALL_DIR)/$1-native; \
+ MAKEFLAGS="$(KERL_MAKEFLAGS)" $(KERL) build git $(OTP_GIT) $1 $1; \
+ $(KERL) install $1 $(KERL_INSTALL_DIR)/$1; \
fi
endef
@@ -59,10 +50,10 @@ ERLANG_OTP := $(notdir $(lastword $(sort\
endif
ERLANG_OTP ?=
-ERLANG_HIPE ?=
# Use kerl to enforce a specific Erlang/OTP version for a project.
ifneq ($(strip $(ERLANG_OTP)),)
+
export PATH := $(KERL_INSTALL_DIR)/$(ERLANG_OTP)/bin:$(PATH)
SHELL := env PATH=$(PATH) $(SHELL)
$(eval $(call kerl_otp_target,$(ERLANG_OTP)))
@@ -73,18 +64,4 @@ $(info Building Erlang/OTP $(ERLANG_OTP)... Please wait...)
$(shell $(MAKE) $(KERL_INSTALL_DIR)/$(ERLANG_OTP) ERLANG_OTP=$(ERLANG_OTP) BUILD_ERLANG_OTP=1 >&2)
endif
-else
-# Same for a HiPE enabled VM.
-ifneq ($(strip $(ERLANG_HIPE)),)
-export PATH := $(KERL_INSTALL_DIR)/$(ERLANG_HIPE)-native/bin:$(PATH)
-SHELL := env PATH=$(PATH) $(SHELL)
-$(eval $(call kerl_hipe_target,$(ERLANG_HIPE)))
-
-# Build Erlang/OTP only if it doesn't already exist.
-ifeq ($(wildcard $(KERL_INSTALL_DIR)/$(ERLANG_HIPE)-native)$(BUILD_ERLANG_OTP),)
-$(info Building HiPE-enabled Erlang/OTP $(ERLANG_OTP)... Please wait...)
-$(shell $(MAKE) $(KERL_INSTALL_DIR)/$(ERLANG_HIPE)-native ERLANG_HIPE=$(ERLANG_HIPE) BUILD_ERLANG_OTP=1 >&2)
-endif
-
-endif
endif
diff --git a/core/test.mk b/core/test.mk
index 8054abc..d576619 100644
--- a/core/test.mk
+++ b/core/test.mk
@@ -41,18 +41,21 @@ test_erlc_verbose = $(test_erlc_verbose_$(V))
define compile_test_erl
$(test_erlc_verbose) erlc -v $(TEST_ERLC_OPTS) -o $(TEST_DIR) \
- -pa ebin/ -I include/ $(1)
+ -pa ebin/ -I include/ $1
endef
ERL_TEST_FILES = $(call core_find,$(TEST_DIR)/,*.erl)
+
$(ERLANG_MK_TMP)/$(PROJECT).last-testdir-build: $(ERL_TEST_FILES) $(MAKEFILE_LIST)
- $(eval FILES_TO_COMPILE := $(if $(filter $(MAKEFILE_LIST),$?),$(filter $(ERL_TEST_FILES),$^),$?))
+# When we have to recompile files in src/ the .d file always gets rebuilt.
+# Therefore we want to ignore it when rebuilding test files.
+ $(eval FILES_TO_COMPILE := $(if $(filter $(filter-out $(PROJECT).d,$(MAKEFILE_LIST)),$?),$(filter $(ERL_TEST_FILES),$^),$(filter $(ERL_TEST_FILES),$?)))
$(if $(strip $(FILES_TO_COMPILE)),$(call compile_test_erl,$(FILES_TO_COMPILE)) && touch $@)
endif
test-build:: IS_TEST=1
test-build:: ERLC_OPTS=$(TEST_ERLC_OPTS)
-test-build:: $(if $(wildcard src),$(if $(wildcard ebin/test),,clean)) $(if $(IS_APP),,deps test-deps)
+test-build:: $(if $(wildcard src),$(if $(wildcard ebin/test),,beam-cache-restore-test)) $(if $(IS_APP),,deps test-deps)
# We already compiled everything when IS_APP=1.
ifndef IS_APP
ifneq ($(wildcard src),)