2 # SConstruct build file. See http://www.scons.org for details.
5 def Glob(dirs, pattern = '*' ):
10 for file in os.listdir( Dir(dir).srcnode().abspath ):
11 if fnmatch.fnmatch(file, pattern) :
12 files.append( os.path.join( dir, file ) )
14 print "Warning, couldn't find directory '%s': %s" % (dir, str(e))
18 # thanks to Michael P Jung
19 def CheckSDLConfig(context, minVersion):
20 context.Message('Checking for sdl-config >= %s... ' % minVersion)
21 from popen2 import Popen3
22 p = Popen3(['sdl-config', '--version'])
24 out = p.fromchild.readlines()
29 # unable to parse output!
32 # TODO validate output and catch exceptions
33 version = map(int, out[0].strip().split('.'))
34 minVersion = map(int, minVersion.split('.'))
35 # TODO comparing versions that way only works for pure numeric version
36 # numbers and fails for custom extensions. I don't care about this at
37 # the moment as sdl-config never used such version numbers afaik.
38 ret = (version >= minVersion)
43 opts = Options('build_config.py')
44 opts.Add('CXX', 'The C++ compiler', 'g++')
45 opts.Add('CXXFLAGS', 'Additional C++ compiler flags', '')
46 opts.Add('CPPPATH', 'Additional preprocessor paths', '')
47 opts.Add('CPPFLAGS', 'Additional preprocessor flags', '')
48 opts.Add('CPPDEFINES', 'defined constants', '')
49 opts.Add('LIBPATH', 'Additional library paths', '')
50 opts.Add('LIBS', 'Additional libraries', '')
52 'destination directory for installation. It is prepended to PREFIX', '')
53 opts.Add('PREFIX', 'Installation prefix', '/usr/local')
54 opts.Add(EnumOption('VARIANT', 'Build variant', 'optimize',
55 ['optimize', 'debug', 'profile']))
57 env = Environment(options = opts)
59 if not os.path.exists("build_config.py"):
60 print "build_config.py doesn't exist - Generating new build config..."
62 conf = Configure(env, custom_tests = {
63 'CheckSDLConfig' : CheckSDLConfig
66 if not conf.CheckSDLConfig('1.2.4'):
67 print "Couldn't find libSDL >= 1.2.4"
69 if not conf.CheckLib('SDL_mixer'):
70 print "Couldn't find SDL_mixer library!"
72 if not conf.CheckLib('SDL_image'):
73 print "Couldn't find SDL_image library!"
75 if not conf.CheckLib('GL'):
76 print "Couldn't find OpenGL library!"
81 env.ParseConfig('sdl-config --cflags --libs')
82 env.Append(CPPDEFINES = \
83 {'DATA_PREFIX':"'\"" + env['PREFIX'] + "/share/supertux\"'" ,
84 'LOCALEDIR' :"'\"" + env['PREFIX'] + "/locales\"'"})
85 opts.Save("build_config.py", env)
87 print "Using build_config.py"
90 if env['VARIANT'] == "optimize":
91 env.Append(CXXFLAGS = "-O2 -g -Wall")
92 elif env['VARIANT'] == "debug":
93 env.Append(CXXFLAGS = "-O0 -g3 -Wall -Werror")
94 env.Append(CPPDEFINES = { "DEBUG":"1" })
95 elif env['VARIANT'] == "profile":
96 env.Append(CXXFLAGS = "-pg -O2")
98 build_dir="build/" + env['PLATFORM'] + "/" + env['VARIANT']
100 env.Append(CPPPATH = ["#", "#/src", "#/lib"])
101 env.Append(LIBS = ["supertux"])
102 env.Append(LIBPATH=["#" + build_dir + "/lib"])
104 env.Export(["env", "Glob"])
105 env.SConscript("lib/SConscript", build_dir=build_dir + "/lib", duplicate=0)
106 env.SConscript("src/SConscript", build_dir=build_dir + "/src", duplicate=0)