source: SConstruct @ 3413

Last change on this file since 3413 was 3359, checked in by jack, 18 years ago

SCons will now byte-compile any .py files found.

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