Just read in the SuperTux WIKI that there is a need for graphics of keys.... well:
[supertux.git] / SConstruct
index 41f6cb8..abddd64 100644 (file)
@@ -1,16 +1,53 @@
 #
 # SConstruct build file. See http://www.scons.org for details.
 import os
+import glob
 
-# based on a script from chenlee@ustc.edu
-def Glob(dirs, pattern = '*' ):
-    import os, fnmatch 
-    files = []
-    for dir in dirs:
-        for file in os.listdir( Dir(dir).srcnode().abspath ): 
-            if fnmatch.fnmatch(file, pattern) : 
-                files.append( os.path.join( dir, file ) ) 
-    return files 
+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
+
+    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(pattern):
+    path = GetBuildPath('SConscript').replace('SConscript', '')
+
+    result = []
+    for i in glob.glob(path + pattern): 
+        result.append(i.replace(path, ''))
+
+    return result
+
+def InstallData(files):
+    for file in files:
+        dir = os.path.dirname(file)
+        destdir = os.path.join(env.subst('$DESTDIR/$APPDATADIR'), dir)
+        env.Install(destdir, file)                                        
+
+def InstallExec(files):
+    for file in files:
+        destfile = env.subst('$DESTDIR/$BINDIR/$PROGRAM_PREFIX') + file + \
+            env.subst('$PROGRAM_POSTFIX')
+        env.InstallAs(destfile, file)
 
 # thanks to Michael P Jung
 def CheckSDLConfig(context, minVersion):
@@ -36,29 +73,73 @@ def CheckSDLConfig(context, minVersion):
     context.Result(ret)
     return ret
 
+# 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', '')
+
+# installation path options
+opts.Add('PREFIX', 'prefix for architecture-independent files', '/usr/local')
+opts.Add('EPREFIX', 'prefix for architecture-dependent files', '$PREFIX')
+opts.Add('BINDIR', 'user executables directory', '$EPREFIX/bin')
+#opts.Add('SBINDIR', 'system admin executables directory', '$EPREFIX/sbin')
+#opts.Add('LIBEXECDIR', 'program executables directory', '$EPREFIX/libexec')
+opts.Add('DATADIR', 'read-only architecture-independent data directory',
+    '$PREFIX/share')
+#opts.Add('SYSCONFDIR', 'read-only single-machine data directory', '$PREFIX/etc')
+#opts.Add('SHAREDSTATEDIR', 'modifiable architecture-independent data directory',
+#    '$PREFIX/com')
+#opts.Add('LOCALSTATEDIR', 'modifiable single-machine data directory',
+#    '$PREFIX/var')
+opts.Add('LIBDIR', 'object code libraries directory', '$EPREFIX/lib')
+opts.Add('INCLUDEDIR', 'C header files directory', '$PREFIX/include')
+#opts.Add('OLDINCLUDEDIR', 'C header files for non-gcc directory',
+#    '$PREFIX/include')
+#opts.Add('INFODIR', 'info documentation directory', '$PREFIX/info')
+#opts.Add('MANDIR', 'man documentation directory', '$PREFIX/man')
 opts.Add('DESTDIR', \
         'destination directory for installation. It is prepended to PREFIX', '')
-opts.Add('PREFIX', 'Installation prefix', '/usr/local')
+
+# misc options
+opts.Add('PROGRAM_PREFIX', 'prepend PREFIX to installed program names', '')
+opts.Add('PROGRAM_SUFFIX', 'append SUFFIX to installed program names', '')
 opts.Add(EnumOption('VARIANT', 'Build variant', 'optimize',
             ['optimize', 'debug', 'profile']))
 
 env = Environment(options = opts)
-env.SourceSignatures('timestamp')
+Help(opts.GenerateHelpText(env))
+
+# Package options
+env['PACKAGE_NAME'] = 'SuperTux'
+env['PACKAGE_VERSION'] = '0.2-cvs'
+env['PACKAGE_BUGREPORT'] = 'supertux-devel@lists.sourceforge.net'
+env['PACKAGE'] = env['PACKAGE_NAME'].lower()
+env['PACKAGE_STRING'] = env['PACKAGE_NAME'] + " " + env['PACKAGE_VERSION']
+
+# directories
+env['APPDATADIR'] = "$DATADIR/$PACKAGE"
+env['LOCALEDIR'] = "$DATADIR/locale"
 
-if not os.path.exists("build_config.py"):
-    print "build_config.py doesn't exist - Generating new build config..."
+
+# 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", env['PACKAGE'])
+    header.Define("PACKAGE_NAME", env['PACKAGE_NAME'])
+    header.Define("PACKAGE_VERSION", env['PACKAGE_VERSION'])
+    header.Define("PACKAGE_BUGREPORT", env['PACKAGE_BUGREPORT'])
+    header.Define("PACKAGE_STRING", env['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)
@@ -76,27 +157,35 @@ if not os.path.exists("build_config.py"):
 
     env.ParseConfig('sdl-config --cflags --libs')
     env.Append(CPPDEFINES = \
-        {'DATA_PREFIX':"'\"" + env['PREFIX'] + "/share/supertux\"'" ,
-         'LOCALEDIR'  :"'\"" + env['PREFIX'] + "/locales\"'"})
+        {'DATA_PREFIX':"'\"" + env.subst('$APPDATADIR') + "\"'" ,
+         'LOCALEDIR'  :"'\"" + env.subst('$LOCALEDIR') + "\"'"})
     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")
+    env.Append(CXXFLAGS = "-O2 -g -Wall")
 elif env['VARIANT'] == "debug":
-    env.Append(CXXFLAGS = "-O0 -g3")
+    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']
 
+# create some install aliases (only add paths here that are really used)
+env.Alias('install-data', env.subst('$DESTDIR/$APPDATADIR'))
+env.Alias('install-exec', env.subst('$DESTDIR/$BINDIR'))
+env.Alias('install', ['install-data', 'install-exec'])
+
+# append some include dirs and link libsupertux with main app
 env.Append(CPPPATH = ["#", "#/src", "#/lib"])
 env.Append(LIBS = ["supertux"])
 env.Append(LIBPATH=["#" + build_dir + "/lib"])
 
-env.Export(["env", "Glob"])
+env.Export(["env", "Glob", "InstallData", "InstallExec"])
 env.SConscript("lib/SConscript", build_dir=build_dir + "/lib", duplicate=0)
 env.SConscript("src/SConscript", build_dir=build_dir + "/src", duplicate=0)
+env.SConscript("data/SConscript", build_dir=build_dir + "/data", duplicate=0)
+env.SConscript("SConscript", build_dir=build_dir, duplicate=0)