aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--core/erlc.mk3
-rw-r--r--doc/src/guide/app.asciidoc12
-rw-r--r--doc/src/guide/external_plugins.asciidoc7
-rw-r--r--test/core_app.mk30
-rw-r--r--test/core_plugins.mk76
5 files changed, 124 insertions, 4 deletions
diff --git a/core/erlc.mk b/core/erlc.mk
index 04c11e5..96690da 100644
--- a/core/erlc.mk
+++ b/core/erlc.mk
@@ -198,7 +198,8 @@ endef
ebin/$(PROJECT).app:: $(ERL_FILES) $(CORE_FILES)
$(if $(strip $?),$(call compile_erl,$?))
$(eval GITDESCRIBE := $(shell git describe --dirty --abbrev=7 --tags --always --first-parent 2>/dev/null || true))
- $(eval MODULES := $(patsubst %,'%',$(sort $(notdir $(basename $(ERL_FILES) $(CORE_FILES))))))
+ $(eval MODULES := $(patsubst %,'%',$(sort $(notdir $(basename \
+ $(filter-out $(ERLC_EXCLUDE_PATHS),$(ERL_FILES) $(CORE_FILES)))))))
ifeq ($(wildcard src/$(PROJECT).app.src),)
$(app_verbose) echo $(subst $(newline),,$(subst ",\",$(call app_file,$(GITDESCRIBE),$(MODULES)))) \
> ebin/$(PROJECT).app
diff --git a/doc/src/guide/app.asciidoc b/doc/src/guide/app.asciidoc
index 528f6e3..0c6f137 100644
--- a/doc/src/guide/app.asciidoc
+++ b/doc/src/guide/app.asciidoc
@@ -239,6 +239,18 @@ include erlang.mk
ERLC_OPTS := $(filter-out -Werror,$(ERLC_OPTS))
----
+==== ERLC_EXCLUDE
+
+`ERLC_EXCLUDE` can be used to exclude some modules from the
+compilation. It's there for handling special cases, you should
+not normally need it.
+
+To exclude a module, simply list it in the variable, either
+before or after including Erlang.mk:
+
+[source,make]
+ERLC_EXCLUDE = cowboy_http2
+
=== Cold and hot builds
The first time you run `make`, Erlang.mk will build everything.
diff --git a/doc/src/guide/external_plugins.asciidoc b/doc/src/guide/external_plugins.asciidoc
index e5fdbd7..027b1b9 100644
--- a/doc/src/guide/external_plugins.asciidoc
+++ b/doc/src/guide/external_plugins.asciidoc
@@ -65,8 +65,11 @@ For eaxmple, if you have two plugins 'mk/dist.mk' and
file:
[source,make]
-include mk/dist.mk
-include mk/templates.mk
+THIS := $(dir $(realpath $(lastword $(MAKEFILE_LIST))))
+include $(THIS)/mk/dist.mk
+include $(THIS)/mk/templates.mk
+
+The `THIS` variable is required to relatively include files.
This allows users to not only be able to select individual
plugins, but also select all plugins from the dependency
diff --git a/test/core_app.mk b/test/core_app.mk
index a091554..a782e65 100644
--- a/test/core_app.mk
+++ b/test/core_app.mk
@@ -1,6 +1,6 @@
# Core: Building applications.
-CORE_APP_CASES = asn1 erlc-opts erlc-opts-filter error generate-erl generate-erl-include generate-erl-prepend hrl hrl-recursive mib no-app no-makedep xrl xrl-include yrl yrl-include
+CORE_APP_CASES = asn1 erlc-exclude erlc-opts erlc-opts-filter error generate-erl generate-erl-include generate-erl-prepend hrl hrl-recursive mib no-app no-makedep xrl xrl-include yrl yrl-include
CORE_APP_TARGETS = $(addprefix core-app-,$(CORE_APP_CASES))
CORE_APP_CLEAN_TARGETS = $(addprefix clean-,$(CORE_APP_TARGETS))
@@ -130,6 +130,34 @@ core-app-asn1: build clean-core-app-asn1
[{module, M} = code:load_file(M) || M <- Mods], \
halt()"
+core-app-erlc-exclude: build clean-core-app-erlc-exclude
+
+ $i "Bootstrap a new OTP library named $(APP)"
+ $t mkdir $(APP)/
+ $t cp ../erlang.mk $(APP)/
+ $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
+
+ $i "Generate .erl files"
+ $t echo "-module(boy)." > $(APP)/src/boy.erl
+ $t echo "-module(girl)." > $(APP)/src/girl.erl
+
+ $i "Exclude boy.erl from the compilation"
+ $t echo "ERLC_EXCLUDE = boy" >> $(APP)/Makefile
+
+ $i "Build the application"
+ $t $(MAKE) -C $(APP) $v
+
+ $i "Check that boy.erl was not compiled"
+ $t test ! -e $(APP)/ebin/boy.beam
+
+ $i "Check that the application was compiled correctly (without boy.erl)"
+ $t $(ERL) -pa $(APP)/ebin/ -eval " \
+ ok = application:start($(APP)), \
+ {ok, Mods = [girl]} \
+ = application:get_key($(APP), modules), \
+ [{module, M} = code:load_file(M) || M <- Mods], \
+ halt()"
+
core-app-erlc-opts: build clean-core-app-erlc-opts
$i "Bootstrap a new OTP library named $(APP)"
diff --git a/test/core_plugins.mk b/test/core_plugins.mk
new file mode 100644
index 0000000..632585a
--- /dev/null
+++ b/test/core_plugins.mk
@@ -0,0 +1,76 @@
+# Core: External plugins.
+
+CORE_PLUGINS_CASES = all one
+CORE_PLUGINS_TARGETS = $(addprefix core-plugins-,$(CORE_PLUGINS_CASES))
+CORE_PLUGINS_CLEAN_TARGETS = $(addprefix clean-,$(CORE_PLUGINS_TARGETS))
+
+.PHONY: core-plugins $(CORE_PLUGINS_TARGETS) clean-core-plugins $(CORE_PLUGINS_CLEAN_TARGETS)
+
+clean-core-plugins: $(CORE_PLUGINS_CLEAN_TARGETS)
+
+$(CORE_PLUGINS_CLEAN_TARGETS):
+ $t rm -rf $(APP_TO_CLEAN)/
+
+core-plugins: $(CORE_PLUGINS_TARGETS)
+
+core-plugins-all: build clean-core-plugins-all
+
+ $i "Bootstrap a new OTP library named $(APP)"
+ $t mkdir $(APP)/
+ $t cp ../erlang.mk $(APP)/
+ $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
+
+ $i "Create a local git repository with two plugins"
+ $t mkdir -p $(APP)/plugin_dep/mk
+ $t echo "plugin1: ; @echo \$$@" > $(APP)/plugin_dep/mk/plugin1.mk
+ $t echo "plugin2: ; @echo \$$@" > $(APP)/plugin_dep/mk/plugin2.mk
+ $t echo "THIS := \$$(dir \$$(realpath \$$(lastword \$$(MAKEFILE_LIST))))" > $(APP)/plugin_dep/plugins.mk
+ $t printf "%s\n" "include \$$(THIS)/mk/plugin1.mk" >> $(APP)/plugin_dep/plugins.mk
+ $t printf "%s\n" "include \$$(THIS)/mk/plugin2.mk" >> $(APP)/plugin_dep/plugins.mk
+# We check that overriding THIS doesn't cause an error.
+ $t echo "THIS :=" >> $(APP)/plugin_dep/plugins.mk
+ $t cd $(APP)/plugin_dep && git init && git add . && git commit -m "Tests"
+
+ $i "Add dependency and plugins to the Makefile"
+ $t sed -i.bak '2i\
+DEPS = plugin_dep\
+dep_plugin_dep = git file://$(abspath $(APP)/plugin_dep) master\
+DEP_PLUGINS = plugin_dep\
+' $(APP)/Makefile
+
+ $i "Run 'make plugin1' and check that it prints plugin1"
+ $t test -n "`$(MAKE) -C $(APP) plugin1 | grep plugin1`"
+
+ $i "Run 'make plugin2' and check that it prints plugin2"
+ $t test -n "`$(MAKE) -C $(APP) plugin2 | grep plugin2`"
+
+core-plugins-one: build clean-core-plugins-one
+
+ $i "Bootstrap a new OTP library named $(APP)"
+ $t mkdir $(APP)/
+ $t cp ../erlang.mk $(APP)/
+ $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
+
+ $i "Create a local git repository with two plugins"
+ $t mkdir -p $(APP)/plugin_dep/mk
+ $t echo "plugin1: ; @echo \$$@" > $(APP)/plugin_dep/mk/plugin1.mk
+ $t echo "plugin2: ; @echo \$$@" > $(APP)/plugin_dep/mk/plugin2.mk
+ $t echo "THIS := \$$(dir \$$(realpath \$$(lastword \$$(MAKEFILE_LIST))))" > $(APP)/plugin_dep/plugins.mk
+ $t printf "%s\n" "include \$$(THIS)/mk/plugin1.mk" >> $(APP)/plugin_dep/plugins.mk
+ $t printf "%s\n" "include \$$(THIS)/mk/plugin2.mk" >> $(APP)/plugin_dep/plugins.mk
+# We check that overriding THIS doesn't cause an error.
+ $t echo "THIS :=" >> $(APP)/plugin_dep/plugins.mk
+ $t cd $(APP)/plugin_dep && git init && git add . && git commit -m "Tests"
+
+ $i "Add dependency and plugins to the Makefile"
+ $t sed -i.bak '2i\
+DEPS = plugin_dep\
+dep_plugin_dep = git file://$(abspath $(APP)/plugin_dep) master\
+DEP_PLUGINS = plugin_dep/mk/plugin1.mk\
+' $(APP)/Makefile
+
+ $i "Run 'make plugin1' and check that it prints plugin1"
+ $t test -n "`$(MAKE) -C $(APP) plugin1 | grep plugin1`"
+
+ $i "Run 'make plugin2' and confirm the target doesn't exist"
+ $t if `$(MAKE) -C $(APP) plugin2`; then false; fi