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

« back to all changes in this revision

Viewing changes to config_unix.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 Unix"""
 
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
localbase = os.environ.get('LOCALBASE', '')
 
9
 
 
10
 
 
11
class Dependency:
 
12
    def __init__(self, name, checkhead, checklib, lib):
 
13
        self.name = name
 
14
        self.inc_dir = None
 
15
        self.lib_dir = None
 
16
        self.lib = lib
 
17
        self.found = 0
 
18
        self.checklib = checklib
 
19
        self.checkhead = checkhead
 
20
        self.cflags = ''
 
21
    
 
22
    def configure(self, incdirs, libdirs):
 
23
        incname = self.checkhead
 
24
        libnames = self.checklib, string.lower(self.name)
 
25
        
 
26
        for dir in incdirs:
 
27
            path = os.path.join(dir, incname)
 
28
            if os.path.isfile(path):
 
29
                self.inc_dir = dir
 
30
        for dir in libdirs:
 
31
            for name in libnames:
 
32
                path = os.path.join(dir, name)
 
33
                if os.path.isfile(path):
 
34
                    self.lib_dir = dir
 
35
                
 
36
        if self.lib_dir and self.inc_dir:
 
37
            print self.name + '        '[len(self.name):] + ': found'
 
38
            self.found = 1
 
39
        else:
 
40
            print self.name + '        '[len(self.name):] + ': not found'
 
41
 
 
42
 
 
43
 
 
44
sdl_lib_name = 'SDL'
 
45
if sys.platform.find('bsd') != -1:
 
46
    sdl_lib_name = 'SDL-1.2'
 
47
 
 
48
DEPS = [
 
49
    Dependency('SDL', 'SDL.h', 'lib'+sdl_lib_name+'.so', sdl_lib_name),
 
50
    Dependency('FONT', 'SDL_ttf.h', 'libSDL_ttf.so', 'SDL_ttf'),
 
51
    Dependency('IMAGE', 'SDL_image.h', 'libSDL_image.so', 'SDL_image'),
 
52
    Dependency('MIXER', 'SDL_mixer.h', 'libSDL_mixer.so', 'SDL_mixer'),
 
53
    Dependency('SMPEG', 'smpeg.h', 'libsmpeg.so', 'smpeg'),
 
54
]
 
55
 
 
56
 
 
57
def main():
 
58
    global DEPS
 
59
    
 
60
    print 'calling "sdl-config"'
 
61
    configinfo = "-I/usr/local/include/SDL -L/usr/local/lib -D_REENTRANT -lSDL"
 
62
    try:
 
63
        configinfo = os.popen(configcommand).readlines()
 
64
        print 'Found SDL version:', configinfo[0]
 
65
        configinfo = ' '.join(configinfo[1:])
 
66
        configinfo = configinfo.split()
 
67
        for w in configinfo[:]:
 
68
            if ',' in w: configinfo.remove(w)
 
69
        configinfo = ' '.join(configinfo)
 
70
        #print 'Flags:', configinfo
 
71
    except:
 
72
        raise SystemExit, """Cannot locate command, "sdl-config". Default SDL compile
 
73
flags have been used, which will likely require a little editing."""
 
74
 
 
75
    print 'Hunting dependencies...'
 
76
    if localbase:
 
77
        incdirs = [localbase + '/include/SDL']
 
78
        libdirs = [localbase + '/lib']
 
79
    else:
 
80
        incdirs = []
 
81
        libdirs = []
 
82
        for arg in configinfo.split():
 
83
            if arg[:2] == '-I':
 
84
                incdirs.append(arg[2:])
 
85
            elif arg[:2] == '-L':
 
86
                libdirs.append(arg[2:])
 
87
    for d in DEPS:
 
88
        d.configure(incdirs, libdirs)
 
89
 
 
90
    DEPS[0].inc_dirs = []
 
91
    DEPS[0].lib_dirs = []
 
92
    DEPS[0].cflags = configinfo
 
93
 
 
94
    return DEPS
 
95
 
 
96
    
 
97
if __name__ == '__main__':
 
98
    print """This is the configuration subscript for Unix.
 
99
Please run "config.py" for full configuration."""
 
100