~ubuntu-branches/ubuntu/natty/pygame/natty

« back to all changes in this revision

Viewing changes to config_win.py

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2010-01-14 17:02:11 UTC
  • mfrom: (1.3.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20100114170211-21eop2ja7mr9vdcr
Tags: 1.9.1release-0ubuntu1
* New upstream version (lp: #433304)
* debian/control:
  - build-depends on libportmidi-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
"""Config on Windows"""
2
2
 
3
 
import dll
 
3
# **** The search part is broken. For instance, the png Visual Studio project
 
4
# places to dll in a directory not checked by this module.
 
5
 
 
6
from setup_win_common import get_definitions
 
7
 
4
8
import os, sys
 
9
import re
5
10
from glob import glob
6
11
from distutils.sysconfig import get_python_inc
7
12
 
 
13
try:
 
14
    raw_input
 
15
except NameError:
 
16
    raw_input = input
 
17
 
8
18
huntpaths = ['..', '..\\..', '..\\*', '..\\..\\*']
9
19
 
10
20
 
13
23
    lib_hunt = ['VisualC\\SDL\\Release', 'VisualC\\Release', 'Release', 'lib']
14
24
    def __init__(self, name, wildcards, libs=None, required = 0):
15
25
        if libs is None:
16
 
            libs = [dll.name_to_root(name)]
 
26
            libs = []
17
27
        self.name = name
18
28
        self.wildcards = wildcards
19
29
        self.required = required
22
32
        self.inc_dir = None
23
33
        self.lib_dir = None
24
34
        self.libs = libs
25
 
        self.found = 0
 
35
        self.found = False
26
36
        self.cflags = ''
27
37
                 
28
38
    def hunt(self):
40
50
 
41
51
    def choosepath(self):
42
52
        if not self.paths:
43
 
            print 'Path for ', self.name, 'not found.'
44
 
            if self.required: print 'Too bad that is a requirement! Hand-fix the "Setup"'
 
53
            print ("Path for %s not found." % self.name)
 
54
            if self.required:
 
55
                print ('Too bad that is a requirement! Hand-fix the "Setup"')
45
56
        elif len(self.paths) == 1:
46
57
            self.path = self.paths[0]
47
 
            print 'Path for '+self.name+':', self.path
 
58
            print ("Path for %s:' % self.name")
48
59
        else:
49
 
            print 'Select path for '+self.name+':'
 
60
            print ("Select path for %s:" % self.name)
50
61
            for i in range(len(self.paths)):
51
 
                print '  ', i+1, '=', self.paths[i]
52
 
            print '  ', 0, '= <Nothing>'
53
 
            choice = raw_input('Select 0-'+`len(self.paths)`+' (1=default):')
 
62
                print ("  %i=%s" % (i + 1, self.paths[i]))
 
63
            print ("  %i = <Nothing>" % 0)
 
64
            choice = raw_input("Select 0-%i (1=default):" % len(self.paths))
54
65
            if not choice: choice = 1
55
66
            else: choice = int(choice)
56
67
            if(choice):
67
78
        self.hunt()
68
79
        self.choosepath()
69
80
        if self.path:
70
 
            self.found = 1
 
81
            self.found = True
71
82
            self.inc_dir = self.findhunt(self.path, Dependency.inc_hunt)
72
83
            self.lib_dir = self.findhunt(self.path, Dependency.lib_hunt)
73
84
 
79
90
        self.inc_dir = ''
80
91
        self.libs = []
81
92
        self.cflags = ''
82
 
        self.found = 0
 
93
        self.found = False
83
94
        self.ver = '0'
84
95
        self.module = module
85
96
        self.header = header
86
97
 
87
98
    def configure(self):
88
 
        self.found = 1
 
99
        self.found = True
89
100
        if self.module:
90
101
            try:
91
102
                self.ver = __import__(self.module).__version__
92
103
            except ImportError:
93
 
                self.found = 0
 
104
                self.found = False
94
105
        if self.found and self.header:
95
106
            fullpath = os.path.join(get_python_inc(0), self.header)
96
107
            if not os.path.isfile(fullpath):
98
109
            else:
99
110
                self.inc_dir = os.path.split(fullpath)[0]
100
111
        if self.found:
101
 
            print self.name + '        '[len(self.name):] + ': found', self.ver
 
112
            print ("%-8.8s: found %s" % (self.name, self.ver))
102
113
        else:
103
 
            print self.name + '        '[len(self.name):] + ': not found'
 
114
            print ("%-8.8s: not found" % self.name)
104
115
 
105
116
 
106
117
class DependencyDLL(Dependency):
107
 
    def __init__(self, name=None, wildcards=None, link=None, libs=None):
108
 
        if libs is None:
109
 
            if name is not None:
110
 
                libs = [dll.name_to_root(name)]
111
 
            elif link is not None:
112
 
                libs = link.libs
113
 
            else:
114
 
                libs = []
115
 
        if name is None:
116
 
            name = link.name
117
 
        Dependency.__init__(self, 'COPYLIB_' + name, wildcards, libs)
118
 
        self.lib_name = name
119
 
        self.test = dll.tester(name)
 
118
    def __init__(self, dll_regex, lib=None, wildcards=None, libs=None, link=None):
 
119
        if lib is None:
 
120
            lib = link.libs[0]
 
121
        Dependency.__init__(self, 'COPYLIB_' + lib, wildcards, libs)
 
122
        self.lib_name = lib
 
123
        self.test = re.compile(dll_regex, re.I).match
120
124
        self.lib_dir = '_'
121
 
        self.found = 1
 
125
        self.found = True
122
126
        self.link = link
123
127
 
124
128
    def configure(self):
142
146
                    if self.test(e) and os.path.isfile(os.path.join(path, e)):
143
147
                        # Found
144
148
                        self.lib_dir = os.path.join(path, e).replace('\\', '/')
145
 
                        print "DLL for %s is %s" % (self.lib_name, self.lib_dir)
 
149
                        print ("DLL for %s is %s" % (self.lib_name, self.lib_dir))
146
150
                        return
147
 
        print "DLL for %s not found" % self.lib_name
 
151
        print ("DLL for %s not found" % self.lib_name)
148
152
 
149
 
                    
150
153
class DependencyWin(object):
151
 
    def __init__(self, name, libs):
 
154
    def __init__(self, name, cflags):
152
155
        self.name = name
153
156
        self.inc_dir = None
154
157
        self.lib_dir = None
155
 
        self.libs = libs
156
 
        self.found = 1
157
 
        self.cflags = ''
 
158
        self.libs = []
 
159
        self.found = True
 
160
        self.cflags = cflags
158
161
        
159
162
    def configure(self):
160
163
        pass
161
164
 
162
 
 
163
 
DEPS = [
164
 
    Dependency('SDL', ['SDL-[1-9].*'], required=1),
165
 
    Dependency('FONT', ['SDL_ttf-[2-9].*']),
166
 
    Dependency('IMAGE', ['SDL_image-[1-9].*']),
167
 
    Dependency('MIXER', ['SDL_mixer-[1-9].*']),
168
 
    Dependency('SMPEG', ['smpeg-[0-9].*', 'smpeg']),
169
 
    DependencyWin('SCRAP', ['user32', 'gdi32']),
170
 
    Dependency('JPEG', ['jpeg-[6-9]*']),
171
 
    Dependency('PNG', ['libpng-[1-9].*']),
172
 
    DependencyDLL('TIFF', ['tiff-[3-9].*']),
173
 
    DependencyDLL('VORBIS', ['libvorbis-[1-9].*']),
174
 
    DependencyDLL('OGG', ['libogg-[1-9].*']),
175
 
    DependencyDLL('Z', ['zlib-[1-9].*']),
176
 
]
177
 
 
178
 
DEPS += [DependencyDLL(link=dep) for dep in DEPS[:] if type(dep) is Dependency]
179
 
DEPS += [DependencyDLL('VORBISFILE', link=DEPS[9])]
 
165
class DependencyGroup(object):
 
166
    def __init__(self):
 
167
        self.dependencies =[]
 
168
        self.dlls = []
 
169
 
 
170
    def add(self, name, lib, wildcards, dll_regex, libs=None, required=0):
 
171
        if libs is None:
 
172
            libs = []
 
173
        dep = Dependency(name, wildcards, [lib], required)
 
174
        self.dependencies.append(dep)
 
175
        self.dlls.append(DependencyDLL(dll_regex, link=dep, libs=libs))
 
176
 
 
177
    def add_win(self, name, cflags):
 
178
        self.dependencies.append(DependencyWin(name, cflags))
 
179
                                 
 
180
    def add_dll(self, dll_regex, lib=None, wildcards=None, libs=None, link_lib=None):
 
181
        link = None
 
182
        if link_lib is not None:
 
183
            name = 'COPYLIB_' + link_lib
 
184
            for d in self.dlls:
 
185
                if d.name == name:
 
186
                    link = d
 
187
                    break
 
188
            else:
 
189
                raise KeyError("Link lib %s not found" % link_lib)
 
190
        self.dlls.append(DependencyDLL(dll_regex, lib, wildcards, libs, link))
 
191
 
 
192
    def configure(self):
 
193
        for d in self:
 
194
            d.configure()
 
195
 
 
196
    def __iter__(self):
 
197
        for d in self.dependencies:
 
198
            yield d
 
199
        for d in self.dlls:
 
200
            yield d
 
201
 
 
202
DEPS = DependencyGroup()
 
203
DEPS.add('SDL', 'SDL', ['SDL-[1-9].*'], r'(lib){0,1}SDL\.dll$', required=1)
 
204
DEPS.add('FONT', 'SDL_ttf', ['SDL_ttf-[2-9].*'], r'(lib){0,1}SDL_ttf\.dll$', ['SDL', 'z'])
 
205
DEPS.add('IMAGE', 'SDL_image', ['SDL_image-[1-9].*'], r'(lib){0,1}SDL_image\.dll$',
 
206
         ['SDL', 'jpeg', 'png', 'tiff'], 0),
 
207
DEPS.add('MIXER', 'SDL_mixer', ['SDL_mixer-[1-9].*'], r'(lib){0,1}SDL_mixer\.dll$',
 
208
         ['SDL', 'vorbisfile', 'smpeg'])
 
209
DEPS.add('SMPEG', 'smpeg', ['smpeg-[0-9].*', 'smpeg'], r'smpeg\.dll$', ['SDL'])
 
210
DEPS.add('PNG', 'png', ['libpng-[1-9].*'], r'(png|libpng13)\.dll$', ['z'])
 
211
DEPS.add('JPEG', 'jpeg', ['jpeg-[6-9]*'], r'(lib){0,1}jpeg\.dll$')
 
212
DEPS.add('PORTMIDI', 'portmidi', ['portmidi'], r'portmidi\.dll$')
 
213
#DEPS.add('PORTTIME', 'porttime', ['porttime'], r'porttime\.dll$')
 
214
DEPS.add_dll(r'(lib){0,1}tiff\.dll$', 'tiff', ['tiff-[3-9].*'], ['jpeg', 'z'])
 
215
DEPS.add_dll(r'(z|zlib1)\.dll$', 'z', ['zlib-[1-9].*'])
 
216
DEPS.add_dll(r'(libvorbis-0|vorbis)\.dll$', 'vorbis', ['libvorbis-[1-9].*'],
 
217
             ['ogg'])
 
218
DEPS.add_dll(r'(libvorbisfile-3|vorbisfile)\.dll$', 'vorbisfile',
 
219
             link_lib='vorbis', libs=['vorbis'])
 
220
DEPS.add_dll(r'(libogg-0|ogg)\.dll$', 'ogg', ['libogg-[1-9].*'])
 
221
for d in get_definitions():
 
222
    DEPS.add_win(d.name, d.value)
 
223
 
180
224
 
181
225
def setup_prebuilt():
182
226
    setup = open('Setup', 'w')
183
 
    for line in open('Setup.in').readlines():
184
 
        if line[:3] == '#--': continue
185
 
        if line[:6] == 'SDL = ':
186
 
            line = 'SDL = -Iprebuilt/include -Iprebuilt/include/SDL -Lprebuilt/lib -lSDL\n'
187
 
        if line[:8] == 'SMPEG = ':
188
 
            line = 'SMPEG = -Iprebuilt/include/smpeg -lsmpeg\n'
189
 
        if line[:8] == 'SCRAP = ':
190
 
            line = 'SCRAP = -luser32 -lgdi32\n'
191
 
        setup.write(line)
 
227
    try:
 
228
        try:
 
229
            setup_win_in = open(os.path.join('prebuilt', 'Setup_Win.in'))
 
230
        except IOError:
 
231
            raise IOError("prebuilt missing required Setup_Win.in")
 
232
 
 
233
        # Copy Setup.in to Setup, replacing the BeginConfig/EndConfig
 
234
        # block with prebuilt\Setup_Win.in .
 
235
        setup_in = open('Setup.in')
 
236
        try:
 
237
            do_copy = True
 
238
            for line in setup_in:
 
239
                if line.startswith('#--StartConfig'):
 
240
                    do_copy = False
 
241
                    setup.write(setup_win_in.read())
 
242
                    try:
 
243
                        setup_win_common_in = open('Setup_Win_Common.in')
 
244
                    except:
 
245
                        pass
 
246
                    else:
 
247
                        try:
 
248
                            setup.write(setup_win_common_in.read())
 
249
                        finally:
 
250
                            setup_win_common_in.close()
 
251
                elif line.startswith('#--EndConfig'):
 
252
                    do_copy = True
 
253
                elif do_copy:
 
254
                    setup.write(line)
 
255
        finally:
 
256
            setup_in.close()
 
257
    finally:
 
258
        setup.close()
192
259
 
193
260
 
194
261
def main():
199
266
            raise SystemExit()
200
267
 
201
268
    global DEPS
202
 
    for d in DEPS:
203
 
        d.configure()
204
269
    
205
 
    return DEPS
 
270
    DEPS.configure()
 
271
    return list(DEPS)
206
272
 
207
273
if __name__ == '__main__':
208
 
    print """This is the configuration subscript for Windows.
209
 
Please run "config.py" for full configuration."""
 
274
    print ("""This is the configuration subscript for Windows.
 
275
Please run "config.py" for full configuration.""")
210
276