srcdir                    := @srcdir@
CC                        := @CC@
PATH_TO_SRC               := @PATH_TO_SRC@
path_to_src               := PATH_TO_SRC
ifeq ($(PATH_TO_SRC),@$(path_to_src)@)
  PATH_TO_SRC             := .
endif

TOOL_SRC                  := $(wildcard $(srcdir)/tools/*.lua)
HAVE_LUA_JSON             := @HAVE_LUA_JSON@
ifeq ($(HAVE_LUA_JSON),yes)
  TOOL_SRC                := $(filter-out $(srcdir)/tools/json.lua, $(TOOL_SRC))
endif

CURRENT_MK                := $(lastword $(MAKEFILE_LIST))
PATH_TO_LUA	  	  := @PATH_TO_LUA@
export IGNORE_DIRS        := $(shell $(PATH_TO_LUA)/lua $(srcdir)/src/ignore_dirs_converter @IGNORE_DIRS@)
REDIRECT                  := @REDIRECT@
LMOD_FULL_SETTARG_SUPPORT := $(shell echo "@SETTARG@"       | tr '[:upper:]' '[:lower:]')
USE_DOT_FILES             := $(shell echo "@USE_DOT_FILES@" | tr '[:upper:]' '[:lower:]')
PREPEND_BLOCK     	  := $(shell echo "@PREPEND_BLOCK@" | tr '[:upper:]' '[:lower:]')
COLORIZE          	  := $(shell echo "@COLORIZE@"      | tr '[:upper:]' '[:lower:]')
SYS_LD_LIB_PATH           := @SYS_LD_LIB_PATH@
SYS_LD_PRELOAD            := @SYS_LD_PRELOAD@
SYS_LUA_PATH              := @SYS_LUA_PATH@
SYS_LUA_CPATH             := @SYS_LUA_CPATH@
CASE_INDEPENDENT_SORTING  := @CASE_INDEPENDENT_SORTING@
ZSH_SITE_FUNCTIONS_DIRS   := @ZSH_SITE_FUNCTIONS_DIRS@
SPIDER_CACHE_DESCRIPT_FN  := @SPIDER_CACHE_DESCRIPT_FN@
CHECK_VALID               := @CHECK_VALID@
ANCIENT           	  := @ANCIENT@
ALLOW_TCL_MFILES          := @ALLOW_TCL_MFILES@
MPATH_AVAIL               := @MPATH_AVAIL@
TMOD_PATH_RULE            := @TMOD_PATH_RULE@
CACHED_LOADS              := @CACHED_LOADS@
EXACT_MATCH               := @EXACT_MATCH@
DUPLICATE_PATHS           := @DUPLICATE_PATHS@
DISABLE_NAME_AUTOSWAP     := @DISABLE_NAME_AUTOSWAP@
SHORT_TIME        	  := @SHORT_TIME@
PIN_VERSIONS              := @PIN_VERSIONS@
AUTO_SWAP        	  := @AUTO_SWAP@
SPIDER_CACHE_DIRS 	  := @SPIDER_CACHE_DIRS@
LEGACY_ORDERING           := @LEGACY_ORDERING@
EXPORT_MODULE             := @EXPORT_MODULE@
BASENAME                  := @BASENAME@
PS                        := @PS@
EXPR                      := @EXPR@
PATH_TO_HASHSUM   	  := @PATH_TO_HASHSUM@
PATH_TO_LUAC              := @PATH_TO_LUAC@
PATH_TO_PAGER	  	  := @PATH_TO_PAGER@
PATH_TO_TCLSH             := @PATH_TO_TCLSH@
PATH_TO_TR                := @PATH_TO_TR@
MODULEPATH_ROOT   	  := @MODULEPATH_ROOT@
VERSION_SRC	  	  := $(srcdir)/src/Version.lua
LUA_INCLUDE       	  := @LUA_INCLUDE@
UPDATE_SYSTEM_FN  	  := @UPDATE_SYSTEM_FN@
GIT_BRANCH                := master
GIT_PROG                  := @PATH_TO_GIT@
GIT_VERSION               := $(shell if [ -n "$(GIT_PROG)" -a -d .git ]; then lmodV=`git describe --always`; echo "($$lmodV)"; else echo "@git@"; fi)
prefix		  	  := @prefix@
package		  	  := lmod
version		  	  := $(shell cd $(srcdir)/src; $(PATH_TO_LUA)/lua -e "V=require('Version'); print(V.tag())")
PKGV		  	  := $(prefix)/share/$(package)/$(version)
PKG		  	  := $(prefix)/share/$(package)/$(package)
LIBEXEC		  	  := $(prefix)/share/$(package)/$(version)/libexec
SHELLS                    := $(prefix)/share/$(package)/$(version)/shells
TOOLS                     := $(prefix)/share/$(package)/$(version)/tools
SETTARG                   := $(prefix)/share/$(package)/$(version)/settarg
INIT		  	  := $(prefix)/share/$(package)/$(version)/init
LMOD_MF 	  	  := $(prefix)/share/$(package)/$(version)/modulefiles/Core
MAN_PAGES                 := $(prefix)/share/man/man1
LMOD_MF_SOURCE            := $(patsubst %, $(srcdir)/%, MF/*.version.lua)
SETTARG_SOURCE            := $(patsubst %, $(srcdir)/%, settarg/*.lua  settarg/targ.in)

DIRLIST		  	  := $(DESTDIR)$(LIBEXEC) $(DESTDIR)$(TOOLS) $(DESTDIR)$(SETTARG) \
                             $(DESTDIR)$(SHELLS)  $(DESTDIR)$(INIT)  $(DESTDIR)$(LIB)     \
                             $(DESTDIR)$(LMOD_MF) $(DESTDIR)$(MAN_PAGES)

STANDALONE_PRGM   	  := src/lmod.in.lua src/addto.in.lua src/getmt.in.lua      \
                             src/processMT.in.lua src/spider.in.lua                 \
                             src/processModuleUsage.in.lua src/reportUsers.in.lua   \
                             src/clearMT_cmd.in.lua src/ml_cmd.in.lua               \
                             src/spiderCacheSupport.in.lua                          \
                             src/sh_to_modulefile.in.lua                            \
	                     src/update_lmod_system_cache_files.in                  \
                             src/ignore_dirs_converter
STANDALONE_PRGM           := $(patsubst %, $(srcdir)/%, $(STANDALONE_PRGM))
SHELL_INIT	  	  := bash.in csh.in ksh.in tcsh.in zsh.in sh.in perl.in r.in \
                             env_modules_python.py.in lmod_bash_completions
SHELL_INIT	  	  := $(patsubst %, $(srcdir)/init/%, $(SHELL_INIT))
LMODRC_INIT               := $(patsubst %, $(srcdir)/init/%, lmodrc.lua)


ZSH_FUNCS                 := _ml _module
ZSH_FUNCS                 := $(patsubst %, $(srcdir)/init/zsh/%, $(ZSH_FUNCS))

STARTUP		  	  := profile.in cshrc.in
STARTUP		  	  := $(patsubst %, $(srcdir)/init/%, $(STARTUP))

MAIN_DIR	  	  := Makefile.in INSTALL configure README_lua_modulefiles.txt \
                             README README.old License

CONTRIB_DIRS           	  :=  \
                              BuildSystemCacheFile              \
                              Deprecating_Modules               \
                              SitePackage                       \
                              TACC                              \
                              bash_patch                        \
                              converting_shell_to_module_files  \
                              hook                              \
                              parseVersions                     \
                              settarg                           \
                              tracking_module_usage             \
                              tricky_modulefiles



CONTRIB                   := $(patsubst %, $(srcdir)/contrib/%, $(CONTRIB_DIRS))
lua_code	  	  := $(filter-out %.in.lua, $(wildcard $(srcdir)/src/*.lua))   \
                             $(wildcard $(srcdir)/src/*.tcl)
VDATE		  	  := $(shell date +'%F %H:%M %:z')

ComputeHashSum    	  := $(srcdir)/src/computeHashSum.in.lua
spiderCacheSupportCMD     := $(PATH_TO_LUA)/lua $(srcdir)/src/spiderCacheSupport.in.lua
export L_PATH              =  $(LUA_PATH)
export L_CPATH             =  $(LUA_CPATH)

HAVE_LUA_TERM             := @HAVE_LUA_TERM@
ifneq ($(HAVE_LUA_TERM),yes)
  PKGS := pkgs
  LIB  := $(prefix)/$(package)/$(version)/lib
endif

.PHONY: test pkgs man_pages

all:
	@echo done

uninstall:
	$(RM) -rf $(DESTDIR)$(prefix)/$(package)
	@echo "If you added lmod files to /etc/profile.d please remove them."

pre-install: $(DIRLIST) lmodrc_init shell_init startup libexec spiderCacheSupport \
             Inst_Tools Inst_Shells Inst_Settarg Inst_Lmod_MF $(PKGS) other_tools \
             man_pages

install: pre-install  zsh_tab_funcs
	$(MAKE) PKGV=$(PKG) shell_init
	$(RM) $(DESTDIR)$(PKG)
	ln -s $(version) $(DESTDIR)$(PKG)

echo:
	@echo Version: $(version)
	@echo IGNORE_DIRS: $(IGNORE_DIRS)
	@echo LUA_PATH: $$LUA_PATH
	@echo L_PATH: "$(L_PATH)"

man_pages:
	-$(PATH_TO_LUA)/lua $(srcdir)/src/lmod.in.lua bash --help >/dev/null 2> $(DESTDIR)$(MAN_PAGES)/module.1

$(DIRLIST) :
	mkdir -p $@

__installMe:
	-for i in $(FILELIST); do                                     	   	  \
           bareN=$${i##*/};                                           	   	  \
           fn=$${bareN%%.in*};                                        	   	  \
           ext=$${bareN#*.};                                          	   	  \
	   : echo "DIRLOC/fn: $(DIRLOC)/$$fn";                             	  \
           sed  -e 's|@PREFIX@|$(prefix)|g'                            	   	  \
	        -e 's|@path_to_lua@|$(PATH_TO_LUA)|g'                 	   	  \
	        -e 's|@path_to_hashsum@|$(PATH_TO_HASHSUM)|g'         	   	  \
	        -e 's|@path_to_pager@|$(PATH_TO_PAGER)|g'             	   	  \
	        -e 's|@case_independent_sorting@|$(CASE_INDEPENDENT_SORTING)|g'   \
                -e 's|@lmod_full_settarg_support@|$(LMOD_FULL_SETTARG_SUPPORT)|g' \
                -e 's|@use_dot_files@|$(USE_DOT_FILES)|g'             	   	  \
                -e 's|@git@|$(GIT_VERSION)|g'                              	  \
                -e 's|--@ignore_dirs@--|$(IGNORE_DIRS)|g'                         \
	        -e 's|@sys_lua_path@|$(SYS_LUA_PATH)|g'                  	  \
	        -e 's|@sys_lua_cpath@|$(SYS_LUA_CPATH)|g'                  	  \
                -e 's|@path_to_luac@|$(PATH_TO_LUAC)|g'                  	  \
                -e 's|@have_lua_term@|$(HAVE_LUA_TERM)|g'                  	  \
                -e 's|@have_lua_json@|$(HAVE_LUA_JSON)|g'                  	  \
                -e 's|@tr@|$(PATH_TO_TR)|g'                             	  \
                -e 's|@tclsh@|$(PATH_TO_TCLSH)|g'                             	  \
                -e 's|@disable_name_autoswap@|$(DISABLE_NAME_AUTOSWAP)|g'     	  \
	        -e 's|@tmod_path_rule@|$(TMOD_PATH_RULE)|g'            	   	  \
	        -e 's|@redirect@|$(REDIRECT)|g'                       	   	  \
	        -e 's|@basename@|$(BASENAME)|g'                       	   	  \
	        -e 's|@cached_loads@|$(CACHED_LOADS)|g'                	   	  \
	        -e 's|@check_for_valid_module_files@|$(CHECK_VALID)|g'            \
	        -e 's|@ps@|$(PS)|g'                              	   	  \
	        -e 's|@expr@|$(EXPR)|g'                              	   	  \
	        -e 's|@libexec@|$(LIBEXEC)|g'                       	   	  \
	        -e 's|@legacy_ordering@|$(LEGACY_ORDERING)|g'           	  \
	        -e 's|@pin_versions@|$(PIN_VERSIONS)|g'                	   	  \
	        -e 's|@auto_swap@|$(AUTO_SWAP)|g'                      	   	  \
	        -e 's|@sys_ld_lib_path@|$(SYS_LD_LIB_PATH)|g'                     \
	        -e 's|@sys_ld_preload@|$(SYS_LD_PRELOAD)|g'                       \
	        -e 's|@export_module@|$(EXPORT_MODULE)|g'             	   	  \
                -e 's|@lmod_version@|$(version)|g'               	   	  \
                -e 's|@exact_match@|$(EXACT_MATCH)|g'               	   	  \
	        -e 's|@ancient@|$(ANCIENT)|g'                         	   	  \
	        -e 's|@prepend_block@|$(PREPEND_BLOCK)|g'             	   	  \
	        -e 's|@colorize@|$(COLORIZE)|g'                       	   	  \
	        -e 's|@duplicate_paths@|$(DUPLICATE_PATHS)|g'      	   	  \
	        -e 's|@allow_tcl_mfiles@|$(ALLOW_TCL_MFILES)|g'      	   	  \
	        -e 's|@mpath_avail@|$(MPATH_AVAIL)|g'            	   	  \
	        -e 's|@short_time@|$(SHORT_TIME)|g'                   	   	  \
	        -e 's|@cacheDirs@|$(SPIDER_CACHE_DIRS)|g'             	   	  \
	        -e 's|@updateSystemFn@|$(UPDATE_SYSTEM_FN)|g'         	   	  \
	        -e 's|@modulepath_root@|$(MODULEPATH_ROOT)|g'         	   	  \
                -e 's|@PKGV@|$(PKGV)|g'                                    	  \
                -e 's|@PKG@|$(PKG)|g'         < $$i > $(DIRLOC)/$$fn; 	   	  \
            [ "$$ext" = "in.lua" -o "$$ext" = "tcl" -o "$$ext" = "in" ] && 	  \
               chmod +x $(DIRLOC)/$$fn;                                    	  \
            if [ "$$ext" = "version.lua" ]; then                           	  \
               mname=$${bareN%%.*};                                        	  \
	       : echo "DIRLOC: $(DIRLOC)/$$mname";                         	  \
	       mkdir -p $(DIRLOC)/$$mname;                                 	  \
               mv $(DIRLOC)/$$fn $(DIRLOC)/$$mname/$(version).lua;         	  \
            fi;                                                            	  \
        done

generate_doc:
	ldoc .


shell_init: $(SHELL_INIT)
	$(MAKE) FILELIST="$^" DIRLOC=$(DESTDIR)$(INIT)    __installMe

lmodrc_init: $(LMODRC_INIT)
	$(MAKE) FILELIST="$^" DIRLOC=$(DESTDIR)$(INIT)    __installMe

startup: $(STARTUP)
	$(MAKE) FILELIST="$^" DIRLOC=$(DESTDIR)$(INIT)    __installMe

other_tools: $(ComputeHashSum) $(STANDALONE_PRGM)
	$(MAKE) FILELIST="$^" DIRLOC=$(DESTDIR)$(LIBEXEC) __installMe

spiderCacheSupport:
	$(spiderCacheSupportCMD) --cacheDirs "$(SPIDER_CACHE_DIRS)"          \
	                         --updateFn  "$(UPDATE_SYSTEM_FN)"           \
                                 --descriptFn "$(SPIDER_CACHE_DESCRIPT_FN)"  \
                                 >> $(DESTDIR)$(INIT)/lmodrc.lua;

src/computeHashSum: $(ComputeHashSum)
	$(MAKE) FILELIST="$^" DIRLOC="$(prefix)/src"                __installMe
	chmod +x $@

pkgs:
	cd $(srcdir)/pkgs; \
        $(MAKE) LUA_INC=$(LUA_INCLUDE)  LIB=$(DESTDIR)$(LIB) \
                SHARE=$(DESTDIR)$(LIBEXEC) CC=$(CC) install

zsh_tab_funcs: $(ZSH_FUNCS)
	-if [ -n "$(ZSH_SITE_FUNCTIONS_DIRS)" ]; then               \
          for i in $${ZSH_SITE_FUNCTIONS_DIRS//:/ }; do             \
            cp $^ $(DESTDIR)$$i  2> /dev/null;                      \
	  done;                                                     \
	  true;                                                     \
        fi

makefile: $(srcdir)/Makefile.in ./config.status
	./config.status $@

config.status:
	./config.status --recheck

dist:
	git archive --prefix=Lmod-$(version)/ $(GIT_BRANCH) > Lmod-$(version).tar
	$(RM) -rf DIST;                               			     	 \
        mkdir DIST;                                   			     	 \
        cd DIST;                                      			     	 \
        tar xf ../Lmod-$(version).tar;                			     	 \
        $(RM) ../Lmod-$(version).tar;                 			     	 \
        echo "Lmod"-$(version) > .fname;                		     	 \
        perl -p -i -e 's/\@git\@/$(GIT_VERSION)/g' `cat .fname`/src/Version.lua; \
        tar chf `cat .fname`.tar `cat .fname`;           		     	 \
        bzip2 `cat .fname`.tar;                           		     	 \
        mv `cat .fname`.tar.bz2  ..;                         		     	 \
        cd ..; $(RM) -rf DIST



_dist: _distMkDir _distMainDir _distSrc _distSetup _distSetupZsh \
       _distVersion _distPkgs _distMF    _distContrib _distTar

_distMkDir:
	$(RM) -r $(DistD)
	mkdir $(DistD)


_distContrib:
	mkdir $(DistD)/contrib
	cp -r $(CONTRIB) $(DistD)/contrib

_distSrc:
	mkdir $(DistD)/src $(DistD)/tools $(DistD)/settarg $(DistD)/shells
	cp $(lua_code) $(ComputeHashSum) $(STANDALONE_PRGM) $(DistD)/src
	cp tools/*.lua $(DistD)/tools
	cp $(SETTARG_SOURCE) $(DistD)/settarg
	cp shells/*.lua $(DistD)/shells

_distVersion:
	perl -p -i -e 's/\@git\@/$(GIT_VERSION)/g' $(DistD)/src/Version.lua

_distPkgs:
	mkdir $(DistD)/pkgs
	cp -r pkgs/* $(DistD)/pkgs

_distSetup:
	mkdir $(DistD)/init
	cp $(SHELL_INIT) $(STARTUP) $(LMODRC_INIT) $(DistD)/init

_distSetupZsh:
	mkdir $(DistD)/init/zsh
	cp $(ZSH_FUNCS) $(DistD)/init/zsh



_distMainDir:
	cp $(MAIN_DIR) $(DistD)

_distMF:
	mkdir $(DistD)/MF
	cp -r MF $(DistD)/

_distTar:
	echo "Lmod"-$(version) > .fname;                		   \
	$(RM) -r `cat .fname` `cat .fname`.tar*;         		   \
	mv ${DistD} `cat .fname`;                            		   \
	tar chf `cat .fname`.tar `cat .fname`;           		   \
	bzip2 `cat .fname`.tar;                           		   \
	rm -rf `cat .fname` .fname;


ml_dist:
	$(MAKE) DistD=DIST _ml_dist

_ml_dist: _distMkDir
	cp src/ml_cmd.in.lua ML_README.txt $(DistD)
	echo "ml"-$(version) > .fname;                                     \
	$(RM) -r `cat .fname` `cat .fname`.tar*;         		   \
	mv ${DistD} `cat .fname`;                            		   \
	tar chf `cat .fname`.tar `cat .fname`;           		   \
	bzip2 `cat .fname`.tar;                           		   \
	rm -rf `cat .fname` .fname;

test:
	cd rt; unset TMFuncPATH; tm .

tags: build_tags
	$(RM) file_list.*

build_tags:
	find . \( -regex '.*~$$\|.*/\.git\|.*/\.git/' -prune \)  \
               -o -type f > file_list.1.txt
	sed -e 's|.*/.git.*||g'                                  \
            -e 's|.*/rt/.*/t1/.*||g'                             \
            -e 's|./rt/funny_files/mf/.*||g'                     \
            -e 's|.*/html/.*$$||g'                               \
            -e 's|./TAGS||g'                                     \
            -e 's|./makefile||g'                                 \
            -e 's|./configure$$||g'                              \
            -e 's|.*\.DS_Store$$||g'                             \
            -e 's|.*\.tgz$$||g'                                  \
            -e 's|.*\.tar\.gz$$||g'                              \
            -e 's|.*\.tar\.bz2$$||g'                             \
            -e 's|.*\.csv$$||g'                                  \
	    -e 's|.*\.aux$$||g'                                  \
	    -e 's|.*\.fdb_latexmk$$||g'                          \
	    -e 's|.*\.fls$$||g'                                  \
	    -e 's|.*\.nav$$||g'                                  \
	    -e 's|.*\.out$$||g'                                  \
	    -e 's|.*\.pdf$$||g'                                  \
	    -e 's|.*\.pyc$$||g'                                  \
	    -e 's|.*db\.conf$$||g'                               \
	    -e 's|.*\.pyo$$||g'                                  \
	    -e 's|.*\.snm$$||g'                                  \
	    -e 's|.*\.toc$$||g'                                  \
	    -e 's|.*\.vrb$$||g'                                  \
	    -e 's|.*\.key$$||g'                                  \
            -e 's|^#.*||g'                                       \
            -e 's|.*/#.*||g'                                     \
            -e 's|\.#.*||g'                                      \
            -e 's|.*/\.#.*||g'                                   \
            -e 's|.*\.pdf$$||g'                                  \
            -e 's|.*\.used$$||g'                                 \
            -e 's|./.*\.log$$||g'                                \
            -e 's|./testreports/.*||g'                           \
            -e 's|./docs/build/.*||g'                            \
            -e 's|./config\.status$$||g'                         \
            -e 's|.*\~$$||g'                                     \
            -e 's|./lmod.check.txt*||g'                          \
            -e 's|./file_list\..*||g'                            \
            -e '/^\s*$$/d'                                       \
	       < file_list.1.txt > file_list.2.txt
	etags  `cat file_list.2.txt`


libexec:  $(lua_code)
	$(MAKE) FILELIST="$^" DIRLOC=$(DESTDIR)$(LIBEXEC) __installMe

Inst_Tools: $(TOOL_SRC)
	$(MAKE) FILELIST="$^" DIRLOC=$(DESTDIR)$(TOOLS) __installMe

Inst_Shells: $(srcdir)/shells/*.lua
	$(MAKE) FILELIST="$^" DIRLOC=$(DESTDIR)$(SHELLS) __installMe

Inst_Settarg: $(SETTARG_SOURCE)
	$(MAKE) FILELIST="$^" DIRLOC=$(DESTDIR)$(SETTARG) __installMe


Inst_Lmod_MF: $(LMOD_MF_SOURCE)
	$(MAKE) FILELIST="$^" DIRLOC=$(DESTDIR)$(LMOD_MF) __installMe

clean:
	$(RM) config.log *.o
	cd $(srcdir)/pkgs; $(MAKE) LIB=$(DESTDIR)$(LIB) SHARE=$(DESTDIR)$(LIBEXEC) clean

clobber: clean

distclean: clobber
	$(RM) makefile config.status

world_update:
	@git status -s > /tmp/git_st_$$$$;                                         \
        if [ -s /tmp/git_st_$$$$ ]; then                                           \
            echo "All files not checked in => try again";                          \
        else                                                                       \
            git push github;                                                       \
            git push --tags github;                                                \
            git push sf;                                                           \
            git push --tags sf;                                                    \
        fi;                                                                        \
        rm -f /tmp/git_st_$$$$

gittag:
        ifneq ($(TAG),)
	  @git status -s > /tmp/git_st_$$$$;                                         \
          if [ -s /tmp/git_st_$$$$ ]; then                                           \
	    echo "All files not checked in => try again";                            \
	  else                                                                       \
	    $(RM)                                                    $(VERSION_SRC); \
	    echo "--module('Version')"                            >  $(VERSION_SRC); \
	    echo 'local M={}'                                     >> $(VERSION_SRC); \
	    echo 'function M.tag()  return "$(TAG)"   end'        >> $(VERSION_SRC); \
	    echo 'function M.git()'                               >> $(VERSION_SRC); \
            echo '   local s = "@git@"'                           >> $(VERSION_SRC); \
            echo '   if (s == "@" .. "git@")     then s = "" end' >> $(VERSION_SRC); \
            echo '   if (s == "("..M.tag()..")") then s = "" end' >> $(VERSION_SRC); \
            echo '   return s'                                    >> $(VERSION_SRC); \
            echo 'end'                                            >> $(VERSION_SRC); \
	    echo 'function M.date() return "$(VDATE)" end'        >> $(VERSION_SRC); \
	    echo 'function M.name()'                              >> $(VERSION_SRC); \
            echo '  local a = {}'                                 >> $(VERSION_SRC); \
	    echo '  a[#a+1] = M.tag()'                            >> $(VERSION_SRC); \
	    echo '  a[#a+1] = M.git()'                            >> $(VERSION_SRC); \
	    echo '  a[#a+1] = M.date()'                           >> $(VERSION_SRC); \
	    echo '  return table.concat(a," ")'                   >> $(VERSION_SRC); \
	    echo 'end'                                            >> $(VERSION_SRC); \
	    echo 'return M'                                       >> $(VERSION_SRC); \
            git commit -m "moving to TAG_VERSION $(TAG)"             $(VERSION_SRC); \
            git tag -a $(TAG) -m 'Setting TAG_VERSION to $(TAG)'                   ; \
	    git push --tags                                                        ; \
          fi;                                                                        \
          rm -f /tmp/git_st_$$$$
        else
	  @echo "To git tag do: make gittag TAG=?"
        endif
