Release build script.
authorOleksandr Gavenko <gavenkoa@gmail.com>
Thu, 11 Sep 2014 03:37:22 +0300
changeset 48 32b976d3fd10
parent 47 74b1f4d0f9a4
child 49 4b48e9e06000
Release build script.
Makefile
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Makefile	Thu Sep 11 03:37:22 2014 +0300
@@ -0,0 +1,208 @@
+#
+# You can override such variables in Makefile.config:
+#
+#   SF_USER     SourceForge user name.
+
+################################################################
+# Standard GNU Makefile settings.
+
+SHELL = /bin/bash
+export PATH := /bin:/usr/bin:${PATH}
+
+# Disable built in pattern rules.
+MAKEFLAGS += -r
+# Disable built in variables.
+MAKEFLAGS += -R
+# Disable built in suffix rules.
+.SUFFIXES:
+# Delete target file if command fails.
+.DELETE_ON_ERROR:
+# Default target.
+.DEFAULT_GOAL = help
+
+################################################################
+# Build script definitions.
+
+BUILD_SCRIPTS := $(firstword $(MAKEFILE_LIST))
+
+ifneq '' '$(wildcard Makefile.config)'
+  include Makefile.config
+  BUILD_SCRIPTS += Makefile.config
+endif
+
+################################################################
+# Version extracting/generation.
+
+# Prevent making distribution with wrong version.
+ifneq '' '$(filter deploy% dist%,$(MAKECMDGOALS))'
+  ifeq '' '$(MAKE_RESTARTS)'
+    $(info $(shell rm -f VERSION))
+  endif
+endif
+
+# Here are vmajor and vminor. Look README section "Versioning rules."
+-include VERSION
+
+VERSION:
+	\
+vtagdist=$$(hg log -r . --template '{latesttagdistance}'); \
+vatrelease=$$([ $$vtagdist -le 1 ] && echo yes || echo no); \
+vtag=$$(hg log -r . --template '{latesttag}'); \
+vmajor=$${vtag#t}; \
+vmajor=$${vmajor%%.*}; \
+vminor=$${vtag#*.}; \
+vrev=$$(hg id -i); \
+visclean=$$(case $$vrev in *+) echo no;; *) echo yes;; esac); \
+vrev=$${vrev%+}; \
+{ \
+echo "vrev=$$vrev"; \
+echo "vtag=$$vtag"; \
+echo "vtagdist=$$vtagdist"; \
+echo "visclean=$$visclean"; \
+echo "vatrelease=$$vatrelease"; \
+echo "vmajor=$$vmajor"; \
+echo "vminor=$$vminor"; \
+} >VERSION
+
+################################################################
+# Determine platform/environment.
+
+host_os = unix
+ifneq '' '$(COMSPEC)'
+  ifneq '' '$(WINDIR)'
+    # Probably under Windows.
+    host_os = windows
+    ifneq '' '$(wildcard /etc/setup/*cygwin*)'
+      # Probably under Cygwin.
+      host_os = cygwin
+    endif
+  endif
+endif
+
+################################################################
+# Project dirs/files.
+
+pkgname = 2048-js-ai
+sfpkgname = js-2048-ai
+fullpkgname = $(pkgname)-$(vmajor).$(vminor)
+
+DIST_DIR = $(fullpkgname)
+
+WWW_FILES := $(wildcard *.js) $(wildcard *.html)
+
+DIST_FILES = $(WWW_FILES) README.rst VERSION
+
+DIST_TARBALLS = $(DIST_DIR).tar.gz $(DIST_DIR).zip
+
+################################################################
+# Deploy targets.
+
+ifeq '' '$(SF_USER)'
+  SF_USER := gavenkoa
+endif
+
+.PHONY: deploy
+deploy: deploy2sf
+
+# First time you deploy to SourceForge (sf) you need manually login to:
+#   $ sftp $(SF_USER),$(pkgname)@web.sourceforge.net
+# as it may require interactive input for accepting server public key.
+# Next time any action fully automated.
+
+.PHONY: deploy2sf
+deploy2sf: deploy2sf-src deploy2sf-www deploy2sf-release
+
+.PHONY: deploy2sf-src
+deploy2sf-src:
+	hg push ssh://$(SF_USER)@hg.code.sf.net/p/$(sfpkgname)/hg || [ $$? = 1 ]
+
+# Will be accessed via http://$(pkgname).sourceforge.net
+.PHONY: deploy2sf-www
+deploy2sf-www: deploy-check $(WWW_FILES)
+	( echo 'cd htdocs'; \
+for f in $(WWW_FILES); do \
+  echo "put $$f"; \
+  echo "chmod 644 $$f"; \
+done; \
+echo 'quit'; \
+) | sftp -b - $(SF_USER),$(sfpkgname)@web.sourceforge.net
+
+.PHONY: deploy2sf-release
+deploy2sf-release: deploy-check $(DIST_TARBALLS)
+	( echo 'cd /home/frs/project/$(shell v=$(sfpkgname); echo $${v:0:1}/$${v:0:2})/$(sfpkgname)'; \
+echo "put  README.rst"; \
+echo "chmod 644 README.rst"; \
+echo "mkdir v$(vmajor).$(vminor)"; \
+echo "cd v$(vmajor).$(vminor)"; \
+for f in $(DIST_TARBALLS); do \
+	echo "put $$f"; \
+	echo "chmod 644 $$f"; \
+done; \
+echo 'quit'; \
+) | sftp -b - $(SF_USER),$(sfpkgname)@frs.sourceforge.net
+
+.PHONY: deploy-check
+deploy-check:
+	\
+case ${visclean} in \
+  no) echo "Local changes found. Build stop."; \
+    exit 1;; \
+esac
+	\
+case $(vatrelease) in \
+  no) echo "We are not at release. Build stop."; \
+    exit 1;; \
+esac
+
+################################################################
+# Dist targets.
+
+.PHONY: dist
+dist: dist-bin
+
+.PHONY: dist-bin
+dist-release: $(DIST_TARBALLS)
+
+%.tar.gz: %
+	tar zcf $*.tar.gz $*
+
+%.tar.bz2: %
+	tar jcf $*.tar.bz2 $*
+
+$(DIST_DIR): $(DIST_FILES)
+	rm -rf $@
+	mkdir $@
+	cp $(DIST_FILES) $@
+
+################################################################
+# Helpers targets.
+
+.PHONY: help
+help:
+	@\
+echo; \
+echo Current configuration:; \
+echo; \
+sed 's=^=  =' <VERSION
+	@if [ -f Makefile.config ]; then \
+		echo; \
+		echo User configuration:; \
+		echo; \
+		sed 's=^=  =' <Makefile.config; \
+	fi
+	@\
+echo; \
+echo Supported targets:; \
+echo; \
+sed -n -e '/^[[:alnum:]_-]*:/{s=^\(.*\):.*=  \1=;p;}' $(BUILD_SCRIPTS)
+
+################################################################
+# Clean targets.
+
+.PHONY: distclean
+distclean: clean
+	rm -f VERSION
+
+.PHONY: clean
+clean:
+	rm -rf $(DIST_DIR) $(DIST_TARBALLS)