Skip to content

Instantly share code, notes, and snippets.

@ben-willmore
Created August 16, 2011 22:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ben-willmore/1150335 to your computer and use it in GitHub Desktop.
Save ben-willmore/1150335 to your computer and use it in GitHub Desktop.
Allow pygame 1.9.1release to build against either frameworks or regular libs on OS X
diff -u -ruN pygame-1.9.1release/config_darwin.py pygame-1.9.1release-fixed/config_darwin.py
--- pygame-1.9.1release/config_darwin.py 2009-07-09 07:13:20.000000000 +0100
+++ pygame-1.9.1release-fixed/config_darwin.py 2011-08-16 22:22:46.000000000 +0100
@@ -1,60 +1,107 @@
-"""Config on Darwin w/ frameworks"""
+"""Config on Darwin without frameworks"""
-import os, sys, string
+import os, sys
from glob import glob
from distutils.sysconfig import get_python_inc
+# Python 2.x/3.x compatibility
+try:
+ raw_input
+except NameError:
+ raw_input = input
+
+configcommand = os.environ.get('SDL_CONFIG', 'sdl-config',)
+configcommand = configcommand + ' --version --cflags --libs'
+localbase = os.environ.get('LOCALBASE', '')
+
+#these get prefixes with '/usr' and '/usr/local' or the $LOCALBASE
+origincdirs = ['/include', '/include/SDL', '/include/SDL',
+ '/include/smpeg' ]
+origlibdirs = ['/lib','/lib64','/X11R6/lib']
+
+def confirm(message):
+ "ask a yes/no question, return result"
+ reply = raw_input('\n' + message + ' [Y/n]:')
+ if reply and (reply[0].lower()) == 'n':
+ return 0
+ return 1
+
+class DependencyProg:
+ def __init__(self, name, envname, exename, minver, defaultlibs):
+ self.name = name
+ command = os.environ.get(envname, exename)
+ self.lib_dir = ''
+ self.inc_dir = ''
+ self.libs = []
+ self.cflags = ''
+ try:
+ config = os.popen(command + ' --version --cflags --libs').readlines()
+ flags = ' '.join(config[1:]).split()
+
+ # remove this GNU_SOURCE if there... since python has it already,
+ # it causes a warning.
+ if '-D_GNU_SOURCE=1' in flags:
+ flags.remove('-D_GNU_SOURCE=1')
+ self.ver = config[0].strip()
+ if minver and self.ver < minver:
+ err= 'WARNING: requires %s version %s (%s found)' % (self.name, self.ver, minver)
+ raise ValueError(err)
+ self.found = 1
+ self.cflags = ''
+ for f in flags:
+ if f[:2] in ('-l', '-D', '-I', '-L'):
+ self.cflags += f + ' '
+ elif f[:3] == '-Wl':
+ self.cflags += '-Xlinker ' + f + ' '
+ if self.name == 'SDL':
+ inc = '-I' + '/usr/X11R6/include'
+ self.cflags = inc + ' ' + self.cflags
+ except:
+ print ('WARNING: "%s" failed!' % command)
+ self.found = 0
+ self.ver = '0'
+ self.libs = defaultlibs
+
+ def configure(self, incdirs, libdir):
+ if self.found:
+ print (self.name + ' '[len(self.name):] + ': found ' + self.ver)
+ self.found = 1
+ else:
+ print (self.name + ' '[len(self.name):] + ': not found')
+
class Dependency:
- libext = '.a'
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.checklib = checklib
self.checkhead = checkhead
self.cflags = ''
-
+
def configure(self, incdirs, libdirs):
incname = self.checkhead
libnames = self.checklib, self.name.lower()
- for dir in incdirs:
- path = os.path.join(dir, incname)
- if os.path.isfile(path):
- self.inc_dir = dir
- break
+
+ if incname:
+ for dir in incdirs:
+ path = os.path.join(dir, incname)
+ if os.path.isfile(path):
+ self.inc_dir = dir
+
for dir in libdirs:
for name in libnames:
path = os.path.join(dir, name)
- if os.path.isfile(path):
+ if filter(os.path.isfile, glob(path+'*')):
self.lib_dir = dir
- break
- if self.lib_dir and self.inc_dir:
+
+ if (incname and self.lib_dir and self.inc_dir) or (not incname and self.lib_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
@@ -66,7 +113,7 @@
self.ver = '0'
self.module = module
self.header = header
-
+
def configure(self, incdirs, libdirs):
self.found = 1
if self.module:
@@ -77,7 +124,7 @@
if self.found and self.header:
fullpath = os.path.join(get_python_inc(0), self.header)
if not os.path.isfile(fullpath):
- found = 0
+ self.found = 0
else:
self.inc_dir = os.path.split(fullpath)[0]
if self.found:
@@ -85,33 +132,104 @@
else:
print (self.name + ' '[len(self.name):] + ': not found')
-DEPS = [
- FrameworkDependency('SDL', 'SDL.h', 'libSDL', 'SDL'),
- FrameworkDependency('FONT', 'SDL_ttf.h', 'libSDL_ttf', 'SDL_ttf'),
- FrameworkDependency('IMAGE', 'SDL_image.h', 'libSDL_image', 'SDL_image'),
- FrameworkDependency('MIXER', 'SDL_mixer.h', 'libSDL_mixer', 'SDL_mixer'),
- FrameworkDependency('SMPEG', 'smpeg.h', 'libsmpeg', 'smpeg'),
- Dependency('PNG', 'png.h', 'libpng', ['png']),
- Dependency('JPEG', 'jpeglib.h', 'libjpeg', ['jpeg']),
- Dependency('SCRAP', '','',[]),
- Dependency('PORTMIDI', 'portmidi.h', 'libportmidi', ['portmidi']),
- FrameworkDependency('PORTTIME', 'CoreMidi.h', 'CoreMidi', 'CoreMidi'),
-]
+sdl_lib_name = 'SDL'
-def main():
- global DEPS
+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')
+
- print ('Hunting dependencies...')
- incdirs = ['/usr/local/include','/opt/local/include']
- libdirs = ['/usr/local/lib','/opt/local/lib']
- newconfig = []
+def main():
+ print ('\nHunting dependencies...')
+ DEPS = [
+ [DependencyProg('SDL', 'SDL_CONFIG', 'sdl-config', '1.2', ['sdl']),
+ FrameworkDependency('SDL', 'SDL.h', 'libSDL', 'SDL')],
+ [Dependency('FONT', 'SDL_ttf.h', 'libSDL_ttf', ['SDL_ttf']),
+ FrameworkDependency('FONT', 'SDL_ttf.h', 'libSDL_ttf', 'SDL_ttf')],
+ [Dependency('IMAGE', 'SDL_image.h', 'libSDL_image', ['SDL_image']),
+ FrameworkDependency('IMAGE', 'SDL_image.h', 'libSDL_image', 'SDL_image')],
+ [Dependency('MIXER', 'SDL_mixer.h', 'libSDL_mixer', ['SDL_mixer']),
+ FrameworkDependency('MIXER', 'SDL_mixer.h', 'libSDL_mixer', 'SDL_mixer')],
+ [DependencyProg('SMPEG', 'SMPEG_CONFIG', 'smpeg-config', '0.4.3', ['smpeg']),
+ FrameworkDependency('SMPEG', 'smpeg.h', 'libsmpeg', 'smpeg')],
+ Dependency('PNG', 'png.h', 'libpng', ['png']),
+ Dependency('JPEG', 'jpeglib.h', 'libjpeg', ['jpeg']),
+ Dependency('SCRAP', '', 'libX11', ['X11']),
+ Dependency('PORTMIDI', 'portmidi.h', 'libportmidi.dylib', ['portmidi']),
+ FrameworkDependency('PORTTIME', 'CoreMidi.h', 'CoreMidi', 'CoreMidi'),
+ #Dependency('GFX', 'SDL_gfxPrimitives.h', 'libSDL_gfx.so', ['SDL_gfx']),
+ ]
+
+ foundDeps = []
+ for d in DEPS:
+ if type(d)==list:
+ success = False
+ for deptype in d:
+ if deptype.found:
+ foundDeps.append(deptype)
+ success = True
+ break
+ if not success:
+ foundDeps.append(d[0])
+ else:
+ foundDeps.append(d)
+
+ DEPS = foundDeps
+
+ if not DEPS[0].found:
+ print ('Unable to run "sdl-config". Please make sure a development version of SDL is installed.')
+ raise SystemExit
+
+ if localbase:
+ incdirs = [localbase+d for d in origincdirs]
+ libdirs = [localbase+d for d in origlibdirs]
+ else:
+ incdirs = []
+ libdirs = []
+ incdirs += ["/usr"+d for d in origincdirs]
+ libdirs += ["/usr"+d for d in origlibdirs]
+ incdirs += ["/usr/local"+d for d in origincdirs]
+ libdirs += ["/usr/local"+d for d in origlibdirs]
+ incdirs += ["/sw"+d for d in origincdirs]
+ libdirs += ["/sw"+d for d in origlibdirs]
+ incdirs += ["/opt/local"+d for d in origincdirs]
+ libdirs += ["/opt/local"+d for d in origlibdirs]
+
+ for arg in DEPS[0].cflags.split():
+ if arg[:2] == '-I':
+ incdirs.append(arg[2:])
+ elif arg[:2] == '-L':
+ libdirs.append(arg[2:])
for d in DEPS:
d.configure(incdirs, libdirs)
+
+ for d in DEPS[1:]:
+ if not d.found:
+ if not confirm("""
+Warning, some of the pygame dependencies were not found. Pygame can still
+compile and install, but games that depend on those missing dependencies
+will not run. Would you like to continue the configuration?"""):
+ raise SystemExit
+ break
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.""")
+ print ("""This is the configuration subscript for Unix.
+Please run "config.py" for full configuration.""")
+
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment