| 1 |
import sys; |
| 2 |
import os |
| 3 |
|
| 4 |
tools = ['default'] |
| 5 |
if os.name == 'nt': |
| 6 |
tools = ['mingw'] |
| 7 |
|
| 8 |
env = Environment(tools = tools) |
| 9 |
|
| 10 |
options_file = None |
| 11 |
if sys.platform == 'linux2': |
| 12 |
options_file = "linux" |
| 13 |
|
| 14 |
elif 'msvc' in env['TOOLS']: |
| 15 |
options_file = "msvc" |
| 16 |
else: |
| 17 |
options_file = "posix" |
| 18 |
|
| 19 |
opts = Options(["config_"+options_file+".py", "custom.py", "custom_"+options_file+".py"], ARGUMENTS) |
| 20 |
opts.Add('CC', 'The C compiler.') |
| 21 |
opts.Add('CXX', 'The C++ compiler (for the tests)') |
| 22 |
opts.Add('CCFLAGS', 'Flags for the compiler.', ['-O2', '-Wall']) |
| 23 |
opts.Add('LINK', 'The linker.') |
| 24 |
opts.Add('LINKFLAGS', 'Linker flags.', []) |
| 25 |
opts.Add('no_cygwin', 'Use -mno-cygwin to build using the mingw compiler on cygwin', 0) |
| 26 |
opts.Add('LIBS', 'libraries', []) |
| 27 |
opts.Add('LIBPATH', 'library path', []) |
| 28 |
|
| 29 |
opts.Add('tolua_bin', 'the resulting binary', 'tolua++') |
| 30 |
opts.Add('tolua_lib', 'the resulting library', 'tolua++') |
| 31 |
opts.Add('TOLUAPP', 'the name of the tolua++ binary (to use with built_dev=1)', 'tolua++') |
| 32 |
|
| 33 |
opts.Add('prefix', 'The installation prefix') |
| 34 |
opts.Add('build_dev', 'Build for development (uses tolua to rebuild toluabind.c with the embeded scripts', 0) |
| 35 |
opts.Add('build_failsafe', "Build using 'factory default' toluabind file (in case build_dev fails)", 0) |
| 36 |
opts.Add('ENV', 'The environment variables') |
| 37 |
opts.Add('shared', 'Build a shared object', False) |
| 38 |
opts.Update(env) |
| 39 |
Help(opts.GenerateHelpText(env)) |
| 40 |
|
| 41 |
def save_config(target, source, env): |
| 42 |
opts.Save('custom.py', env) |
| 43 |
|
| 44 |
cust = env.Command('custom.py', [], save_config) |
| 45 |
env.Alias('configure', [cust]) |
| 46 |
|
| 47 |
env['TOLUAPP_BOOTSTRAP'] = env['tolua_bin']+"_bootstrap"+env['PROGSUFFIX'] |
| 48 |
|
| 49 |
env['build_dev'] = int(env['build_dev']) |
| 50 |
|
| 51 |
## detecting the install directory on win32 |
| 52 |
if 'msvc' in env['TOOLS'] and not (env.has_key('prefix') or env['prefix']): |
| 53 |
|
| 54 |
if env['MSVS'].has_key('PLATFORMSDKDIR'): |
| 55 |
env['prefix'] = env['MSVS']['PLATFORMSDKDIR'] |
| 56 |
|
| 57 |
|
| 58 |
SConscriptChdir(0) |
| 59 |
|
| 60 |
############ helper builders |
| 61 |
def pkg_scan_dep(self, target, source): |
| 62 |
|
| 63 |
import re |
| 64 |
|
| 65 |
## TODO: detectar si el archivo existe antes de abrirlo asi nomas |
| 66 |
pkg = open(source, "rt") |
| 67 |
|
| 68 |
for linea in pkg.xreadlines(): |
| 69 |
dep = re.search("^[\t\w]*\$[cphl]file\s*\"([^\"]+)\"", linea) |
| 70 |
if dep: |
| 71 |
self.Depends(target, '#' + dep.groups()[0]); |
| 72 |
|
| 73 |
if dep.groups()[0][-4:] == '.pkg': |
| 74 |
# recursividad |
| 75 |
self.pkg_scan_dep(target, dep.groups()[0]) |
| 76 |
|
| 77 |
|
| 78 |
def make_tolua_code(self, target, source, pkgname = None, bootstrap = False, use_own = False, use_typeid=None): |
| 79 |
|
| 80 |
ptarget = Dir('.').path + '/' + target |
| 81 |
psource = Dir('.').path + '/' + source |
| 82 |
header = target[:-2] + '.h' |
| 83 |
pheader = Dir('.').path + '/' + header |
| 84 |
|
| 85 |
print("Generating ", target, " from ", source) |
| 86 |
|
| 87 |
tolua = "" |
| 88 |
if bootstrap: |
| 89 |
if os.name == 'nt': |
| 90 |
tolua = 'bin\\'+self['TOLUAPP_BOOTSTRAP'] |
| 91 |
else: |
| 92 |
tolua = 'bin/'+self['TOLUAPP_BOOTSTRAP'] |
| 93 |
print("********* tolua is ", tolua) |
| 94 |
else: |
| 95 |
if use_own: |
| 96 |
if 'msvc' in self['TOOLS']: |
| 97 |
tolua = 'bin\\$tolua_bin' |
| 98 |
else: |
| 99 |
tolua = 'bin/$tolua_bin' |
| 100 |
else: |
| 101 |
tolua = "$TOLUAPP" |
| 102 |
|
| 103 |
if pkgname: |
| 104 |
pkgname = ' -n '+pkgname |
| 105 |
else: |
| 106 |
pkgname = '' |
| 107 |
|
| 108 |
if use_typeid: |
| 109 |
tolua = tolua+' -t' |
| 110 |
|
| 111 |
comando = tolua + ' -C -H ' + pheader + ' -o ' + ptarget + pkgname + ' ' + psource |
| 112 |
command = self.Command(target, source, comando) |
| 113 |
|
| 114 |
self.SideEffect(header, target) |
| 115 |
self.Depends(target, source) |
| 116 |
|
| 117 |
self.pkg_scan_dep(target, psource) |
| 118 |
|
| 119 |
if bootstrap: |
| 120 |
self.Depends(target, "#/bin/$TOLUAPP_BOOTSTRAP") |
| 121 |
if use_own: |
| 122 |
self.Depends(target, "#/bin/$tolua_bin") |
| 123 |
|
| 124 |
return command |
| 125 |
|
| 126 |
|
| 127 |
env.__class__.LuaBinding = make_tolua_code; |
| 128 |
env.__class__.pkg_scan_dep = pkg_scan_dep; |
| 129 |
|
| 130 |
def print_install_error(target, source, env): |
| 131 |
|
| 132 |
msg = """Error: no install prefix was specified, or detected. |
| 133 |
|
| 134 |
you can use the 'prefix' option on command line to specify one. Examples: |
| 135 |
|
| 136 |
scons prefix=/usr/local install |
| 137 |
|
| 138 |
or on Windows: |
| 139 |
|
| 140 |
scons "prefix=c:\\program files\\visual basic" install |
| 141 |
|
| 142 |
Files will be installed on <prefix>/bin, <prefix>/lib and <prefix>/include |
| 143 |
""" |
| 144 |
import SCons.Errors |
| 145 |
raise SCons.Errors.UserError(msg) |
| 146 |
|
| 147 |
########### end of helper builders |
| 148 |
|
| 149 |
env['CPPPATH'] = '#/include' |
| 150 |
env['LIBPATH'] = ['#/lib'] + env['LIBPATH'] |
| 151 |
|
| 152 |
if env['no_cygwin']: |
| 153 |
|
| 154 |
env['CCFLAGS'] += ['-mno-cygwin'] |
| 155 |
env['LINKFLAGS'] += ['-mno-cygwin'] |
| 156 |
|
| 157 |
import string |
| 158 |
|
| 159 |
Export('env') |
| 160 |
|
| 161 |
SConscript('src/lib/SCsub') |
| 162 |
SConscript('src/bin/SCsub') |
| 163 |
#SConscript('src/lib/SCsub') |
| 164 |
SConscript('src/tests/SCsub') |
| 165 |
|
| 166 |
env.Alias('all', [env.bin_target, env.lib_target]) |
| 167 |
env.Alias('test', env.test_targets) |
| 168 |
|
| 169 |
Default('all') |
| 170 |
|
| 171 |
if env['prefix']: |
| 172 |
env.Install(env['prefix']+'/bin', env.bin_target) |
| 173 |
env.Install(env['prefix']+'/lib', env.lib_target) |
| 174 |
env.Install(env['prefix']+'/include', '#include/tolua++.h') |
| 175 |
|
| 176 |
env.Alias('install', [env['prefix']+'/bin', env['prefix']+'/include', env['prefix']+'/lib']) |
| 177 |
else: |
| 178 |
env.Command('install', [], print_install_error) |
| 179 |
env.Depends('install', 'all') |
| 180 |
|
| 181 |
env.Command('deb', [], 'dpkg-buildpackage -I.svn -Icustom.py -Itoluabind_dev.c -Itoluabind_dev.h -Itoluabind_default.o -Icustom.lua -I.sconsign', ENV=os.environ) |
| 182 |
|