SConstruct 7.03 KB
import os
import platform

opts = Variables('DefaultOptions.py')
opts.Add(BoolVariable('DEBUG', 'Set to 1 to build with debug symbols', 0))
opts.Add(BoolVariable('STATIC', 'Set to 1 to build with static libraries', 0))

debug = ARGUMENTS.get('DEBUG', 0)
static = ARGUMENTS.get('STATIC', 0)

print "Platform: ", platform.system()
if platform.system() == 'Windows':
  #os.environ['HOME'] = os.path.join(os.getcwd(), '..', '..') # for windows users
  env = Environment(variables = opts, ENV = os.environ, tools = ['mingw'])
  # print env['ENV']['PATH']
  import SCons
  SCons.Tool.Tool('lex').generate(env)
  SCons.Tool.Tool('yacc').generate(env)
  print env.WhereIs('bison')
else:
  env = Environment(variables = opts, ENV = os.environ)

if debug:
  env.Append(CPPDEFINES = {'DEBUG': None})
  env.Append(CPPDEFINES = {'_DEBUG': None})
else:
  env.Append(CPPDEFINES = {'NDEBUG': None})

compiler_output_name = 'anubis'

if platform.system() == 'Windows':
  env.Append(CPPDEFINES = {'WIN32': None, '_WIN32_IE': '0x0400'})
  # env.Append(CCFLAGS = ' /MD /GX /O2')
  #env.Append(CPPDEFINES = {'__STDC__': None})
  #env.Append(CPPDEFINES = {'_MSC_VER': '600'})
  #additionalLibs.append('ws2_32.lib')
  #additionalLibs.append('shell32.lib')
  env.Append(LIBS=['ws2_32', 'shell32'])
  # env.Append(LINKFLAGS = ' /subsystem:console /incremental:no /machine:I386 ')
else:
  if platform.system() == 'Linux':
    env.Append(CPPDEFINES = {'_LINUX_': None})
  elif platform.system() == 'Darwin':
    env.Append(CPPDEFINES = {'_LINUX_': None})
    # for full path on log
    #env['CXXCOM'] = '$CXX -o $TARGET -c $CXXFLAGS $CCFLAGS $_CCCOMCOM ${SOURCES.abspath}'
    env['CXXCOM'] = env['CXXCOM'].replace('$SOURCES', '${SOURCES.abspath}')
    env['CCCOM']  = env['CCCOM'].replace('$SOURCES', '${SOURCES.abspath}')
  compiler_output_name = 'anubis_with_symbol'

env.Append(CCFLAGS = ' -c -Wall -m32')
env.Append(CFLAGS = ' -Wstrict-prototypes') #Flags only use for C compiler not C++ 
env.Append(LINKFLAGS = ' -m32')
if debug:
  env.Append(CCFLAGS = ' -g3 -O0')
else:
  env.Append(CCFLAGS = ' -O2')
if static:
  env.Append(LINKFLAGS = '-static')


env['DEVDIR'] = os.path.normpath(os.path.join('..'))
env['BASEDIR'] = os.path.normpath(os.path.join(env['DEVDIR'], '..'))

env.Append(CPPPATH = [os.path.join(env['DEVDIR'], 'include'), '.'])
if platform.system() == 'Windows':
  env.Append(CPPPATH = [os.path.join('src', 'win32')])

#SConscript('src/SConscript', exports='env', build_dir='build', duplicate=0)
env.VariantDir('build', 'src', duplicate=0)
env.VariantDir(os.path.join('build', 'win32'), os.path.join('src', 'win32'), duplicate=0)
env.VariantDir(os.path.join('build', 'share'), os.path.join(env['DEVDIR'], 'share'), duplicate=0)
env.VariantDir(os.path.join('build', 'cipher'), os.path.join(env['DEVDIR'], 'cipher'), duplicate=0)

main_src = [os.path.join('build', x) for x in Split("""
  new_var.c interp.c globals.c mallocz.c opdef.c
  unify.c show.c msgtexts.c typedef.c rectype.c typewidth.c implem.c
  determin.c unknowns.c eqcode.c typecmp.c dumpct.c typetools.c destruct.cpp
  compile.c delcode.c symcode.c vminstr.c rwcode.c index.c 
  checkexpr.c polish.c grammar_tools.c nat.cpp optimize.c
  describe.c module_type.c
""")]

share_src = [os.path.join('build', 'share', x) for x in Split("""
  FileIO.cpp
  IniFile.cpp
  String.cpp
  DebugLog.cpp
  MultiPath.cpp
  StringList.cpp
  List.cpp
""")]

