From 6749c2547f5771a5b5bcea6e8d9991abf854ceed Mon Sep 17 00:00:00 2001 From: jacob1 Date: Sun, 8 Jun 2014 19:33:58 -0400 Subject: [PATCH] New SConscript (hopefully better) Fixes a lot of bugs, also almost all options are no longer needed and are just auto-detected --- SConscript | 1073 +++++++++++++-------------- SConstruct | 14 + generator.py | 10 +- src/Config.h | 17 +- src/PowderToySDL.cpp | 11 +- SDLMain.h => src/SDLMain.h | 0 SDLMain.m => src/SDLMain.m | 4 + src/gui/interface/Keys.h | 4 + src/lua/LuaBit.cpp | 7 +- src/lua/LuaButton.cpp | 6 - src/lua/LuaButton.h | 6 - src/lua/LuaCheckbox.cpp | 6 - src/lua/LuaCheckbox.h | 6 - src/lua/LuaComponent.cpp | 6 - src/lua/LuaComponent.h | 6 - src/lua/LuaLabel.cpp | 6 - src/lua/LuaLabel.h | 6 - src/lua/LuaLuna.h | 5 +- src/lua/LuaProgressBar.cpp | 6 - src/lua/LuaProgressBar.h | 6 - src/lua/LuaScriptInterface.h | 7 +- src/lua/LuaSlider.cpp | 6 - src/lua/LuaSlider.h | 6 - src/lua/LuaTextbox.cpp | 6 - src/lua/LuaTextbox.h | 6 - src/lua/LuaWindow.cpp | 6 - src/lua/LuaWindow.h | 6 - src/lua/luainc.h | 23 + src/{ => lua}/socket/auxiliar.c | 0 src/{ => lua}/socket/auxiliar.h | 3 +- src/{ => lua}/socket/buffer.c | 3 - src/{ => lua}/socket/buffer.h | 2 +- src/{ => lua}/socket/except.c | 3 - src/{ => lua}/socket/except.h | 2 +- src/{ => lua}/socket/inet.c | 3 - src/{ => lua}/socket/inet.h | 2 +- src/{ => lua}/socket/io.c | 0 src/{ => lua}/socket/io.h | 2 +- src/{ => lua}/socket/luasocket.c | 10 - src/{ => lua}/socket/luasocket.h | 2 +- src/{ => lua}/socket/options.c | 2 - src/{ => lua}/socket/options.h | 2 +- src/{ => lua}/socket/select.c | 3 - src/{ => lua}/socket/select.h | 0 src/{ => lua}/socket/socket.h | 0 src/{ => lua}/socket/socket.lua.cpp | 6 +- src/{ => lua}/socket/socket.lua.h | 2 +- src/{ => lua}/socket/tcp.c | 3 - src/{ => lua}/socket/tcp.h | 2 +- src/{ => lua}/socket/timeout.c | 3 - src/{ => lua}/socket/timeout.h | 2 +- src/{ => lua}/socket/udp.c | 3 - src/{ => lua}/socket/udp.h | 2 +- src/{ => lua}/socket/unix.c | 3 - src/{ => lua}/socket/unix.h | 2 +- src/{ => lua}/socket/usocket.c | 0 src/{ => lua}/socket/usocket.h | 0 src/{ => lua}/socket/wsocket.c | 0 src/{ => lua}/socket/wsocket.h | 0 src/socket/socket.lua | 133 ---- 60 files changed, 604 insertions(+), 867 deletions(-) mode change 100755 => 100644 SConscript rename SDLMain.h => src/SDLMain.h (100%) rename SDLMain.m => src/SDLMain.m (99%) create mode 100644 src/lua/luainc.h rename src/{ => lua}/socket/auxiliar.c (100%) rename src/{ => lua}/socket/auxiliar.h (98%) rename src/{ => lua}/socket/buffer.c (99%) rename src/{ => lua}/socket/buffer.h (98%) rename src/{ => lua}/socket/except.c (98%) rename src/{ => lua}/socket/except.h (98%) rename src/{ => lua}/socket/inet.c (99%) rename src/{ => lua}/socket/inet.h (98%) rename src/{ => lua}/socket/io.c (100%) rename src/{ => lua}/socket/io.h (98%) rename src/{ => lua}/socket/luasocket.c (92%) rename src/{ => lua}/socket/luasocket.h (98%) rename src/{ => lua}/socket/options.c (99%) rename src/{ => lua}/socket/options.h (98%) rename src/{ => lua}/socket/select.c (99%) rename src/{ => lua}/socket/select.h (100%) rename src/{ => lua}/socket/socket.h (100%) rename src/{ => lua}/socket/socket.lua.cpp (98%) rename src/{ => lua}/socket/socket.lua.h (60%) rename src/{ => lua}/socket/tcp.c (99%) rename src/{ => lua}/socket/tcp.h (97%) rename src/{ => lua}/socket/timeout.c (99%) rename src/{ => lua}/socket/timeout.h (97%) rename src/{ => lua}/socket/udp.c (99%) rename src/{ => lua}/socket/udp.h (97%) rename src/{ => lua}/socket/unix.c (99%) rename src/{ => lua}/socket/unix.h (96%) rename src/{ => lua}/socket/usocket.c (100%) rename src/{ => lua}/socket/usocket.h (100%) rename src/{ => lua}/socket/wsocket.c (100%) rename src/{ => lua}/socket/wsocket.h (100%) delete mode 100644 src/socket/socket.lua diff --git a/SConscript b/SConscript old mode 100755 new mode 100644 index b81ba62a0..4c47413af --- a/SConscript +++ b/SConscript @@ -1,547 +1,526 @@ -# ============ -# 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 time - -# 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:]) - cmdline = cmd + " " + newargs - startupinfo = subprocess.STARTUPINFO() - startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW - proc = subprocess.Popen(cmdline, stdin=subprocess.PIPE, stdout=subprocess.PIPE, - stderr=subprocess.PIPE, startupinfo=startupinfo, shell = False, env = env) - data, err = proc.communicate() - rv = proc.wait() - if rv: - print "=====" - print err - print "=====" - return rv - -def SetupSpawn( env ): - if sys.platform == 'win32': - 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" - raise SystemExit(1) - -# windows specific platform settings -# ++++++++++++++++++++++++++++++++++ - -# if the platform is windows switch to a mingw toolset, use the default otherwise - -if(GetOption('win')): - env = Environment(tools = ['mingw'], ENV = os.environ) -else: - env = Environment(tools = ['default'], ENV = os.environ) - -if(GetOption("copy_env")): - singlevar=["CC","CXX","LD","LIBPATH"] - multivar=["CFLAGS","CCFLAGS","LINKFLAGS"] # variables containing several space separated things - for var in singlevar: - 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: - if var in os.environ: - 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")]) - else: - -# otherwise try to parse the pkg config for sdl and grab the correct flags from there. - - 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) - - -# 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) - else: - env.Append(CPPPATH=[GetOption("lua-dir")]) - 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) - -# if fft is enabled try to parse its config, fail otherwise. - - 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) - -# try to autodetect some libraries, fail otherwise - - #Check for Bzip lib - if not conf.CheckLib('bz2'): - print "libbz2 not found or not installed" - raise SystemExit(1) - - #Check for zlib - if not conf.CheckLib('z'): - print "libz not found or not installed" - raise SystemExit(1) - - if not conf.CheckCHeader("bzlib.h"): - print "bzip2 headers not found" - raise SystemExit(1) - -# finish the configuration - - env = conf.Finish(); -else: - -# if we ARE on macosx add the libraries to LIBS -# .. : seems like we're terrible at mac support? what gives? - - env.Append(LIBS=['z', 'bz2']) - if not GetOption('nofft'): - env.Append(LIBS=['fftw3f']) - -# enviroment setup -# ================ - -# add the correct compiler flags. - -# generic enviroment settings -# +++++++++++++++++++++++++++ - -# 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 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 - -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 - -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']) - 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"]) - - -# windows specific enviroment settings -# ++++++++++++++++++++++++++++++++++++ - -# check if we're compiling for windows, if we are include windows specific libraries and defines. - -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']) - -# 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')]) - else: - env.Append(CPPDEFINES=['SNAPSHOT_ID=' + str(int(time.time()))]) - env.Append(CPPDEFINES='SNAPSHOT') -elif(GetOption('stable')): - env.Append(CPPDEFINES='STABLE') - -if(GetOption('save-version')): - env.Append(CPPDEFINES=['SAVE_VERSION=' + GetOption('save-version')]) - -if(GetOption('minor-version')): - env.Append(CPPDEFINES=['MINOR_VERSION=' + GetOption('minor-version')]) - -if(GetOption('build-number')): - env.Append(CPPDEFINES=['BUILD_NUM=' + GetOption('build-number')]) - -if(GetOption('x86')): - env.Append(CPPDEFINES='X86') - -if(GetOption('debug')): - env.Append(CPPDEFINES='DEBUG') - env.Append(CCFLAGS='-g') - -if(GetOption('sse')): - env.Append(CCFLAGS='-msse') - env.Append(CPPDEFINES='X86_SSE') - -if(GetOption('sse2')): - env.Append(CCFLAGS='-msse2') - env.Append(CPPDEFINES='X86_SSE2') - -if(GetOption('sse3')): - env.Append(CCFLAGS='-msse3') - env.Append(CPPDEFINES='X86_SSE3') - -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')): - 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) - -# 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')): - programName += "64" - -if(not (GetOption('sse2') or GetOption('sse3'))): - programName += "-legacy" - -if(GetOption('macosx')): - programName += "-x" - -if(GetOption('win')): - programName += ".exe" - - -# 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) -Default(t) + +import os +import subprocess +import sys +import platform +import atexit +import time +import SCons.Util + + +# 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:]) + cmdline = cmd + " " + newargs + startupinfo = subprocess.STARTUPINFO() + startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW + proc = subprocess.Popen(cmdline, stdin=subprocess.PIPE, stdout=subprocess.PIPE, + stderr=subprocess.PIPE, startupinfo=startupinfo, shell = False, env = env) + data, err = proc.communicate() + rv = proc.wait() + if rv: + print "=====" + print err + print "=====" + return rv +def SetupSpawn(env): + buf = ourSpawn() + buf.ourenv = env + env['SPAWN'] = buf.ourspawn + +def FatalError(message): + print(message) + raise SystemExit(1) + +#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) + +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++") + +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 = {'PATH' : os.environ['PATH']}) + +#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 "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]) + else: + 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']) + +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 + #include + 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: + pass + + #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: + 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: + pass + + #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") + + #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") + + #Look for bz2 + if not conf.CheckLib(['bz2', 'libbz2']): + FatalError("bz2 development library not found or not installed") + + #Check bz2 header too for some reason + if not conf.CheckCHeader('bzlib.h'): + FatalError("bzip2 headers not found") + + #Look for libz + if not conf.CheckLib('z'): + FatalError("libz not found or not installed") + + #Look for pthreads + if not conf.CheckLib(['pthread', 'pthreadVC2']): + FatalError("pthreads development library not found or not installed") + + 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") + + #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]) + + 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") + + if platform == "Linux": + if not conf.CheckLib('X11'): + FatalError("X11 development library not found or not installed") + + 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") + + #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") + +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() + +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") + + +#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") + + +#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') + + +#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']) + +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') + + +#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") + +if GetOption('opengl') or GetOption('opengl-renderer'): + env.Append(CPPDEFINES=['OGLI', 'PIX32OGL']) + if GetOption('opengl-renderer'): + env.Append(CPPDEFINES='OGLR') + +if GetOption('renderer'): + env.Append(CPPDEFINES='RENDERER') +else: + env.Append(CPPDEFINES='USE_SDL') + +if GetOption("wall"): + if msvc: + env.Append(CCFLAGS='/WX') + else: + env.Append(CCFLAGS='-Werror') +elif GetOption("no-warnings"): + if msvc: + env.Append(CCFLAGS='/W0') + else: + env.Append(CCFLAGS='-w') + + +#Add version defines +if GetOption('save-version'): + env.Append(CPPDEFINES="SAVE_VERSION={}".format(GetOption('save-version'))) + +if GetOption('minor-version'): + env.Append(CPPDEFINES="MINOR_VERSION={}".format(GetOption('minor-version'))) + +if GetOption('build-number'): + env.Append(CPPDEFINES="BUILD_NUM={}".format(GetOption('build-number'))) + +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('beta'): + env.Append(CPPDEFINES="BETA") + + +#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 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"] + + +#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 isX86 and GetOption('no-sse'): + programName += "-legacy" + if platform == "Windows": + programName = programName.capitalize() + programName += ".exe" + elif platform == "Darwin": + programName += "-x" + +#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) + +#Once we get here, finally compile +env.Decider('MD5-timestamp') +SetOption('implicit_cache', 1) +t = env.Program(target=programName, source=sources) +Default(t) diff --git a/SConstruct b/SConstruct index 81456fde4..862d7c7ce 100644 --- a/SConstruct +++ b/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" diff --git a/generator.py b/generator.py index db60a6be7..a5df4863e 100644 --- a/generator.py +++ b/generator.py @@ -223,11 +223,5 @@ std::vector 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") diff --git a/src/Config.h b/src/Config.h index 90252826c..39c381f6a 100644 --- a/src/Config.h +++ b/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" diff --git a/src/PowderToySDL.cpp b/src/PowderToySDL.cpp index 88a680168..e7ab543a4 100644 --- a/src/PowderToySDL.cpp +++ b/src/PowderToySDL.cpp @@ -3,10 +3,13 @@ #include #include #include +#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 #endif #include @@ -49,9 +52,13 @@ extern "C" { using namespace std; -#if defined(USE_SDL) && defined(LIN) +#if defined(WIN) || defined(LIN) +#ifdef SDL_INC +#include +#else #include #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; diff --git a/SDLMain.h b/src/SDLMain.h similarity index 100% rename from SDLMain.h rename to src/SDLMain.h diff --git a/SDLMain.m b/src/SDLMain.m similarity index 99% rename from SDLMain.m rename to src/SDLMain.m index 50c4b890f..fbe9da2df 100644 --- a/SDLMain.m +++ b/src/SDLMain.m @@ -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 /* for MAXPATHLEN */ #include diff --git a/src/gui/interface/Keys.h b/src/gui/interface/Keys.h index 2707d4fdf..43e72ed6d 100644 --- a/src/gui/interface/Keys.h +++ b/src/gui/interface/Keys.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 diff --git a/src/lua/LuaBit.cpp b/src/lua/LuaBit.cpp index f1479d05a..d03db4132 100644 --- a/src/lua/LuaBit.cpp +++ b/src/lua/LuaBit.cpp @@ -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. */ diff --git a/src/lua/LuaButton.cpp b/src/lua/LuaButton.cpp index 1b55f895d..b4adf3b86 100644 --- a/src/lua/LuaButton.cpp +++ b/src/lua/LuaButton.cpp @@ -1,10 +1,4 @@ #ifdef LUACONSOLE -extern "C" -{ -#include "lua.h" -#include "lauxlib.h" -#include "lualib.h" -} #include #include "LuaButton.h" diff --git a/src/lua/LuaButton.h b/src/lua/LuaButton.h index 69a77a4e7..6a7b965f6 100644 --- a/src/lua/LuaButton.h +++ b/src/lua/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" diff --git a/src/lua/LuaCheckbox.cpp b/src/lua/LuaCheckbox.cpp index 55c39db68..24883e916 100644 --- a/src/lua/LuaCheckbox.cpp +++ b/src/lua/LuaCheckbox.cpp @@ -1,10 +1,4 @@ #ifdef LUACONSOLE -extern "C" -{ -#include "lua.h" -#include "lauxlib.h" -#include "lualib.h" -} #include #include "LuaCheckbox.h" diff --git a/src/lua/LuaCheckbox.h b/src/lua/LuaCheckbox.h index 0f2e8ad2a..9dfc5a26a 100644 --- a/src/lua/LuaCheckbox.h +++ b/src/lua/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" diff --git a/src/lua/LuaComponent.cpp b/src/lua/LuaComponent.cpp index 028dfb58c..f455732ea 100644 --- a/src/lua/LuaComponent.cpp +++ b/src/lua/LuaComponent.cpp @@ -1,10 +1,4 @@ #ifdef LUACONSOLE -extern "C" -{ -#include "lua.h" -#include "lauxlib.h" -#include "lualib.h" -} #include #include "LuaComponent.h" diff --git a/src/lua/LuaComponent.h b/src/lua/LuaComponent.h index 8e408909d..6d0fad8b2 100644 --- a/src/lua/LuaComponent.h +++ b/src/lua/LuaComponent.h @@ -1,11 +1,5 @@ #pragma once -extern "C" { - #include "lua.h" - #include "lauxlib.h" - #include "lualib.h" -} - #include "LuaLuna.h" namespace ui diff --git a/src/lua/LuaLabel.cpp b/src/lua/LuaLabel.cpp index 4131918d0..07ad636ac 100644 --- a/src/lua/LuaLabel.cpp +++ b/src/lua/LuaLabel.cpp @@ -1,10 +1,4 @@ #ifdef LUACONSOLE -extern "C" -{ -#include "lua.h" -#include "lauxlib.h" -#include "lualib.h" -} #include #include "LuaScriptInterface.h" diff --git a/src/lua/LuaLabel.h b/src/lua/LuaLabel.h index 2653d9c27..59c86b530 100644 --- a/src/lua/LuaLabel.h +++ b/src/lua/LuaLabel.h @@ -1,11 +1,5 @@ #pragma once -extern "C" { - #include "lua.h" - #include "lauxlib.h" - #include "lualib.h" -} - #include "LuaLuna.h" #include "LuaComponent.h" diff --git a/src/lua/LuaLuna.h b/src/lua/LuaLuna.h index 9fa4042e6..784efa2a3 100644 --- a/src/lua/LuaLuna.h +++ b/src/lua/LuaLuna.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 class Luna { diff --git a/src/lua/LuaProgressBar.cpp b/src/lua/LuaProgressBar.cpp index 787cfcfad..cb6a9faaa 100644 --- a/src/lua/LuaProgressBar.cpp +++ b/src/lua/LuaProgressBar.cpp @@ -1,10 +1,4 @@ #ifdef LUACONSOLE -extern "C" -{ -#include "lua.h" -#include "lauxlib.h" -#include "lualib.h" -} #include #include "LuaProgressBar.h" diff --git a/src/lua/LuaProgressBar.h b/src/lua/LuaProgressBar.h index a27ddee36..1c86b2fd2 100644 --- a/src/lua/LuaProgressBar.h +++ b/src/lua/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" diff --git a/src/lua/LuaScriptInterface.h b/src/lua/LuaScriptInterface.h index edef9dfe2..e73a9b144 100644 --- a/src/lua/LuaScriptInterface.h +++ b/src/lua/LuaScriptInterface.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" diff --git a/src/lua/LuaSlider.cpp b/src/lua/LuaSlider.cpp index f8505d2e3..28b847bfa 100644 --- a/src/lua/LuaSlider.cpp +++ b/src/lua/LuaSlider.cpp @@ -1,10 +1,4 @@ #ifdef LUACONSOLE -extern "C" -{ -#include "lua.h" -#include "lauxlib.h" -#include "lualib.h" -} #include #include "LuaSlider.h" diff --git a/src/lua/LuaSlider.h b/src/lua/LuaSlider.h index a1a97c45f..3fd919ed5 100644 --- a/src/lua/LuaSlider.h +++ b/src/lua/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" diff --git a/src/lua/LuaTextbox.cpp b/src/lua/LuaTextbox.cpp index 89191a65a..474c02d00 100644 --- a/src/lua/LuaTextbox.cpp +++ b/src/lua/LuaTextbox.cpp @@ -1,10 +1,4 @@ #ifdef LUACONSOLE -extern "C" -{ -#include "lua.h" -#include "lauxlib.h" -#include "lualib.h" -} #include #include "LuaScriptInterface.h" diff --git a/src/lua/LuaTextbox.h b/src/lua/LuaTextbox.h index 9a45f618d..9f56740b7 100644 --- a/src/lua/LuaTextbox.h +++ b/src/lua/LuaTextbox.h @@ -1,11 +1,5 @@ #pragma once -extern "C" { - #include "lua.h" - #include "lauxlib.h" - #include "lualib.h" -} - #include "LuaLuna.h" #include "LuaComponent.h" diff --git a/src/lua/LuaWindow.cpp b/src/lua/LuaWindow.cpp index 46701f717..1c12583d8 100644 --- a/src/lua/LuaWindow.cpp +++ b/src/lua/LuaWindow.cpp @@ -1,10 +1,4 @@ #ifdef LUACONSOLE -extern "C" -{ -#include "lua.h" -#include "lauxlib.h" -#include "lualib.h" -} #include #include "LuaScriptInterface.h" diff --git a/src/lua/LuaWindow.h b/src/lua/LuaWindow.h index 187b3ddd8..69123cc22 100644 --- a/src/lua/LuaWindow.h +++ b/src/lua/LuaWindow.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" diff --git a/src/lua/luainc.h b/src/lua/luainc.h new file mode 100644 index 000000000..11940890c --- /dev/null +++ b/src/lua/luainc.h @@ -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 diff --git a/src/socket/auxiliar.c b/src/lua/socket/auxiliar.c similarity index 100% rename from src/socket/auxiliar.c rename to src/lua/socket/auxiliar.c diff --git a/src/socket/auxiliar.h b/src/lua/socket/auxiliar.h similarity index 98% rename from src/socket/auxiliar.h rename to src/lua/socket/auxiliar.h index 18b849554..9a6cceb74 100644 --- a/src/socket/auxiliar.h +++ b/src/lua/socket/auxiliar.h @@ -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); diff --git a/src/socket/buffer.c b/src/lua/socket/buffer.c similarity index 99% rename from src/socket/buffer.c rename to src/lua/socket/buffer.c index 73f4ffa85..44765e6d7 100644 --- a/src/socket/buffer.c +++ b/src/lua/socket/buffer.c @@ -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" /*=========================================================================*\ diff --git a/src/socket/buffer.h b/src/lua/socket/buffer.h similarity index 98% rename from src/socket/buffer.h rename to src/lua/socket/buffer.h index baf93caa0..d7591c8d1 100644 --- a/src/socket/buffer.h +++ b/src/lua/socket/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" diff --git a/src/socket/except.c b/src/lua/socket/except.c similarity index 98% rename from src/socket/except.c rename to src/lua/socket/except.c index 5faa5be00..47b78b4d2 100644 --- a/src/socket/except.c +++ b/src/lua/socket/except.c @@ -6,9 +6,6 @@ \*=========================================================================*/ #include -#include "lua.h" -#include "lauxlib.h" - #include "except.h" /*=========================================================================*\ diff --git a/src/socket/except.h b/src/lua/socket/except.h similarity index 98% rename from src/socket/except.h rename to src/lua/socket/except.h index 81efb29be..044a12157 100644 --- a/src/socket/except.h +++ b/src/lua/socket/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); diff --git a/src/socket/inet.c b/src/lua/socket/inet.c similarity index 99% rename from src/socket/inet.c rename to src/lua/socket/inet.c index f2cddeeab..52544b1a9 100644 --- a/src/socket/inet.c +++ b/src/lua/socket/inet.c @@ -7,9 +7,6 @@ #include #include -#include "lua.h" -#include "lauxlib.h" - #include "inet.h" /*=========================================================================*\ diff --git a/src/socket/inet.h b/src/lua/socket/inet.h similarity index 98% rename from src/socket/inet.h rename to src/lua/socket/inet.h index 766226611..68c30ef1c 100644 --- a/src/socket/inet.h +++ b/src/lua/socket/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" diff --git a/src/socket/io.c b/src/lua/socket/io.c similarity index 100% rename from src/socket/io.c rename to src/lua/socket/io.c diff --git a/src/socket/io.h b/src/lua/socket/io.h similarity index 98% rename from src/socket/io.h rename to src/lua/socket/io.h index cce3aaf55..2d5b9ef3d 100644 --- a/src/socket/io.h +++ b/src/lua/socket/io.h @@ -15,7 +15,7 @@ * RCS ID: $Id: io.h,v 1.11 2005/10/07 04:40:59 diego Exp $ \*=========================================================================*/ #include -#include "lua.h" +#include "../luainc.h" #include "timeout.h" diff --git a/src/socket/luasocket.c b/src/lua/socket/luasocket.c similarity index 92% rename from src/socket/luasocket.c rename to src/lua/socket/luasocket.c index 11ffee94c..d3847b218 100644 --- a/src/socket/luasocket.c +++ b/src/lua/socket/luasocket.c @@ -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 \*=========================================================================*/ diff --git a/src/socket/luasocket.h b/src/lua/socket/luasocket.h similarity index 98% rename from src/socket/luasocket.h rename to src/lua/socket/luasocket.h index 67270abb9..22896085b 100644 --- a/src/socket/luasocket.h +++ b/src/lua/socket/luasocket.h @@ -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 diff --git a/src/socket/options.c b/src/lua/socket/options.c similarity index 99% rename from src/socket/options.c rename to src/lua/socket/options.c index 5da3c518c..a51850501 100644 --- a/src/socket/options.c +++ b/src/lua/socket/options.c @@ -6,8 +6,6 @@ \*=========================================================================*/ #include -#include "lauxlib.h" - #include "auxiliar.h" #include "options.h" #include "inet.h" diff --git a/src/socket/options.h b/src/lua/socket/options.h similarity index 98% rename from src/socket/options.h rename to src/lua/socket/options.h index 4981cf2a0..5a6ba4663 100644 --- a/src/socket/options.h +++ b/src/lua/socket/options.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 */ diff --git a/src/socket/select.c b/src/lua/socket/select.c similarity index 99% rename from src/socket/select.c rename to src/lua/socket/select.c index d70f66271..d2d3cf88b 100644 --- a/src/socket/select.c +++ b/src/lua/socket/select.c @@ -6,9 +6,6 @@ \*=========================================================================*/ #include -#include "lua.h" -#include "lauxlib.h" - #include "socket.h" #include "timeout.h" #include "select.h" diff --git a/src/socket/select.h b/src/lua/socket/select.h similarity index 100% rename from src/socket/select.h rename to src/lua/socket/select.h diff --git a/src/socket/socket.h b/src/lua/socket/socket.h similarity index 100% rename from src/socket/socket.h rename to src/lua/socket/socket.h diff --git a/src/socket/socket.lua.cpp b/src/lua/socket/socket.lua.cpp similarity index 98% rename from src/socket/socket.lua.cpp rename to src/lua/socket/socket.lua.cpp index 4952cce62..2ccebb105 100644 --- a/src/socket/socket.lua.cpp +++ b/src/lua/socket/socket.lua.cpp @@ -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"; diff --git a/src/socket/socket.lua.h b/src/lua/socket/socket.lua.h similarity index 60% rename from src/socket/socket.lua.h rename to src/lua/socket/socket.lua.h index 2e527c859..6642fc81d 100644 --- a/src/socket/socket.lua.h +++ b/src/lua/socket/socket.lua.h @@ -1,2 +1,2 @@ -#include "lua.h" +#include "../luainc.h" void luaopen_socket(lua_State *l); diff --git a/src/socket/tcp.c b/src/lua/socket/tcp.c similarity index 99% rename from src/socket/tcp.c rename to src/lua/socket/tcp.c index 6b8a79b4b..ca133b836 100644 --- a/src/socket/tcp.c +++ b/src/lua/socket/tcp.c @@ -6,9 +6,6 @@ \*=========================================================================*/ #include -#include "lua.h" -#include "lauxlib.h" - #include "auxiliar.h" #include "socket.h" #include "inet.h" diff --git a/src/socket/tcp.h b/src/lua/socket/tcp.h similarity index 97% rename from src/socket/tcp.h rename to src/lua/socket/tcp.h index 511357f37..9178c86f1 100644 --- a/src/socket/tcp.h +++ b/src/lua/socket/tcp.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" diff --git a/src/socket/timeout.c b/src/lua/socket/timeout.c similarity index 99% rename from src/socket/timeout.c rename to src/lua/socket/timeout.c index c1df10218..66aee12ea 100644 --- a/src/socket/timeout.c +++ b/src/lua/socket/timeout.c @@ -6,9 +6,6 @@ \*=========================================================================*/ #include -#include "lua.h" -#include "lauxlib.h" - #include "auxiliar.h" #include "timeout.h" diff --git a/src/socket/timeout.h b/src/lua/socket/timeout.h similarity index 97% rename from src/socket/timeout.h rename to src/lua/socket/timeout.h index d2d896410..7a0841833 100644 --- a/src/socket/timeout.h +++ b/src/lua/socket/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_ { diff --git a/src/socket/udp.c b/src/lua/socket/udp.c similarity index 99% rename from src/socket/udp.c rename to src/lua/socket/udp.c index fc25aa027..50c4e60e5 100644 --- a/src/socket/udp.c +++ b/src/lua/socket/udp.c @@ -6,9 +6,6 @@ \*=========================================================================*/ #include -#include "lua.h" -#include "lauxlib.h" - #include "auxiliar.h" #include "socket.h" #include "inet.h" diff --git a/src/socket/udp.h b/src/lua/socket/udp.h similarity index 97% rename from src/socket/udp.h rename to src/lua/socket/udp.h index 280171217..3fefbc8fe 100644 --- a/src/socket/udp.h +++ b/src/lua/socket/udp.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" diff --git a/src/socket/unix.c b/src/lua/socket/unix.c similarity index 99% rename from src/socket/unix.c rename to src/lua/socket/unix.c index 048630f19..fc9b487e3 100644 --- a/src/socket/unix.c +++ b/src/lua/socket/unix.c @@ -7,9 +7,6 @@ \*=========================================================================*/ #include -#include "lua.h" -#include "lauxlib.h" - #include "auxiliar.h" #include "socket.h" #include "options.h" diff --git a/src/socket/unix.h b/src/lua/socket/unix.h similarity index 96% rename from src/socket/unix.h rename to src/lua/socket/unix.h index f3b543e06..9f23a05a2 100644 --- a/src/socket/unix.h +++ b/src/lua/socket/unix.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" diff --git a/src/socket/usocket.c b/src/lua/socket/usocket.c similarity index 100% rename from src/socket/usocket.c rename to src/lua/socket/usocket.c diff --git a/src/socket/usocket.h b/src/lua/socket/usocket.h similarity index 100% rename from src/socket/usocket.h rename to src/lua/socket/usocket.h diff --git a/src/socket/wsocket.c b/src/lua/socket/wsocket.c similarity index 100% rename from src/socket/wsocket.c rename to src/lua/socket/wsocket.c diff --git a/src/socket/wsocket.h b/src/lua/socket/wsocket.h similarity index 100% rename from src/socket/wsocket.h rename to src/lua/socket/wsocket.h diff --git a/src/socket/socket.lua b/src/socket/socket.lua deleted file mode 100644 index 211adcd1d..000000000 --- a/src/socket/socket.lua +++ /dev/null @@ -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) -