Ignore:
Timestamp:
May 16, 2007, 11:26:11 AM (17 years ago)
Author:
duncan
Message:

Modified to be general, so mesh engine doesn't need its own compile.py file

File:
1 edited

Legend:

Unmodified
Added
Removed
  • anuga_core/source/anuga/mesh_engine/compile.py

    r4435 r4446  
    77     import compile
    88     compile.compile(<filename>,..)
    9 
    10    SPECIAL VERSION FOR TRIANGLE !
    119
    1210   Ole Nielsen, Oct 2001     
     
    2624  """
    2725 
     26 
     27 
    2828  import os, string, sys, types
    2929 
     
    155155  #
    156156  if sys.platform == 'win32':  #Windows
    157     include = os.path.join(sys.exec_prefix, 'include')   
     157    python_include = os.path.join(sys.exec_prefix, 'include')   
    158158  else: 
    159     include = os.path.join(os.path.join(sys.exec_prefix, 'include'),
    160                            'python'+version)
     159    python_include = os.path.join(os.path.join(sys.exec_prefix, 'include'),
     160                                  'python' + version)
    161161
    162162  # Check existence of Python.h
    163163  #
    164   headerfile = include + os.sep +'Python.h'
     164  headerfile = python_include + os.sep + 'Python.h'
    165165  try:
    166166    open(headerfile, 'r')
     
    170170    In debian linux, for example, you need to install a
    171171    package called something like python2.3-dev""" %headerfile
     172
     173
     174
     175  #Add Python path + utilities to includelist (see ticket:31)
     176  #Assume there is only one 'utilities' dir under path dirs
     177 
     178  utilities_include_dir = None
     179  for pathdir in sys.path:
     180
     181    utilities_include_dir = pathdir + os.sep + 'utilities'
     182    #print pathdir
     183    #print utilities_include_dir
     184    try:
     185      os.stat(utilities_include_dir)
     186    except OSError:
     187      pass
     188    else:
     189      #print 'Found %s to be used as include dir' %utilities_include_dir
     190      break
     191
     192  # This is hacky since it
     193  # assumes the location of the compile_all that determines buildroot
     194  try:
     195    utilities_include_dir = buildroot + os.sep + "source" + os.sep + "anuga" \
     196                            + os.sep + 'utilities'
     197  except:
     198    # This will make compile work locally
     199    utilities_include_dir = '.'
     200
     201
     202   
     203  try:
     204    os.stat(utilities_include_dir)
     205  except OSError:
     206    utilities_include_dir = buildroot + os.sep + 'utilities'
     207 
    172208 
    173209 
     
    183219   
    184220    try:
    185       open(FN,'r')
    186     except:   
     221      open(FN, 'r')
     222    except:
    187223      raise Exception, "Could not open: " + FN
    188224
     
    193229    # Compile
    194230    #
    195     s = "%s -c %s -I%s -o %s.o -O3  -DTRILIBRARY=1 -DNO_TIMER=1" %(compiler, FN, include, root)
     231    if utilities_include_dir is None:   
     232      s = '%s -c %s -I"%s" -o "%s.o" -Wall -O3'\
     233          %(compiler, FN, python_include, root)
     234    else:
     235      if FN == "triangle.c" or FN == "mesh_engine_c_layer.c":
     236        s = '%s -c %s -I"%s" -I"%s" -o "%s.o" -O3 -DTRILIBRARY=1 -DNO_TIMER=1'\
     237            %(compiler, FN, python_include, utilities_include_dir, root)
     238      else:
     239        s = '%s -c %s -I"%s" -I"%s" -o "%s.o" -Wall -O3'\
     240            %(compiler, FN, python_include, utilities_include_dir, root)
    196241
    197242    if os.name == 'posix' and os.uname()[4] == 'x86_64':
    198243      #Extra flags for 64 bit architectures
     244      #Second clause will always fail on Win32 because uname is UNIX specific
     245      #but won't get past first clause
    199246
    200247      #FIXME: Which one?
     
    217264 
    218265  # Make shared library (*.so or *.dll)
    219  
    220   s = "%s -%s %s -o %s.%s %s -lm" %(loader, sharedflag, object_files, root1, libext, libs)
     266  if libs is "":
     267    s = '%s -%s %s -o %s.%s -lm' %(loader, sharedflag, object_files, root1, libext)
     268  else:
     269    s = '%s -%s %s -o %s.%s "%s" -lm' %(loader, sharedflag, object_files, root1, libext, libs)
    221270  if verbose:
    222271    print s
     
    312361              except:
    313362                  pass
    314           if  filename == 'mesh_engine.c': # not part of ANUGA
    315               continue
    316           print '--------------- Trying to compile c-extension %s' %filename
     363
     364          print '--------------------------------------'     
     365          print 'Trying to compile c-extension %s in %s'\
     366                %(filename, os.getcwd())
    317367          try:
    318368            if filename == 'triang.c':
    319               print "********** Manually doing dependencies **************"
    320369              compile(['triang.c','triangle.c'])
    321370            elif  filename == 'mesh_engine_c_layer.c':
    322               #print "********** Manually doing dependencies **************"
    323371              compile(['mesh_engine_c_layer.c','triangle.c'])
    324              
    325372            else:
    326373              compile(filename)
    327           except:
    328               print 'Could not compile C extension %s' %filename           
     374          except Exception, e:
     375              print 'Could not compile C extension %s' %filename
    329376          else:
    330377              print 'C extension %s OK' %filename
Note: See TracChangeset for help on using the changeset viewer.