# -*- mode: python -*-
# DOOM build script
# TTimo <ttimo@idsoftware.com> 
# http://scons.sourceforge.net

#*****************************************************************************
#                    The Dark Mod GPL Source Code
# 
# This file is part of the The Dark Mod Source Code, originally based 
# on the Doom 3 GPL Source Code as published in 2011.
# 
# The Dark Mod Source Code 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. For details, see LICENSE.TXT.
# 
# Project: The Dark Mod (http://www.thedarkmod.com/)
# 
#*****************************************************************************

import scons_utils

Import( 'GLOBALS' )
Import( GLOBALS )

# environment for core engine + game + idlib
# has additional include paths which are not used for third-party libraries
g_env_game = g_env_base.Clone()
g_env_game.Append(CPPPATH = '#/idlib')
g_env_game.Append(CPPPATH = '#/framework')
g_env_game.Append(CPPPATH = '#/game')
# stgatilov: turn all ExtLibs::ilInit into simply ::ilInit
g_env_game.Append(CPPFLAGS = '-DExtLibs=')

Export( 'g_env_game' )


source_list = []
# Build three parts of the TDM game: idlib, core engine, game;
source_list += SConscript( '../../sys/scons/SConscript.idlib' )
source_list += SConscript( '../../sys/scons/SConscript.core' )
source_list += SConscript( '../../sys/scons/SConscript.game' )

local_env = g_env_game.Clone()

# Add all custom-built libraries
path_template = '#/ThirdParty/artefacts/{0}/lib/lnx%d_s_gcc5_rel_stdcpp/{1}' % (64 if TARGET_ARCH == 'x64' else 32)
local_env.Append(LIBS = [
	File(path_template.format('zlib', 'libz.a')),
	File(path_template.format('zlib', 'libminizip.a')),
	File(path_template.format('libcurl', 'libcurl.a')),
	File(path_template.format('mbedtls', 'libmbedtls.a')),
	File(path_template.format('mbedtls', 'libmbedx509.a')),
	File(path_template.format('mbedtls', 'libmbedcrypto.a')),
	File(path_template.format('openal', 'libopenal.a')),
	File(path_template.format('vorbis', 'libvorbisfile.a')),
	File(path_template.format('vorbis', 'libvorbis.a')),
	File(path_template.format('ogg', 'libogg.a')),
	File(path_template.format('devil', 'libIL.a')),
	File(path_template.format('libjpeg', 'libjpeg.a')),
	File(path_template.format('libpng', 'libpng16.a')),
	File(path_template.format('ffmpeg', 'libavformat.a')),
	File(path_template.format('ffmpeg', 'libavcodec.a')),
	File(path_template.format('ffmpeg', 'libavutil.a')),
	File(path_template.format('ffmpeg', 'libswscale.a')),
	File(path_template.format('ffmpeg', 'libswresample.a')),
	File(path_template.format('pugixml', 'libpugixml.a')),
])

# Add all standard libraries (taken from system)
local_env.Append( LIBS = [ 'X11', 'Xext', 'Xxf86vm' ] ) # 'Xxf86dga', 
#local_env.Append( LIBPATH = [ '/usr/X11R6/lib' ] )
local_env.Append( LIBPATH = [ '/usr/lib/i386-linux-gnu' ] )
local_env.Append( LIBS = [ 'dl' ] )
local_env.Append( LIBS = [ 'pthread' ] )
local_env.Append( LIBS = [ 'stdc++fs' ] )

thedarkmod = local_env.Program( target = 'thedarkmod', source = source_list )
Return( 'thedarkmod' )
