← Back to team overview

linuxdcpp-team team mailing list archive

[Branch ~linuxdcpp-team/linuxdcpp/trunk] Rev 394: Refactor SConstruct

 

------------------------------------------------------------
revno: 394
committer: Steven Sheehy <steven.sheehy@xxxxxxxxx>
branch nick: trunk
timestamp: Mon 2010-10-11 22:15:21 -0500
message:
  Refactor SConstruct
modified:
  SConstruct


--
lp:linuxdcpp
https://code.launchpad.net/~linuxdcpp-team/linuxdcpp/trunk

Your team LinuxDC++ Team is subscribed to branch lp:linuxdcpp.
To unsubscribe from this branch go to https://code.launchpad.net/~linuxdcpp-team/linuxdcpp/trunk/+edit-subscription
=== modified file 'SConstruct'
--- SConstruct	2010-10-07 04:32:15 +0000
+++ SConstruct	2010-10-12 03:15:21 +0000
@@ -19,19 +19,19 @@
 # Function definitions
 # ----------------------------------------------------------------------
 
-def CheckPKGConfig(context):
+def check_pkg_config(context):
 	context.Message('Checking for pkg-config... ')
 	ret = context.TryAction('pkg-config --version')[0]
 	context.Result(ret)
 	return ret
 
-def CheckPKG(context, name):
+def check_pkg(context, name):
 	context.Message('Checking for %s... ' % name)
 	ret = context.TryAction('pkg-config --exists \'%s\'' % name)[0]
 	context.Result(ret)
 	return ret
 
-def CheckCXXVersion(context, name, major, minor):
+def check_cxx_version(context, name, major, minor):
 	context.Message('Checking for %s >= %d.%d...' % (name, major, minor))
 	ret = commands.getoutput('%s -dumpversion' % name)
 
@@ -46,22 +46,23 @@
 	context.Result(retval)
 	return retval
 
-def CheckBZRRevision():
-	print "Checking tree revision...",
-	retval = ''
+def check_bzr_revision(context):
+	context.Message("Checking bzr revision...")
+	revision = ''
 
 	try:
 		b = branch.Branch.open('.')
-		retval = b.revno()
-		print retval
+		revision = str(b.revno())
 	except:
 		print "failed"
 
-	return retval
+	context.env['LDCPP_BZRREV'] = revision
+	context.Result(revision)
+	return revision
 
 # Install app icons to share/icons and all others to share/linuxdcpp/icons
-def install_icons(icons_dir, env):
-	prefix = env['FAKE_ROOT'] + os.path.join(env['PREFIX'], 'share')
+def install_icons(env, icons_dir):
+	prefix = os.path.join(env['FAKE_ROOT'], env['PREFIX'], 'share')
 
 	for root, dirs, files in os.walk(icons_dir):
 		for file in files:
@@ -101,12 +102,13 @@
 
 env = Environment(ENV = os.environ, options = vars)
 
