Browse Source

Add an erlang-mk target for automated updating of erlang.mk

Loïc Hoguin 10 years ago
parent
commit
92626f1548
3 changed files with 42 additions and 2 deletions
  1. 16 0
      README.md
  2. 13 1
      core/core.mk
  3. 13 1
      erlang.mk

+ 16 - 0
README.md

@@ -219,6 +219,22 @@ If `{id, "git"},` is found in your project's `.app.src`, the
 extended output of `git describe ...` will replace it. This
 can be retrieved at runtime via `application:get_key/2`.
 
+Updating erlang.mk
+------------------
+
+You can update erlang.mk by running `make erlang-mk`. This automated
+update will always take the latest erlang.mk version, compile it and
+replace the erlang.mk of your project with the updated version.
+
+If your project includes a `build.config`, erlang.mk will use it
+when building the updated version.
+
+The `ERLANG_MK_BUILD_CONFIG` variable can be used to rename the
+`build.config` file.
+
+The `ERLANG_MK_BUILD_DIR` variable contains the path to the
+temporary directory used to build the updated erlang.mk.
+
 Bootstrap plugin
 ----------------
 

+ 13 - 1
core/core.mk

@@ -12,7 +12,7 @@
 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 
-.PHONY: all deps app rel docs tests clean distclean help
+.PHONY: all deps app rel docs tests clean distclean help erlang-mk
 
 ERLANG_MK_VERSION = 1
 
@@ -71,3 +71,15 @@ define core_http_get
 	erl -noshell -eval 'ssl:start(), inets:start(), case httpc:request(get, {"$(2)", []}, [{autoredirect, true}], []) of {ok, {{_, 200, _}, _, Body}} -> case file:write_file("$(1)", Body) of ok -> ok; {error, R1} -> halt(R1) end; {error, R2} -> halt(R2) end, halt(0).'
 endef
 endif
+
+# Automated update.
+
+ERLANG_MK_BUILD_CONFIG ?= build.config
+ERLANG_MK_BUILD_DIR ?= .erlang.mk.build
+
+erlang-mk:
+	git clone https://github.com/ninenines/erlang.mk $(ERLANG_MK_BUILD_DIR)
+	if [ -f $(ERLANG_MK_BUILD_CONFIG) ]; then cp $(ERLANG_MK_BUILD_CONFIG) $(ERLANG_MK_BUILD_DIR); fi
+	cd $(ERLANG_MK_BUILD_DIR) && make
+	cp $(ERLANG_MK_BUILD_DIR)/erlang.mk ./erlang.mk
+	rm -rf $(ERLANG_MK_BUILD_DIR)

+ 13 - 1
erlang.mk

@@ -12,7 +12,7 @@
 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 
-.PHONY: all deps app rel docs tests clean distclean help
+.PHONY: all deps app rel docs tests clean distclean help erlang-mk
 
 ERLANG_MK_VERSION = 1
 
@@ -72,6 +72,18 @@ define core_http_get
 endef
 endif
 
+# Automated update.
+
+ERLANG_MK_BUILD_CONFIG ?= build.config
+ERLANG_MK_BUILD_DIR ?= .erlang.mk.build
+
+erlang-mk:
+	git clone https://github.com/ninenines/erlang.mk $(ERLANG_MK_BUILD_DIR)
+	if [ -f $(ERLANG_MK_BUILD_CONFIG) ]; then cp $(ERLANG_MK_BUILD_CONFIG) $(ERLANG_MK_BUILD_DIR); fi
+	cd $(ERLANG_MK_BUILD_DIR) && make
+	cp $(ERLANG_MK_BUILD_DIR)/erlang.mk ./erlang.mk
+	rm -rf $(ERLANG_MK_BUILD_DIR)
+
 # Copyright (c) 2013-2014, Loïc Hoguin <essen@ninenines.eu>
 # This file is part of erlang.mk and subject to the terms of the ISC License.