forked from pvcraven/pygame
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config_darwin.py
158 lines (138 loc) · 5.57 KB
/
config_darwin.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
"""Config on Darwin w/ frameworks"""
import os, sys, string
from glob import glob
from distutils.sysconfig import get_python_inc
from config_unix import DependencyProg
try:
basestring_ = basestring
except NameError:
#python 3.
basestring_ = str
class Dependency:
libext = '.dylib'
def __init__(self, name, checkhead, checklib, libs):
self.name = name
self.inc_dir = None
self.lib_dir = None
self.libs = libs
self.found = 0
self.checklib = checklib + self.libext
self.checkhead = checkhead
self.cflags = ''
def configure(self, incdirs, libdirs):
incnames = self.checkhead
libnames = self.checklib, self.name.lower()
for dir in incdirs:
if isinstance(incnames, basestring_):
incnames = [incnames]
for incname in incnames:
path = os.path.join(dir, incname)
if os.path.isfile(path):
self.inc_dir = os.path.dirname(path)
break
for dir in libdirs:
for name in libnames:
path = os.path.join(dir, name)
if os.path.isfile(path):
self.lib_dir = dir
break
if self.lib_dir and self.inc_dir:
print (self.name + ' '[len(self.name):] + ': found')
self.found = 1
else:
print (self.name + ' '[len(self.name):] + ': not found')
class FrameworkDependency(Dependency):
def configure(self, incdirs, libdirs):
BASE_DIRS = '/', os.path.expanduser('~/'), '/System/'
for n in BASE_DIRS:
n += 'Library/Frameworks/'
fmwk = n + self.libs + '.framework/Versions/Current/'
if os.path.isfile(fmwk + self.libs):
print ('Framework ' + self.libs + ' found')
self.found = 1
self.inc_dir = fmwk + 'Headers'
self.cflags = (
'-Xlinker "-framework" -Xlinker "' + self.libs + '"' +
' -Xlinker "-F' + n + '"')
self.origlib = self.libs
self.libs = ''
return
print ('Framework ' + self.libs + ' not found')
class DependencyPython:
def __init__(self, name, module, header):
self.name = name
self.lib_dir = ''
self.inc_dir = ''
self.libs = []
self.cflags = ''
self.found = 0
self.ver = '0'
self.module = module
self.header = header
def configure(self, incdirs, libdirs):
self.found = 1
if self.module:
try:
self.ver = __import__(self.module).__version__
except ImportError:
self.found = 0
if self.found and self.header:
fullpath = os.path.join(get_python_inc(0), self.header)
if not os.path.isfile(fullpath):
self.found = 0
else:
self.inc_dir = os.path.split(fullpath)[0]
if self.found:
print (self.name + ' '[len(self.name):] + ': found', self.ver)
else:
print (self.name + ' '[len(self.name):] + ': not found')
DEPS = [
[DependencyProg('SDL', 'SDL_CONFIG', 'sdl-config', '1.2', ['sdl']),
FrameworkDependency('SDL', 'SDL.h', 'libSDL', 'SDL')],
[Dependency('FONT', ['SDL_ttf.h', 'SDL/SDL_ttf.h'], 'libSDL_ttf', ['SDL_ttf']),
FrameworkDependency('FONT', 'SDL_ttf.h', 'libSDL_ttf', 'SDL_ttf')],
[Dependency('IMAGE', ['SDL_image.h', 'SDL/SDL_image.h'], 'libSDL_image', ['SDL_image']),
FrameworkDependency('IMAGE', 'SDL_image.h', 'libSDL_image', 'SDL_image')],
[Dependency('MIXER', ['SDL_mixer.h', 'SDL/SDL_mixer.h'], 'libSDL_mixer', ['SDL_mixer']),
FrameworkDependency('MIXER', 'SDL_mixer.h', 'libSDL_mixer', 'SDL_mixer')],
FrameworkDependency('PORTTIME', 'CoreMidi.h', 'CoreMidi', 'CoreMIDI'),
FrameworkDependency('QUICKTIME', 'QuickTime.h', 'QuickTime', 'QuickTime'),
Dependency('PNG', 'png.h', 'libpng', ['png']),
Dependency('JPEG', 'jpeglib.h', 'libjpeg', ['jpeg']),
Dependency('PORTMIDI', 'portmidi.h', 'libportmidi', ['portmidi']),
#DependencyProg('FREETYPE', 'FREETYPE_CONFIG', '/usr/X11R6/bin/freetype-config', '2.0',
DependencyProg('FREETYPE', 'FREETYPE_CONFIG', 'freetype-config', '2.0',
['freetype'], '--ftversion'),
# Scrap is included in sdlmain_osx, there is nothing to look at.
# Dependency('SCRAP', '','',[]),
]
def main():
global DEPS
print ('Hunting dependencies...')
incdirs = ['/usr/local/include', '/usr/local/include/SDL',
#'/usr/X11/include',
'/opt/local/include',
'/opt/local/include/freetype2/freetype']
#libdirs = ['/usr/local/lib', '/usr/X11/lib', '/opt/local/lib']
libdirs = ['/usr/local/lib', '/opt/local/lib']
for d in DEPS:
if isinstance(d, (list, tuple)):
for deptype in d:
deptype.configure(incdirs, libdirs)
else:
d.configure(incdirs, libdirs)
for d in DEPS:
if type(d)==list:
found = False
for deptype in d:
if deptype.found:
found = True
DEPS[DEPS.index(d)] = deptype
break
if not found:
DEPS[DEPS.index(d)] = d[0]
DEPS[0].cflags = '-Ddarwin '+ DEPS[0].cflags
return DEPS
if __name__ == '__main__':
print ("""This is the configuration subscript for OSX Darwin.
Please run "config.py" for full configuration.""")