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)
90 Help(opts.GenerateHelpText(env))
92 # Create build_config.py and config.h
93 if not os.path.exists("build_config.py") or not os.path.exists("config.h"):
94 print "build_config.py or config.h don't exist - Generating new build config..."
96 header = ConfigHeader()
97 header.Define("PACKAGE", PACKAGE)
98 header.Define("PACKAGE_NAME", PACKAGE_NAME)
99 header.Define("PACKAGE_VERSION", PACKAGE_VERSION)
100 header.Define("PACKAGE_BUGREPORT", PACKAGE_BUGREPORT)
101 header.Define("PACKAGE_STRING", PACKAGE_STRING)
103 conf = Configure(env, custom_tests = {
104 'CheckSDLConfig' : CheckSDLConfig
106 if not conf.CheckSDLConfig('1.2.4'):
107 print "Couldn't find libSDL >= 1.2.4"
109 if not conf.CheckLib('SDL_mixer'):
110 print "Couldn't find SDL_mixer library!"
112 if not conf.CheckLib('SDL_image'):
113 print "Couldn't find SDL_image library!"
115 if not conf.CheckLib('GL'):
116 print "Couldn't find OpenGL library!"
121 env.ParseConfig('sdl-config --cflags --libs')
122 env.Append(CPPDEFINES = \
123 {'DATA_PREFIX':"'\"" + env['PREFIX'] + "/share/supertux\"'" ,
124 'LOCALEDIR' :"'\"" + env['PREFIX'] + "/locales\"'"})
125 opts.Save("build_config.py", env)
126 header.Save("config.h")
128 print "Using build_config.py"
130 if env['VARIANT'] == "optimize":
131 env.Append(CXXFLAGS = "-O2 -g -Wall")
132 elif env['VARIANT'] == "debug":
133 env.Append(CXXFLAGS = "-O0 -g3 -Wall -Werror")
134 env.Append(CPPDEFINES = { "DEBUG":"1" })
135 elif env['VARIANT'] == "profile":
136 env.Append(CXXFLAGS = "-pg -O2")
138 build_dir="build/" + env['PLATFORM'] + "/" + env['VARIANT']
140 env.Append(CPPPATH = ["#", "#/src", "#/lib"])
141 env.Append(LIBS = ["supertux"])
142 env.Append(LIBPATH=["#" + build_dir + "/lib"])
144 env.Export(["env", "Glob"])
145 env.SConscript("lib/SConscript", build_dir=build_dir + "/lib", duplicate=0)
146 env.SConscript("src/SConscript", build_dir=build_dir + "/src", duplicate=0)
147 env.SConscript("SConscript", build_dir=build_dir, duplicate=0)