source: SConstruct @ 3460

Last change on this file since 3460 was 3414, checked in by jack, 19 years ago

Added pymetis to the scons scripts

File size: 2.3 KB
Line 
1import os
2import sys
3import py_compile
4
5# Function to build a .pyc from a .py
6def build_pyc(target, source, env):
7    py_compile.compile(str(source[0]), str(target[0]), doraise=True)
8    return None
9
10# Read in build options
11opts = Options('build_options.py')
12opts.Add('GCCFLAGS', 'Flags passed to GCC')
13opts.Add('MSVCFLAGS', 'Flags passed to the MSVC compiler')
14opts.Add('METIS_DIR', 'Location of the metis directory relative to the pymetis directory')
15
16# Create the .pyc builder
17pyc_builder = Builder(action = build_pyc,
18                      suffix = '.pyc',
19                      src_suffix = '.py')
20
21env = Environment(options = opts)
22env.Append(BUILDERS={'Pyc' : pyc_builder})
23
24Help(opts.GenerateHelpText(env))
25
26# Find the path for Python.h and then share it to other SConscripts later on
27# Where to find the Python.h
28if sys.platform == 'win32':
29    # Prefer MinGW over MSVC
30    Tool('mingw')(env)
31
32    python_include = os.path.join(sys.exec_prefix, 'include')
33    # Windows installs need to be told the lib path and the python library name
34    # else it won't work right.
35    python_libdir = os.path.join(sys.exec_prefix, 'libs')
36    env.Append(LIBPATH=[python_libdir])
37    python_libname = 'python%d%d' % (sys.version_info[0:2])
38    env.Append(LIBS=[python_libname])
39else:
40    python_include = os.path.join(os.path.join(sys.exec_prefix, 'include'),
41                                  'python' + sys.version[:3])
42   
43# Check existence of Python.h
44headerfile = python_include + os.sep + 'Python.h'
45try:
46    open(headerfile, 'r')
47except:
48    raise """Did not find Python header file %s.
49    Make sure files for Python C-extensions are installed.
50    In debian linux, for example, you need to install a
51    package called something like python2.3-dev""" %headerfile
52
53env.Append(CPPPATH=[python_include])
54
55# Set appropriate CCFLAGS for the compiler.
56if env['CC'] == 'gcc':
57    env.Append(CCFLAGS=['${GCCFLAGS}'])
58elif env['CC'] == 'cl':
59    env.Append(CCFLAGS=['${MSVCFLAGS}'])
60
61Export('env')
62
63# Build .pyc files of every .py in here and below.
64files = []
65dirs = filter(os.path.isdir, os.listdir('.'))
66while(dirs != []):
67    dirs += filter(os.path.isdir, map(lambda x : dirs[0] + os.sep + x, os.listdir(dirs[0])))
68    files += filter(lambda x : x[-3:] == '.py', map(lambda x : dirs[0] + os.sep + x, os.listdir(dirs[0])))
69    dirs = dirs[1:]
70for x in files:
71    env.Pyc(x + 'c', x)
72
73SConscript(['inundation/SConscript'])
Note: See TracBrowser for help on using the repository browser.