#
-# A simple SConstruct file.
-# See http://www.scons.org/ for more information about what SCons is and how it
-# may help you... :-)
-# I've never done anything with SCons before. Quite obviously this script is in
-# a non-working state!! Maybe someone with more knowledge of the materia who
-# thinks that SCons might be better suited than make can take over....
-# - Benjamin P. 'litespeed' Jung -
-#
+# SConstruct build file. See http://www.scons.org for details.
+import os
-# TODO: such static entries are obviously not what we want.
-# Using e.g. 'sdl-config' to obtain parameters would be muuuuuch
-# better.
-
-
-DATA_PREFIX = '\\\"/usr/local/share/supertux\\\"'
-LOCALEDIR = '\\\"/usr/local/share/locale\\\"'
-
-SDL_DYNAMIC_CCFLAGS = ['-D_REENTRANT', '-lSDL -lpthread']
-SDL_STATIC_CCFLAGS = ['-lSDL -lpthread -lm -ldl -lasound -L/usr/X11R6/lib -lX11 -lXext -lvga -laa']
-
-CCFLAGS = ['-DHAVE_CONFIG_H', '-O2', '-DDATA_PREFIX=' + DATA_PREFIX, '-DLOCALEDIR=' + LOCALEDIR]
-
-LIBSUPERTUX_DYNAMIC_CCFLAGS = SDL_DYNAMIC_CCFLAGS + CCFLAGS
-LIBSUPERTUX_STATIC_CCFLAGS = SDL_STATIC_CCFLAGS + CCFLAGS
-
-CPPPATH = ['/usr/include/SDL', 'src', 'lib', 'intl', '.']
-
-libsupertux_src = [
- 'lib/app/globals.cpp',
- 'lib/app/setup.cpp',
- 'lib/audio/musicref.cpp',
- 'lib/audio/sound_manager.cpp',
- 'lib/gui/button.cpp',
- 'lib/gui/menu.cpp',
- 'lib/gui/mousecursor.cpp',
- 'lib/math/physic.cpp',
- 'lib/math/vector.cpp',
- 'lib/special/game_object.cpp',
- 'lib/special/moving_object.cpp',
- 'lib/special/sprite.cpp',
- 'lib/special/sprite_manager.cpp',
- 'lib/special/timer.cpp',
- 'lib/special/frame_rate.cpp',
- 'lib/utils/configfile.cpp',
- 'lib/utils/lispreader.cpp',
- 'lib/utils/lispwriter.cpp',
- 'lib/video/drawing_context.cpp',
- 'lib/video/font.cpp',
- 'lib/video/screen.cpp',
- 'lib/video/surface.cpp'
-]
-
-supertux_src = [
- 'src/background.cpp',
- 'src/badguy.cpp',
- 'src/badguy_specs.cpp',
- 'src/bitmask.cpp',
- 'src/camera.cpp',
- 'src/collision.cpp',
- 'src/door.cpp',
- 'src/gameloop.cpp',
- 'src/gameobjs.cpp',
- 'src/high_scores.cpp',
- 'src/interactive_object.cpp',
- 'src/intro.cpp',
- 'src/level.cpp',
- 'src/level_subset.cpp',
- 'src/leveleditor.cpp',
- 'src/misc.cpp',
- 'src/particlesystem.cpp',
- 'src/player.cpp',
- 'src/resources.cpp',
- 'src/scene.cpp',
- 'src/sector.cpp',
- 'src/special.cpp',
- 'src/statistics.cpp',
- 'src/supertux.cpp',
- 'src/tile.cpp',
- 'src/tile_manager.cpp',
- 'src/tilemap.cpp',
- 'src/title.cpp',
- 'src/worldmap.cpp'
-]
-
-
-
-StaticLibrary(
- target='lib/supertux',
- source=libsupertux_src,
- CPPPATH=CPPPATH,
- CCFLAGS=LIBSUPERTUX_STATIC_CCFLAGS
-)
-
-Program(
- target='src/supertux',
- source=supertux_src,
- CPPPATH=CPPPATH,
- CCFLAGS=LIBSUPERTUX_STATIC_CCFLAGS,
- LIBPATH='lib',
- LIBS='supertux'
-)
+class ConfigHeader:
+ def __init__(self):
+ self.defines = { }
+ self.prefix = ""
+ self.postfix = ""
+ def SetPrefix(self, prefix):
+ self.prefix = prefix
+ def SetPostfix(self, postfix):
+ self.postfix = postfix
-#
-# The following lines _should_ (hehe!) build a shared SuperTux library (hey! At
-# least that part works pretty fine...) and then create a supertux exceutable
-# which links dynamically against that lib.
-#
-#SharedLibrary(
-# target='lib/supertux',
-# source=libsupertux_src,
-# CPPPATH=CPPPATH,
-# CCFLAGS=CCFLAGS
-#)
-#Program(
-# target='src/supertux',
-# source=supertux_src,
-# CPPPATH=CPPPATH,
-# CCFLAGS=LIBSUPERTUX_DYNAMIC_CCFLAGS
-#)
+ def Define(self, name, value = ""):
+ self.defines[name] = value
+
+ def Save(self, filename):
+ file = open(filename, 'w')
+ file.write("/* %s. Generated by SConstruct */\n" % (filename))
+ file.write("\n")
+ file.write(self.prefix + "\n")
+ for key, value in self.defines.iteritems():
+ file.write("#define %s \"%s\"\n" % (key, value))
+ file.write(self.postfix + "\n")
+ file.close()
+
+def Glob(dirs, pattern = '*' ):
+ import os, fnmatch
+ files = []
+ for dir in dirs:
+ try:
+ for file in os.listdir( Dir(dir).srcnode().abspath ):
+ if fnmatch.fnmatch(file, pattern) :
+ files.append( os.path.join( dir, file ) )
+ except Exception, e:
+ print "Warning, couldn't find directory '%s': %s" % (dir, str(e))
+
+ return files
+
+# thanks to Michael P Jung
+def CheckSDLConfig(context, minVersion):
+ context.Message('Checking for sdl-config >= %s... ' % minVersion)
+ from popen2 import Popen3
+ p = Popen3(['sdl-config', '--version'])
+ ret = p.wait()
+ out = p.fromchild.readlines()
+ if ret != 0:
+ context.Result(False)
+ return False
+ if len(out) != 1:
+ # unable to parse output!
+ context.Result(False)
+ return False
+ # TODO validate output and catch exceptions
+ version = map(int, out[0].strip().split('.'))
+ minVersion = map(int, minVersion.split('.'))
+ # TODO comparing versions that way only works for pure numeric version
+ # numbers and fails for custom extensions. I don't care about this at
+ # the moment as sdl-config never used such version numbers afaik.
+ ret = (version >= minVersion)
+ context.Result(ret)
+ return ret
+
+# Package options
+PACKAGE_NAME = "SuperTux"
+PACKAGE_VERSION = "0.2-cvs"
+PACKAGE_BUGREPORT = "supertux-devel@lists.sourceforge.net"
+PACKAGE = PACKAGE_NAME.lower()
+PACKAGE_STRING = PACKAGE_NAME + " " + PACKAGE_VERSION
+
+# User configurable options
+opts = Options('build_config.py')
+opts.Add('CXX', 'The C++ compiler', 'g++')
+opts.Add('CXXFLAGS', 'Additional C++ compiler flags', '')
+opts.Add('CPPPATH', 'Additional preprocessor paths', '')
+opts.Add('CPPFLAGS', 'Additional preprocessor flags', '')
+opts.Add('CPPDEFINES', 'defined constants', '')
+opts.Add('LIBPATH', 'Additional library paths', '')
+opts.Add('LIBS', 'Additional libraries', '')
+opts.Add('DESTDIR', \
+ 'destination directory for installation. It is prepended to PREFIX', '')
+opts.Add('PREFIX', 'Installation prefix', '/usr/local')
+opts.Add(EnumOption('VARIANT', 'Build variant', 'optimize',
+ ['optimize', 'debug', 'profile']))
+
+env = Environment(options = opts)
+
+# Create build_config.py and config.h
+if not os.path.exists("build_config.py") or not os.path.exists("config.h"):
+ print "build_config.py or config.h don't exist - Generating new build config..."
+
+ header = ConfigHeader()
+ header.Define("PACKAGE", PACKAGE)
+ header.Define("PACKAGE_NAME", PACKAGE_NAME)
+ header.Define("PACKAGE_VERSION", PACKAGE_VERSION)
+ header.Define("PACKAGE_BUGREPORT", PACKAGE_BUGREPORT)
+ header.Define("PACKAGE_STRING", PACKAGE_STRING)
+
+ conf = Configure(env, custom_tests = {
+ 'CheckSDLConfig' : CheckSDLConfig
+ })
+ if not conf.CheckSDLConfig('1.2.4'):
+ print "Couldn't find libSDL >= 1.2.4"
+ Exit(1)
+ if not conf.CheckLib('SDL_mixer'):
+ print "Couldn't find SDL_mixer library!"
+ Exit(1)
+ if not conf.CheckLib('SDL_image'):
+ print "Couldn't find SDL_image library!"
+ Exit(1)
+ if not conf.CheckLib('GL'):
+ print "Couldn't find OpenGL library!"
+ Exit(1)
+
+ env = conf.Finish()
+
+ env.ParseConfig('sdl-config --cflags --libs')
+ env.Append(CPPDEFINES = \
+ {'DATA_PREFIX':"'\"" + env['PREFIX'] + "/share/supertux\"'" ,
+ 'LOCALEDIR' :"'\"" + env['PREFIX'] + "/locales\"'"})
+ opts.Save("build_config.py", env)
+ header.Save("config.h")
+else:
+ print "Using build_config.py"
+
+if env['VARIANT'] == "optimize":
+ env.Append(CXXFLAGS = "-O2 -g -Wall")
+elif env['VARIANT'] == "debug":
+ env.Append(CXXFLAGS = "-O0 -g3 -Wall -Werror")
+ env.Append(CPPDEFINES = { "DEBUG":"1" })
+elif env['VARIANT'] == "profile":
+ env.Append(CXXFLAGS = "-pg -O2")
+
+build_dir="build/" + env['PLATFORM'] + "/" + env['VARIANT']
+
+env.Append(CPPPATH = ["#", "#/src", "#/lib"])
+env.Append(LIBS = ["supertux"])
+env.Append(LIBPATH=["#" + build_dir + "/lib"])
+
+env.Export(["env", "Glob"])
+env.SConscript("lib/SConscript", build_dir=build_dir + "/lib", duplicate=0)
+env.SConscript("src/SConscript", build_dir=build_dir + "/src", duplicate=0)