-conf = Configure(env,
+conf = env.Configure(clean = False,
 	custom_tests =
 	{
-		'CheckPKGConfig' : CheckPKGConfig,
-		'CheckPKG' : CheckPKG,
-		'CheckCXXVersion' : CheckCXXVersion
+		'CheckPKGConfig' : check_pkg_config,
+		'CheckPKG' : check_pkg,
+		'CheckCXXVersion' : check_cxx_version,
+		'CheckBZRRevision' : check_bzr_revision
 	},
 	conf_dir = 'build/sconf',
 	log_file = 'build/sconf/config.log')
@@ -126,10 +128,14 @@
 if os.environ.has_key('CFLAGS'):
 	conf.env['CFLAGS'] = os.environ['CFLAGS'].split()
 
+conf.env['CPPDEFINES'] = [] # Initialize as a list so Append doesn't concat strings
+
 env.SConsignFile('build/sconf/.sconsign')
 vars.Save('build/sconf/scache.conf', env)
 Help(vars.GenerateHelpText(env))
 
+env.AddMethod(install_icons, 'InstallIcons')
+
 # ----------------------------------------------------------------------
 # Dependencies
 # ----------------------------------------------------------------------
@@ -163,12 +169,13 @@
 		print '\tNote: You might have the lib but not the headers'
 		Exit(1)
 
+	# TODO: Implement a plugin system so libnotify doesn't have compile-time dependencies
 	if not conf.CheckPKG('libnotify >= 0.4.1'):
 		print '\tlibnotify >= 0.4.1 not found, disabling notifications.'
 		print '\tNote: You might have the lib but not the headers'
-		conf.env['HAVE_LIBNOTIFY'] = False
 	else:
-		conf.env['HAVE_LIBNOTIFY'] = True
+		conf.env.Append(CPPDEFINES = 'HAVE_LIBNOTIFY')
+		conf.env.ParseConfig('pkg-config --libs libnotify')
 	
 	if not conf.CheckCXXHeader('boost/version.hpp', '<>'):
 		print '\tboost not found.'
@@ -218,10 +225,12 @@
 	if not conf.CheckHeader('iconv.h'):
 		Exit(1)
 	elif conf.CheckLibWithHeader('iconv', 'iconv.h', 'c', 'iconv(0, (const char **)0, 0, (char**)0, 0);'):
-		conf.env['ICONV_CONST'] = 'const'
+		conf.env.Append(CPPDEFINES = ('ICONV_CONST', 'const'))
 
 	if conf.CheckHeader(['sys/types.h', 'sys/socket.h', 'ifaddrs.h', 'net/if.h']):
-		conf.env['HAVE_IFADDRS_H'] = True
+		conf.env.Append(CPPDEFINES = 'HAVE_IFADDRS_H')
+
+	conf.CheckBZRRevision()
 
 	env = conf.Finish()
 
@@ -230,8 +239,6 @@
 # Compile and link flags
 # ----------------------------------------------------------------------
 
-	env['LDCPP_BZRREV'] = CheckBZRRevision()
-
 	# todo: remove -fpermissive and fix the errors
 	env.Append(CXXFLAGS = ['-I.', '-fpermissive'])
 	env.Append(CPPDEFINES = ['_GNU_SOURCE', '_LARGEFILE_SOURCE', ('_FILE_OFFSET_BITS', '64'), '_REENTRANT'])
@@ -240,23 +247,12 @@
 		env.Append(LINKFLAGS = '-Wl,--as-needed')
 
 	if os.name == 'mac' or os.sys.platform == 'darwin':
-		env['ICONV_CONST'] = ''
+		conf.env.Append(CPPDEFINES = ('ICONV_CONST', ''))
 
 	if os.sys.platform == 'sunos5':
-		env['ICONV_CONST'] = 'const'
+		conf.env.Append(CPPDEFINES = ('ICONV_CONST', 'const'))
 		env.Append(LIBS = ['socket', 'nsl'])
 
-	if env.get('ICONV_CONST'):
-		env.Append(CPPDEFINES = ('ICONV_CONST', env['ICONV_CONST']))
-
-	if env.get('HAVE_IFADDRS_H'):
-		env.Append(CPPDEFINES = 'HAVE_IFADDRS_H')
-
-	# TODO: Implement a plugin system so libnotify doesn't have compile-time dependencies
-	if env.get('HAVE_LIBNOTIFY'):
-		env.Append(CPPDEFINES = 'HAVE_LIBNOTIFY')
-		env.ParseConfig('pkg-config --libs libnotify')
-
 	if env.get('debug'):
 		env.Append(CPPDEFINES = '_DEBUG')
 		env.Append(CXXFLAGS = ['-g', '-ggdb', '-Wall'])
@@ -287,7 +283,6 @@
 # Build
 # ----------------------------------------------------------------------
 
-
 	Export('env')
 
 	# Build the dcpp library
@@ -312,7 +307,7 @@
 	prefix = env['FAKE_ROOT'] + env['PREFIX']
 	desktop_file = os.path.join('data', APP_NAME + '.desktop')
 
-	install_icons('icons/hicolor/', env)
+	env.InstallIcons('icons/hicolor/')
 	env.Alias('install', env.Install(dir = os.path.join(prefix, 'share', APP_NAME, 'glade'), source = glade_files))
 	env.Alias('install', env.Install(dir = os.path.join(prefix, 'share', 'doc', APP_NAME), source = text_files))
 	env.Alias('install', env.Install(dir = os.path.join(prefix, 'share', 'applications'), source = desktop_file))