import os

Import('*')

#TODO: find a way to remove the .orig files astyle leaves around. Probably in
#      scons-tools/astyle.py

SRC=simpleglob("*.cc")+["build_id.cc"]

srcenv=env.Clone()

Export('srcenv')

# Ordering is paramount in the SConscript calls!
#
# Each SConscript returns one or more SCons.Node(s) that will be used for
# linking the library.
#
# The final reverse() is needed because the linker scans it's parameter list
# in reverse. Do not simply reverse the order of the SConscript calls
# themselves: other things might be happening in there that profit from correct
# ordering (ordering of compilation is always controlled directly by scons
# itself, though)
libs=[]
libs+=SConscript('filesystem/SConscript')
libs+=SConscript('sound/SConscript')
libs+=SConscript('ui/ui_basic/SConscript')
libs+=SConscript('ui/ui_fs_menus/SConscript')
libs+=list(SConscript('editor/SConscript'))
libs+=SConscript('trigger/SConscript')
libs+=SConscript('events/SConscript')
libs.reverse()

srcenv.Append(INDENTLIST=[
	'helper.h',
	'helper.cc',
	'journal.h',
	'journal.cc',
	'journal_exceptions.h',
	'journal_exceptions.cc',
	'main.cc',
	'wlapplication.h',
	'wlapplication.cc',
	])
indent=srcenv.astyle(source=srcenv['INDENTLIST'])
env.Alias("indent", indent)

binary=srcenv.Program(target='widelands', source=SRC+libs)
copybinary=srcenv.Command('#/widelands', binary, Copy('widelands', os.path.join(BUILDDIR, 'widelands')))

Return('copybinary')
