use -Wall -Werror in debug mode
[supertux.git] / SConstruct
1 #
2 # SConstruct build file. See http://www.scons.org for details.
3 import os
4
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 # thanks to Michael P Jung
15 def CheckSDLConfig(context, minVersion):
16     context.Message('Checking for sdl-config >= %s... ' % minVersion)
17     from popen2 import Popen3
18     p = Popen3(['sdl-config', '--version'])
19     ret = p.wait()
20     out = p.fromchild.readlines()
21     if ret != 0:
22         context.Result(False)
23         return False
24     if len(out) != 1:
25         # unable to parse output!
26         context.Result(False)
27         return False
28     # TODO validate output and catch exceptions
29     version = map(int, out[0].strip().split('.'))
30     minVersion = map(int, minVersion.split('.'))
31     # TODO comparing versions that way only works for pure numeric version
32     # numbers and fails for custom extensions. I don't care about this at
33     # the moment as sdl-config never used such version numbers afaik.
34     ret = (version >= minVersion)
35     context.Result(ret)
36     return ret
37
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('CPPDEFINES', 'defined constants', '')
45 opts.Add('LIBPATH', 'Additional library paths', '')
46 opts.Add('LIBS', 'Additional libraries', '')
47 opts.Add('DESTDIR', \
48         'destination directory for installation. It is prepended to PREFIX', '')
49 opts.Add('PREFIX', 'Installation prefix', '/usr/local')
50 opts.Add(EnumOption('VARIANT', 'Build variant', 'optimize',
51             ['optimize', 'debug', 'profile']))
52
53 env = Environment(options = opts)
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 -Wall -Werror")
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)