1 | import os |
---|
2 | import sys |
---|
3 | import py_compile |
---|
4 | |
---|
5 | # Function to build a .pyc from a .py |
---|
6 | def 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 |
---|
11 | opts = Options('build_options.py') |
---|
12 | opts.Add('GCCFLAGS', 'Flags passed to GCC') |
---|
13 | opts.Add('MSVCFLAGS', 'Flags passed to the MSVC compiler') |
---|
14 | |
---|
15 | # Create the .pyc builder |
---|
16 | pyc_builder = Builder(action = build_pyc, |
---|
17 | suffix = '.pyc', |
---|
18 | src_suffix = '.py') |
---|
19 | |
---|
20 | env = Environment(options = opts) |
---|
21 | env.Append(BUILDERS={'Pyc' : pyc_builder}) |
---|
22 | |
---|
23 | Help(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 |
---|
27 | if 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]) |
---|
38 | else: |
---|
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 |
---|
43 | headerfile = python_include + os.sep + 'Python.h' |
---|
44 | try: |
---|
45 | open(headerfile, 'r') |
---|
46 | except: |
---|
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 | |
---|
52 | env.Append(CPPPATH=[python_include]) |
---|
53 | |
---|
54 | # Set appropriate CCFLAGS for the compiler. |
---|
55 | if env['CC'] == 'gcc': |
---|
56 | env.Append(CCFLAGS=['${GCCFLAGS}']) |
---|
57 | elif env['CC'] == 'cl': |
---|
58 | env.Append(CCFLAGS=['${MSVCFLAGS}']) |
---|
59 | |
---|
60 | Export('env') |
---|
61 | |
---|
62 | # Build .pyc files of every .py in here and below. |
---|
63 | files = [] |
---|
64 | dirs = filter(os.path.isdir, os.listdir('.')) |
---|
65 | while(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:] |
---|
69 | for x in files: |
---|
70 | env.Pyc(x + 'c', x) |
---|
71 | |
---|
72 | SConscript(['inundation/SConscript']) |
---|