more fixes
[supertux.git] / SConstruct
1 #
2 # SConstruct build file. See http://www.scons.org for details.
3
4 # based on a script from chenlee@ustc.edu
5 def Glob(dirs, pattern = '*' ):
6     import os, fnmatch 
7     files = []
8     for dir in dirs:
9         for file in os.listdir( Dir(dir).srcnode().abspath ): 
10             if fnmatch.fnmatch(file, pattern) : 
11                 files.append( os.path.join( dir, file ) ) 
12     return files 
13
14 def CheckSDLConfig(context, minVersion):
15     context.Message('Checking for sdl-config >= %s... ' % minVersion)
16     from popen2 import Popen3
17     p = Popen3(['sdl-config', '--version'])
18     ret = p.wait()
19     out = p.fromchild.readlines()
20     if ret != 0:
21         context.Result(False)
22         return False
23     if len(out) != 1:
24         # unable to parse output!
25         context.Result(False)
26         return False
27     # TODO validate output and catch exceptions
28     version = map(int, out[0].strip().split('.'))
29     minVersion = map(int, minVersion.split('.'))
30     # TODO comparing versions that way only works for pure numeric version
31     # numbers and fails for custom extensions. I don't care about this at
32     # the moment as sdl-config never used such version numbers afaik.
33     ret = (version >= minVersion)
34     context.Result(ret)
35     return ret
36
37 opts = Options('custom.py')
38 opts.Add('CXX', 'The C++ compiler', 'g++')
39 opts.Add('CXXFLAGS', 'Additional C++ compiler flags', '')
40 opts.Add('CPPPATH', 'Additional preprocessor paths', '')
41 opts.Add('CPPFLAGS', 'Additional preprocessor flags', '')
42 opts.Add('LIBPATH', 'Additional library paths', '')
43 opts.Add('LIBS', 'Additional libraries', '')
44 opts.Add('DESTDIR', \
45         'destination directory for installation. It is prepended to PREFIX', '')
46 opts.Add('PREFIX', 'Installation prefix', '/usr/local')
47
48 env = Environment(options = opts)
49 conf = Configure(env, custom_tests = {
50     'CheckSDLConfig' : CheckSDLConfig        
51 })
52
53 # TODO check -config apps in the Configure context
54    
55 if not conf.CheckSDLConfig('1.2.4'):
56     print "Couldn't find libSDL >= 1.2.4"
57     Exit(1)
58 if not conf.CheckLib('SDL_mixer'):
59     print "Couldn't find SDL_mixer library!"
60     Exit(1)
61 if not conf.CheckLib('SDL_image'):
62     print "Couldn't find SDL_image library!"
63     Exit(1)
64 if not conf.CheckLib('GL'):
65     print "Couldn't find OpenGL library!"
66     Exit(1)
67
68 env = conf.Finish()
69
70 env.ParseConfig('sdl-config --cflags --libs')
71 env.Append(CPPPATH = ["#", "#/src", "#/lib"])
72 env.Append(CPPDEFINES = \
73         {'DATA_PREFIX':"'\"" + env['PREFIX'] + "/share/supertux\"'" ,
74          'LOCALEDIR'  :"'\"" + env['PREFIX'] + "/locales\"'"})
75
76 build_dir="build/" + env['PLATFORM']
77
78 env.Append(LIBS = ["supertux"])
79 env.Append(LIBPATH=["#" + build_dir + "/lib"])
80
81 env.Export(["env", "Glob"])
82 env.SConscript("lib/SConscript", build_dir=build_dir + "/lib", duplicate=0)
83 env.SConscript("src/SConscript", build_dir=build_dir + "/src", duplicate=0)
84
85 #for i in env.items():
86 #    print str(i)
87
88 # link all program targets to top builddir as a convenience