Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: mongoose
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 196 lines (164 sloc) 6.711 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
# vim: set filetype=python:
import os
import subprocess
import platform
import re
import sys

from os.path import join, dirname, abspath
from types import DictType, StringTypes
from glob import glob

TORA_VERSION_STR='0.0.3'

AddOption('--prefix',
    dest='prefix',
    nargs=1,
    type='string',
    action='store',
    metavar='DIR',
    default='/usr/local/',
    help='installation prefix'
)

env = Environment(
    LIBS=['re2', 'pthread', 'dl'],
    LIBPATH=['./'],
    CXXFLAGS=['-std=c++0x'],
    CCFLAGS=['-Wall', '-Wno-sign-compare', '-Ivendor/boost_1_49_0/', '-I./vendor/re2/', '-fstack-protector', '-march=native', '-g',
        # '-DPERLISH_CLOSURE'
    ],
    PREFIX=GetOption('prefix')
)
print 'PREFIX: ' + env['PREFIX']
re2_env = Environment(
    CCFLAGS=['-pthread', '-Wno-sign-compare', '-O2', '-I./vendor/re2/'],
    LIBS=['pthread'],
)

if os.uname()[0]=='Darwin':
    re2_env.Replace(CXX='clang++', CC='clang')
    env.Replace(CXX='clang++', CC='clang')
    # env.Append(CXXFLAGS=['-Werror'])
    env.Append(
        CCFLAGS=['-Wno-unused-function', '-DBOOST_NO_CHAR16_T', '-DBOOST_NO_CHAR32_T'],
        CXXFLAGS=['-Wno-unneeded-internal-declaration'],
    )
else:
    re2_env.Replace(CXX='g++')
    env.Replace(CXX='g++')
    env.Append(
        LINKFLAGS=['-Wl,-E', '-Wl,-Bsymbolic', '-rdynamic'],
    )

if ARGUMENTS.get('glog', 0):
    env.Append(LIBS=['glog'], CCFLAGS=['-DENABLE_GLOG'])

if ARGUMENTS.get('profile', 0):
    env.Append(CXXFLAGS=['-pg', '-Dprofile'])
    env.Append(LINKFLAGS=['-pg'])

if ARGUMENTS.get('ndebug', 1) != '0':
    env.Append(CCFLAGS=['-DNDEBUG'])
    env.Append(CCFLAGS=['-O2'])
else:
    env.Append(CCFLAGS=['-O0'])

# scons debug=1
if ARGUMENTS.get('debug', 0):
    env.Append(CCFLAGS=['-g'])

re2files = [
    Glob('vendor/re2/re2/*.cc'),
    'vendor/re2/util/rune.cc',
    'vendor/re2/util/valgrind.cc',
    'vendor/re2/util/stringprintf.cc',
    'vendor/re2/util/strutil.cc',
    'vendor/re2/util/hash.cc',
    'vendor/re2/util/stringpiece.cc',
]
libfiles = [
    "tora/" + x for x in Split('''
parser.cc value.cc compiler.cc
node.cc op.cc vm.cc util.cc
symbol_table.cc package_map.cc frame.cc package.cc operator.cc
builtin.cc
object.cc pad_list.cc

ops.gen.cc token.gen.cc lexer.gen.cc vm.gen.cc nodes.gen.cc symbols.gen.cc

inspector.cc peek.cc disasm.cc

value/code.cc value/hash.cc value/str.cc value/array.cc value/regexp.cc value/range.cc
value/object.cc value/int.cc value/bool.cc value/exception.cc
value/bytes.cc

object/str.cc object/array.cc object/dir.cc object/stat.cc object/env.cc object/time.cc object/file.cc object/socket.cc object/internals.cc object/caller.cc object/code.cc object/symbol.cc
object/dynaloader.cc object/object.cc object/metaclass.cc
object/bytes.cc object/regexp.cc object/hash.cc
object/re2_regexp_matched.cc

''')
]


########
# tests.

programs = ['bin/tora']
for src in glob("tests/test_*.cc"):
    programs.append(env.Program(src.rstrip(".cc") + '.t', [
        libfiles,
        src,
    ]))

if 'test' in COMMAND_LINE_TARGETS:
    prefix = 'PERL5LIB=util/:$PERL5LIB '
    prove_path = 'prove'
    try:
        os.stat('/Users/tokuhirom/perl5/perlbrew/perls/perl-5.15.3/bin/prove') # throws exception if not exists
        prove_path = '/Users/tokuhirom/perl5/perlbrew/perls/perl-5.15.3/bin/prove'
    except: pass
    try:
        os.stat('/Users/tokuhirom/perl5/perlbrew/perls/perl-5.15.2/bin/prove')
        prove_path = '/Users/tokuhirom/perl5/perlbrew/perls/perl-5.15.2/bin/prove'
    except: pass
    env.Command('test', programs, prefix + " " + prove_path + ' --source Tora --source Executable -r tests/ t/tra/*.tra t/tra/*/*.tra --source Perl t')

