New SConscript (hopefully better)
Fixes a lot of bugs, also almost all options are no longer needed and are just auto-detected
This commit is contained in:
parent
44405827b0
commit
6749c2547f
869
SConscript
Executable file → Normal file
869
SConscript
Executable file → Normal file
@ -1,39 +1,15 @@
|
||||
# ============
|
||||
# SCons script
|
||||
# ============
|
||||
|
||||
# the purpose of this script is to run a build of tpt from start to finish, including dependency checks.
|
||||
|
||||
# .. contents :: Table of Contents
|
||||
|
||||
# ============
|
||||
# requirements
|
||||
# ============
|
||||
|
||||
import SCons.Util
|
||||
|
||||
# stdlib
|
||||
# ======
|
||||
|
||||
import os
|
||||
import sys
|
||||
import subprocess
|
||||
import sys
|
||||
import platform
|
||||
import atexit
|
||||
import time
|
||||
import SCons.Util
|
||||
|
||||
# 3rd party
|
||||
# =========
|
||||
|
||||
# nothing besides scons.
|
||||
|
||||
# =================
|
||||
# long commandlines
|
||||
# =================
|
||||
|
||||
# .. : Fix for long command line - http://scons.org/wiki/LongCmdLinesOnWin32
|
||||
|
||||
# because of an implementation detail commandlines are limited to 10000 characters on windows using mingw. the following fix was copied from
|
||||
# http://scons.org/wiki/LongCmdLinesOnWin32 and circumvents this issue.
|
||||
|
||||
class ourSpawn:
|
||||
def ourspawn(self, sh, escape, cmd, args, env):
|
||||
newargs = ' '.join(args[1:])
|
||||
@ -49,499 +25,502 @@ class ourSpawn:
|
||||
print err
|
||||
print "====="
|
||||
return rv
|
||||
|
||||
def SetupSpawn( env ):
|
||||
if sys.platform == 'win32':
|
||||
def SetupSpawn(env):
|
||||
buf = ourSpawn()
|
||||
buf.ourenv = env
|
||||
env['SPAWN'] = buf.ourspawn
|
||||
|
||||
# ===================
|
||||
# commandline options
|
||||
# ===================
|
||||
|
||||
# the following defines all optional commandlines
|
||||
|
||||
AddOption('--opengl',dest="opengl",action='store_true',default=False,help="Build with OpenGL interface support.")
|
||||
AddOption('--opengl-renderer',dest="opengl-renderer",action='store_true',default=False,help="Build with OpenGL renderer support. (requires --opengl)")
|
||||
AddOption('--renderer',dest="renderer",action='store_true',default=False,help="Save renderer")
|
||||
AddOption('--64bit',dest="_64bit",action='store_true',default=False,help="64-bit platform target")
|
||||
AddOption('--32bit',dest="_32bit",action='store_true',default=False,help="32-bit platform target")
|
||||
AddOption('--static',dest="static",action="store_true",default=False,help="Static linking, reduces external library dependancies but increased file size")
|
||||
AddOption('--pthreadw32-static',dest="ptw32-static",action="store_true",default=False,help="Use PTW32_STATIC_LIB for pthreadw32 headers")
|
||||
AddOption('--python-ver',dest="pythonver",default=False,help="Python version to use for generator.py")
|
||||
AddOption('--release',dest="release",action='store_true',default=False,help="Enable optimisations (Will slow down compiling)")
|
||||
AddOption('--lua-dir',dest="lua-dir",default=False,help="Directory for lua includes")
|
||||
AddOption('--sdl-dir',dest="sdl-dir",default=False,help="Directory for SDL includes")
|
||||
AddOption('--tool',dest="toolprefix",default=False,help="Prefix")
|
||||
AddOption('--sse',dest="sse",action='store_true',default=False,help="Enable SSE optimisations")
|
||||
AddOption('--sse2',dest="sse2",action='store_true',default=False,help="Enable SSE2 optimisations")
|
||||
AddOption('--sse3',dest="sse3",action='store_true',default=False,help="Enable SSE3 optimisations")
|
||||
AddOption('--x86',dest="x86",action='store_true',default=True,help="Target Intel x86 platform")
|
||||
AddOption('--nofft',dest="nofft", action='store_true',default=False,help="Do not use fftw3f for gravity.")
|
||||
AddOption('--nolua',dest="nolua", action='store_true',default=False,help="Disable all lua scripting features.")
|
||||
|
||||
AddOption('--warnings-as-errors', dest="warnings_as_errors", action="store_true", default=False, help="Treat all warnings as errors")
|
||||
AddOption('--debugging', dest="debug", action="store_true", default=False, help="Enable debug options")
|
||||
AddOption('--beta',dest="beta",action='store_true',default=False,help="Beta build.")
|
||||
AddOption('--save-version',dest="save-version",default=False,help="Save version.")
|
||||
AddOption('--minor-version',dest="minor-version",default=False,help="Minor version.")
|
||||
AddOption('--build-number',dest="build-number",default=False,help="Build number.")
|
||||
AddOption('--snapshot',dest="snapshot",action='store_true',default=False,help="Snapshot build.")
|
||||
AddOption('--snapshot-id',dest="snapshot-id",default=False,help="Snapshot build ID.")
|
||||
AddOption('--stable',dest="stable",default=True,help="Non snapshot build")
|
||||
AddOption('--aao', dest="everythingAtOnce", action='store_true', default=False, help="Compile the whole game without generating intermediate objects (very slow), enable this when using compilers like clang or mscc that don't support -fkeep-inline-functions")
|
||||
|
||||
AddOption('--fullclean',dest="justwork",action='store_true',default=False,help="for when nothing else works. Deletes all sconscript temporary files.")
|
||||
AddOption('--copy-env',dest="copy_env",action='store_true',default=False,help="copy some common enviroment variables from the parent enviroment.")
|
||||
|
||||
# using one of these commandline options is compulsory
|
||||
|
||||
AddOption('--win',dest="win",action='store_true',default=False,help="Windows platform target.")
|
||||
AddOption('--lin',dest="lin",action='store_true',default=False,help="Linux platform target")
|
||||
AddOption('--macosx',dest="macosx",action='store_true',default=False,help="Mac OS X platform target")
|
||||
AddOption('--rpi',dest="rpi",action='store_true',default=False,help="Raspbain platform target")
|
||||
|
||||
# ============
|
||||
# main program
|
||||
# ============
|
||||
|
||||
# the gist of the compiling rules are defined here
|
||||
|
||||
|
||||
if(GetOption("justwork")):
|
||||
import shutil
|
||||
try:
|
||||
shutil.rmtree("../.sconf_temp/")
|
||||
except:
|
||||
print "couldn't remove .sconf_temp"
|
||||
try:
|
||||
os.remove("../.sconsign.dblite")
|
||||
except:
|
||||
print "couldn't remove .sconsign.dblite"
|
||||
|
||||
# platform selection
|
||||
# ==================
|
||||
|
||||
# generic platform settings
|
||||
# +++++++++++++++++++++++++
|
||||
|
||||
# check if a platform is specified.
|
||||
# .. : TODO: make it suggest commandline options if it isn't
|
||||
|
||||
if((not GetOption('lin')) and (not GetOption('win')) and (not GetOption('rpi')) and (not GetOption('macosx'))):
|
||||
print "You must specify a platform to target"
|
||||
def FatalError(message):
|
||||
print(message)
|
||||
raise SystemExit(1)
|
||||
|
||||
# windows specific platform settings
|
||||
# ++++++++++++++++++++++++++++++++++
|
||||
#wrapper around SCons' AddOption
|
||||
def AddSconsOption(name, default, hasArgs, help):
|
||||
AddOption("--{0}".format(name), dest=name, action=("store" if hasArgs else "store_true"), default=default, help=help)
|
||||
|
||||
# if the platform is windows switch to a mingw toolset, use the default otherwise
|
||||
AddSconsOption('win', False, False, "Target Windows")
|
||||
AddSconsOption('lin', False, False, "Target Linux")
|
||||
AddSconsOption('mac', False, False, "Target Mac OS X")
|
||||
AddSconsOption('msvc', False, False, "Use the Microsoft Visual Studio compiler")
|
||||
AddSconsOption("tool", False, True, "Tool prefix appended before gcc/g++")
|
||||
|
||||
if(GetOption('win')):
|
||||
env = Environment(tools = ['mingw'], ENV = os.environ)
|
||||
AddSconsOption('beta', False, False, "Beta build.")
|
||||
AddSconsOption('save-version', False, True, "Save version.")
|
||||
AddSconsOption('minor-version', False, True, "Minor version.")
|
||||
AddSconsOption('build-number', False, True, "Build number.")
|
||||
AddSconsOption('snapshot', False, False, "Snapshot build.")
|
||||
AddSconsOption('snapshot-id', False, True, "Snapshot build ID.")
|
||||
|
||||
AddSconsOption('64bit', False, False, "Compile a 64 bit binary")
|
||||
AddSconsOption('32bit', False, False, "Compile a 32 bit binary")
|
||||
AddSconsOption("universal", False, False, "compile universal binaries on Mac OS X")
|
||||
AddSconsOption('no-sse', False, False, "Disable SSE optimizations")
|
||||
AddSconsOption('sse', True, False, "Enable SSE optimizations (default)")
|
||||
AddSconsOption('sse2', True, False, "Enable SSE2 optimizations (default)")
|
||||
AddSconsOption('sse3', False, False, "Enable SSE3 optimizations")
|
||||
AddSconsOption('native', False, False, "Enable optimizations specific to your cpu")
|
||||
AddSconsOption('release', True, False, "Enable loop / compiling optimizations (default)")
|
||||
|
||||
AddSconsOption('debugging', False, False, "Compile with debug symbols")
|
||||
AddSconsOption('static', False, False, "Compile statically")
|
||||
AddSconsOption('opengl', False, False, "Build with OpenGL interface support")
|
||||
AddSconsOption('opengl-renderer', False, False, "Build with OpenGL renderer support (turns on --opengl)") #Note: this has nothing to do with --renderer, only tells the game to render particles with opengl
|
||||
AddSconsOption('renderer', False, False, "Build the save renderer")
|
||||
|
||||
AddSconsOption('wall', False, False, "Error on all warnings")
|
||||
AddSconsOption('no-warnings', True, False, "Disable all compiler warnings (default)")
|
||||
AddSconsOption('nolua', False, False, "Target Linux")
|
||||
AddSconsOption('nofft', False, False, "Target Mac OS X")
|
||||
AddSconsOption("output", False, True, "Executable output name")
|
||||
|
||||
|
||||
#detect platform automatically, but it can be overrided
|
||||
tool = GetOption('tool')
|
||||
isX86 = platform.machine() in ["AMD64", "i386", "i686", "x86", "x86_64"]
|
||||
platform = compilePlatform = platform.system()
|
||||
if GetOption('win'):
|
||||
platform = "Windows"
|
||||
elif GetOption('lin'):
|
||||
platform = "Linux"
|
||||
elif GetOption('mac'):
|
||||
platform = "Darwin"
|
||||
elif compilePlatform not in ["Linux", "Windows", "Darwin"]:
|
||||
FatalError("Unknown platform: {0}".format(platform))
|
||||
|
||||
msvc = GetOption('msvc')
|
||||
if msvc and platform != "Windows":
|
||||
FatalError("Error: --msvc only works on windows")
|
||||
|
||||
#Create SCons Environment
|
||||
if platform == "Windows" and not GetOption('msvc'):
|
||||
env = Environment(tools = ['mingw'], ENV = {'PATH' : os.environ['PATH']})
|
||||
else:
|
||||
env = Environment(tools = ['default'], ENV = os.environ)
|
||||
env = Environment(tools = ['default'], ENV = {'PATH' : os.environ['PATH']})
|
||||
|
||||
if(GetOption("copy_env")):
|
||||
singlevar=["CC","CXX","LD","LIBPATH"]
|
||||
multivar=["CFLAGS","CCFLAGS","LINKFLAGS"] # variables containing several space separated things
|
||||
for var in singlevar:
|
||||
#attempt to automatically find cross compiler
|
||||
if not tool and compilePlatform == "Linux" and compilePlatform != platform:
|
||||
if platform == "Darwin":
|
||||
crossList = ["i686-apple-darwin9", "i686-apple-darwin10"]
|
||||
elif not GetOption('64bit'):
|
||||
crossList = ["mingw32", "i386-mingw32msvc", "i486-mingw32msvc", "i586-mingw32msvc", "i686-mingw32msvc"]
|
||||
else:
|
||||
crossList = ["x86_64-w64-mingw32", "i686-w64-mingw32", "amd64-mingw32msvc"]
|
||||
for i in crossList:
|
||||
if WhereIs("{}-g++".format(i)):
|
||||
env['ENV']['PATH'] = "/usr/{0}/bin:{1}".format(i, os.environ['PATH'])
|
||||
tool = i+"-"
|
||||
break
|
||||
if not tool:
|
||||
print("Could not automatically find cross compiler, use --tool to specify manually")
|
||||
|
||||
#set tool prefix
|
||||
#more things may to be set (http://clam-project.org/clam/trunk/CLAM/scons/sconstools/crossmingw.py), but this works for us
|
||||
if tool:
|
||||
env['CC'] = tool+env['CC']
|
||||
env['CXX'] = tool+env['CXX']
|
||||
if platform == "Windows":
|
||||
env['RC'] = tool+env['RC']
|
||||
env['STRIP'] = tool+'strip'
|
||||
|
||||
#copy environment variables because scons doesn't do this by default
|
||||
for var in ["CC","CXX","LD","LIBPATH"]:
|
||||
if var in os.environ:
|
||||
env[var] = os.environ[var]
|
||||
print "WARNING: copying enviroment variable {}={!r}".format(var,os.environ[var])
|
||||
for var in multivar:
|
||||
print "copying enviroment variable {}={!r}".format(var,os.environ[var])
|
||||
# variables containing several space separated things
|
||||
for var in ["CFLAGS","CCFLAGS","CXXFLAGS","LINKFLAGS","CPPDEFINES","CPPPATH"]:
|
||||
if var in os.environ:
|
||||
if var in env:
|
||||
env[var] += SCons.Util.CLVar(os.environ[var])
|
||||
print "WARNING: copying enviroment variable {}={!r}".format(var,os.environ[var])
|
||||
|
||||
# macosx specific platform settings
|
||||
# +++++++++++++++++++++++++++++++++
|
||||
|
||||
# if we're not on MACOSX check for headers etc
|
||||
|
||||
if not GetOption("macosx"):
|
||||
conf = Configure(env)
|
||||
|
||||
# if sdl-dir is set check if we can find the sdl header there, if we can't just pass the header path to the compiler.
|
||||
|
||||
if(GetOption("sdl-dir")):
|
||||
if not conf.CheckCHeader(GetOption("sdl-dir") + '/SDL.h'):
|
||||
print "sdl headers not found or not installed"
|
||||
raise SystemExit(1)
|
||||
else:
|
||||
env.Append(CPPPATH=[GetOption("sdl-dir")])
|
||||
env[var] = SCons.Util.CLVar(os.environ[var])
|
||||
print "copying enviroment variable {}={!r}".format(var,os.environ[var])
|
||||
|
||||
#Used for intro text / executable name, actual bit flags are only set if the --64bit/--32bit command line args are given
|
||||
def add32bitflags(env):
|
||||
env.Append(CPPDEFINES='_32BIT')
|
||||
env["BIT"] = 32
|
||||
def add64bitflags(env):
|
||||
if platform == "Windows":
|
||||
env.Append(CPPDEFINES='__CRT__NO_INLINE')
|
||||
env.Append(LINKFLAGS='-Wl,--stack=16777216')
|
||||
env.Append(CPPDEFINES='_64BIT')
|
||||
env["BIT"] = 64
|
||||
#add 32/64 bit defines before configuration
|
||||
if GetOption('64bit'):
|
||||
env.Append(LINKFLAGS='-m64')
|
||||
env.Append(CCFLAGS='-m64')
|
||||
add64bitflags(env)
|
||||
elif GetOption('32bit'):
|
||||
env.Append(LINKFLAGS='-m32')
|
||||
env.Append(CCFLAGS='-m32')
|
||||
add32bitflags(env)
|
||||
|
||||
if GetOption('universal'):
|
||||
if platform != "Darwin":
|
||||
FatalError("Error: --universal only works on Mac OS X")
|
||||
else:
|
||||
env.Append(CCFLAGS=['-arch', 'i386', '-arch', 'x86_64'])
|
||||
env.Append(LINKFLAGS=['-arch', 'i386', '-arch', 'x86_64'])
|
||||
|
||||
# otherwise try to parse the pkg config for sdl and grab the correct flags from there.
|
||||
env.Append(CPPPATH=['src/', 'data/', 'generated/'])
|
||||
if GetOption("msvc"):
|
||||
if GetOption("static"):
|
||||
env.Append(LIBPATH='StaticLibs/')
|
||||
else:
|
||||
env.Append(LIBPATH='Libraries/')
|
||||
|
||||
#Check 32/64 bit
|
||||
def CheckBit(context):
|
||||
context.Message('Checking if 64 bit... ')
|
||||
program = """#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
int main() {
|
||||
printf("%d", (int)sizeof(size_t));
|
||||
return 0;
|
||||
}
|
||||
"""
|
||||
ret = context.TryCompile(program, '.c')
|
||||
if ret == 0:
|
||||
return False
|
||||
ret = context.TryRun(program, '.c')
|
||||
if ret[1] == '':
|
||||
return False
|
||||
context.Result(int(ret[1]) == 8)
|
||||
if int(ret[1]) == 8:
|
||||
print("Adding 64 bit compile flags")
|
||||
add64bitflags(context.env)
|
||||
elif int(ret[1]) == 4:
|
||||
print("Adding 32 bit compile flags")
|
||||
add32bitflags(context.env)
|
||||
return ret[1]
|
||||
|
||||
#Custom function to check for Mac OS X frameworks
|
||||
def CheckFramework(context, framework):
|
||||
import SCons.Conftest
|
||||
#Extreme hack, TODO: maybe think of a better one (like replicating CheckLib here) or at least just fix the message
|
||||
ret = SCons.Conftest.CheckLib(context, ['m" -framework {}"'.format(framework)], autoadd = 0)
|
||||
context.did_show_result = 1
|
||||
if not ret:
|
||||
context.env.Append(LINKFLAGS=["-framework", framework])
|
||||
if framework != "Cocoa":
|
||||
env.Append(CPPPATH=['/Library/Frameworks/{}.framework/Headers/'.format(framework)])
|
||||
return not ret
|
||||
|
||||
#function that finds libraries and appends them to LIBS
|
||||
def findLibs(env, conf):
|
||||
#Windows specific libs
|
||||
if platform == "Windows":
|
||||
if msvc:
|
||||
libChecks = ['shell32', 'wsock32', 'user32', 'Advapi32']
|
||||
if GetOption('static'):
|
||||
libChecks += ['msvcrt', 'dxguid']
|
||||
for i in libChecks:
|
||||
if not conf.CheckLib(i):
|
||||
FatalError("Error: some windows libraries not found or not installed, make sure your compiler is set up correctly")
|
||||
else:
|
||||
if not conf.CheckLib('mingw32') or not conf.CheckLib('ws2_32'):
|
||||
FatalError("Error: some windows libraries not found or not installed, make sure your compiler is set up correctly")
|
||||
|
||||
if not conf.CheckLib('SDLmain'):
|
||||
FatalError("libSDLmain not found or not installed")
|
||||
|
||||
if platform == "Darwin":
|
||||
if not conf.CheckFramework("SDL"):
|
||||
FatalError("SDL framework not found or not installed")
|
||||
elif not GetOption('renderer'):
|
||||
if platform != "Darwin":
|
||||
#Look for SDL
|
||||
if not conf.CheckLib("SDL"):
|
||||
FatalError("SDL development library not found or not installed")
|
||||
if platform == "Linux" or compilePlatform == "Linux":
|
||||
try:
|
||||
env.ParseConfig('sdl-config --cflags')
|
||||
env.ParseConfig('sdl-config --libs')
|
||||
except:
|
||||
if not conf.CheckLib("SDL"):
|
||||
print "libSDL not found or not installed"
|
||||
raise SystemExit(1)
|
||||
pass
|
||||
|
||||
|
||||
# if lua is enabled try to parse the lua pgk-config, or the lua-dir option if given
|
||||
|
||||
if not GetOption("nolua"):
|
||||
if(GetOption("lua-dir")):
|
||||
if not conf.CheckCHeader(GetOption("lua-dir") + '/lua.h'):
|
||||
print "lua5.1 headers not found or not installed"
|
||||
raise SystemExit(1)
|
||||
#look for SDL.h
|
||||
if not GetOption('renderer') and not conf.CheckCHeader('SDL.h'):
|
||||
if conf.CheckCHeader('SDL/SDL.h'):
|
||||
env.Append(CPPDEFINES=["SDL_INC"])
|
||||
else:
|
||||
env.Append(CPPPATH=[GetOption("lua-dir")])
|
||||
FatalError("SDL.h not found")
|
||||
|
||||
if not GetOption('nolua') and not GetOption('renderer'):
|
||||
#Look for Lua
|
||||
if not conf.CheckLib(['lua5.1', 'lua-5.1', 'lua51', 'lua']):
|
||||
if platform != "Darwin" or not conf.CheckFramework("Lua"):
|
||||
FatalError("lua5.1 development library not found or not installed")
|
||||
if platform == "Linux":
|
||||
try:
|
||||
env.ParseConfig('pkg-config --cflags lua5.1')
|
||||
env.ParseConfig('pkg-config --libs lua5.1')
|
||||
except:
|
||||
#Check for Lua lib
|
||||
if not conf.CheckLib('lua5.1') and not conf.CheckLib('lua-5.1') and not conf.CheckLib('lua51') and not conf.CheckLib('lua'):
|
||||
print "liblua5.1 not found or not installed"
|
||||
raise SystemExit(1)
|
||||
pass
|
||||
|
||||
# if fft is enabled try to parse its config, fail otherwise.
|
||||
#Look for lua.h
|
||||
if not conf.CheckCHeader('lua.h'):
|
||||
if conf.CheckCHeader('lua5.1/lua.h'):
|
||||
env.Append(CPPDEFINES=["LUA_INC"])
|
||||
else:
|
||||
FatalError("lua.h not found")
|
||||
|
||||
if not GetOption('nofft'):
|
||||
# Check for FFT lib
|
||||
if not conf.CheckLib('fftw3f') and not conf.CheckLib('fftw3f-3'):
|
||||
print "libfftw3f not found or not installed"
|
||||
raise SystemExit(1)
|
||||
#Look for fftw
|
||||
if not GetOption('nofft') and not conf.CheckLib(['fftw3f', 'fftw3f-3', 'libfftw3f-3']):
|
||||
FatalError("fftw3f development library not found or not installed")
|
||||
|
||||
# try to autodetect some libraries, fail otherwise
|
||||
#Look for bz2
|
||||
if not conf.CheckLib(['bz2', 'libbz2']):
|
||||
FatalError("bz2 development library not found or not installed")
|
||||
|
||||
#Check for Bzip lib
|
||||
if not conf.CheckLib('bz2'):
|
||||
print "libbz2 not found or not installed"
|
||||
raise SystemExit(1)
|
||||
#Check bz2 header too for some reason
|
||||
if not conf.CheckCHeader('bzlib.h'):
|
||||
FatalError("bzip2 headers not found")
|
||||
|
||||
#Check for zlib
|
||||
#Look for libz
|
||||
if not conf.CheckLib('z'):
|
||||
print "libz not found or not installed"
|
||||
raise SystemExit(1)
|
||||
FatalError("libz not found or not installed")
|
||||
|
||||
if not conf.CheckCHeader("bzlib.h"):
|
||||
print "bzip2 headers not found"
|
||||
raise SystemExit(1)
|
||||
#Look for pthreads
|
||||
if not conf.CheckLib(['pthread', 'pthreadVC2']):
|
||||
FatalError("pthreads development library not found or not installed")
|
||||
|
||||
# finish the configuration
|
||||
if msvc:
|
||||
if not conf.CheckHeader('dirent.h') or not conf.CheckHeader('fftw3.h') or not conf.CheckHeader('pthread.h') or not conf.CheckHeader('sched.h') or not conf.CheckHeader('zlib.h'):
|
||||
FatalError("Required headers not found")
|
||||
else:
|
||||
#Look for libm
|
||||
if not conf.CheckLib('m'):
|
||||
FatalError("libm not found or not installed")
|
||||
|
||||
env = conf.Finish();
|
||||
else:
|
||||
#Look for OpenGL libraries
|
||||
if GetOption('opengl'):
|
||||
if platform == "Linux":
|
||||
if not conf.CheckLib('GL'):
|
||||
FatalError("libGL not found or not installed")
|
||||
try:
|
||||
env.ParseConfig('pkg-config --libs glew gl glu')
|
||||
except:
|
||||
FatalError(sys.exc_info()[0])
|
||||
|
||||
# if we ARE on macosx add the libraries to LIBS
|
||||
# .. : seems like we're terrible at mac support? what gives?
|
||||
elif platform == "Windows":
|
||||
if not conf.CheckLib('opengl32'):
|
||||
FatalError("opengl32 not found or not installed")
|
||||
if not conf.CheckLib('glew32'):
|
||||
FatalError("glew32 not found or not installed")
|
||||
elif platform == "Darwin":
|
||||
if not conf.CheckFramework("OpenGL"):
|
||||
FatalError("OpenGL framework not found or not installed")
|
||||
|
||||
env.Append(LIBS=['z', 'bz2'])
|
||||
if not GetOption('nofft'):
|
||||
env.Append(LIBS=['fftw3f'])
|
||||
if platform == "Linux":
|
||||
if not conf.CheckLib('X11'):
|
||||
FatalError("X11 development library not found or not installed")
|
||||
|
||||
# enviroment setup
|
||||
# ================
|
||||
if not conf.CheckLib('rt'):
|
||||
FatalError("librt not found or not installed")
|
||||
elif platform == "Windows":
|
||||
#Look for regex
|
||||
if not conf.CheckLib(['gnurx', 'regex']):
|
||||
FatalError("regex not found or not installed")
|
||||
|
||||
# add the correct compiler flags.
|
||||
#These need to go last
|
||||
if not conf.CheckLib('gdi32') or not conf.CheckLib('winmm') or (not msvc and not conf.CheckLib('dxguid')):
|
||||
FatalError("Error: some windows libraries not found or not installed, make sure your compiler is set up correctly")
|
||||
elif platform == "Darwin":
|
||||
if not conf.CheckFramework("Cocoa"):
|
||||
FatalError("Cocoa framework not found or not installed")
|
||||
|
||||
# generic enviroment settings
|
||||
# +++++++++++++++++++++++++++
|
||||
if not GetOption('clean'):
|
||||
conf = Configure(env)
|
||||
conf.AddTest('CheckFramework', CheckFramework)
|
||||
conf.AddTest('CheckBit', CheckBit)
|
||||
if not conf.CheckCC() or not conf.CheckCXX():
|
||||
FatalError("compiler not correctly configured")
|
||||
if isX86 and not GetOption('32bit') and not GetOption('64bit'):
|
||||
conf.CheckBit()
|
||||
findLibs(env, conf)
|
||||
env = conf.Finish()
|
||||
|
||||
# check if a tool prefix is set, and if it is select the propper tools for building.
|
||||
# .. : TODO someone explain wtf this actually does
|
||||
if not msvc:
|
||||
if platform == "Windows":
|
||||
env.Append(CCFLAGS=['-std=gnu++98'])
|
||||
else:
|
||||
env.Append(CXXFLAGS=['-std=c++98'])
|
||||
env.Append(CXXFLAGS="-Wno-invalid-offsetof")
|
||||
|
||||
if GetOption("toolprefix"):
|
||||
env['CC'] = GetOption("toolprefix")+env['CC']
|
||||
env['CXX'] = GetOption("toolprefix")+env['CXX']
|
||||
if GetOption('win'):
|
||||
env['RC'] = GetOption("toolprefix")+env['RC']
|
||||
|
||||
# make sure the compiler can find the source data and generated files. enable warnings, set C++ flavor, and keep inline functions
|
||||
#Add platform specific flags and defines
|
||||
if platform == "Windows":
|
||||
env.Append(CPPDEFINES=["WIN", "_WIN32_WINNT=0x0501"])
|
||||
if msvc:
|
||||
env.Append(CCFLAGS=['/Gm', '/Zi', '/EHsc']) #enable minimal rebuild, enable exceptions
|
||||
env.Append(LINKFLAGS=['/SUBSYSTEM:WINDOWS', '/OPT:REF', '/OPT:ICF'])
|
||||
if GetOption('static'):
|
||||
env.Append(CCFLAGS='/GL') #whole program optimization (linker may freeze indefinitely without this)
|
||||
env.Append(LINKFLAGS=['/NODEFAULTLIB:LIBCMT.lib', '/LTCG'])
|
||||
else:
|
||||
env.Append(LINKFLAGS='/NODEFAULTLIB:msvcrt.lib')
|
||||
else:
|
||||
env.Append(LINKFLAGS='-mwindows')
|
||||
elif platform == "Linux":
|
||||
env.Append(CPPDEFINES="LIN")
|
||||
elif platform == "Darwin":
|
||||
env.Append(CPPDEFINES="MACOSX")
|
||||
env.Append(LINKFLAGS="-headerpad_max_install_names")
|
||||
|
||||
env.Append(CPPPATH=['src/', 'data/', 'generated/'])
|
||||
env.Append(CXXFLAGS=['-std=c++98'])
|
||||
env.Append(LIBS=['pthread', 'm'])
|
||||
env.Append(CPPDEFINES=["_GNU_SOURCE", "USE_STDINT", "_POSIX_C_SOURCE=200112L"])
|
||||
|
||||
# set the warnings we want, treat all warnings as errors, and ignore all "offsetof" warnings
|
||||
#Add architecture flags and defines
|
||||
if isX86:
|
||||
env.Append(CPPDEFINES='X86')
|
||||
if not GetOption('no-sse'):
|
||||
if GetOption('sse'):
|
||||
if msvc:
|
||||
env.Append(CCFLAGS='/arch:SSE')
|
||||
else:
|
||||
env.Append(CCFLAGS='-msse')
|
||||
env.Append(CPPDEFINES='X86_SSE')
|
||||
if GetOption('sse2'):
|
||||
if msvc:
|
||||
env.Append(CCFLAGS='/arch:SSE2')
|
||||
else:
|
||||
env.Append(CCFLAGS='-msse2')
|
||||
env.Append(CPPDEFINES='X86_SSE2')
|
||||
if GetOption('sse3'):
|
||||
if msvc:
|
||||
env.Append(CCFLAGS='/arch:SSE3')
|
||||
else:
|
||||
env.Append(CCFLAGS='-msse3')
|
||||
env.Append(CPPDEFINES='X86_SSE3')
|
||||
if GetOption('native') and not msvc:
|
||||
env.Append(CCFLAGS='-march=native')
|
||||
|
||||
env.Append(CCFLAGS=['-Wno-invalid-offsetof']);
|
||||
if GetOption('warnings_as_errors'):
|
||||
env.Append(CCFLAGS=['-Werror']);
|
||||
|
||||
# check all enabled libs, and add a define if they are enabled.
|
||||
|
||||
if not GetOption('nofft'):
|
||||
env.Append(CPPDEFINES=["GRAVFFT"])
|
||||
if not GetOption('nolua'):
|
||||
env.Append(CPPDEFINES=["LUACONSOLE"])
|
||||
|
||||
# check if we need to use PTW32_STATIC_LIB for pthreadw32 headers, won't compile statically without this
|
||||
|
||||
if GetOption("ptw32-static"):
|
||||
env.Append(CPPDEFINES=['PTW32_STATIC_LIB']);
|
||||
|
||||
# check if we need to do static linking.
|
||||
|
||||
if(GetOption('static')):
|
||||
env.Append(LINKFLAGS=['-static-libgcc'])
|
||||
|
||||
# check if we need to compile the save renderer. add a define accordingly. compile the game by default.
|
||||
|
||||
if(GetOption('renderer')):
|
||||
env.Append(CPPDEFINES=['RENDERER'])
|
||||
else:
|
||||
env.Append(CPPDEFINES=["USE_SDL"])
|
||||
|
||||
# apply optimisations if it's a release build
|
||||
|
||||
if(GetOption('release')):
|
||||
if GetOption('macosx'):
|
||||
env.Append(CCFLAGS=['-O3', '-ftree-vectorize', '-funsafe-math-optimizations', '-ffast-math', '-fomit-frame-pointer'])
|
||||
#Add optimization flags and defines
|
||||
if GetOption('debugging'):
|
||||
if msvc:
|
||||
env.Append(CCFLAGS='/Od')
|
||||
if GetOption('static'):
|
||||
env.Append(CCFLAGS='/MTd')
|
||||
else:
|
||||
env.Append(CCFLAGS='/MDd')
|
||||
else:
|
||||
env.Append(CCFLAGS=['-Wall', '-pg', '-g'])
|
||||
elif GetOption('release'):
|
||||
if msvc:
|
||||
env.Append(CCFLAGS=['/O2', '/fp:fast'])
|
||||
if GetOption('static'):
|
||||
env.Append(CCFLAGS='/MT')
|
||||
else:
|
||||
env.Append(CCFLAGS='/MD')
|
||||
else:
|
||||
env.Append(CCFLAGS=['-O3', '-ftree-vectorize', '-funsafe-math-optimizations', '-ffast-math', '-fomit-frame-pointer', '-funsafe-loop-optimizations'])
|
||||
|
||||
# rpi specific enviroment settings
|
||||
# ++++++++++++++++++++++++++++++++
|
||||
|
||||
# check if we're compiling for raspberry pi, if we are include rpi specific libraries and defines.
|
||||
|
||||
if(GetOption('rpi')):
|
||||
if(GetOption('opengl')):
|
||||
env.ParseConfig('pkg-config --libs glew gl glu')
|
||||
openGLLibs = ['GL']
|
||||
env.Append(LIBS=['X11', 'rt'])
|
||||
env.Append(CPPDEFINES=["LIN"])
|
||||
if GetOption('static'):
|
||||
if not msvc:
|
||||
env.Append(CCFLAGS='-static-libgcc')
|
||||
env.Append(LINKFLAGS='-static-libgcc')
|
||||
if platform == "Windows":
|
||||
env.Append(CPPDEFINES='PTW32_STATIC_LIB')
|
||||
if not msvc:
|
||||
env.Append(LINKFLAGS='-Wl,-Bstatic')
|
||||
|
||||
|
||||
# windows specific enviroment settings
|
||||
# ++++++++++++++++++++++++++++++++++++
|
||||
#Add other flags and defines
|
||||
if not GetOption('nofft'):
|
||||
env.Append(CPPDEFINES="GRAVFFT")
|
||||
if not GetOption('nolua') and not GetOption('renderer'):
|
||||
env.Append(CPPDEFINES="LUACONSOLE")
|
||||
|
||||
# check if we're compiling for windows, if we are include windows specific libraries and defines.
|
||||
if GetOption('opengl') or GetOption('opengl-renderer'):
|
||||
env.Append(CPPDEFINES=['OGLI', 'PIX32OGL'])
|
||||
if GetOption('opengl-renderer'):
|
||||
env.Append(CPPDEFINES='OGLR')
|
||||
|
||||
if(GetOption('win')):
|
||||
openGLLibs = ['opengl32', 'glew32']
|
||||
env.Prepend(LIBS=['mingw32', 'ws2_32', 'SDLmain', 'SDL'])
|
||||
env.Append(CCFLAGS=['-std=gnu++98'])
|
||||
env.Append(LIBS=['winmm', 'gdi32'])
|
||||
env.Append(CPPDEFINES=["WIN"])
|
||||
env.Append(LINKFLAGS=['-mwindows'])
|
||||
if(GetOption('_64bit')):
|
||||
env.Append(CPPDEFINES=['__CRT__NO_INLINE'])
|
||||
env.Append(LINKFLAGS=['-Wl,--stack=16777216'])
|
||||
if GetOption('renderer'):
|
||||
env.Append(CPPDEFINES='RENDERER')
|
||||
else:
|
||||
env.Append(CPPDEFINES='USE_SDL')
|
||||
|
||||
# linux specific enviroment settings
|
||||
# ++++++++++++++++++++++++++++++++++++
|
||||
|
||||
# check if we're compiling for linux, if we are include linux specific libraries and defines.
|
||||
|
||||
if(GetOption('lin')):
|
||||
if(GetOption('opengl')):
|
||||
env.ParseConfig('pkg-config --libs glew gl glu')
|
||||
openGLLibs = ['GL']
|
||||
env.Append(LIBS=['X11', 'rt'])
|
||||
env.Append(CPPDEFINES=["LIN"])
|
||||
if GetOption('_64bit'):
|
||||
env.Append(LINKFLAGS=['-m64'])
|
||||
env.Append(CCFLAGS=['-m64'])
|
||||
elif GetOption('_32bit'):
|
||||
env.Append(LINKFLAGS=['-m32'])
|
||||
env.Append(CCFLAGS=['-m32'])
|
||||
|
||||
# macosx specific enviroment settings
|
||||
# ++++++++++++++++++++++++++++++++++++
|
||||
|
||||
# check if we're compiling for macosx, if we are include macosx specific libraries and defines.
|
||||
|
||||
if(GetOption('macosx')):
|
||||
env.Append(CPPDEFINES=["MACOSX"])
|
||||
env.Append(CCFLAGS=['-I/Library/Frameworks/SDL.framework/Headers'])
|
||||
env.Append(CCFLAGS=['-I/Library/Frameworks/Lua.framework/Headers'])
|
||||
if not GetOption('nofft'):
|
||||
env.Append(LINKFLAGS=['-lfftw3f'])
|
||||
env.Append(LINKFLAGS=['-framework'])
|
||||
env.Append(LINKFLAGS=['SDL'])
|
||||
env.Append(LINKFLAGS=['-framework'])
|
||||
env.Append(LINKFLAGS=['Lua'])
|
||||
env.Append(LINKFLAGS=['-framework']);
|
||||
env.Append(LINKFLAGS=['Cocoa'])
|
||||
#env.Append(LINKFLAGS=['-framework SDL'])
|
||||
#env.Append(LINKFLAGS=['-framework Lua'])
|
||||
#env.Append(LINKFLAGS=['-framework Cocoa'])
|
||||
if GetOption('_64bit'):
|
||||
env.Append(LINKFLAGS=['-m64'])
|
||||
env.Append(CCFLAGS=['-m64'])
|
||||
elif GetOption('_32bit'):
|
||||
env.Append(LINKFLAGS=['-m32'])
|
||||
env.Append(CCFLAGS=['-m32'])
|
||||
|
||||
# defines
|
||||
# =======
|
||||
|
||||
# A lot of commandline flags translate directly into defines. those flags follow:
|
||||
|
||||
if GetOption('_64bit'):
|
||||
env.Append(CPPDEFINES=["_64BIT"])
|
||||
if GetOption('_32bit'):
|
||||
env.Append(CPPDEFINES=["_32BIT"])
|
||||
|
||||
if(GetOption('beta')):
|
||||
env.Append(CPPDEFINES='BETA')
|
||||
|
||||
if(not GetOption('snapshot') and not GetOption('beta') and not GetOption('release') and not GetOption('stable')):
|
||||
env.Append(CPPDEFINES='SNAPSHOT_ID=0')
|
||||
env.Append(CPPDEFINES='SNAPSHOT')
|
||||
elif(GetOption('snapshot') or GetOption('snapshot-id')):
|
||||
if(GetOption('snapshot-id')):
|
||||
env.Append(CPPDEFINES=['SNAPSHOT_ID=' + GetOption('snapshot-id')])
|
||||
if GetOption("wall"):
|
||||
if msvc:
|
||||
env.Append(CCFLAGS='/WX')
|
||||
else:
|
||||
env.Append(CPPDEFINES=['SNAPSHOT_ID=' + str(int(time.time()))])
|
||||
env.Append(CPPDEFINES='SNAPSHOT')
|
||||
elif(GetOption('stable')):
|
||||
env.Append(CPPDEFINES='STABLE')
|
||||
env.Append(CCFLAGS='-Werror')
|
||||
elif GetOption("no-warnings"):
|
||||
if msvc:
|
||||
env.Append(CCFLAGS='/W0')
|
||||
else:
|
||||
env.Append(CCFLAGS='-w')
|
||||
|
||||
if(GetOption('save-version')):
|
||||
env.Append(CPPDEFINES=['SAVE_VERSION=' + GetOption('save-version')])
|
||||
|
||||
if(GetOption('minor-version')):
|
||||
env.Append(CPPDEFINES=['MINOR_VERSION=' + GetOption('minor-version')])
|
||||
#Add version defines
|
||||
if GetOption('save-version'):
|
||||
env.Append(CPPDEFINES="SAVE_VERSION={}".format(GetOption('save-version')))
|
||||
|
||||
if(GetOption('build-number')):
|
||||
env.Append(CPPDEFINES=['BUILD_NUM=' + GetOption('build-number')])
|
||||
if GetOption('minor-version'):
|
||||
env.Append(CPPDEFINES="MINOR_VERSION={}".format(GetOption('minor-version')))
|
||||
|
||||
if(GetOption('x86')):
|
||||
env.Append(CPPDEFINES='X86')
|
||||
if GetOption('build-number'):
|
||||
env.Append(CPPDEFINES="BUILD_NUM={}".format(GetOption('build-number')))
|
||||
|
||||
if(GetOption('debug')):
|
||||
env.Append(CPPDEFINES='DEBUG')
|
||||
env.Append(CCFLAGS='-g')
|
||||
if GetOption('snapshot-id'):
|
||||
env.Append(CPPDEFINES=["SNAPSHOT", "SNAPSHOT_ID={}".format(GetOption('snapshot-id'))])
|
||||
elif GetOption('snapshot'):
|
||||
env.Append(CPPDEFINES=["SNAPSHOT", "SNAPSHOT_ID={}".format(str(int(time.time())))])
|
||||
|
||||
if(GetOption('sse')):
|
||||
env.Append(CCFLAGS='-msse')
|
||||
env.Append(CPPDEFINES='X86_SSE')
|
||||
if GetOption('beta'):
|
||||
env.Append(CPPDEFINES="BETA")
|
||||
|
||||
if(GetOption('sse2')):
|
||||
env.Append(CCFLAGS='-msse2')
|
||||
env.Append(CPPDEFINES='X86_SSE2')
|
||||
|
||||
if(GetOption('sse3')):
|
||||
env.Append(CCFLAGS='-msse3')
|
||||
env.Append(CPPDEFINES='X86_SSE3')
|
||||
#Generate list of sources to compile
|
||||
sources = Glob("src/*.cpp") + Glob("src/*/*.cpp") + Glob("src/*/*/*.cpp") + Glob("generated/*.cpp")
|
||||
if not GetOption('nolua') and not GetOption('renderer'):
|
||||
sources += Glob("src/lua/socket/*.c")
|
||||
|
||||
if(GetOption('opengl')):
|
||||
env.Append(CPPDEFINES=["OGLI", "PIX32OGL"])
|
||||
env.Append(LIBS=openGLLibs)
|
||||
|
||||
if(GetOption('opengl') and GetOption('opengl-renderer')):
|
||||
env.Append(CPPDEFINES=["OGLR"])
|
||||
elif(GetOption('opengl-renderer')):
|
||||
print "opengl-renderer requires opengl"
|
||||
raise SystemExit(1)
|
||||
|
||||
# compiling
|
||||
# =========
|
||||
|
||||
# sources
|
||||
# +++++++
|
||||
|
||||
# find all source files
|
||||
|
||||
# generic sources
|
||||
# ---------------
|
||||
sources=Glob("src/*.cpp")
|
||||
|
||||
sources+=Glob("src/*/*.cpp")
|
||||
sources+=Glob("src/*/*/*.cpp")
|
||||
if not GetOption('nolua'):
|
||||
sources+=Glob("src/socket/*.c")
|
||||
|
||||
# windows specific sources
|
||||
# ------------------------
|
||||
|
||||
if(GetOption('win')):
|
||||
if platform == "Windows" and not msvc:
|
||||
sources += env.RES('resources/powder-res.rc')
|
||||
sources = filter(lambda source: not 'src\\simulation\\Gravity.cpp' in str(source), sources)
|
||||
sources = filter(lambda source: not 'src/simulation/Gravity.cpp' in str(source), sources)
|
||||
envCopy = env.Clone()
|
||||
envCopy.Append(CCFLAGS='-mstackrealign')
|
||||
sources += envCopy.Object('src/simulation/Gravity.cpp')
|
||||
elif platform == "Darwin":
|
||||
sources += ["src/SDLMain.m"]
|
||||
|
||||
# macosx specific sources
|
||||
# -----------------------
|
||||
|
||||
if(GetOption('macosx')):
|
||||
sources +=["SDLMain.m"]
|
||||
|
||||
# apply `long commandlines`_ fix
|
||||
# ==============================
|
||||
|
||||
# apply the commandline fix
|
||||
|
||||
SetupSpawn(env)
|
||||
|
||||
# find proper executable name
|
||||
# ===========================
|
||||
|
||||
# use some settings to detect what name to use for the executable
|
||||
|
||||
programName = "powder"
|
||||
|
||||
if(GetOption('renderer')):
|
||||
programName = "render"
|
||||
|
||||
if(GetOption('win')):
|
||||
if(GetOption('renderer')):
|
||||
programName = "Render"
|
||||
else:
|
||||
programName = "Powder"
|
||||
|
||||
if(GetOption('_64bit')):
|
||||
#Program output name
|
||||
if GetOption('output'):
|
||||
programName = GetOption('output')
|
||||
else:
|
||||
programName = GetOption('renderer') and "render" or "powder"
|
||||
if "BIT" in env and env["BIT"] == 64:
|
||||
programName += "64"
|
||||
|
||||
if(not (GetOption('sse2') or GetOption('sse3'))):
|
||||
if isX86 and GetOption('no-sse'):
|
||||
programName += "-legacy"
|
||||
|
||||
if(GetOption('macosx')):
|
||||
if platform == "Windows":
|
||||
programName = programName.capitalize()
|
||||
programName += ".exe"
|
||||
elif platform == "Darwin":
|
||||
programName += "-x"
|
||||
|
||||
if(GetOption('win')):
|
||||
programName += ".exe"
|
||||
#strip binary after compilation
|
||||
def strip():
|
||||
global programName
|
||||
global env
|
||||
try:
|
||||
os.system("{0} {1}/{2}".format(env['STRIP'] if 'STRIP' in env else "strip", GetOption('builddir'), programName))
|
||||
except:
|
||||
print("Couldn't strip binary")
|
||||
if not GetOption('debugging') and not GetOption('clean') and not msvc:
|
||||
atexit.register(strip)
|
||||
|
||||
#Long command line fix for mingw on windows
|
||||
if compilePlatform == "Windows" and not msvc:
|
||||
SetupSpawn(env)
|
||||
|
||||
# detect python executable name
|
||||
# =============================
|
||||
|
||||
# detect the executable name for python so we can run some generator scripts
|
||||
|
||||
if(GetOption('pythonver')):
|
||||
pythonVer = GetOption('pythonver')
|
||||
elif(GetOption('lin')):
|
||||
pythonVer = "python2"
|
||||
else:
|
||||
pythonVer = "python"
|
||||
|
||||
# Extra compiler flag to fix stack alignment
|
||||
# When Windows creates the gravity calculation thread, it has 4 byte stack alignment
|
||||
# But we need 16 byte alignment so that SSE instructions in FFTW work without crashing
|
||||
if(GetOption('win')):
|
||||
envCopy = env.Clone()
|
||||
envCopy.Append(CCFLAGS=['-mstackrealign'])
|
||||
#envCopy.Append(CCFLAGS=['-mincoming-stack-boundary=2'])
|
||||
sources+=envCopy.Object('src/simulation/Gravity.cpp')
|
||||
|
||||
# run generator commands
|
||||
# ======================
|
||||
|
||||
env.Command(['generated/ElementClasses.cpp', 'generated/ElementClasses.h'], Glob('src/simulation/elements/*.cpp'), pythonVer + " generator.py elements $TARGETS $SOURCES")
|
||||
sources+=Glob("generated/ElementClasses.cpp")
|
||||
|
||||
env.Command(['generated/ToolClasses.cpp', 'generated/ToolClasses.h'], Glob('src/simulation/simtools/*.cpp'), pythonVer + " generator.py tools $TARGETS $SOURCES")
|
||||
sources+=Glob("generated/ToolClasses.cpp")
|
||||
|
||||
# final settings
|
||||
# ==============
|
||||
|
||||
# make a MD5 checksum decide wether or not a file changed. we had some problems with using the modification date for this purpose.
|
||||
|
||||
env.Decider('MD5')
|
||||
|
||||
# set a default target
|
||||
|
||||
t=env.Program(target=programName, source=sources)
|
||||
#Once we get here, finally compile
|
||||
env.Decider('MD5-timestamp')
|
||||
SetOption('implicit_cache', 1)
|
||||
t = env.Program(target=programName, source=sources)
|
||||
Default(t)
|
||||
|
14
SConstruct
14
SConstruct
@ -1,2 +1,16 @@
|
||||
#run generator.py
|
||||
if not GetOption('clean'):
|
||||
execfile("generator.py")
|
||||
|
||||
AddOption('--builddir',dest="builddir",default="build",help="Directory to build to.")
|
||||
SConscript('SConscript', variant_dir=GetOption('builddir'), duplicate=0)
|
||||
if GetOption('clean'):
|
||||
import os, shutil
|
||||
try:
|
||||
shutil.rmtree(".sconf_temp/")
|
||||
except:
|
||||
print "couldn't remove .sconf_temp"
|
||||
try:
|
||||
os.remove(".sconsign.dblite")
|
||||
except:
|
||||
print "couldn't remove .sconsign.dblite"
|
||||
|
10
generator.py
10
generator.py
@ -223,11 +223,5 @@ std::vector<SimTool*> GetTools()
|
||||
f.write(toolContent)
|
||||
f.close()
|
||||
|
||||
if(len(sys.argv) > 3):
|
||||
if(sys.argv[1] == "elements"):
|
||||
generateElements(sys.argv[4:], sys.argv[2], sys.argv[3])
|
||||
elif(sys.argv[1] == "tools"):
|
||||
generateTools(sys.argv[4:], sys.argv[2], sys.argv[3])
|
||||
else:
|
||||
generateElements(os.listdir("src/simulation/elements"), "generated/ElementClasses.cpp", "generated/ElementClasses.h")
|
||||
generateTools(os.listdir("src/simulation/simtools"), "generated/ToolClasses.cpp", "generated/ToolClasses.h")
|
||||
generateElements(os.listdir("src/simulation/elements"), "generated/ElementClasses.cpp", "generated/ElementClasses.h")
|
||||
generateTools(os.listdir("src/simulation/simtools"), "generated/ToolClasses.cpp", "generated/ToolClasses.h")
|
||||
|
17
src/Config.h
17
src/Config.h
@ -26,20 +26,11 @@
|
||||
#ifndef SNAPSHOT_ID
|
||||
#define SNAPSHOT_ID 0
|
||||
#endif
|
||||
|
||||
#ifndef STABLE
|
||||
#ifndef BETA
|
||||
#define BETA
|
||||
#define SNAPSHOT
|
||||
#endif
|
||||
#endif
|
||||
//VersionInfoEnd
|
||||
|
||||
//#define IGNORE_UPDATES //uncomment this for mods, to not get any update notifications
|
||||
|
||||
#if defined(DEBUG) || defined(RENDERER) || defined(X86_SSE2)
|
||||
#define HIGH_QUALITY_RESAMPLE //High quality image resampling, slower but much higher quality than my terribad linear interpolation
|
||||
#endif
|
||||
|
||||
#if defined(SNAPSHOT)
|
||||
#define IDENT_RELTYPE "S"
|
||||
@ -52,14 +43,18 @@
|
||||
#if defined(WIN)
|
||||
#if defined(_64BIT)
|
||||
#define IDENT_PLATFORM "WIN64"
|
||||
#else
|
||||
#elif defined(_32BIT)
|
||||
#define IDENT_PLATFORM "WIN32"
|
||||
#else
|
||||
#define IDENT_PLATFORM "WIN"
|
||||
#endif
|
||||
#elif defined(LIN)
|
||||
#if defined(_64BIT)
|
||||
#define IDENT_PLATFORM "LIN64"
|
||||
#else
|
||||
#elif defined(_32BIT)
|
||||
#define IDENT_PLATFORM "LIN32"
|
||||
#else
|
||||
#define IDENT_PLATFORM "LIN"
|
||||
#endif
|
||||
#elif defined(MACOSX)
|
||||
#define IDENT_PLATFORM "MACOSX"
|
||||
|
@ -3,10 +3,13 @@
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <time.h>
|
||||
#ifdef SDL_INC
|
||||
#include "SDL/SDL.h"
|
||||
#else
|
||||
#include "SDL.h"
|
||||
#endif
|
||||
#ifdef WIN
|
||||
#define _WIN32_WINNT 0x0501 //Necessary for some macros and functions, tells windows.h to include functions only available in Windows XP or later
|
||||
#include "SDL_syswm.h"
|
||||
#include <direct.h>
|
||||
#endif
|
||||
#include <iostream>
|
||||
@ -49,9 +52,13 @@ extern "C" {
|
||||
|
||||
using namespace std;
|
||||
|
||||
#if defined(USE_SDL) && defined(LIN)
|
||||
#if defined(WIN) || defined(LIN)
|
||||
#ifdef SDL_INC
|
||||
#include <SDL/SDL_syswm.h>
|
||||
#else
|
||||
#include <SDL_syswm.h>
|
||||
#endif
|
||||
#endif
|
||||
#if defined(USE_SDL) && defined(LIN) && defined(SDL_VIDEO_DRIVER_X11)
|
||||
SDL_SysWMinfo sdl_wminfo;
|
||||
Atom XA_CLIPBOARD, XA_TARGETS, XA_UTF8_STRING;
|
||||
|
@ -5,7 +5,11 @@
|
||||
Feel free to customize this file to suit your needs
|
||||
*/
|
||||
|
||||
#ifdef SDL_INC
|
||||
#include "SDL/SDL.h"
|
||||
#else
|
||||
#include "SDL.h"
|
||||
#endif
|
||||
#include "SDLMain.h"
|
||||
#include <sys/param.h> /* for MAXPATHLEN */
|
||||
#include <unistd.h>
|
@ -1,6 +1,10 @@
|
||||
|
||||
#if defined(USE_SDL)
|
||||
#ifdef SDL_INC
|
||||
#include "SDL/SDL.h"
|
||||
#else
|
||||
#include "SDL.h"
|
||||
#endif
|
||||
#define KEY_UNKNOWN SDLK_UNKNOWN
|
||||
#define KEY_UP SDLK_UP
|
||||
#define KEY_NUM_UP SDLK_KP8
|
||||
|
@ -29,12 +29,7 @@
|
||||
|
||||
#define LUA_BITOP_VERSION "1.0.2"
|
||||
|
||||
extern "C"
|
||||
{
|
||||
#include "lua.h"
|
||||
#include "lauxlib.h"
|
||||
#include "lualib.h"
|
||||
}
|
||||
#include "luainc.h"
|
||||
|
||||
#ifdef _MSC_VER
|
||||
/* MSVC is stuck in the last century and doesn't have C99's stdint.h. */
|
||||
|
@ -1,10 +1,4 @@
|
||||
#ifdef LUACONSOLE
|
||||
extern "C"
|
||||
{
|
||||
#include "lua.h"
|
||||
#include "lauxlib.h"
|
||||
#include "lualib.h"
|
||||
}
|
||||
|
||||
#include <iostream>
|
||||
#include "LuaButton.h"
|
||||
|
@ -1,11 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
extern "C" {
|
||||
#include "lua.h"
|
||||
#include "lauxlib.h"
|
||||
#include "lualib.h"
|
||||
}
|
||||
|
||||
#include "LuaLuna.h"
|
||||
#include "LuaComponent.h"
|
||||
|
||||
|
@ -1,10 +1,4 @@
|
||||
#ifdef LUACONSOLE
|
||||
extern "C"
|
||||
{
|
||||
#include "lua.h"
|
||||
#include "lauxlib.h"
|
||||
#include "lualib.h"
|
||||
}
|
||||
|
||||
#include <iostream>
|
||||
#include "LuaCheckbox.h"
|
||||
|
@ -1,11 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
extern "C" {
|
||||
#include "lua.h"
|
||||
#include "lauxlib.h"
|
||||
#include "lualib.h"
|
||||
}
|
||||
|
||||
#include "LuaLuna.h"
|
||||
#include "LuaComponent.h"
|
||||
|
||||
|
@ -1,10 +1,4 @@
|
||||
#ifdef LUACONSOLE
|
||||
extern "C"
|
||||
{
|
||||
#include "lua.h"
|
||||
#include "lauxlib.h"
|
||||
#include "lualib.h"
|
||||
}
|
||||
|
||||
#include <iostream>
|
||||
#include "LuaComponent.h"
|
||||
|
@ -1,11 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
extern "C" {
|
||||
#include "lua.h"
|
||||
#include "lauxlib.h"
|
||||
#include "lualib.h"
|
||||
}
|
||||
|
||||
#include "LuaLuna.h"
|
||||
|
||||
namespace ui
|
||||
|
@ -1,10 +1,4 @@
|
||||
#ifdef LUACONSOLE
|
||||
extern "C"
|
||||
{
|
||||
#include "lua.h"
|
||||
#include "lauxlib.h"
|
||||
#include "lualib.h"
|
||||
}
|
||||
|
||||
#include <iostream>
|
||||
#include "LuaScriptInterface.h"
|
||||
|
@ -1,11 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
extern "C" {
|
||||
#include "lua.h"
|
||||
#include "lauxlib.h"
|
||||
#include "lualib.h"
|
||||
}
|
||||
|
||||
#include "LuaLuna.h"
|
||||
#include "LuaComponent.h"
|
||||
|
||||
|
@ -1,10 +1,7 @@
|
||||
#pragma once
|
||||
//http://lua-users.org/wiki/SimplerCppBinding
|
||||
|
||||
extern "C" {
|
||||
#include "lua.h"
|
||||
#include "lauxlib.h"
|
||||
}
|
||||
#include "luainc.h"
|
||||
|
||||
template <typename T> class Luna
|
||||
{
|
||||
|
@ -1,10 +1,4 @@
|
||||
#ifdef LUACONSOLE
|
||||
extern "C"
|
||||
{
|
||||
#include "lua.h"
|
||||
#include "lauxlib.h"
|
||||
#include "lualib.h"
|
||||
}
|
||||
|
||||
#include <iostream>
|
||||
#include "LuaProgressBar.h"
|
||||
|
@ -1,11 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
extern "C" {
|
||||
#include "lua.h"
|
||||
#include "lauxlib.h"
|
||||
#include "lualib.h"
|
||||
}
|
||||
|
||||
#include "LuaLuna.h"
|
||||
#include "LuaComponent.h"
|
||||
|
||||
|
@ -1,12 +1,7 @@
|
||||
#ifndef LUASCRIPTINTERFACE_H_
|
||||
#define LUASCRIPTINTERFACE_H_
|
||||
|
||||
extern "C"
|
||||
{
|
||||
#include "lua.h"
|
||||
#include "lauxlib.h"
|
||||
#include "lualib.h"
|
||||
}
|
||||
#include "luainc.h"
|
||||
|
||||
#include "CommandInterface.h"
|
||||
#include "simulation/Simulation.h"
|
||||
|
@ -1,10 +1,4 @@
|
||||
#ifdef LUACONSOLE
|
||||
extern "C"
|
||||
{
|
||||
#include "lua.h"
|
||||
#include "lauxlib.h"
|
||||
#include "lualib.h"
|
||||
}
|
||||
|
||||
#include <iostream>
|
||||
#include "LuaSlider.h"
|
||||
|
@ -1,11 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
extern "C" {
|
||||
#include "lua.h"
|
||||
#include "lauxlib.h"
|
||||
#include "lualib.h"
|
||||
}
|
||||
|
||||
#include "LuaLuna.h"
|
||||
#include "LuaComponent.h"
|
||||
|
||||
|
@ -1,10 +1,4 @@
|
||||
#ifdef LUACONSOLE
|
||||
extern "C"
|
||||
{
|
||||
#include "lua.h"
|
||||
#include "lauxlib.h"
|
||||
#include "lualib.h"
|
||||
}
|
||||
|
||||
#include <iostream>
|
||||
#include "LuaScriptInterface.h"
|
||||
|
@ -1,11 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
extern "C" {
|
||||
#include "lua.h"
|
||||
#include "lauxlib.h"
|
||||
#include "lualib.h"
|
||||
}
|
||||
|
||||
#include "LuaLuna.h"
|
||||
#include "LuaComponent.h"
|
||||
|
||||
|
@ -1,10 +1,4 @@
|
||||
#ifdef LUACONSOLE
|
||||
extern "C"
|
||||
{
|
||||
#include "lua.h"
|
||||
#include "lauxlib.h"
|
||||
#include "lualib.h"
|
||||
}
|
||||
|
||||
#include <iostream>
|
||||
#include "LuaScriptInterface.h"
|
||||
|
@ -1,11 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
extern "C" {
|
||||
#include "lua.h"
|
||||
#include "lauxlib.h"
|
||||
#include "lualib.h"
|
||||
}
|
||||
|
||||
#include "LuaLuna.h"
|
||||
|
||||
#include "gui/interface/Platform.h"
|
||||
|
23
src/lua/luainc.h
Normal file
23
src/lua/luainc.h
Normal file
@ -0,0 +1,23 @@
|
||||
#ifndef LUAINC_H
|
||||
#define LUAINC_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#ifdef LUA_INC
|
||||
#include "lua5.1/lua.h"
|
||||
#include "lua5.1/lauxlib.h"
|
||||
#include "lua5.1/lualib.h"
|
||||
#else
|
||||
#include "lua.h"
|
||||
#include "lauxlib.h"
|
||||
#include "lualib.h"
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -31,8 +31,7 @@
|
||||
* RCS ID: $Id: auxiliar.h,v 1.9 2005/10/07 04:40:59 diego Exp $
|
||||
\*=========================================================================*/
|
||||
|
||||
#include "lua.h"
|
||||
#include "lauxlib.h"
|
||||
#include "../luainc.h"
|
||||
|
||||
int auxiliar_open(lua_State *L);
|
||||
void auxiliar_newclass(lua_State *L, const char *classname, luaL_reg *func);
|
@ -4,9 +4,6 @@
|
||||
*
|
||||
* RCS ID: $Id: buffer.c,v 1.28 2007/06/11 23:44:54 diego Exp $
|
||||
\*=========================================================================*/
|
||||
#include "lua.h"
|
||||
#include "lauxlib.h"
|
||||
|
||||
#include "buffer.h"
|
||||
|
||||
/*=========================================================================*\
|
@ -17,7 +17,7 @@
|
||||
*
|
||||
* RCS ID: $Id: buffer.h,v 1.12 2005/10/07 04:40:59 diego Exp $
|
||||
\*=========================================================================*/
|
||||
#include "lua.h"
|
||||
#include "../luainc.h"
|
||||
|
||||
#include "io.h"
|
||||
#include "timeout.h"
|
@ -6,9 +6,6 @@
|
||||
\*=========================================================================*/
|
||||
#include <stdio.h>
|
||||
|
||||
#include "lua.h"
|
||||
#include "lauxlib.h"
|
||||
|
||||
#include "except.h"
|
||||
|
||||
/*=========================================================================*\
|
@ -28,7 +28,7 @@
|
||||
* RCS ID: $Id: except.h,v 1.2 2005/09/29 06:11:41 diego Exp $
|
||||
\*=========================================================================*/
|
||||
|
||||
#include "lua.h"
|
||||
#include "../luainc.h"
|
||||
|
||||
int except_open(lua_State *L);
|
||||
|
@ -7,9 +7,6 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "lua.h"
|
||||
#include "lauxlib.h"
|
||||
|
||||
#include "inet.h"
|
||||
|
||||
/*=========================================================================*\
|
@ -16,7 +16,7 @@
|
||||
*
|
||||
* RCS ID: $Id: inet.h,v 1.16 2005/10/07 04:40:59 diego Exp $
|
||||
\*=========================================================================*/
|
||||
#include "lua.h"
|
||||
#include "../luainc.h"
|
||||
#include "socket.h"
|
||||
#include "timeout.h"
|
||||
|
@ -15,7 +15,7 @@
|
||||
* RCS ID: $Id: io.h,v 1.11 2005/10/07 04:40:59 diego Exp $
|
||||
\*=========================================================================*/
|
||||
#include <stdio.h>
|
||||
#include "lua.h"
|
||||
#include "../luainc.h"
|
||||
|
||||
#include "timeout.h"
|
||||
|
@ -14,16 +14,6 @@
|
||||
* RCS ID: $Id: luasocket.c,v 1.53 2005/10/07 04:40:59 diego Exp $
|
||||
\*=========================================================================*/
|
||||
|
||||
/*=========================================================================*\
|
||||
* Standard include files
|
||||
\*=========================================================================*/
|
||||
#include "lua.h"
|
||||
#include "lauxlib.h"
|
||||
|
||||
#if !defined(LUA_VERSION_NUM) || (LUA_VERSION_NUM < 501)
|
||||
#include "compat-5.1.h"
|
||||
#endif
|
||||
|
||||
/*=========================================================================*\
|
||||
* LuaSocket includes
|
||||
\*=========================================================================*/
|
@ -8,7 +8,7 @@
|
||||
*
|
||||
* RCS ID: $Id: luasocket.h,v 1.25 2007/06/11 23:44:54 diego Exp $
|
||||
\*=========================================================================*/
|
||||
#include "lua.h"
|
||||
#include "../luainc.h"
|
||||
|
||||
/*-------------------------------------------------------------------------*\
|
||||
* Current socket library version
|
@ -6,8 +6,6 @@
|
||||
\*=========================================================================*/
|
||||
#include <string.h>
|
||||
|
||||
#include "lauxlib.h"
|
||||
|
||||
#include "auxiliar.h"
|
||||
#include "options.h"
|
||||
#include "inet.h"
|
@ -10,7 +10,7 @@
|
||||
* RCS ID: $Id: options.h,v 1.4 2005/10/07 04:40:59 diego Exp $
|
||||
\*=========================================================================*/
|
||||
|
||||
#include "lua.h"
|
||||
#include "../luainc.h"
|
||||
#include "socket.h"
|
||||
|
||||
/* option registry */
|
@ -6,9 +6,6 @@
|
||||
\*=========================================================================*/
|
||||
#include <string.h>
|
||||
|
||||
#include "lua.h"
|
||||
#include "lauxlib.h"
|
||||
|
||||
#include "socket.h"
|
||||
#include "timeout.h"
|
||||
#include "select.h"
|
@ -1,10 +1,6 @@
|
||||
#ifdef LUACONSOLE
|
||||
// socket.lua from luasocket compiled into a cpp file
|
||||
extern "C" {
|
||||
#include "lua.h"
|
||||
#include "lauxlib.h"
|
||||
#include "lualib.h"
|
||||
}
|
||||
#include "../luainc.h"
|
||||
void luaopen_socket(lua_State *l){
|
||||
int socket_luac_sz=4061;
|
||||
const char* socket_luac="-----------------------------------------------------------------------------\012-- LuaSocket helper module\012-- Author: Diego Nehab\012-- RCS ID: $Id: socket.lua,v 1.22 2005/11/22 08:33:29 diego Exp $\012-----------------------------------------------------------------------------\012\012-----------------------------------------------------------------------------\012-- Declare module and import dependencies\012-----------------------------------------------------------------------------\012local base = _G\012local string = require(\042string\042)\012local math = require(\042math\042)\012local socket = require(\042socket.core\042)\012module(\042socket\042)\012\012-----------------------------------------------------------------------------\012-- Exported auxiliar functions\012-----------------------------------------------------------------------------\012function connect(address, port, laddress, lport)\012 local sock, err = socket.tcp()\012 if not sock then return nil, err end\012 if laddress then\012 local res, err = sock:bind(laddress, lport, -1)\012 if not res then return nil, err end\012 end\012 local res, err = sock:connect(address, port)\012 if not res then return nil, err end\012 return sock\012end\012\012function bind(host, port, backlog)\012 local sock, err = socket.tcp()\012 if not sock then return nil, err end\012 sock:setoption(\042reuseaddr\042, true)\012 local res, err = sock:bind(host, port)\012 if not res then return nil, err end\012 res, err = sock:listen(backlog)\012 if not res then return nil, err end\012 return sock\012end\012\012try = newtry()\012\012function choose(table)\012 return function(name, opt1, opt2)\012 if base.type(name) ~= \042string\042 then\012 name, opt1, opt2 = \042default\042, name, opt1\012 end\012 local f = table[name or \042nil\042]\012 if not f then base.error(\042unknown key (\042.. base.tostring(name) ..\042)\042, 3)\012 else return f(opt1, opt2) end\012 end\012end\012\012-----------------------------------------------------------------------------\012-- Socket sources and sinks, conforming to LTN12\012-----------------------------------------------------------------------------\012-- create namespaces inside LuaSocket namespace\012sourcet = {}\012sinkt = {}\012\012BLOCKSIZE = 2048\012\012sinkt[\042close-when-done\042] = function(sock)\012 return base.setmetatable({\012 getfd = function() return sock:getfd() end,\012 dirty = function() return sock:dirty() end\012 }, {\012 __call = function(self, chunk, err)\012 if not chunk then\012 sock:close()\012 return 1\012 else return sock:send(chunk) end\012 end\012 })\012end\012\012sinkt[\042keep-open\042] = function(sock)\012 return base.setmetatable({\012 getfd = function() return sock:getfd() end,\012 dirty = function() return sock:dirty() end\012 }, {\012 __call = function(self, chunk, err)\012 if chunk then return sock:send(chunk)\012 else return 1 end\012 end\012 })\012end\012\012sinkt[\042default\042] = sinkt[\042keep-open\042]\012\012sink = choose(sinkt)\012\012sourcet[\042by-length\042] = function(sock, length)\012 return base.setmetatable({\012 getfd = function() return sock:getfd() end,\012 dirty = function() return sock:dirty() end\012 }, {\012 __call = function()\012 if length <= 0 then return nil end\012 local size = math.min(socket.BLOCKSIZE, length)\012 local chunk, err = sock:receive(size)\012 if err then return nil, err end\012 length = length - string.len(chunk)\012 return chunk\012 end\012 })\012end\012\012sourcet[\042until-closed\042] = function(sock)\012 local done\012 return base.setmetatable({\012 getfd = function() return sock:getfd() end,\012 dirty = function() return sock:dirty() end\012 }, {\012 __call = function()\012 if done then return nil end\012 local chunk, err, partial = sock:receive(socket.BLOCKSIZE)\012 if not err then return chunk\012 elseif err == \042closed\042 then\012 sock:close()\012 done = 1\012 return partial\012 else return nil, err end\012 end\012 })\012end\012\012\012sourcet[\042default\042] = sourcet[\042until-closed\042]\012\012source = choose(sourcet)\012\012";
|
@ -1,2 +1,2 @@
|
||||
#include "lua.h"
|
||||
#include "../luainc.h"
|
||||
void luaopen_socket(lua_State *l);
|
@ -6,9 +6,6 @@
|
||||
\*=========================================================================*/
|
||||
#include <string.h>
|
||||
|
||||
#include "lua.h"
|
||||
#include "lauxlib.h"
|
||||
|
||||
#include "auxiliar.h"
|
||||
#include "socket.h"
|
||||
#include "inet.h"
|
@ -16,7 +16,7 @@
|
||||
*
|
||||
* RCS ID: $Id: tcp.h,v 1.7 2005/10/07 04:40:59 diego Exp $
|
||||
\*=========================================================================*/
|
||||
#include "lua.h"
|
||||
#include "../luainc.h"
|
||||
|
||||
#include "buffer.h"
|
||||
#include "timeout.h"
|
@ -6,9 +6,6 @@
|
||||
\*=========================================================================*/
|
||||
#include <stdio.h>
|
||||
|
||||
#include "lua.h"
|
||||
#include "lauxlib.h"
|
||||
|
||||
#include "auxiliar.h"
|
||||
#include "timeout.h"
|
||||
|
@ -6,7 +6,7 @@
|
||||
*
|
||||
* RCS ID: $Id: timeout.h,v 1.14 2005/10/07 04:40:59 diego Exp $
|
||||
\*=========================================================================*/
|
||||
#include "lua.h"
|
||||
#include "../luainc.h"
|
||||
|
||||
/* timeout control structure */
|
||||
typedef struct t_timeout_ {
|
@ -6,9 +6,6 @@
|
||||
\*=========================================================================*/
|
||||
#include <string.h>
|
||||
|
||||
#include "lua.h"
|
||||
#include "lauxlib.h"
|
||||
|
||||
#include "auxiliar.h"
|
||||
#include "socket.h"
|
||||
#include "inet.h"
|
@ -14,7 +14,7 @@
|
||||
*
|
||||
* RCS ID: $Id: udp.h,v 1.10 2005/10/07 04:40:59 diego Exp $
|
||||
\*=========================================================================*/
|
||||
#include "lua.h"
|
||||
#include "../luainc.h"
|
||||
|
||||
#include "timeout.h"
|
||||
#include "socket.h"
|
@ -7,9 +7,6 @@
|
||||
\*=========================================================================*/
|
||||
#include <string.h>
|
||||
|
||||
#include "lua.h"
|
||||
#include "lauxlib.h"
|
||||
|
||||
#include "auxiliar.h"
|
||||
#include "socket.h"
|
||||
#include "options.h"
|
@ -10,7 +10,7 @@
|
||||
*
|
||||
* RCS ID: $Id: unix.h,v 1.9 2006/03/13 07:16:39 diego Exp $
|
||||
\*=========================================================================*/
|
||||
#include "lua.h"
|
||||
#include "../luainc.h"
|
||||
|
||||
#include "buffer.h"
|
||||
#include "timeout.h"
|
@ -1,133 +0,0 @@
|
||||
-----------------------------------------------------------------------------
|
||||
-- LuaSocket helper module
|
||||
-- Author: Diego Nehab
|
||||
-- RCS ID: $Id: socket.lua,v 1.22 2005/11/22 08:33:29 diego Exp $
|
||||
-----------------------------------------------------------------------------
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
-- Declare module and import dependencies
|
||||
-----------------------------------------------------------------------------
|
||||
local base = _G
|
||||
local string = require("string")
|
||||
local math = require("math")
|
||||
local socket = require("socket.core")
|
||||
module("socket")
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
-- Exported auxiliar functions
|
||||
-----------------------------------------------------------------------------
|
||||
function connect(address, port, laddress, lport)
|
||||
local sock, err = socket.tcp()
|
||||
if not sock then return nil, err end
|
||||
if laddress then
|
||||
local res, err = sock:bind(laddress, lport, -1)
|
||||
if not res then return nil, err end
|
||||
end
|
||||
local res, err = sock:connect(address, port)
|
||||
if not res then return nil, err end
|
||||
return sock
|
||||
end
|
||||
|
||||
function bind(host, port, backlog)
|
||||
local sock, err = socket.tcp()
|
||||
if not sock then return nil, err end
|
||||
sock:setoption("reuseaddr", true)
|
||||
local res, err = sock:bind(host, port)
|
||||
if not res then return nil, err end
|
||||
res, err = sock:listen(backlog)
|
||||
if not res then return nil, err end
|
||||
return sock
|
||||
end
|
||||
|
||||
try = newtry()
|
||||
|
||||
function choose(table)
|
||||
return function(name, opt1, opt2)
|
||||
if base.type(name) ~= "string" then
|
||||
name, opt1, opt2 = "default", name, opt1
|
||||
end
|
||||
local f = table[name or "nil"]
|
||||
if not f then base.error("unknown key (".. base.tostring(name) ..")", 3)
|
||||
else return f(opt1, opt2) end
|
||||
end
|
||||
end
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
-- Socket sources and sinks, conforming to LTN12
|
||||
-----------------------------------------------------------------------------
|
||||
-- create namespaces inside LuaSocket namespace
|
||||
sourcet = {}
|
||||
sinkt = {}
|
||||
|
||||
BLOCKSIZE = 2048
|
||||
|
||||
sinkt["close-when-done"] = function(sock)
|
||||
return base.setmetatable({
|
||||
getfd = function() return sock:getfd() end,
|
||||
dirty = function() return sock:dirty() end
|
||||
}, {
|
||||
__call = function(self, chunk, err)
|
||||
if not chunk then
|
||||
sock:close()
|
||||
return 1
|
||||
else return sock:send(chunk) end
|
||||
end
|
||||
})
|
||||
end
|
||||
|
||||
sinkt["keep-open"] = function(sock)
|
||||
return base.setmetatable({
|
||||
getfd = function() return sock:getfd() end,
|
||||
dirty = function() return sock:dirty() end
|
||||
}, {
|
||||
__call = function(self, chunk, err)
|
||||
if chunk then return sock:send(chunk)
|
||||
else return 1 end
|
||||
end
|
||||
})
|
||||
end
|
||||
|
||||
sinkt["default"] = sinkt["keep-open"]
|
||||
|
||||
sink = choose(sinkt)
|
||||
|
||||
sourcet["by-length"] = function(sock, length)
|
||||
return base.setmetatable({
|
||||
getfd = function() return sock:getfd() end,
|
||||
dirty = function() return sock:dirty() end
|
||||
}, {
|
||||
__call = function()
|
||||
if length <= 0 then return nil end
|
||||
local size = math.min(socket.BLOCKSIZE, length)
|
||||
local chunk, err = sock:receive(size)
|
||||
if err then return nil, err end
|
||||
length = length - string.len(chunk)
|
||||
return chunk
|
||||
end
|
||||
})
|
||||
end
|
||||
|
||||
sourcet["until-closed"] = function(sock)
|
||||
local done
|
||||
return base.setmetatable({
|
||||
getfd = function() return sock:getfd() end,
|
||||
dirty = function() return sock:dirty() end
|
||||
}, {
|
||||
__call = function()
|
||||
if done then return nil end
|
||||
local chunk, err, partial = sock:receive(socket.BLOCKSIZE)
|
||||
if not err then return chunk
|
||||
elseif err == "closed" then
|
||||
sock:close()
|
||||
done = 1
|
||||
return partial
|
||||
else return nil, err end
|
||||
end
|
||||
})
|
||||
end
|
||||
|
||||
|
||||
sourcet["default"] = sourcet["until-closed"]
|
||||
|
||||
source = choose(sourcet)
|
||||
|
Loading…
Reference in New Issue
Block a user