# scons build file for the sequential graph coarsening.
#
# You can build it in the following variants:
#
#   debug         debug symbols, assertions, no optimization.
#   optimized     no debug symbols, no assertions, optimization.
#   poptimized    debug symbols, no assertions, optimization.
#   doptimized    debug symbols, assertions, optimization.
#
#   scons variant=${variant}

import os
import platform
import sys

# Get the current platform.
SYSTEM = platform.uname()[0]
HOST = platform.uname()[1]

# Get shortcut to $HOME.
HOME = os.environ['HOME']

def GetEnvironment():
  """Get environment variables from command line and environment.

  Exits on errors.

  Returns
    Environment with the configuration from the command line.
  """
  opts = Variables()
  opts.Add('variant', 'the variant to build, debug or optimized', 'debug')

  env = Environment(options=opts, ENV=os.environ)
  if not env['variant'] in ['debug', 'optimized', 'pdebug', 'profilingoptimized']:
    print('Illegal value for variant: %s' % env['variant'])
    sys.exit(1)

  # Special configuration for 64 bit machines.
  if platform.architecture()[0] == '64bit':
     env.Append(CPPFLAGS=['-DPOINTER64=1'])

  return env

# Get the common environment.
env = GetEnvironment()
env.Append(CPPPATH=['../../extern/argtable-2.10/include'])
env.Append(LIBPATH=['../../extern/argtable-2.10/lib'])

if SYSTEM == 'Darwin':
        env.Append(CPPPATH=['/opt/local/include/','../include'])
        env.Append(LIBPATH=['/opt/local/lib/'])

env['CXX'] = 'mpicxx'
env['CC']  = 'mpicc'
env.Append(CPPPATH=['../../extern/argtable3-3.0.3/'])
env.Append(CPPPATH=['../../lib'])
env.Append(CPPPATH=['../..//lib/tools'])
env.Append(CPPPATH=['../../lib/partition'])
env.Append(CPPPATH=['../../lib/io'])
env.Append(CPPPATH=['../../lib/partition/uncoarsening/refinement/quotient_graph_refinement/flow_refinement/'])
env.Append(LIBPATH=['../../extern/kaHIP_lib/'])
env.Append(CPPPATH=['../../extern/kaHIP_lib/'])
env.Append(CPPPATH=['../../lib'])
env.Append(CPPPATH=['../../app'])
env.Append(CPPPATH=['../../../lib/tools'])
env.Append(CPPPATH=['../../../lib/partition'])
env.Append(CPPPATH=['../../../lib/io'])
env.Append(CPPPATH=['../../../lib/partition/uncoarsening/refinement/quotient_graph_refinement/flow_refinement/'])


# Apply variant specific settings.
if env['variant'] == 'optimized':
  env.Append(CXXFLAGS = '-g0 -O3  -DNDEBUG -funroll-loops -Wextra -Wall -Winline -fno-stack-limit -static  -Wno-unused-parameter -Wno-inline -std=c++11')
  env.Append(CCFLAGS = '-g0 -O3  -DNDEBUG')
elif env['variant'] == 'pdebug':
  # Optimized with debug symbols for profiling.
  env.Append(CXXFLAGS = '-g -pg  -Wall -Winline -std=c++11')
  env.Append(CCFLAGS = '-g -pg ')
elif env['variant'] == 'profilingoptimized':
  # Optimized with debug symbols and assertions.
  env.Append(CXXFLAGS = '-pg -g -O0 -DSPEEDPROFILING -fno-stack-limit -Wall -Winline -std=c++11')
  env.Append(CCFLAGS = '-pg -g -O0 -DSPEEDPROFILING -Winline')
else:
  # Debug settings.
  env.Append(CXXFLAGS = '-g -O0 -Wall -fno-stack-limit -Winline -std=c++11')
  env.Append(CCFLAGS = '-g -O0 -Winline')


# Execute the SConscript.
SConscript('SConscript', exports=['env'],variant_dir=env['variant'], duplicate=False)
