2 # SConstruct build file. See http://www.scons.org for details.
12 def SetPrefix(self, prefix):
15 def SetPostfix(self, postfix):
16 self.postfix = postfix
18 def Define(self, name, value = ""):
19 self.defines[name] = value
21 def Save(self, filename):
22 file = open(filename, 'w')
23 file.write("/* %s. Generated by SConstruct */\n" % (filename))
25 file.write(self.prefix + "\n")
26 for key, value in self.defines.iteritems():
27 file.write("#define %s \"%s\"\n" % (key, value))
28 file.write(self.postfix + "\n")
32 path = GetBuildPath('SConscript').replace('SConscript', '')
35 for i in glob.glob(path + pattern):
36 result.append(i.replace(path, ''))
40 def InstallData(files):
42 dir = os.path.dirname(file)
43 destdir = os.path.join(env.subst('$DESTDIR/$APPDATADIR'), dir)
44 env.Install(destdir, file)
46 def InstallExec(files):
48 destfile = env.subst('$DESTDIR/$BINDIR/$PROGRAM_PREFIX') + file + \
49 env.subst('$PROGRAM_POSTFIX')
50 env.InstallAs(destfile, file)
52 # thanks to Michael P Jung
53 def CheckSDLConfig(context, minVersion):
54 context.Message('Checking for sdl-config >= %s... ' % minVersion)
55 from popen2 import Popen3
56 p = Popen3(['sdl-config', '--version'])
58 out = p.fromchild.readlines()
63 # unable to parse output!
66 # TODO validate output and catch exceptions
67 version = map(int, out[0].strip().split('.'))
68 minVersion = map(int, minVersion.split('.'))
69 # TODO comparing versions that way only works for pure numeric version
70 # numbers and fails for custom extensions. I don't care about this at
71 # the moment as sdl-config never used such version numbers afaik.
72 ret = (version >= minVersion)
76 # User configurable options
77 opts = Options('build_config.py')
78 opts.Add('CXX', 'The C++ compiler', 'g++')
79 opts.Add('CXXFLAGS', 'Additional C++ compiler flags', '')
80 opts.Add('CPPPATH', 'Additional preprocessor paths', '')
81 opts.Add('CPPFLAGS', 'Additional preprocessor flags', '')
82 opts.Add('CPPDEFINES', 'defined constants', '')
83 opts.Add('LIBPATH', 'Additional library paths', '')
84 opts.Add('LIBS', 'Additional libraries', '')
86 # installation path options
87 opts.Add('PREFIX', 'prefix for architecture-independent files', '/usr/local')
88 opts.Add('EPREFIX', 'prefix for architecture-dependent files', '$PREFIX')
89 opts.Add('BINDIR', 'user executables directory', '$EPREFIX/bin')
90 #opts.Add('SBINDIR', 'system admin executables directory', '$EPREFIX/sbin')
91 #opts.Add('LIBEXECDIR', 'program executables directory', '$EPREFIX/libexec')
92 opts.Add('DATADIR', 'read-only architecture-independent data directory',
94 #opts.Add('SYSCONFDIR', 'read-only single-machine data directory', '$PREFIX/etc')
95 #opts.Add('SHAREDSTATEDIR', 'modifiable architecture-independent data directory',
97 #opts.Add('LOCALSTATEDIR', 'modifiable single-machine data directory',
99 opts.Add('LIBDIR', 'object code libraries directory', '$EPREFIX/lib')
100 opts.Add('INCLUDEDIR', 'C header files directory', '$PREFIX/include')
101 #opts.Add('OLDINCLUDEDIR', 'C header files for non-gcc directory',
103 #opts.Add('INFODIR', 'info documentation directory', '$PREFIX/info')
104 #opts.Add('MANDIR', 'man documentation directory', '$PREFIX/man')
105 opts.Add('DESTDIR', \
106 'destination directory for installation. It is prepended to PREFIX', '')
109 opts.Add('PROGRAM_PREFIX', 'prepend PREFIX to installed program names', '')
110 opts.Add('PROGRAM_SUFFIX', 'append SUFFIX to installed program names', '')
111 opts.Add(EnumOption('VARIANT', 'Build variant', 'optimize',
112 ['optimize', 'debug', 'profile']))
114 env = Environment(options = opts)
115 Help(opts.GenerateHelpText(env))
118 env['PACKAGE_NAME'] = 'SuperTux'
119 env['PACKAGE_VERSION'] = '0.2-cvs'
120 env['PACKAGE_BUGREPORT'] = 'supertux-devel@lists.sourceforge.net'
121 env['PACKAGE'] = env['PACKAGE_NAME'].lower()
122 env['PACKAGE_STRING'] = env['PACKAGE_NAME'] + " " + env['PACKAGE_VERSION']
125 env['APPDATADIR'] = "$DATADIR/$PACKAGE"
126 env['LOCALEDIR'] = "$DATADIR/locale"
129 # Create build_config.py and config.h
130 if not os.path.exists("build_config.py") or not os.path.exists("config.h"):
131 print "build_config.py or config.h don't exist - Generating new build config..."
133 header = ConfigHeader()
134 header.Define("PACKAGE", env['PACKAGE'])
135 header.Define("PACKAGE_NAME", env['PACKAGE_NAME'])
136 header.Define("PACKAGE_VERSION", env['PACKAGE_VERSION'])
137 header.Define("PACKAGE_BUGREPORT", env['PACKAGE_BUGREPORT'])
138 header.Define("PACKAGE_STRING", env['PACKAGE_STRING'])
140 conf = Configure(env, custom_tests = {
141 'CheckSDLConfig' : CheckSDLConfig
143 if not conf.CheckSDLConfig('1.2.4'):
144 print "Couldn't find libSDL >= 1.2.4"
146 if not conf.CheckLib('SDL_mixer'):
147 print "Couldn't find SDL_mixer library!"
149 if not conf.CheckLib('SDL_image'):
150 print "Couldn't find SDL_image library!"
152 if not conf.CheckLib('GL'):
153 print "Couldn't find OpenGL library!"
158 env.ParseConfig('sdl-config --cflags --libs')
159 env.Append(CPPDEFINES = \
160 {'DATA_PREFIX':"'\"" + env.subst('$APPDATADIR') + "\"'" ,
161 'LOCALEDIR' :"'\"" + env.subst('$LOCALEDIR') + "\"'"})
162 opts.Save("build_config.py", env)
163 header.Save("config.h")
165 print "Using build_config.py"
167 if env['VARIANT'] == "optimize":
168 env.Append(CXXFLAGS = "-O2 -g -Wall")
169 elif env['VARIANT'] == "debug":
170 env.Append(CXXFLAGS = "-O0 -g3 -Wall -Werror")
171 env.Append(CPPDEFINES = { "DEBUG":"1" })
172 elif env['VARIANT'] == "profile":
173 env.Append(CXXFLAGS = "-pg -O2")
175 build_dir="build/" + env['PLATFORM'] + "/" + env['VARIANT']
177 # create some install aliases (only add paths here that are really used)
178 env.Alias('install-data', env.subst('$DESTDIR/$APPDATADIR'))
179 env.Alias('install-exec', env.subst('$DESTDIR/$BINDIR'))
180 env.Alias('install', ['install-data', 'install-exec'])
182 # append some include dirs and link libsupertux with main app
183 env.Append(CPPPATH = ["#", "#/src", "#/lib"])
184 env.Append(LIBS = ["supertux"])
185 env.Append(LIBPATH=["#" + build_dir + "/lib"])
187 env.Export(["env", "Glob", "InstallData", "InstallExec"])
188 env.SConscript("lib/SConscript", build_dir=build_dir + "/lib", duplicate=0)
189 env.SConscript("src/SConscript", build_dir=build_dir + "/src", duplicate=0)
190 env.SConscript("data/SConscript", build_dir=build_dir + "/data", duplicate=0)
191 env.SConscript("SConscript", build_dir=build_dir, duplicate=0)