~ubuntu-branches/ubuntu/gutsy/pygame/gutsy

« back to all changes in this revision

Viewing changes to config_darwin.py

  • Committer: Bazaar Package Importer
  • Author(s): Ed Boraas
  • Date: 2002-02-20 06:39:24 UTC
  • Revision ID: james.westby@ubuntu.com-20020220063924-amlzj7tqkeods4eq
Tags: upstream-1.4
ImportĀ upstreamĀ versionĀ 1.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
"""Config on Darwin w/ frameworks"""
 
2
 
 
3
import os, sys, shutil, string
 
4
from glob import glob
 
5
 
 
6
configcommand = os.environ.get('SDL_CONFIG', 'sdl-config')
 
7
configcommand = configcommand + ' --version --cflags --libs'
 
8
 
 
9
class Dependency:
 
10
    libext = '.dylib'
 
11
    def __init__(self, name, checkhead, checklib, lib):
 
12
        self.name = name
 
13
        self.inc_dir = None
 
14
        self.lib_dir = None
 
15
        self.lib = lib
 
16
        self.found = 0
 
17
        self.checklib = checklib+self.libext
 
18
        self.checkhead = checkhead
 
19
        self.cflags = ''
 
20
    
 
21
    def configure(self, incdirs, libdirs):
 
22
        incname = self.checkhead
 
23
        libnames = self.checklib, string.lower(self.name)
 
24
        for dir in incdirs:
 
25
            path = os.path.join(dir, incname)
 
26
            if os.path.isfile(path):
 
27
                self.inc_dir = dir
 
28
                break
 
29
        for dir in libdirs:
 
30
            for name in libnames:
 
31
                path = os.path.join(dir, name)
 
32
                if os.path.isfile(path):
 
33
                    self.lib_dir = dir
 
34
                    break 
 
35
        if self.lib_dir and self.inc_dir:
 
36
            print self.name + '        '[len(self.name):] + ': found'
 
37
            self.found = 1
 
38
        else:
 
39
            print self.name + '        '[len(self.name):] + ': not found'
 
40
 
 
41
class FrameworkDependency(Dependency):
 
42
    def configure(self, incdirs, libdirs):
 
43
      for n in '/Library/Frameworks/','~/Library/Frameworks/','/System/Library/Frameworks/':
 
44
        if os.path.isfile(n+self.lib+'.framework/Versions/Current/'+self.lib):
 
45
          print 'Framework '+self.lib+' found'
 
46
          self.found = 1
 
47
          self.inc_dir = n+self.lib+'.framework/Versions/Current/Headers'
 
48
          self.cflags = '-Ddarwin -Xlinker "-F'+n+self.lib+'.framework" -Xlinker "-framework" -Xlinker "'+self.lib+'"'
 
49
          self.origlib = self.lib
 
50
          self.lib = ''
 
51
          return
 
52
      print 'Framework '+self.lib+' not found'
 
53
 
 
54
sdl_lib_name = 'SDL'
 
55
if sys.platform.find('bsd') != -1:
 
56
    sdl_lib_name = 'SDL-1.2'
 
57
 
 
58
DEPS = [
 
59
    FrameworkDependency('SDL', 'SDL.h', 'lib'+sdl_lib_name, 'SDL'),
 
60
    FrameworkDependency('FONT', 'SDL_ttf.h', 'libSDL_ttf', 'SDL_ttf'),
 
61
    FrameworkDependency('IMAGE', 'SDL_image.h', 'libSDL_image', 'SDL_image'),
 
62
    FrameworkDependency('MIXER', 'SDL_mixer.h', 'libSDL_mixer', 'SDL_mixer'),
 
63
    Dependency('SMPEG', 'smpeg.h', 'libsmpeg', 'smpeg'),
 
64
]
 
65
 
 
66
 
 
67
from distutils.util import split_quoted
 
68
def main():
 
69
    global DEPS
 
70
    
 
71
    print 'calling "sdl-config"'
 
72
    configinfo = "-I/usr/local/include/SDL -L/usr/local/lib -D_REENTRANT -lSDL"
 
73
    try:
 
74
        configinfo = os.popen(configcommand).readlines()
 
75
        print 'Found SDL version:', configinfo[0]
 
76
        configinfo = ' '.join(configinfo[1:])
 
77
        configinfo = configinfo.split()
 
78
        for w in configinfo[:]:
 
79
            if ',' in w: configinfo.remove(w)
 
80
        configinfo = ' '.join(configinfo)
 
81
        #print 'Flags:', configinfo
 
82
    except:
 
83
        raise SystemExit, """Cannot locate command, "sdl-config". Default SDL compile
 
84
flags have been used, which will likely require a little editing."""
 
85
 
 
86
    print 'Hunting dependencies...'
 
87
    incdirs = ['/usr/local/include/smpeg']
 
88
    libdirs = []
 
89
    extralib = []
 
90
    newconfig = []
 
91
    eat_next = None
 
92
    for arg in split_quoted(configinfo):
 
93
      if eat_next:
 
94
        eat_next.append(arg)  
 
95
        eat_next=None
 
96
        continue
 
97
      if arg[:2] == '-I':
 
98
        incdirs.append(arg[2:])
 
99
        newconfig.append(arg)
 
100
      elif arg[:2] == '-L':
 
101
        libdirs.append(arg[2:])
 
102
        newconfig.append(arg)
 
103
      elif arg[:2] == '-F':
 
104
        extralib.append(arg)
 
105
      elif arg == '-framework':
 
106
        extralib.append(arg)
 
107
        eat_next = extralib
 
108
    for d in DEPS:
 
109
      d.configure(incdirs, libdirs)
 
110
 
 
111
    newconfig.extend(map(lambda x:'-Xlinker "%s"'%x,extralib))
 
112
    if sys.platform.find('darwin') != -1:
 
113
      newconfig.append('-Ddarwin')
 
114
    configinfo = ' '.join(newconfig)
 
115
    DEPS[0].inc_dirs = []
 
116
    DEPS[0].lib_dirs = []
 
117
    DEPS[0].cflags = configinfo
 
118
    return DEPS
 
119
 
 
120
    
 
121
if __name__ == '__main__':
 
122
    print """This is the configuration subscript for Unix.
 
123
             Please run "config.py" for full configuration."""