root/04/tools/build.py

Revision 31, 4.3 kB (checked in by ug, 5 years ago)

Fix sgfparserC support

Line 
1#!/usr/bin/python
2
3import os
4import sys
5from string import find, join
6
7base = '/home/ug/kombilo/'
8version = '04'
9htmldir = '/home/ug/html/kombilo/'
10sourcedir = base + version + '/' + sys.argv[1] + '/'
11
12def general(target):
13    targetdir = base + target + '/kombilo' + version
14
15    os.system('rm -r %s-old' % targetdir)
16    os.system('mv %s %s-old' % (targetdir, targetdir))
17
18    os.system('mkdir %s' % targetdir)
19   
20    for file in ['kombilo.py', 'v.py', 'board1.py', 'sgfparser.py',
21                 'kombilo.app', 'v.app', 'matchC.cc', 'sgfparserC.cc',
22                 'menus.def', 'setup-ext.py']:
23        os.system('cp %s%s %s' % (sourcedir, file, targetdir))
24
25    os.system('mkdir %s/doc' % targetdir)
26    for file in ['tutorial.html', 'kombilo.doc', 'readme.txt',
27                 'license.txt', 'install.txt', 'onepixel.gif', '*.jpg']:
28        os.system('cp %sdoc/%s %s/doc' % (sourcedir, file, targetdir))
29
30    os.system('mkdir %s/gifs' % targetdir)
31    for file in ['*.gif']:
32        os.system('cp %sgifs/%s %s/gifs' % (sourcedir, file, targetdir))
33
34   
35def linux():
36    targetdir = base + 'lin/kombilo' + version
37
38    for file in ['unixinst.py']:
39        os.system('cp %s%s %s' % (sourcedir, file, targetdir))
40
41    # first line of kombilo.py, v.py should be #!/usr/bin/python
42
43    for filename in ['kombilo.py', 'v.py']:
44        file = open('%s/%s' % (targetdir, filename))
45        lines = file.readlines()
46        file.close()
47
48        lines[0] = '#!/usr/bin/python\n'
49        file = open('%s/%s' % (targetdir, filename), 'w')
50        for l in lines: file.write(l)
51        file.close()
52
53    # tar, gz everything
54
55    os.chdir(base + 'lin')
56   
57    os.system('tar cf kombilo%s.tar kombilo%s' % (version, version))
58    os.system('gzip -f kombilo%s.tar' % version)
59
60    os.system('cp kombilo%s.tar.gz %s' % (version, htmldir))
61
62    # compile C++ extension
63
64    for python_version in ['2.1', '2.2', '2.3']:
65        os.chdir(targetdir)
66        filelist = ['matchC.so', 'sgfparserC.so']
67
68        for file in filelist:
69            os.system('python%s setup-ext.py build' % (python_version))
70
71        os.system('tar cf Cext%s-%s.tar -C build/lib.linux-i686-%s %s' % (version, python_version, python_version, join([f for f in filelist], ' ')))
72        os.system('gzip -f Cext%s-%s.tar' % (version,python_version))
73        os.system('cp Cext%s-%s.tar.gz %s' % (version,python_version[-3:], htmldir))
74
75def windows():
76    targetdir = base + 'win/kombilo' + version
77
78    # adapt matchC.cc
79
80    for filename in ['matchC.cc', 'sgfparserC.cc']:
81
82        file = open('%s/%s' % (targetdir, filename))
83        lines = file.readlines()
84        file.close()
85
86        file = open('%s/%s' % (targetdir, filename), 'w')
87        for line in lines:
88            file.write(line)
89            if find(line, 'extern') != -1:
90                file.write('  __declspec(dllexport)\n')
91        file.close()
92
93    # unix2dos text files
94
95    os.chdir(targetdir)
96    for filename in ['*.py', '*.cc', '*.app',
97                     'doc/*.txt', 'doc/kombilo.doc', 'doc/tutorial.html']:
98        os.system('unix2dos %s' % filename)
99
100    os.system('mv kombilo.py kombilo.pyw')
101
102    # zip everything
103
104    os.chdir(base + 'win')
105    os.system('rm kombilo%swin.zip' % version)
106    os.system('zip -r -q kombilo%swin kombilo%s' % (version, version))
107
108    os.system('cp kombilo%swin.zip %s' % (version, htmldir))
109   
110
111def others():
112    targetdir = base + 'oth/kombilo' + version
113
114    # unix2dos text files
115
116    os.chdir(targetdir)
117    for filename in ['*.py', 'matchC.*', 'doc/*.txt',
118                     'doc/kombilo.doc', 'doc/tutorial.html']:
119        os.system('unix2dos %s' % filename)
120
121    # zip everything
122
123    os.chdir(base + 'oth')
124    os.system('rm kombilo%s.zip' % version)
125    os.system('zip -r -q kombilo%s kombilo%s' % (version, version))
126
127    os.system('cp kombilo%s.zip %s' % (version, htmldir))
128   
129
130for target in sys.argv[2:]:
131    if target == 'lin':
132        general('lin')
133        linux()
134        print 'built linux'
135    elif target == 'win':
136        general('win')
137        windows()
138        print 'built windows'
139    elif target == 'oth':
140        general('oth')
141        others()
142        print 'built others'
143    elif target == 'html':
144        os.system('cp %s/doc/tutorial.html %s' % (sourcedir, version, htmldir))
145        os.system('cp %s/doc/*.jpg %s' % (sourcedir, version, htmldir))
146        print 'copied tutorial to html'
Note: See TracBrowser for help on using the browser.