import os

Import('env')

# Target specific SCons command line variables
vars = Variables()
vars.Add(BoolVariable('FORCE32', 'Force building 32 bit on 64 bit architecture',           os.environ.get('AJ_FORCE32', False)))
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 = ['pthread'])

# Cross compile setup
if os.environ.has_key('CROSS_PREFIX'):
    cc = env['CC']
    cxx = env['CXX']
    ar = env['AR']
    ranlib = env['RANLIB']
    env.Replace(CC = os.environ['CROSS_PREFIX'] + cc)
    env.Replace(CXX = os.environ['CROSS_PREFIX'] + cxx)
    env.Replace(LINK = os.environ['CROSS_PREFIX'] + cc)
    env.Replace(AR = os.environ['CROSS_PREFIX'] + ar)
    env.Replace(RANLIB = os.environ['CROSS_PREFIX'] + ranlib)
    env['ENV']['STAGING_DIR'] = os.environ.get('STAGING_DIR', '')
if os.environ.has_key('CROSS_PATH'):
    env['ENV']['PATH'] = ':'.join([ os.environ['CROSS_PATH'], env['ENV']['PATH'] ] )
if os.environ.has_key('CROSS_CFLAGS'):
    env.Append(CFLAGS=os.environ['CROSS_CFLAGS'].split())
if os.environ.has_key('CROSS_LINKFLAGS'):
    env.Append(LINKFLAGS=os.environ['CROSS_LINKFLAGS'].split())

# Compiler flags
env.Append(CFLAGS = [
    '-pipe',
    '-funsigned-char',
    '-fno-strict-aliasing',
    '-Wall',
    '-Waggregate-return',
    '-Wbad-function-cast',
    '-Wcast-align',
    '-Wfloat-equal',
    '-Wformat=2',
    '-Wno-deprecated-declarations',
    '-Wno-unknown-pragmas',
    '-Wpacked',
    '-Wpointer-arith',
    '-Wshadow',
    '-Wundef',
    '-Wwrite-strings'
])

if env['FORCE32']:
    env.Append(CFLAGS = '-m32')
    env.Append(LINKFLAGS = '-m32')
env.Append(CPPDEFINES = [ 'AJ_MAIN' ])
if env['NO_AUTH']:
    env.Append(CPPDEFINES = [ 'TEST_DISABLE_SECURITY' ])

# Debug/Release Variants
if env['VARIANT'] == 'debug':
    env.Append(CFLAGS = '-g')
else:
    env.Append(CFLAGS = '-Os')

#env['build_shared'] = True
#env['connectivity_options'] = [ 'tcp', 'ardp' ]

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