import os
import platform

Import('env')

default_target_os = 'win7'
allowed_target_oss = ('win7', 'win10')

# Target specific SCons command line variables
default_msvc_version = os.environ.get('AJ_MSVC_VERSION', '12.0')
supported_msvc_versions = [ '8.0', '9.0', '10.0', '11.0', '11.0Exp', '12.0', '12.0Exp', '14.0', '14.0Exp' ]

vars = Variables()
vars.Add(EnumVariable('OS', 'Target OS', default_target_os, allowed_values = allowed_target_oss))
vars.Add(EnumVariable('MSVC_VERSION', 'MSVC compiler version - Windows', default_msvc_version, allowed_values = supported_msvc_versions))
vars.Add(BoolVariable('NO_AUTH', "Compile in authentication mechanism's to the code base", os.environ.get('AJ_NO_AUTH', False)))
vars.Update(env)
Help(vars.GenerateHelpText(env))

# Platform libraries
env.Append(LIBS = ['advapi32'])

# Compiler flags
env.Append(CFLAGS = ['/J', '/W3', '/nologo'])
env.Append(CPPDEFINES = ['_CRT_SECURE_NO_WARNINGS', 'AJ_MAIN'])
if env['NO_AUTH']:
    env.Append(CPPDEFINES = ['TEST_DISABLE_SECURITY'])

# Debug/Release Variants
if env['VARIANT'] == 'debug':
    env.Append(CFLAGS = ['/Zi', '/Od', '/MDd'])
    env.Append(CPPDEFINES = ['_DEBUG'])
    env.Append(LINKFLAGS = ['/debug'])
else:
   env.Append(CFLAGS = ['/Gy', '/O1', '/GF', '/MD'])
   env.Append(LINKFLAGS = ['/opt:ref', '/NODEFAULTLIB:libcmt.lib'])

env['connectivity_options'] = ['tcp', 'ardp']

# Support running on Win7 and newer Windows versions.
env.Append(CPPDEFINES = [('_WIN32_WINNT', '_WIN32_WINNT_WIN7')])

# This is needed in order to build with Scons and Visual Studio multiple targets
# in parallel using the -j option. See alljoyn\build_core\conf\windows\SConscript.
env['CCPDBFLAGS'] = '/Z7'
env['PDB'] = '${TARGET.base}.pdb'
env.Append(LINKFLAGS=['/PDB:${TARGET.base}.pdb'])

# Large Memory Platform
env.Append(CPPDEFINES = ['AJ_NVRAM_SIZE=64000'])
env.Append(CPPDEFINES = ['AJ_NUM_REPLY_CONTEXTS=8'])
