Просмотр исходного кода

Make autopatch of Erlang.mk projects less obtrusive

We do not touch the erlang.mk file anymore. We only patch the
Makefile to include the top-level Erlang.mk by changing the
'include erlang.mk' line to look for ERLANG_MK_FILENAME if it
is defined. The modified Makefile can be committed safely.
Loïc Hoguin 8 лет назад
Родитель
Сommit
3f8688e0d0
4 измененных файлов с 15 добавлено и 9 удалено
  1. 1 0
      core/core.mk
  2. 1 1
      core/deps-tools.mk
  3. 8 4
      core/deps.mk
  4. 5 4
      doc/src/guide/deps.asciidoc

+ 1 - 0
core/core.mk

@@ -15,6 +15,7 @@
 .PHONY: all app apps deps search rel relup docs install-docs check tests clean distclean help erlang-mk
 .PHONY: all app apps deps search rel relup docs install-docs check tests clean distclean help erlang-mk
 
 
 ERLANG_MK_FILENAME := $(realpath $(lastword $(MAKEFILE_LIST)))
 ERLANG_MK_FILENAME := $(realpath $(lastword $(MAKEFILE_LIST)))
+export ERLANG_MK_FILENAME
 
 
 ERLANG_MK_VERSION = rolling
 ERLANG_MK_VERSION = rolling
 
 

+ 1 - 1
core/deps-tools.mk

@@ -74,7 +74,7 @@ endif
 	$(verbose) set -e; for dep in $^ ; do \
 	$(verbose) set -e; for dep in $^ ; do \
 		if ! grep -qs ^$$dep$$ $(ERLANG_MK_RECURSIVE_TMP_LIST); then \
 		if ! grep -qs ^$$dep$$ $(ERLANG_MK_RECURSIVE_TMP_LIST); then \
 			echo $$dep >> $(ERLANG_MK_RECURSIVE_TMP_LIST); \
 			echo $$dep >> $(ERLANG_MK_RECURSIVE_TMP_LIST); \
-			if grep -qs -E "^[[:blank:]]*include[[:blank:]]+(erlang\.mk|.*/erlang\.mk)$$" \
+			if grep -qs -E "^[[:blank:]]*include[[:blank:]]+(erlang\.mk|.*/erlang\.mk|.*ERLANG_MK_FILENAME.*)$$" \
 			 $$dep/GNUmakefile $$dep/makefile $$dep/Makefile; then \
 			 $$dep/GNUmakefile $$dep/makefile $$dep/Makefile; then \
 				$(MAKE) -C $$dep fetch-deps \
 				$(MAKE) -C $$dep fetch-deps \
 				 IS_DEP=1 \
 				 IS_DEP=1 \

+ 8 - 4
core/deps.mk

@@ -164,11 +164,15 @@ define dep_autopatch_noop
 	printf "noop:\n" > $(DEPS_DIR)/$(1)/Makefile
 	printf "noop:\n" > $(DEPS_DIR)/$(1)/Makefile
 endef
 endef
 
 
-# Overwrite erlang.mk with the current file by default.
+# Replace "include erlang.mk" with a line that will load the parent Erlang.mk
+# if given. Do it for all 3 possible Makefile file names.
 ifeq ($(NO_AUTOPATCH_ERLANG_MK),)
 ifeq ($(NO_AUTOPATCH_ERLANG_MK),)
 define dep_autopatch_erlang_mk
 define dep_autopatch_erlang_mk
-	echo "include $(call core_relpath,$(dir $(ERLANG_MK_FILENAME)),$(DEPS_DIR)/app)/erlang.mk" \
-		> $(DEPS_DIR)/$1/erlang.mk
+	$t for f in Makefile makefile GNUmakefile; do \
+		if [ -f $(DEPS_DIR)/$1/$$f ]; then \
+			sed -i.bak s/'include *erlang.mk'/'include $$(if $$(ERLANG_MK_FILENAME),$$(ERLANG_MK_FILENAME),erlang.mk)'/ $(DEPS_DIR)/$1/$$f; \
+		fi \
+	done
 endef
 endef
 else
 else
 define dep_autopatch_erlang_mk
 define dep_autopatch_erlang_mk
@@ -411,7 +415,7 @@ define dep_autopatch_rebar.erl
 			end,
 			end,
 			[PortSpec(S) || S <- PortSpecs]
 			[PortSpec(S) || S <- PortSpecs]
 	end,
 	end,
-	Write("\ninclude $(call core_relpath,$(dir $(ERLANG_MK_FILENAME)),$(DEPS_DIR)/app)/erlang.mk"),
+	Write("\ninclude $$\(if $$\(ERLANG_MK_FILENAME),$$\(ERLANG_MK_FILENAME),erlang.mk)"),
 	RunPlugin = fun(Plugin, Step) ->
 	RunPlugin = fun(Plugin, Step) ->
 		case erlang:function_exported(Plugin, Step, 2) of
 		case erlang:function_exported(Plugin, Step, 2) of
 			false -> ok;
 			false -> ok;

+ 5 - 4
doc/src/guide/deps.asciidoc

@@ -487,10 +487,11 @@ on the kind of project it finds the dependency to be.
 as their build tool. This essentially patches Rebar out, and
 as their build tool. This essentially patches Rebar out, and
 fixes and converts the project to be compatible with Erlang.mk.
 fixes and converts the project to be compatible with Erlang.mk.
 
 
-* Erlang.mk projects have their 'erlang.mk' file redirect to
-the top-level project's Erlang.mk. This is to ensure that
-functionality works across all dependencies, even if the
-dependency's Erlang.mk is outdated.
+* Erlang.mk projects have their 'Makefile' patched, if necessary,
+to include the top-level project's Erlang.mk. This is to ensure
+that functionality works across all dependencies, even if the
+dependency's Erlang.mk is outdated. The patched Makefile
+can be safely committed if necessary.
 
 
 * Other Erlang projects get a small Erlang.mk Makefile
 * Other Erlang projects get a small Erlang.mk Makefile
 generated automatically.
 generated automatically.