2 # SConstruct build file. See http://www.scons.org for details.
11 def SetPrefix(self, prefix):
14 def SetPostfix(self, postfix):
15 self.postfix = postfix
17 def Define(self, name, value = ""):
18 self.defines[name] = value
20 def Save(self, filename):
21 file = open(filename, 'w')
22 file.write("/* %s. Generated by SConstruct */\n" % (filename))
24 file.write(self.prefix + "\n")
25 for key, value in self.defines.iteritems():
26 file.write("#define %s \"%s\"\n" % (key, value))
27 file.write(self.postfix + "\n")
30 def Glob(dirs, pattern = '*' ):
35 for file in os.listdir( Dir(dir).srcnode().abspath ):
36 if fnmatch.fnmatch(file, pattern) :
37 files.append( os.path.join( dir, file ) )
39 print "Warning, couldn't find directory '%s': %s" % (dir, str(e))
43 # thanks to Michael P Jung
44 def CheckSDLConfig(context, minVersion):
45 context.Message('Checking for sdl-config >= %s... ' % minVersion)
46 from popen2 import Popen3
47 p = Popen3(['sdl-config', '--version'])
49 out = p.fromchild.readlines()
54 # unable to parse output!
57 # TODO validate output and catch exceptions
58 version = map(int, out[0].strip().split('.'))
59 minVersion = map(int, minVersion.split('.'))
60 # TODO comparing versions that way only works for pure numeric version
61 # numbers and fails for custom extensions. I don't care about this at
62 # the moment as sdl-config never used such version numbers afaik.
63 ret = (version >= minVersion)
68 PACKAGE_NAME = "SuperTux"
69 PACKAGE_VERSION = "0.2-cvs"
70 PACKAGE_BUGREPORT = "supertux-devel@lists.sourceforge.net"
71 PACKAGE = PACKAGE_NAME.lower()
72 PACKAGE_STRING = PACKAGE_NAME + " " + PACKAGE_VERSION
74 # User configurable options
75 opts = Options('build_config.py')
76 opts.Add('CXX', 'The C++ compiler', 'g++')
77 opts.Add('CXXFLAGS', 'Additional C++ compiler flags', '')
78 opts.Add('CPPPATH', 'Additional preprocessor paths', '')
79 opts.Add('CPPFLAGS', 'Additional preprocessor flags', '')
80 opts.Add('CPPDEFINES', 'defined constants', '')
81 opts.Add('LIBPATH', 'Additional library paths', '')
82 opts.Add('LIBS', 'Additional libraries', '')
84 'destination directory for installation. It is prepended to PREFIX', '')
85 opts.Add('PREFIX', 'Installation prefix', '/usr/local')
86 opts.Add(EnumOption('VARIANT', 'Build variant', 'optimize',
87 ['optimize', 'debug', 'profile']))
89 env = Environment(options = opts)
91 # Create build_config.py and config.h
92 if not os.path.exists("build_config.py") or not os.path.exists("config.h"):
93 print "build_config.py or config.h don't exist - Generating new build config..."
95 header = ConfigHeader()
96 header.Define("PACKAGE", PACKAGE)
97 header.Define("PACKAGE_NAME", PACKAGE_NAME)
98 header.Define("PACKAGE_VERSION", PACKAGE_VERSION)
99 header.Define("PACKAGE_BUGREPORT", PACKAGE_BUGREPORT)
100 header.Define("PACKAGE_STRING", PACKAGE_STRING)
102 conf = Configure(env, custom_tests = {
103 'CheckSDLConfig' : CheckSDLConfig
105 if not conf.CheckSDLConfig('1.2.4'):
106 print "Couldn't find libSDL >= 1.2.4"
108 if not conf.CheckLib('SDL_mixer'):
109 print "Couldn't find SDL_mixer library!"
111 if not conf.CheckLib('SDL_image'):
112 print "Couldn't find SDL_image library!"
114 if not conf.CheckLib('GL'):
115 print "Couldn't find OpenGL library!"
120 env.ParseConfig('sdl-config --cflags --libs')
121 env.Append(CPPDEFINES = \
122 {'DATA_PREFIX':"'\"" + env['PREFIX'] + "/share/supertux\"'" ,
123 'LOCALEDIR' :"'\"" + env['PREFIX'] + "/locales\"'"})
124 opts.Save("build_config.py", env)
125 header.Save("config.h")
127 print "Using build_config.py"
129 if env['VARIANT'] == "optimize":
130 env.Append(CXXFLAGS = "-O2 -g -Wall")
131 elif env['VARIANT'] == "debug":
132 env.Append(CXXFLAGS = "-O0 -g3 -Wall -Werror")
133 env.Append(CPPDEFINES = { "DEBUG":"1" })
134 elif env['VARIANT'] == "profile":
135 env.Append(CXXFLAGS = "-pg -O2")
137 build_dir="build/" + env['PLATFORM'] + "/" + env['VARIANT']
139 env.Append(CPPPATH = ["#", "#/src", "#/lib"])
140 env.Append(LIBS = ["supertux"])
141 env.Append(LIBPATH=["#" + build_dir + "/lib"])
143 env.Export(["env", "Glob"])
144 env.SConscript("lib/SConscript", build_dir=build_dir + "/lib", duplicate=0)
145 env.SConscript("src/SConscript", build_dir=build_dir + "/src", duplicate=0)