From 4f59af14f2977a2d925f7b0d97caf49a4d6d31de Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= <essen@ninenines.eu>
Date: Mon, 14 Sep 2015 18:13:46 +0200
Subject: Make relx work on Windows/MSYS2

---
 core/core.mk             |  8 +++++++-
 plugins/relx.mk          |  4 +---
 test/Makefile            |  8 ++++++++
 test/plugin_bootstrap.mk | 11 +++++++++++
 4 files changed, 27 insertions(+), 4 deletions(-)

diff --git a/core/core.mk b/core/core.mk
index c2a153c..a9cb808 100644
--- a/core/core.mk
+++ b/core/core.mk
@@ -141,6 +141,12 @@ define erlang
 $(ERL) $(2) -pz $(ERLANG_MK_TMP)/rebar/ebin -eval "$(subst $(newline),,$(subst ",\",$(1)))" -- erlang.mk
 endef
 
+ifeq ($(PLATFORM),msys2)
+core_native_path = $(subst \,\\\\,$(shell cygpath -w $1))
+else
+core_native_path = $1
+endif
+
 ifeq ($(shell which wget 2>/dev/null | wc -l), 1)
 define core_http_get
 	wget --no-check-certificate -O $(1) $(2)|| rm $(1)
@@ -162,7 +168,7 @@ define core_http_get.erl
 endef
 
 define core_http_get
-	$(call erlang,$(call core_http_get.erl,$(1),$(2)))
+	$(call erlang,$(call core_http_get.erl,$(call core_native_path,$1),$2))
 endef
 endif
 
diff --git a/plugins/relx.mk b/plugins/relx.mk
index 063a475..8140fcd 100644
--- a/plugins/relx.mk
+++ b/plugins/relx.mk
@@ -5,10 +5,8 @@
 
 # Configuration.
 
-RELX_CONFIG ?= $(CURDIR)/relx.config
-
 RELX ?= $(CURDIR)/relx
-export RELX
+RELX_CONFIG ?= $(CURDIR)/relx.config
 
 RELX_URL ?= https://github.com/erlware/relx/releases/download/v2.0.0/relx
 RELX_OPTS ?=
diff --git a/test/Makefile b/test/Makefile
index 4f715a3..ba612fa 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -11,6 +11,14 @@ APP_TO_CLEAN = $(subst -,_,$(patsubst clean-%,%,$@))
 
 ERL = erl +A0 -noinput -boot start_clean
 
+# Platform, condensed version.
+
+ifeq ($(shell uname -o),Msys)
+	PLATFORM = msys2
+else
+	PLATFORM = unix
+endif
+
 # OTP master, for downloading files for testing.
 
 OTP_MASTER = https://raw.githubusercontent.com/erlang/otp/master
diff --git a/test/plugin_bootstrap.mk b/test/plugin_bootstrap.mk
index 42ce932..b927a92 100644
--- a/test/plugin_bootstrap.mk
+++ b/test/plugin_bootstrap.mk
@@ -90,11 +90,22 @@ bootstrap-rel: build clean-bootstrap-rel
 	$t test -f $(APP)/ebin/$(APP)_sup.beam
 
 	$i "Check that the release was generated"
+ifeq ($(PLATFORM),msys2)
+	$t test -f $(APP)/_rel/$(APP)_release/bin/$(APP)_release.cmd
+else
 	$t test -f $(APP)/_rel/$(APP)_release/bin/$(APP)_release
+endif
 
 	$i "Check that the release can be started and stopped"
+ifeq ($(PLATFORM),msys2)
+	$t $(APP)/_rel/$(APP)_release/bin/$(APP)_release.cmd install $v
+	$t $(APP)/_rel/$(APP)_release/bin/$(APP)_release.cmd start $v
+	$t $(APP)/_rel/$(APP)_release/bin/$(APP)_release.cmd stop $v
+	$t $(APP)/_rel/$(APP)_release/bin/$(APP)_release.cmd uninstall $v
+else
 	$t $(APP)/_rel/$(APP)_release/bin/$(APP)_release start $v
 	$t $(APP)/_rel/$(APP)_release/bin/$(APP)_release stop $v
+endif
 
 	$i "Check that there's no erl_crash.dump file"
 	$t test ! -f $(APP)/_rel/$(APP)_release/erl_crash.dump
-- 
cgit v1.2.3