1 | #!/usr/bin/python |
---|
2 | # Copyright Bruno da Silva de Oliveira 2003. Use, modification and |
---|
3 | # distribution is subject to the Boost Software License, Version 1.0. |
---|
4 | # (See accompanying file LICENSE_1_0.txt or copy at |
---|
5 | # http:#www.boost.org/LICENSE_1_0.txt) |
---|
6 | |
---|
7 | import os |
---|
8 | import glob |
---|
9 | import shutil |
---|
10 | import sys |
---|
11 | import time |
---|
12 | |
---|
13 | #============================================================================= |
---|
14 | # win32 configuration |
---|
15 | #============================================================================= |
---|
16 | if sys.platform == 'win32': |
---|
17 | |
---|
18 | includes = '-ID:/programming/libraries/boost-cvs/boost -ID:/Bin/Python/include' |
---|
19 | build_pyste_cmd = 'python ../src/Pyste/pyste.py --pyste-ns=pyste --cache-dir=cache %s ' % includes |
---|
20 | compile_single_cmd = 'cl /nologo /GR /GX -c %s -I. ' % includes |
---|
21 | link_single_cmd = 'link /nologo /DLL '\ |
---|
22 | '/libpath:D:/programming/libraries/boost-cvs/lib /libpath:D:/Bin/Python/libs '\ |
---|
23 | 'boost_python.lib python24.lib /out:_%s.dll ' |
---|
24 | obj_ext = 'obj' |
---|
25 | |
---|
26 | #============================================================================= |
---|
27 | # linux configuration |
---|
28 | #============================================================================= |
---|
29 | elif sys.platform == 'linux2': |
---|
30 | |
---|
31 | build_pyste_cmd = 'python ../src/Pyste/pyste.py -I. ' |
---|
32 | compile_single_cmd = 'g++ -shared -c -I. -I/usr/include/python2.4 ' |
---|
33 | link_single_cmd = 'g++ -shared -o _%s.so -lboost_python ' |
---|
34 | obj_ext = 'o' |
---|
35 | |
---|
36 | |
---|
37 | |
---|
38 | def build_pyste(multiple, module): |
---|
39 | rest = '%s --module=_%s %s.pyste' % (multiple, module, module) |
---|
40 | execute(build_pyste_cmd + rest) |
---|
41 | |
---|
42 | |
---|
43 | def compile_single(module): |
---|
44 | module_obj = '' |
---|
45 | if os.path.isfile(module+'.cpp'): |
---|
46 | execute(compile_single_cmd + module+'.cpp') |
---|
47 | module_obj = module + '.' + obj_ext |
---|
48 | execute(compile_single_cmd + ('_%s.cpp' % module)) |
---|
49 | link = link_single_cmd % module |
---|
50 | execute(link + ('_%s.%s ' % (module, obj_ext)) + module_obj) |
---|
51 | |
---|
52 | |
---|
53 | def compile_multiple(module): |
---|
54 | module_obj = '' |
---|
55 | if os.path.isfile(module+'.cpp'): |
---|
56 | execute(compile_single_cmd + module+'.cpp') |
---|
57 | module_obj = module + '.' + obj_ext |
---|
58 | files = glob.glob('_%s/*.cpp' % module) |
---|
59 | for f in files: |
---|
60 | execute(compile_single_cmd + f) |
---|
61 | def basename(name): |
---|
62 | return os.path.basename(os.path.splitext(name)[0]) |
---|
63 | objs = [basename(x) + '.' + obj_ext for x in files] |
---|
64 | objs.append(module_obj) |
---|
65 | execute((link_single_cmd % module) + ' '.join(objs)) |
---|
66 | |
---|
67 | |
---|
68 | def execute(cmd): |
---|
69 | os.system(cmd) |
---|
70 | |
---|
71 | |
---|
72 | def run_tests(): |
---|
73 | if os.system('python runtests.py') != 0: |
---|
74 | raise RuntimeError, 'tests failed' |
---|
75 | |
---|
76 | |
---|
77 | def cleanup(): |
---|
78 | modules = get_modules() |
---|
79 | extensions = '*.dll *.pyc *.obj *.exp *.lib *.o *.so' |
---|
80 | files = [] |
---|
81 | for module in modules: |
---|
82 | files.append('_' + module + '.cpp') |
---|
83 | for ext in extensions.split(): |
---|
84 | files += glob.glob(ext) |
---|
85 | files.append('build.log') |
---|
86 | for file in files: |
---|
87 | try: |
---|
88 | os.remove(file) |
---|
89 | except OSError: pass |
---|
90 | |
---|
91 | for module in modules: |
---|
92 | try: |
---|
93 | shutil.rmtree('_' + module) |
---|
94 | except OSError: pass |
---|
95 | |
---|
96 | |
---|
97 | def main(multiple, module=None): |
---|
98 | if module is None: |
---|
99 | modules = get_modules() |
---|
100 | else: |
---|
101 | modules = [module] |
---|
102 | |
---|
103 | start = time.clock() |
---|
104 | for module in modules: |
---|
105 | build_pyste(multiple, module) |
---|
106 | print '-'*50 |
---|
107 | print 'Building pyste files: %0.2f seconds' % (time.clock()-start) |
---|
108 | print |
---|
109 | |
---|
110 | start = time.clock() |
---|
111 | for module in modules: |
---|
112 | if multiple: |
---|
113 | compile_multiple(module) |
---|
114 | else: |
---|
115 | compile_single(module) |
---|
116 | print '-'*50 |
---|
117 | print 'Compiling files: %0.2f seconds' % (time.clock()-start) |
---|
118 | print |
---|
119 | if len(modules) == 1: |
---|
120 | os.system('python %sUT.py' % modules[0]) |
---|
121 | else: |
---|
122 | run_tests() |
---|
123 | #cleanup() |
---|
124 | |
---|
125 | |
---|
126 | def get_modules(): |
---|
127 | def getname(file): |
---|
128 | return os.path.splitext(os.path.basename(file))[0] |
---|
129 | return [getname(x) for x in glob.glob('*.pyste')] |
---|
130 | |
---|
131 | if __name__ == '__main__': |
---|
132 | if len(sys.argv) > 1: |
---|
133 | module = sys.argv[1] |
---|
134 | else: |
---|
135 | module = None |
---|
136 | try: |
---|
137 | # main('--multiple', module) |
---|
138 | main('', module) |
---|
139 | except RuntimeError, e: |
---|
140 | print e |
---|