/[ascend]/trunk/SConstruct
ViewVC logotype

Diff of /trunk/SConstruct

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 393 by johnpye, Thu Mar 30 14:46:37 2006 UTC revision 395 by johnpye, Fri Mar 31 06:09:03 2006 UTC
# Line 144  if not conf.CheckLib('tk'): Line 144  if not conf.CheckLib('tk'):
144      with_tcktk_gui = False      with_tcktk_gui = False
145    
146    
147    # Python... obviously we're already running python, so we just need to
148    # check that we can link to the python library OK:
149    
150  if platform.system()=="Windows":  if platform.system()=="Windows":
151      #conf.env.Append(LIBPATH='c:\Python24\libs')      #conf.env.Append(LIBPATH='c:\Python24\libs')
152      #conf.env.Append(CPPPATH='c:\Python24\include')      #conf.env.Append(CPPPATH='c:\Python24\include')
153      python_header='Python.h'      #python_header='Python.h'
154      python_lib=['python24']      python_lib='python24'
155      #python_libpath=['c:\\Python24\\libs']      #python_libpath=['c:\\Python24\\libs']
156      #python_cpppath=['c:\\Python24\\include']      #python_cpppath=['c:\\Python24\\include']
157  else:  else:
158      python_header='python2.4/Python.h'      #python_header='python2.4/Python.h'
159      python_lib=['python2.4']      python_lib='python2.4'
160      #python_libpath=[]      #python_libpath=[]
161      #python_cpppath=['/usr/include/python2.4']      #python_cpppath=['/usr/include/python2.4']
       
162    
163  # Python  #if not conf.CheckLibWithHeader(python_lib,python_header,'C'
164  if not conf.CheckLibWithHeader(python_lib,python_header,'C'):  #       , LIBPATH=[distutils.sysconfig.PREFIX+"/libs"]
165      print "Didn't find Python 2.4 ("+python_lib+")"  #       , CPPPATH=[distutils.sysconfig.get_python_inc()]
166      with_python = False  #):
167  else:  #   print "Didn't find Python 2.4 ("+python_lib+")"
168      env.Append(PYTHON_LIBPATH=[distutils.sysconfig.PREFIX+"/libs"])  #   with_python = False
169      #env.Append(PYTHON_LIB=python_lib)  #else:
170      env.Append(PYTHON_CPPPATH=[distutils.sysconfig.get_python_inc()])  
171      print "PYTHON_LIBPATH =",env['PYTHON_LIBPATH']  
172      print "PYTHON_CPPPATH =",env['PYTHON_CPPPATH']  # SWIG version
173    env['SWIG']=['c:\\msys\\1.0\\home\\john\\swigwin-1.3.29\\swig.exe']
174    env['ENV']['SWIGFEATURES']='-O'
175    
176    
177  # TODO: -D_HPUX_SOURCE is needed  # TODO: -D_HPUX_SOURCE is needed
178    
# Line 175  else: Line 180  else:
180    
181  # TODO: detect if dynamic libraries are possible or not  # TODO: detect if dynamic libraries are possible or not
182    
183    conf.Finish()
184    
185    env.Append(PYTHON_LIBPATH=[distutils.sysconfig.PREFIX+"/libs"])
186    env.Append(PYTHON_LIB=[python_lib])
187    env.Append(PYTHON_CPPPATH=[distutils.sysconfig.get_python_inc()])
188    print "PYTHON_LIBPATH =",env['PYTHON_LIBPATH']
189    print "PYTHON_CPPPATH =",env['PYTHON_CPPPATH']
190    
191  #------------------------------------------------------  #------------------------------------------------------
192  # RECIPE: 'SubstInFile', used in pygtk SConscript  # RECIPE: 'SubstInFile', used in pygtk SConscript
193    
 import SCons.Util  
