view utils/scons/scons_builders.py @ 384:621b062e752d

Modified the code blocks project files to fit with the new build system. Code blocks now uses scons to build each of the configurations. The python configurations build properly but fail during link with a bunch of undefined references insides of the swig generated dll, not sure why. Also updated the win32-config.py so that it no longer relies on variables defined outside of itself, this was causing code blocks to not be able to build. Updated a couple of the batch scripts so they run properly.
author vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
date Wed, 20 Jan 2010 05:56:18 +0000
parents 64738befdf3b
children 81641655bc38
line wrap: on
line source

import os, sys

#**************************************************************************
#project file generators (scon builders)
#**************************************************************************

_sep = os.path.sep
msvcbuildpath = os.path.join('build', 'win32', 'build_environments', 'visual_studio_8')
msvcbuildpath9 = os.path.join('build', 'win32', 'build_environments', 'visual_studio_9')
cbbuildpath_win32 = os.path.join('build', 'win32', 'build_environments', 'code_blocks')
cbbuildpath_linux = os.path.join('build', 'linux', 'code_blocks')


def generate_msvc_project(target, source, env):
	def create_dict_tree(source_dict):
		for f in source_dict.keys():
			parts = f.split(os.path.sep, 1)
			if len(parts) > 1:
				try:
					source_dict[parts[0]][parts[1]] = {}
				except KeyError:
					source_dict[parts[0]] = {}
					source_dict[parts[0]][parts[1]] = {}
				del source_dict[f]
		for k, d in source_dict.items():
			create_dict_tree(d)
		return source_dict

	def get_msvc_repr(d, tabcount=2, curpath=''):
		retstr = []
		for k in sorted(d.keys()):
			newpath = os.path.join(curpath, k)
			if len(d[k].keys()):
				retstr.append(tabcount * '\t' + '<Filter Name="%s">' % k)
				retstr.append(get_msvc_repr(d[k], tabcount+1, newpath))
				retstr.append(tabcount * '\t' + '</Filter>')
			else:
				newpath = os.path.join('..', '..', '..', '..', 'engine', newpath)
				retstr.append(tabcount * '\t' + '<File RelativePath="%s"></File>' % newpath.replace('/','\\'))
		return '\n'.join(retstr)

	vcpaths = [os.path.abspath(str(f)).rsplit('%sengine%s' % (_sep, _sep))[-1] for f in source]
	vcpaths.append(os.path.join('swigwrappers', 'python', 'fife_wrap.cc'))
	xmlstr = get_msvc_repr(create_dict_tree(dict([[p, {}] for p in vcpaths])))
	projtxt = open(os.path.join(msvcbuildpath, 'engine_template.xml'), 'r').read()
	projtxt = projtxt.replace('__FILE_INSERTION_POINT__', xmlstr)

	oldprojtxt = ''
	try:
		oldprojtxt = open(str(target[0]), 'r').read()
	except:
		pass

	if(oldprojtxt <> projtxt):
		open(str(target[0]), 'w').write(projtxt)
		print "FIFE msvc project file succesfully created (%s)" % os.path.abspath(str(target[0]))
	else:
		print "FIFE msvc project file already up-to-date (%s)" % os.path.abspath(str(target[0]))


