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