env.Command('test.valgrind', ['bin/tora'], 'perl misc/valgrind.pl');

if 'bench' in COMMAND_LINE_TARGETS:
    env.Command('bench', [], 'git log --oneline | head -1 && scons ndebug=1 test && ./bin/tora -V && time ./bin/tora benchmark/fib/fib.tra 39')

if 'op' in COMMAND_LINE_TARGETS:
    env.Command('op', [], 'git log --oneline | head -1 && scons && ./bin/tora -V ; sudo opcontrol --reset; sudo opcontrol --start && time ./bin/tora benchmark/fib/fib.tra 39 ; sudo opcontrol --stop')

########
# main programs
env.Command(['tora/nodes.gen.h', 'tora/nodes.gen.cc'], 'tora/nodes.gen.pl', 'perl tora/nodes.gen.pl > tora/nodes.gen.h');
env.Command(['tora/token.gen.cc', 'tora/token.gen.h'], ['tora/token.gen.pl', 'tora/parser.h'], 'perl tora/token.gen.pl');
env.Command(['tora/lexer.gen.cc'], 'tora/lexer.re', 're2c tora/lexer.re > tora/lexer.gen.cc');
env.Command(['tora/vm.gen.cc', 'tora/ops.gen.h', 'tora/ops.gen.cc'], ['tora/vm.gen.pl', 'vm.inc'], 'perl -I misc/Text-MicroTemplate/ tora/vm.gen.pl > tora/vm.gen.cc');
env.Command(['tora/symbols.gen.cc', 'tora/symbols.gen.h'], ['tora/symbols.gen.pl'], 'perl -I misc/Text-MicroTemplate/ tora/symbols.gen.pl');
t = env.Command(['tora/parser.h', 'tora/parser.cc'], ['tools/lemon/lemon', 'tora/parser.yy', 'tora/lempar.c'], './tools/lemon/lemon tora/parser.yy');
Clean(t, 'tora/parser.out')

libre2 = re2_env.Library('re2', re2files)

TORA_PREFIX = env.get('PREFIX')
TORA_CC = env.get('CC')
TORA_CXX = env.get('CXX')
TORA_CCFLAGS = ' '.join(env.get('CCFLAGS'))
TORA_CXXFLAGS = ' '.join(env.get('CXXFLAGS'))
# config.h
with open('tora/config.h', 'w') as f:
    f.write("#pragma once\n")
    f.write('#define TORA_CCFLAGS "' + TORA_CCFLAGS + "\"\n")
    f.write('#define TORA_PREFIX "' + TORA_PREFIX + "\"\n")
    f.write('#define TORA_VERSION_STR "' + TORA_VERSION_STR + "\"\n")

with open('lib/Config.tra', 'w') as f:
    f.write("my $Config = {\n")
    f.write(" TORA_PREFIX => '" + TORA_PREFIX + "',\n")
    f.write(" TORA_CC => '" + TORA_CC + "',\n")
    f.write(" TORA_CXX => '" + TORA_CXX + "',\n")
    f.write(" TORA_CCFLAGS => '" + TORA_CCFLAGS + "',\n")
    f.write(" TORA_CXXFLAGS => '" + TORA_CXXFLAGS + "',\n")
    f.write(" TORA_VERSION_STR => '" + TORA_VERSION_STR + "',\n")
    f.write("};\n")
    f.write("sub tora_config() {\n")
    f.write(" $Config;\n")
    f.write("}\n")

tora = env.Program('bin/tora', [
    ['tora/main.cc'],
    libfiles,
    libre2
])
Default(tora)

env.Program('hoge', [
    ['hoge.cc'],
    libre2
])

# lemon
lemon_env = Environment()
lemon_env.Append(CCFLAGS=['-O2'])
lemon_env.Program('tools/lemon/lemon', ['tools/lemon/lemon.c']);

# instalation
installs = []
installs += [env.Install(env['PREFIX']+'/bin/', 'bin/tora')];
installs+=[env.InstallAs(env['PREFIX']+'/lib/tora-'+TORA_VERSION_STR, 'lib/')]
env.Alias('install', [env['PREFIX']+'/bin/', installs])

Something went wrong with that request. Please try again.