Package _setup :: Package make :: Module default_targets
[hide private]
[frames] | no frames]

Source Code for Module _setup.make.default_targets

  1  # -*- coding: ascii -*- 
  2  # 
  3  # Copyright 2007, 2008, 2009, 2010 
  4  # Andr\xe9 Malo or his licensors, as applicable 
  5  # 
  6  # Licensed under the Apache License, Version 2.0 (the "License"); 
  7  # you may not use this file except in compliance with the License. 
  8  # You may obtain a copy of the License at 
  9  # 
 10  #     http://www.apache.org/licenses/LICENSE-2.0 
 11  # 
 12  # Unless required by applicable law or agreed to in writing, software 
 13  # distributed under the License is distributed on an "AS IS" BASIS, 
 14  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
 15  # See the License for the specific language governing permissions and 
 16  # limitations under the License. 
 17  """ 
 18  ================== 
 19   Simple make base 
 20  ================== 
 21   
 22  Simple make base. 
 23  """ 
 24  __author__ = u"Andr\xe9 Malo" 
 25  __docformat__ = "restructuredtext en" 
 26   
 27  import os as _os 
 28  import sys as _sys 
 29   
 30  from _setup import make as _make 
 31  from _setup import shell as _shell 
 32   
 33   
34 -class MakefileTarget(_make.Target):
35 """ Create a make file """ 36 NAME = 'makefile' 37
38 - def run(self):
39 def escape(value): 40 """ Escape for make and shell """ 41 return '"%s"' % value.replace( 42 '\\', '\\\\').replace( 43 '"', '\\"').replace( 44 '$', '\\$$')
45 def decorate(line, prefix='# ', width=78, char='~', padding=' '): 46 """ Decorate a line """ 47 line = line.center(width - len(prefix)) 48 return '%s%s%s%s%s%s' % ( 49 prefix, 50 char * (len(line) - len(line.lstrip()) - len(padding)), 51 padding, 52 line.strip(), 53 padding, 54 char * (len(line) - len(line.rstrip()) - len(padding)), 55 )
56 57 python = escape(_sys.executable) 58 script = escape(_sys.argv[0]) 59 targets = self.runner.targetinfo() 60 names = [] 61 for name, info in targets.items(): 62 if not info['hide']: 63 names.append(name) 64 names.sort() 65 66 fp = file(_shell.native('Makefile'), 'w') 67 print >> fp, decorate("Generated Makefile, DO NOT EDIT") 68 print >> fp, decorate("python %s %s" % ( 69 _os.path.basename(script), self.NAME 70 )) 71 print >> fp 72 print >> fp, "_default_:" 73 print >> fp, "\t@%s %s" % (python, script) 74 for name in names: 75 print >> fp, "\n" 76 print >> fp, "# %s" % \ 77 targets[name]['desc'].splitlines()[0].strip() 78 print >> fp, "%s:" % name 79 print >> fp, "\t@%s %s %s" % (python, script, escape(name)) 80 print >> fp 81 print >> fp, ".PHONY: _default_, %s\n\n" % ', '.join(names) 82 fp.close() 83 84
85 -class CleanTarget(_make.Target):
86 """ Clean the mess """ 87 NAME = 'clean' 88 _scm, _dist = True, False 89
90 - def run(self):
91 self.runner.run_clean(scm=self._scm, dist=self._dist)
92 93
94 -class DistCleanTarget(CleanTarget):
95 """ Clean as freshly unpacked dist package """ 96 NAME = 'distclean' 97 _scm, _dist = False, True
98 99
100 -class ExtraCleanTarget(CleanTarget):
101 """ Clean everything """ 102 NAME = 'extraclean' 103 _scm, _dist = True, True
104