194  import re  import re
195    from SCons.Script import *  # the usual scons stuff you get in a SConscript
196    
197  def do_subst_in_file(targetfile, sourcefile, dict):  def TOOL_SUBST(env):
198      """Replace all instances of the keys of dict with their values.      """Adds SubstInFile builder, which substitutes the keys->values of SUBST_DICT
199      For example, if dict is {'%VERSION%': '1.2345', '%BASE%': 'MyProg'},      from the source to the target.
200      then all instances of %VERSION% in the file will be replaced with 1.2345 etc.      The values of SUBST_DICT first have any construction variables expanded
201        (its keys are not expanded).
202        If a value of SUBST_DICT is a python callable function, it is called and
203        the result is expanded as the value.
204        If there's more than one source and more than one target, each target gets
205        substituted from the corresponding source.
206      """      """
207      try:      env.Append(TOOLS = 'SUBST')
208          f = open(sourcefile, 'rb')      def do_subst_in_file(targetfile, sourcefile, dict):
209          contents = f.read()          """Replace all instances of the keys of dict with their values.
210          f.close()          For example, if dict is {'%VERSION%': '1.2345', '%BASE%': 'MyProg'},
211      except:          then all instances of %VERSION% in the file will be replaced with 1.2345 etc.
212          raise RuntimeError("Can't read source file %s" % sourcefile)          """
213      for (k,v) in dict.items():          try:
214          contents = re.sub(k, v, contents)              f = open(sourcefile, 'rb')
215      try:              contents = f.read()
216          f = open(targetfile, 'wb')              f.close()
217          f.write(contents)          except:
218          f.close()              raise SCons.Errors.UserError, "Can't read source file %s"%sourcefile
219      except:          for (k,v) in dict.items():
220          raise RuntimeError("Can't write target file %s" % targetfile)              contents = re.sub(k, v, contents)
221      return 0 # success          try:
222                f = open(targetfile, 'wb')
223  def subst_in_file(target, source, env):              f.write(contents)
224      if not env.has_key('SUBST_DICT'):              f.close()
225          raise RuntimeError("SubstInFile requires SUBST_DICT to be set.")          except:
226      d = dict(env['SUBST_DICT']) # copy it              raise SCons.Errors.UserError, "Can't write target file %s"%targetfile
227      for (k,v) in d.items():          return 0 # success
228          if callable(v):  
229              d[k] = env.subst(v())      def subst_in_file(target, source, env):
230          elif SCons.Util.is_String(v):          if not env.has_key('SUBST_DICT'):
231              d[k]=env.subst(v)              raise SCons.Errors.UserError, "SubstInFile requires SUBST_DICT to be set."
232          else:          d = dict(env['SUBST_DICT']) # copy it
233              raise RuntimeError(          for (k,v) in d.items():
234                  "SubstInFile: key %s: %s must be a string or callable" % (              if callable(v):
235                      k, repr(v)                  d[k] = env.subst(v())
236              ))              elif SCons.Util.is_String(v):
237      for (t,s) in zip(target, source):                  d[k]=env.subst(v)
238          return do_subst_in_file(str(t), str(s), d)              else:
239                    raise SCons.Errors.UserError, "SubstInFile: key %s: %s must be a string or callable"%(k, repr(v))
240  def subst_in_file_string(target, source, env):          for (t,s) in zip(target, source):
241      """This is what gets printed on the console."""              return do_subst_in_file(str(t), str(s), d)
242      return '\n'.join(['Substituting vars from %s into %s'%(str(s), str(t))  
243                          for (t,s) in zip(target, source)])      def subst_in_file_string(target, source, env):
244            """This is what gets printed on the console."""
245  env['BUILDERS']['SubstInFile'] = Builder(          return '\n'.join(['Substituting vars from %s into %s'%(str(s), str(t))
246      action = subst_in_file                            for (t,s) in zip(target, source)])
247      , suffix = ''  
248      , src_suffix = '.in'      def subst_emitter(target, source, env):
249  )          """Add dependency from substituted SUBST_DICT to target.
250            Returns original target, source tuple unchanged.
251            """
252            d = env['SUBST_DICT'].copy() # copy it
253            for (k,v) in d.items():
254                if callable(v):
255                    d[k] = env.subst(v())
256                elif SCons.Util.is_String(v):
257                    d[k]=env.subst(v)
258            Depends(target, SCons.Node.Python.Value(d))
259            return target, source
260    
261        subst_action=SCons.Action.Action(subst_in_file, subst_in_file_string)
262        env['BUILDERS']['SubstInFile'] = Builder(action=subst_action, emitter=subst_emitter)
263    
264    TOOL_SUBST(env)
265    
266  #------------------------------------------------------  #------------------------------------------------------
267  # SUBDIRECTORIES....  # SUBDIRECTORIES....

Legend:
Removed from v.393  
changed lines
  Added in v.395

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22