|
| 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 | + tolua = "" |
| 86 | + if bootstrap: |
| 87 | + if os.name == 'nt': |
| 88 | + tolua = 'bin\\'+self['TOLUAPP_BOOTSTRAP'] |
| 89 | + else: |
| 90 | + tolua = 'bin/'+self['TOLUAPP_BOOTSTRAP'] |
| 91 | + print("********* tolua is ", tolua) |
| 92 | + else: |
| 93 | + if use_own: |
| 94 | + if 'msvc' in self['TOOLS']: |
| 95 | + tolua = 'bin\\$tolua_bin' |
| 96 | + else: |
| 97 | + tolua = 'bin/$tolua_bin' |
| 98 | + else: |
| 99 | + tolua = "$TOLUAPP" |
| 100 | + |
| 101 | + if pkgname: |
| 102 | + pkgname = ' -n '+pkgname |
| 103 | + else: |
| 104 | + pkgname = '' |
| 105 | + |
| 106 | + if use_typeid: |
| 107 | + tolua = tolua+' -t' |
| 108 | + |
| 109 | + comando = tolua + ' -C -H ' + pheader + ' -o ' + ptarget + pkgname + ' ' + psource |
| 110 | + command = self.Command(target, source, comando) |
| 111 | + |
| 112 | + self.SideEffect(header, target) |
| 113 | + self.Depends(target, source) |
| 114 | + |
| 115 | + self.pkg_scan_dep(target, psource) |
| 116 | + |
| 117 | + if bootstrap: |
| 118 | + self.Depends(target, "#/bin/$TOLUAPP_BOOTSTRAP") |
| 119 | + if use_own: |
| 120 | + self.Depends(target, "#/bin/$tolua_bin") |
| 121 | + |
| 122 | + return command |
| 123 | + |
| 124 | + |
| 125 | +env.__class__.LuaBinding = make_tolua_code; |
| 126 | +env.__class__.pkg_scan_dep = pkg_scan_dep; |
| 127 | + |
| 128 | +def print_install_error(target, source, env): |
| 129 | + |
| 130 | + msg = """Error: no install prefix was specified, or detected. |
| 131 | +
|
| 132 | +you can use the 'prefix' option on command line to specify one. Examples: |
| 133 | +
|
| 134 | + scons prefix=/usr/local install |
| 135 | +
|
| 136 | +or on Windows: |
| 137 | +
|
| 138 | + scons "prefix=c:\\program files\\visual basic" install |
| 139 | +
|
| 140 | +Files will be installed on <prefix>/bin, <prefix>/lib and <prefix>/include |
| 141 | +""" |
| 142 | + import SCons.Errors |
| 143 | + raise SCons.Errors.UserError(msg) |
| 144 | + |
| 145 | +########### end of helper builders |
| 146 | + |
| 147 | +env['CPPPATH'] = '#/include' |
| 148 | +env['LIBPATH'] = ['#/lib'] + env['LIBPATH'] |
| 149 | + |
| 150 | +if env['no_cygwin']: |
| 151 | + |
| 152 | + env['CCFLAGS'] += ['-mno-cygwin'] |
| 153 | + env['LINKFLAGS'] += ['-mno-cygwin'] |
| 154 | + |
| 155 | +import string |
| 156 | + |
| 157 | +Export('env') |
| 158 | + |
| 159 | +SConscript('src/lib/SCsub') |
| 160 | +SConscript('src/bin/SCsub') |
| 161 | +#SConscript('src/lib/SCsub') |
| 162 | +SConscript('src/tests/SCsub') |
| 163 | + |
| 164 | +env.Alias('all', [env.bin_target, env.lib_target]) |
| 165 | +env.Alias('test', env.test_targets) |
| 166 | + |
| 167 | +Default('all') |
| 168 | + |
| 169 | +if env['prefix']: |
| 170 | + env.Install(env['prefix']+'/bin', env.bin_target) |
| 171 | + env.Install(env['prefix']+'/lib', env.lib_target) |
| 172 | + env.Install(env['prefix']+'/include', '#include/tolua++.h') |
| 173 | + |
| 174 | + env.Alias('install', [env['prefix']+'/bin', env['prefix']+'/include', env['prefix']+'/lib']) |
| 175 | +else: |
| 176 | + env.Command('install', [], print_install_error) |
| 177 | + env.Depends('install', 'all') |
| 178 | + |
| 179 | +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) |
| 180 | + |
0 commit comments