#!/usr/bin/env python
#-*- coding:utf-8 -*-

from __future__ import with_statement

if __name__ == '__main__':
    import os, sys
    if os.path.exists("Makefile"):
        os.remove("Makefile")
    files = ' '.join(sys.argv[1:])
    if files=='': files = '*.vsl'

    if len(sys.argv)>1: fil=sys.argv[1].split('.')[0]+'.cvsl'
    else: fil='*.vsl'

    with open("Makefile","w") as f:
        f.write(
'''# makefile auto-generated by vmake tools. Do not edit.

VSLEXT=*.vsl
VSLBINEXT=*.vm
PYTHON=/usr/bin/python
INSTALLDIR=/usr/local/bin/
VSLCOMPIL=$(INSTALLDIR)vslc
VSLVM=$(INSTALLDIR)vsl
CLEANPYC=rm *.pyc
MAINCMD=compil
LINE   ='  ----------------------------------------------'
LICENCE='  ---    VSL Compiler - under GPL Licence    ---'
AUTHOR ='  ---  Authors: David Jacot, Anthony Mougin  ---'

all: info compil

compil: info
	@($(PYTHON) $(VSLCOMPIL) '''+files+''')

run: compil
	@(echo '\\n   ----------   RUNNING   ----------\\n')
	@($(PYTHON) $(VSLVM) bin/'''+fil+''')

clean: info *.pyc
	@($(CLEANPYC))

info:
	@(echo $(LINE))
	@(echo $(LICENCE))
	@(echo $(AUTHOR))
	@(echo $(LINE))''')


