[NiL-SVN] SF.net SVN: nil: [523] trunk/nil-ng
Status: Alpha
Brought to you by:
e-user
|
From: <e-...@us...> - 2007-09-22 21:12:28
|
Revision: 523
http://nil.svn.sourceforge.net/nil/?rev=523&view=rev
Author: e-user
Date: 2007-09-22 14:12:28 -0700 (Sat, 22 Sep 2007)
Log Message:
-----------
deeply improved and abstracted autoconfiguration process
Modified Paths:
--------------
trunk/nil-ng/SConstruct
Added Paths:
-----------
trunk/nil-ng/configure.py
trunk/nil-ng/dependencies.py
Modified: trunk/nil-ng/SConstruct
===================================================================
--- trunk/nil-ng/SConstruct 2007-09-22 21:11:23 UTC (rev 522)
+++ trunk/nil-ng/SConstruct 2007-09-22 21:12:28 UTC (rev 523)
@@ -1,18 +1,11 @@
#!/usr/bin/env python
# NiL SConstruct script.
#
-# Original version by:
-# H. Ilari Liusvaara (hli...@cc...)
+# copyright (C) 2005,2006,2007 Alexander Kahl (e-...@gm...)
#
-# Adapted and optimized at 2005-08-25 19:07:40 by:
-# Alexander Kahl (e-...@us...)
-#
-# copyright (C) 2004 H. Ilari Liusvaara (hli...@cc...)
-# 2005,2006,2007 Alexander Kahl (e-...@us...)
-#
-# This program is free software; you can redistribute it and/or modify
+# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
+# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
@@ -21,42 +14,52 @@
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
import os
-import ConfigParser
+import platform
+import glob
+from configure import *
-### Name and version
+Help("""
+Possible options:
+ debug: enable debugging
+ profile: enable profiling
+ distclean: make distclean
+""")
+
+### Static definitions
package='nil-ng'
-version='0.1'
-config_conf='config.conf'
-config_cache='config.cache'
+version='0.0.1'
appname = 'nil'
+dependencies_cache = 'dependencies.cache'
###
-### Import the environment from the shell
+### Dynamic definitions
env = Environment(ENV = os.environ)
+x86_64 = platform.machine() == 'x86_64'
###
+### Prerequisites
env.EnsurePythonVersion(2, 5)
-env.EnsureSConsVersion(0, 96)
+env.EnsureSConsVersion(0, 97)
+###
-Help("""
-Possible options:
- debug: enable debugging
- profile: enable profiling
- distclean: make distclean
-""")
-
### Custom builder to create ChangeLog file from svn repository messages
-logbld = Builder(action = 'svn2cl --break-before-msg --strip-prefix=trunk/nil-ng/ -o $TARGET')
-env.Append(BUILDERS = {'ChangeLog' : logbld})
+changelog_builder = Builder(action = 'svn2cl --break-before-msg --strip-prefix=trunk/nil-ng/ -o $TARGET')
+configuration_builder = Builder(action = autoconf)
+env.Append(BUILDERS = {'ChangeLog' : changelog_builder,
+ 'Autoconf' : configuration_builder})
###
-### Enhance scons -c with convenient distclean call
+### Enhance scons -c with a convenient distclean call
if ARGUMENTS.get('distclean', 0):
- env.Clean([appname, appname + 'd'], ['config.cache', 'signatures.dblite', 'config.log', '.sconf_temp'])
+ env.Clean([appname, appname + 'd'], [dependencies_cache,
+ 'signatures.dblite',
+ '.sconsign.dblite',
+ 'config.log',
+ '.sconf_temp',
+ glob.glob('*.pyc')])
###
### Determine compiler flags
@@ -70,51 +73,8 @@
env.Append(CCFLAGS = ccflags)
###
+autoconf(env, dependencies_cache)
-
-def CheckSDLConfig(context, minVersion):
- context.Message('Checking for SDL >= %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
- version = map(int, out[0].strip().split('.'))
- minVersion = map(int, minVersion.split('.'))
- ret = (version >= minVersion)
- if ret == False:
- context.Display('Expected at least version %s, found %s.'
- % (minVersion, version))
- context.Result(False)
- return False
-
- context.Result(True)
- return True
-
-def CheckPKGConfig(context, package, minVersion):
- context.Message('Checking for %s >= %s... ' % (package, minVersion))
- from popen2 import Popen3
- p = Popen3(['pkg-config', '--atleast-version=' + minVersion, package])
- ret = p.wait()
- if ret != 0:
- context.Result(False)
- p = Popen3(['pkg-config', '--modversion', package])
- ret = p.wait()
- out = p.fromchild.readlines()
- context.Display('Expected at least version %s, found %s.'
- % (minVersion, out))
- return False
-
- # read flags...
- context.Result(True)
- return True
-
def Descend():
list = []
for file in os.listdir('.'):
@@ -122,118 +82,7 @@
list.append(file + '/SConscript')
return list
-### Configure our environment
-conf=Configure(env, custom_tests = {
- 'CheckSDLConfig' : CheckSDLConfig,
- 'CheckPKGConfig' : CheckPKGConfig
- })
-
-config = ConfigParser.ConfigParser()
-config.read(config_conf)
-
-cache = ConfigParser.ConfigParser()
-
-if os.path.exists(config_cache):
- print "Using cache file: "+config_cache
- cache.read(config_cache)
-else:
- print "Creating cache file: "+config_cache
- cache.add_section("cheaders")
- cache.add_section("ccheaders")
- cache.add_section("clibs")
- cache.add_section("cclibs")
- cache.add_section("pkgconfig")
-
-file = open(config_cache, 'w')
-
-for option in config.options("cheaders"):
- if (cache.has_option("cheaders", option) and cache.get("cheaders", option) == "True") or config.has_option("clibs", option):
- continue
-
- if not conf.CheckCHeader(config.get("cheaders", option)):
- print option + " must be installed!"
- cache.set("cheaders", option, False)
- cache.write(file)
- file.close()
- Exit(1)
- else:
- cache.set("cheaders", option, True)
-
-for option in config.options("ccheaders"):
- if (cache.has_option("ccheaders", option) and cache.get("ccheaders", option) == "True") or config.has_option("cclibs", option):
- continue
-
- if not conf.CheckCXXHeader(config.get("ccheaders", option)):
- print option + " must be installed!"
- cache.set("ccheaders", option, False)
- cache.write(file)
- file.close()
- Exit(1)
- else:
- cache.set("ccheaders", option, True)
-
-for option in config.options("clibs"):
- if cache.has_option("clibs", option) and cache.get("clibs", option) == "True":
- env.Append(LIBS = [config.get("clibs", option)])
- continue
-
- if not conf.CheckLibWithHeader(config.get("clibs", option), config.get("cheaders", option), 'c', '', "True"):
- print "Couldn't find " + option + " library!"
- cache.set("clibs", option, False)
- cache.write(file)
- file.close()
- Exit(1)
- else:
- cache.set("clibs", option, True)
- env.Append(LIBS = [config.get("clibs", option)])
-
-for option in config.options("cclibs"):
- if cache.has_option("cclibs", option) and cache.get("cclibs", option) == "True":
- env.Append(LIBS = [config.get("cclibs", option)])
- continue
-
- if not conf.CheckLibWithHeader(config.get("cclibs", option), config.get("ccheaders", option), 'c++', '', "True"):
- print "Couldn't find " + option + " library!"
- cache.set("cclibs", option, False)
- cache.write(file)
- file.close()
- Exit(1)
- else:
- cache.set("cclibs", option, True)
- env.Append(LIBS = [config.get("cclibs", option)])
-
-for option in config.options("pkgconfig"):
- if cache.has_option("pkgconfig", option) and cache.get("pkgconfig", option) == "True":
- env.ParseConfig('pkg-config --cflags --libs %s' % option)
- continue
-
- if not conf.CheckPKGConfig(option, config.get("pkgconfig", option)):
- cache.set("pkgconfig", option, False)
- cache.write(file)
- file.close()
- Exit(1)
- else:
- cache.set("pkgconfig", option, True)
- env.ParseConfig('pkg-config --cflags --libs %s' % option)
-
-
-if not (cache.has_option("clibs", "SDL") and cache.get("clibs", "SDL") == "True"):
- if not conf.CheckSDLConfig('1.2.4'):
- cache.set("clibs", "SDL", False)
- cache.write(file)
- file.close()
- Exit(1)
- else:
- cache.set("clibs", "SDL", True)
-env.ParseConfig('sdl-config --cflags --libs')
-
-cache.write(file)
-file.close()
-
-env = conf.Finish()
-###
-
-### Finish the environment configuration
+### environment configuration
env['APPNAME'] = package
env.Append(CPPPATH = "#src") # The hash marks means to treat this directory as an absolute path
env.SourceSignatures('MD5')
@@ -253,8 +102,13 @@
serversource = SConscript('src/SConscript')
###
-### These are the targets: nil, nild, ChangeLog
#env.ChangeLog('ChangeLog', '')
-env.Program(target = appname, source = commonsource + clientsource)
-env.Program(target = appname + 'd', source = commonsource + serversource)
+#target_autoconf = create_autoconf_target()
+target_client = Alias('client', appname)
+target_server = Alias('server', appname + 'd')
+target_all = Alias('all', [target_client, target_server])
+env.Program(appname, commonsource + clientsource)
+env.Program(appname + 'd', commonsource + serversource)
+# env.AddPreAction(appname, autoconf(env)) Doesn't work right now..
+env.Default(target_all)
###
Added: trunk/nil-ng/configure.py
===================================================================
--- trunk/nil-ng/configure.py (rev 0)
+++ trunk/nil-ng/configure.py 2007-09-22 21:12:28 UTC (rev 523)
@@ -0,0 +1,175 @@
+#!/usr/bin/env python
+# Python module to make SCons more autoconf-like
+#
+# copyright (C) 2005,2006,2007 Alexander Kahl (e-...@gm...)
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+from SCons.Script import *
+import dependencies
+
+def autoconf(env, dependencies_cache):
+ print "autoconf: Starting scons autoconf"
+ print "autoconf: Using cache file: " + dependencies_cache
+ cache = Options(dependencies_cache)
+ cache.Add('CCFLAGS')
+ cache.Add('LINKFLAGS')
+ cache.Add('CPPPATH')
+ cache.Add('CPPDEFINES')
+ cache.Add('LIBS')
+ cache.Add('LIBPATH')
+ cache.Add('autoconf')
+ cache.Update(env)
+
+ if not env.has_key('autoconf'):
+ env['autoconf'] = {}
+
+ if deftrue(env, 'configured'):
+ print "autoconf: Already configured."
+ return 0
+
+ conf = Configure(env, custom_tests = {
+ 'CheckVersion' : check_version,
+ 'CheckPKGConfig' : check_pkg_config,
+ })
+
+ depend = dependencies.get()
+ process_versions(env, conf, depend['versions'])
+ process_pkg_config(env, conf, depend['pkgconfig'])
+ process_c_headers(env, conf, depend['cheaders'])
+ process_cc_headers(env, conf, depend['ccheaders'])
+ process_libs(env, conf, depend['libs'])
+
+ #env.ParseConfig("sdl-config --version", function = CheckSDLConfig)
+ env = conf.Finish()
+ cache.Save(dependencies_cache, env)
+
+ if env.has_key('error') and env['error'] == True:
+ print "autoconf: Autoconf was not successful."
+ return 1
+ else:
+ print "autoconf: Autoconf was successful."
+ validate(env, 'configured')
+ cache.Save(dependencies_cache, env)
+ return 0
+
+def process_c_headers(env, conf, items):
+ for key in items:
+ if deftrue(env, key):
+ continue
+
+ if conf.CheckCHeader(items[key][0]):
+ validate(env, key)
+ else:
+ env['error'] = True
+
+def process_cc_headers(env, conf, items):
+ for key in items:
+ if deftrue(env, key):
+ continue
+
+ if conf.CheckCXXHeader(items[key][0]):
+ validate(env, key)
+ else:
+ env['error'] = True
+
+def process_libs(env, conf, items):
+ for key in items:
+ if deftrue(env, key):
+ continue
+
+ if conf.CheckLibWithHeader(items[key][0], items[key][1], items[key][2], items[key][3], items[key][4]):
+ validate(env, key)
+ else:
+ env['error'] = True
+
+def process_versions(env, conf, items):
+ for key in items:
+ if deftrue(env, key):
+ continue
+
+ if conf.CheckVersion(key, items[key][0], items[key][1], items[key][2], items[key][3]):
+ validate(env, key)
+ else:
+ env['error'] = True
+
+def process_pkg_config(env, conf, items):
+ for key in items:
+ if deftrue(env, key):
+ continue
+
+ if conf.CheckPKGConfig(key, items[key][0], items[key][1], items[key][2]):
+ validate(env, key)
+ else:
+ env['error'] = True
+
+def deftrue(env, key):
+ return env['autoconf'].has_key(key) and env['autoconf'][key] == True
+
+def validate(env, key):
+ env['autoconf'][key] = True
+
+def check_version(context, package, version_command, add_command, min_version, greater_allowed):
+ context.Message('Checking for %s >= %s... ' % (package, min_version))
+ from popen2 import Popen3
+ p = Popen3(version_command)
+ 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
+
+ version = out[0]
+ version_split = map(int, version.strip().split('.'))
+ min_version_split = map(int, min_version.split('.'))
+
+ if greater_allowed:
+ ret = (version_split >= min_version_split)
+ else:
+ ret = (version_split == min_version_split)
+
+ context.Result(ret)
+
+ if ret == False:
+ if greater_allowed:
+ context.Display('Expected at least version %s, found %s. ' % (min_version, version))
+ else:
+ context.Display('Expected version %s, found %s. ' % (min_version, version))
+ else:
+ context.env.ParseConfig(add_command)
+
+ return ret
+
+
+def check_pkg_config(context, name, package, min_version, modifier):
+ context.Message('Checking for %s >= %s... ' % (name, min_version))
+ from popen2 import Popen3
+
+ p = Popen3(['pkg-config', ('--%s-version=' % modifier) + min_version, package])
+ ret = p.wait()
+ if ret != 0:
+ context.Result(False)
+ p = Popen3(['pkg-config', '--modversion', package])
+ ret = p.wait()
+ out = p.fromchild.readlines()
+ context.Display('Expected %s version %s, found %s.' % (modifier, min_version, out))
+ return False
+
+ context.env.ParseConfig('pkg-config --cflags --libs ' + package)
+ context.Result(True)
+ return True
Added: trunk/nil-ng/dependencies.py
===================================================================
--- trunk/nil-ng/dependencies.py (rev 0)
+++ trunk/nil-ng/dependencies.py 2007-09-22 21:12:28 UTC (rev 523)
@@ -0,0 +1,40 @@
+#!/usr/bin/env python
+# NiL Dependencies
+#
+# copyright (C) 2005,2006,2007 Alexander Kahl (e-...@us...)
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+def get():
+ return {
+ 'cheaders': {
+ },
+ 'ccheaders': {
+ },
+ 'libs': {
+ 'pthread': ['pthread', 'pthread.h', 'c', None, True],
+ 'SDL mixer': ['SDL_mixer', 'SDL_mixer.h', 'c', None, True],
+ 'SDL image': ['SDL_image', 'SDL_image.h', 'c', None, True],
+ 'SDL ttf': ['SDL_ttf', 'SDL_ttf.h', 'c', None, True],
+ 'SDL net': ['SDL_net', 'SDL_net.h', 'c', None, True],
+ 'Open GL': ['GL', 'GL/gl.h', 'c', None, True],
+ 'physfs': ['physfs', 'physfs.h', 'c', None, True],
+ },
+ 'pkgconfig': {
+ 'LibXML2': ['libxml-2.0', '2.6', 'atleast'],
+ },
+ 'versions': {
+ 'SDL': ['sdl-config --version', 'sdl-config --cflags --libs', '1.2.10', True],
+ }
+ }
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|