def generate_msvc_project9(target, source, env):
	def create_dict_tree(source_dict):
		for f in source_dict.keys():
			parts = f.split(os.path.sep, 1)
			if len(parts) > 1:
				try:
					source_dict[parts[0]][parts[1]] = {}
				except KeyError:
					source_dict[parts[0]] = {}
					source_dict[parts[0]][parts[1]] = {}
				del source_dict[f]
		for k, d in source_dict.items():
			create_dict_tree(d)
		return source_dict

	def get_msvc_repr(d, tabcount=2, curpath=''):
		retstr = []
		for k in sorted(d.keys()):
			newpath = os.path.join(curpath, k)
			if len(d[k].keys()):
				retstr.append(tabcount * '\t' + '<Filter Name="%s">' % k)
				retstr.append(get_msvc_repr(d[k], tabcount+1, newpath))
				retstr.append(tabcount * '\t' + '</Filter>')
			else:
				newpath = os.path.join('..', '..', '..', '..', 'engine', newpath)
				retstr.append(tabcount * '\t' + '<File RelativePath="%s"></File>' % newpath.replace('/','\\'))
		return '\n'.join(retstr)

	vcpaths = [os.path.abspath(str(f)).rsplit('%sengine%s' % (_sep, _sep))[-1] for f in source]
	vcpaths.append(os.path.join('swigwrappers', 'python', 'fife_wrap.cc'))
	xmlstr = get_msvc_repr(create_dict_tree(dict([[p, {}] for p in vcpaths])))
	projtxt = open(os.path.join(msvcbuildpath9, 'engine_template.xml'), 'r').read()
	projtxt = projtxt.replace('__FILE_INSERTION_POINT__', xmlstr)

	oldprojtxt = ''
	try:
		oldprojtxt = open(str(target[0]), 'r').read()
	except:
		pass

	if(oldprojtxt <> projtxt):
		open(str(target[0]), 'w').write(projtxt)
		print "FIFE msvc9 project file succesfully created (%s)" % os.path.abspath(str(target[0]))
	else:
		print "FIFE msvc9 project file already up-to-date (%s)" % os.path.abspath(str(target[0]))

def generate_codeblocks_project_win32(target, source, env):
	codeblocksHeaderDef = \
	'''		<Unit filename="..\..\..\engine\%s">
				<Option compilerVar=""/>
				<Option compile="0"/>
				<Option link="0"/>
				<Option target="default"/>
			</Unit>'''

	codeblocksCppDef = \
	'''		<Unit filename="..\..\..\..\engine\%s">
				<Option compilerVar="CPP"/>
				<Option target="default"/>
			</Unit>'''
	xmlstr = []
	for f in source:
		newf = os.path.abspath(str(f)).rsplit('%sengine%s' % (_sep, _sep))[-1]
		newf = newf.replace('/', '\\')
		if str(f).endswith('.hpp') or str(f).endswith('.h'):
			xmlstr.append(codeblocksHeaderDef % newf)
		else:
			xmlstr.append(codeblocksCppDef % newf)
	
	xmlstr.append(codeblocksCppDef % os.path.join('swigwrappers', 'python', 'fife_wrap.cc'))

	projtxt = open(os.path.join(cbbuildpath_win32, 'engine_template.xml'), 'r').read()
	projtxt = projtxt.replace('__FILE_INSERTION_POINT__', '\n'.join(xmlstr))
	open(str(target[0]), 'w').write(projtxt)
	print "FIFE code::blocks project file succesfully created (%s)" % os.path.abspath(str(target[0]))

def generate_codeblocks_project_linux(target, source, env):
	codeblocksHeaderDef = \
	'''		<Unit filename="../../../engine/%s">
				<Option compilerVar=""/>
				<Option compile="0"/>
				<Option link="0"/>
				<Option target="default"/>
			</Unit>'''

	codeblocksCppDef = \
	'''		<Unit filename="../../../engine/%s">
				<Option compilerVar="CPP"/>
				<Option target="default"/>
			</Unit>'''
	xmlstr = []
	for f in source:
		newf = os.path.abspath(str(f)).rsplit('%sengine%s' % (_sep, _sep))[-1]
		newf = newf.replace('/', '\\')
		if str(f).endswith('.hpp') or str(f).endswith('.h'):
			xmlstr.append(codeblocksHeaderDef % newf)
		else:
			xmlstr.append(codeblocksCppDef % newf)
			
	xmlstr.append(codeblocksCppDef % os.path.join('swigwrappers', 'python', 'fife_wrap.cc'))

	projtxt = open(os.path.join(cbbuildpath_linux, 'engine_template.xml'), 'r').read()
	projtxt = projtxt.replace('__FILE_INSERTION_POINT__', '\n'.join(xmlstr))
	open(str(target[0]), 'w').write(projtxt)
	print "FIFE code::blocks project file succesfully created (%s)" % os.path.abspath(str(target[0]))