special_src = [os.path.join('build', x) for x in Split("""
  expr.cpp output.cpp main.cpp predef.c
""")]

cipher_src = [os.path.join('build', 'cipher', x) for x in Split("""
  blowfish.c sha1.c
""")]

if platform.system() == 'Windows':
  main_rc = [os.path.join('build', 'win32', x) for x in Split("""
    compiler.rc
  """)]
  share_src.extend([os.path.join('build', 'share', x) for x in Split("""
    win32stuff.cpp
  """)])
else:
  main_rc = []
  share_src.extend([os.path.join('build', 'share', x) for x in Split("""
    linuxstuff.cpp
  """)])

#
# scanner
#

grammar = env.CFile('src/grammar.tab.c', 'src/grammar.y', YACCFLAGS = '-l -v -d')
env.Depends(grammar, 'src/compil.h')


lexer = env.CFile('src/lex.yy.c', 'src/lexer.l')
env.Depends(lexer, grammar)
env.Depends(lexer, 'src/compil.h')

#
# shared objects
#
specialDefs = env['CPPDEFINES'].copy()
specialDefs['__STDC__'] = None
gammar_obj = env.StaticObject([ grammar[0] ] + lexer, CPPDEFINES= specialDefs)
main_obj = env.Object(main_src) + gammar_obj
share_obj = env.Object(share_src)
cipher_obj = env.Object(cipher_src)


#
# The 'private' Anubis compiler (used only by the developers)
# It is used for compiling 'predefined.anubis'
#
myenv = env.Clone()

specialDefs = env['CPPDEFINES'].copy()
specialDefs['myanubis'] = None
special_obj = myenv.Object(special_src, CPPDEFINES = specialDefs, OBJPREFIX = 'my_')
myenv.Ignore(special_obj, 'src/predef_npd.aux')
myanubis = myenv.Program('myanubis', main_obj + share_obj + special_obj + cipher_obj)

#
# Making the anubis predefine
#

#def predefEmitter(target, source, env):
#  return (['predef_npd.aux', 'predef.aux'], 
#          ['predef.anubis', os.path.join(env['DEVDIR'], 'library', 'predefined.anubis'), myanubis)

#predefBuilder = Builder(emitter = predefEmitter,
#                        action = 'build/myanubis -predef -Isrc')
#env.Append(BUILDERS = {'Predef' : predefBuilder})

predef = env.Command('src/predef_npd.aux', #['predef_npd.aux', 'predef.aux'],
                     ['src/predef.anubis', os.path.join(env['DEVDIR'], 'library', 'predefined.anubis'), myanubis],
                     [Delete(os.path.join('src', 'predef.aux')),
                      Delete("$TARGET"),
                      'cd src && ' + os.path.join('..', 'myanubis -predef')])
#cd src
#myanubis -predef
#in: src/predef.anubis library/predefined.anubis
#out: predef.aux predef.


#
# The Anubis compiler without predef.dat nor ankh/djed 
#
npdenv = env.Clone()

specialDefs = env['CPPDEFINES'].copy()
specialDefs['_no_predef_dat_'] = None
special_obj = npdenv.Object(special_src, CPPDEFINES = specialDefs, OBJPREFIX = 'npd_')
npdenv.Depends(special_obj, predef)
if platform.system() == 'Windows':
  rsc = npdenv.RES(main_rc)
else:
  rsc = []
anubis = npdenv.Program(compiler_output_name, main_obj + share_obj + special_obj + cipher_obj + rsc)

if platform.system() != 'Windows':
  if not debug:
    anubis = npdenv.Command('anubis', compiler_output_name, 'strip -o $TARGET $SOURCE')
  else:
    anubis = npdenv.Command('anubis', compiler_output_name, 'cp $SOURCE $TARGET')

if platform.system() != 'Windows':
  installPath = os.path.join(env['BASEDIR'], 'anubis_distrib', 'linux_install', 'bin')
  binDir = os.path.join(env['ENV']['HOME'], 'bin')
else:
  installPath = os.path.join(env['BASEDIR'], 'anubis_distrib', 'win32_install', 'bin')
  binDir = os.path.normpath(os.path.join(env['BASEDIR'], 'bin', 'anubis'))

env.Install(installPath, anubis)
env.Install(binDir, anubis)
env.Alias('install', [installPath, binDir])

env.Alias('all', [anubis, 'install'])
print 'BINDIR=', binDir
Default('all')




Help("""
Type: 'scons compiler' to build the production program,
      'scons debug' to build the debug version.
"""
  + opts.GenerateHelpText(env))

print 'BUILD_TARGETS is', map(str, BUILD_TARGETS)