Makefile
changeset 48 32b976d3fd10
child 49 4b48e9e06000
equal deleted inserted replaced
47:74b1f4d0f9a4 48:32b976d3fd10
       
     1 #
       
     2 # You can override such variables in Makefile.config:
       
     3 #
       
     4 #   SF_USER     SourceForge user name.
       
     5 
       
     6 ################################################################
       
     7 # Standard GNU Makefile settings.
       
     8 
       
     9 SHELL = /bin/bash
       
    10 export PATH := /bin:/usr/bin:${PATH}
       
    11 
       
    12 # Disable built in pattern rules.
       
    13 MAKEFLAGS += -r
       
    14 # Disable built in variables.
       
    15 MAKEFLAGS += -R
       
    16 # Disable built in suffix rules.
       
    17 .SUFFIXES:
       
    18 # Delete target file if command fails.
       
    19 .DELETE_ON_ERROR:
       
    20 # Default target.
       
    21 .DEFAULT_GOAL = help
       
    22 
       
    23 ################################################################
       
    24 # Build script definitions.
       
    25 
       
    26 BUILD_SCRIPTS := $(firstword $(MAKEFILE_LIST))
       
    27 
       
    28 ifneq '' '$(wildcard Makefile.config)'
       
    29   include Makefile.config
       
    30   BUILD_SCRIPTS += Makefile.config
       
    31 endif
       
    32 
       
    33 ################################################################
       
    34 # Version extracting/generation.
       
    35 
       
    36 # Prevent making distribution with wrong version.
       
    37 ifneq '' '$(filter deploy% dist%,$(MAKECMDGOALS))'
       
    38   ifeq '' '$(MAKE_RESTARTS)'
       
    39     $(info $(shell rm -f VERSION))
       
    40   endif
       
    41 endif
       
    42 
       
    43 # Here are vmajor and vminor. Look README section "Versioning rules."
       
    44 -include VERSION
       
    45 
       
    46 VERSION:
       
    47 	\
       
    48 vtagdist=$$(hg log -r . --template '{latesttagdistance}'); \
       
    49 vatrelease=$$([ $$vtagdist -le 1 ] && echo yes || echo no); \
       
    50 vtag=$$(hg log -r . --template '{latesttag}'); \
       
    51 vmajor=$${vtag#t}; \
       
    52 vmajor=$${vmajor%%.*}; \
       
    53 vminor=$${vtag#*.}; \
       
    54 vrev=$$(hg id -i); \
       
    55 visclean=$$(case $$vrev in *+) echo no;; *) echo yes;; esac); \
       
    56 vrev=$${vrev%+}; \
       
    57 { \
       
    58 echo "vrev=$$vrev"; \
       
    59 echo "vtag=$$vtag"; \
       
    60 echo "vtagdist=$$vtagdist"; \
       
    61 echo "visclean=$$visclean"; \
       
    62 echo "vatrelease=$$vatrelease"; \
       
    63 echo "vmajor=$$vmajor"; \
       
    64 echo "vminor=$$vminor"; \
       
    65 } >VERSION
       
    66 
       
    67 ################################################################
       
    68 # Determine platform/environment.
       
    69 
       
    70 host_os = unix
       
    71 ifneq '' '$(COMSPEC)'
       
    72   ifneq '' '$(WINDIR)'
       
    73     # Probably under Windows.
       
    74     host_os = windows
       
    75     ifneq '' '$(wildcard /etc/setup/*cygwin*)'
       
    76       # Probably under Cygwin.
       
    77       host_os = cygwin
       
    78     endif
       
    79   endif
       
    80 endif
       
    81 
       
    82 ################################################################
       
    83 # Project dirs/files.
       
    84 
       
    85 pkgname = 2048-js-ai
       
    86 sfpkgname = js-2048-ai
       
    87 fullpkgname = $(pkgname)-$(vmajor).$(vminor)
       
    88 
       
    89 DIST_DIR = $(fullpkgname)
       
    90 
       
    91 WWW_FILES := $(wildcard *.js) $(wildcard *.html)
       
    92 
       
    93 DIST_FILES = $(WWW_FILES) README.rst VERSION
       
    94 
       
    95 DIST_TARBALLS = $(DIST_DIR).tar.gz $(DIST_DIR).zip
       
    96 
       
    97 ################################################################
       
    98 # Deploy targets.
       
    99 
       
   100 ifeq '' '$(SF_USER)'
       
   101   SF_USER := gavenkoa
       
   102 endif
       
   103 
       
   104 .PHONY: deploy
       
   105 deploy: deploy2sf
       
   106 
       
   107 # First time you deploy to SourceForge (sf) you need manually login to:
       
   108 #   $ sftp $(SF_USER),$(pkgname)@web.sourceforge.net
       
   109 # as it may require interactive input for accepting server public key.
       
   110 # Next time any action fully automated.
       
   111 
       
   112 .PHONY: deploy2sf
       
   113 deploy2sf: deploy2sf-src deploy2sf-www deploy2sf-release
       
   114 
       
   115 .PHONY: deploy2sf-src
       
   116 deploy2sf-src:
       
   117 	hg push ssh://$(SF_USER)@hg.code.sf.net/p/$(sfpkgname)/hg || [ $$? = 1 ]
       
   118 
       
   119 # Will be accessed via http://$(pkgname).sourceforge.net
       
   120 .PHONY: deploy2sf-www
       
   121 deploy2sf-www: deploy-check $(WWW_FILES)
       
   122 	( echo 'cd htdocs'; \
       
   123 for f in $(WWW_FILES); do \
       
   124   echo "put $$f"; \
       
   125   echo "chmod 644 $$f"; \
       
   126 done; \
       
   127 echo 'quit'; \
       
   128 ) | sftp -b - $(SF_USER),$(sfpkgname)@web.sourceforge.net
       
   129 
       
   130 .PHONY: deploy2sf-release
       
   131 deploy2sf-release: deploy-check $(DIST_TARBALLS)
       
   132 	( echo 'cd /home/frs/project/$(shell v=$(sfpkgname); echo $${v:0:1}/$${v:0:2})/$(sfpkgname)'; \
       
   133 echo "put  README.rst"; \
       
   134 echo "chmod 644 README.rst"; \
       
   135 echo "mkdir v$(vmajor).$(vminor)"; \
       
   136 echo "cd v$(vmajor).$(vminor)"; \
       
   137 for f in $(DIST_TARBALLS); do \
       
   138 	echo "put $$f"; \
       
   139 	echo "chmod 644 $$f"; \
       
   140 done; \
       
   141 echo 'quit'; \
       
   142 ) | sftp -b - $(SF_USER),$(sfpkgname)@frs.sourceforge.net
       
   143 
       
   144 .PHONY: deploy-check
       
   145 deploy-check:
       
   146 	\
       
   147 case ${visclean} in \
       
   148   no) echo "Local changes found. Build stop."; \
       
   149     exit 1;; \
       
   150 esac
       
   151 	\
       
   152 case $(vatrelease) in \
       
   153   no) echo "We are not at release. Build stop."; \
       
   154     exit 1;; \
       
   155 esac
       
   156 
       
   157 ################################################################
       
   158 # Dist targets.
       
   159 
       
   160 .PHONY: dist
       
   161 dist: dist-bin
       
   162 
       
   163 .PHONY: dist-bin
       
   164 dist-release: $(DIST_TARBALLS)
       
   165 
       
   166 %.tar.gz: %
       
   167 	tar zcf $*.tar.gz $*
       
   168 
       
   169 %.tar.bz2: %
       
   170 	tar jcf $*.tar.bz2 $*
       
   171 
       
   172 $(DIST_DIR): $(DIST_FILES)
       
   173 	rm -rf $@
       
   174 	mkdir $@
       
   175 	cp $(DIST_FILES) $@
       
   176 
       
   177 ################################################################
       
   178 # Helpers targets.
       
   179 
       
   180 .PHONY: help
       
   181 help:
       
   182 	@\
       
   183 echo; \
       
   184 echo Current configuration:; \
       
   185 echo; \
       
   186 sed 's=^=  =' <VERSION
       
   187 	@if [ -f Makefile.config ]; then \
       
   188 		echo; \
       
   189 		echo User configuration:; \
       
   190 		echo; \
       
   191 		sed 's=^=  =' <Makefile.config; \
       
   192 	fi
       
   193 	@\
       
   194 echo; \
       
   195 echo Supported targets:; \
       
   196 echo; \
       
   197 sed -n -e '/^[[:alnum:]_-]*:/{s=^\(.*\):.*=  \1=;p;}' $(BUILD_SCRIPTS)
       
   198 
       
   199 ################################################################
       
   200 # Clean targets.
       
   201 
       
   202 .PHONY: distclean
       
   203 distclean: clean
       
   204 	rm -f VERSION
       
   205 
       
   206 .PHONY: clean
       
   207 clean:
       
   208 	rm -rf $(DIST_DIR) $(DIST_TARBALLS)