2012-07-22 12:51:05 -05:00
import os , sys , subprocess , time
2012-07-07 13:08:05 -05:00
##Fix for long command line - http://scons.org/wiki/LongCmdLinesOnWin32
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
AddOption ( ' --opengl-renderer ' , dest = " opengl-renderer " , action = ' store_true ' , default = False , help = " Build with OpenGL renderer support. (requires --opengl) " )
AddOption ( ' --opengl ' , dest = " opengl " , action = ' store_true ' , default = False , help = " Build with OpenGL interface support. " )
2012-07-20 15:19:37 -05:00
AddOption ( ' --win32 ' , dest = " win32 " , action = ' store_true ' , default = False , help = " 32bit Windows platform target. " )
2012-07-29 10:55:26 -05:00
AddOption ( ' --lin ' , dest = " lin " , action = ' store_true ' , default = False , help = " Linux platform target " )
2012-07-20 15:19:37 -05:00
AddOption ( ' --macosx ' , dest = " macosx " , action = ' store_true ' , default = False , help = " Mac OS X platform target " )
2012-07-29 10:55:26 -05:00
AddOption ( ' --64bit ' , dest = " _64bit " , action = ' store_true ' , default = False , help = " 64-bit platform target (Linux only at the moment) " )
2012-07-11 15:11:13 -05:00
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 " )
2012-07-07 13:08:05 -05:00
AddOption ( ' --release ' , dest = " release " , action = ' store_true ' , default = False , help = " Enable optimisations (Will slow down compiling) " )
2012-07-08 08:03:51 -05:00
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 " )
2012-07-11 15:11:13 -05:00
AddOption ( ' --tool ' , dest = " toolprefix " , default = False , help = " Prefix " )
2012-07-20 15:19:37 -05:00
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 " )
2012-07-28 12:37:49 -05:00
AddOption ( ' --debugging ' , dest = " debug " , action = " store_true " , default = False , help = " Enable debug options " )
2012-07-22 13:33:56 -05:00
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 " , default = False , help = " Snapshot build. " )
2012-07-29 10:55:26 -05:00
if ( ( not GetOption ( ' lin ' ) ) and ( not GetOption ( ' win32 ' ) ) and ( not GetOption ( ' macosx ' ) ) ) :
2012-07-20 15:19:37 -05:00
print " You must specify a platform to target "
raise SystemExit ( 1 )
2012-07-07 13:08:05 -05:00
if ( GetOption ( ' win32 ' ) ) :
env = Environment ( tools = [ ' mingw ' ] , ENV = os . environ )
else :
env = Environment ( ENV = os . environ )
2012-07-11 15:11:13 -05:00
if GetOption ( " toolprefix " ) :
env [ ' CC ' ] = GetOption ( " toolprefix " ) + env [ ' CC ' ]
env [ ' CXX ' ] = GetOption ( " toolprefix " ) + env [ ' CXX ' ]
env [ ' RC ' ] = GetOption ( " toolprefix " ) + env [ ' RC ' ]
2012-07-07 13:08:05 -05:00
#Check for headers and libraries
conf = Configure ( env )
2012-07-08 08:03:51 -05:00
try :
env . ParseConfig ( ' sdl-config --cflags ' )
env . ParseConfig ( ' sdl-config --libs ' )
except :
conf . CheckLib ( " SDL " )
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 :
2012-07-08 13:26:31 -05:00
env . Append ( CPPPATH = GetOption ( " sdl-dir " ) )
2012-07-07 13:08:05 -05:00
2012-07-08 08:03:51 -05:00
#Find correct lua include dir
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 :
2012-07-08 13:26:31 -05:00
env . Append ( CPPPATH = GetOption ( " lua-dir " ) )
2012-07-07 13:08:05 -05:00
#Check for FFT lib
2012-07-08 08:03:51 -05:00
if not conf . CheckLib ( ' fftw3f ' ) and not conf . CheckLib ( ' fftw3f-3 ' ) :
2012-07-07 13:08:05 -05:00
print " libfftw3f not found or not installed "
raise SystemExit ( 1 )
#Check for Lua lib
2012-07-08 08:03:51 -05:00
if not conf . CheckLib ( ' lua ' ) and not conf . CheckLib ( ' lua5.1 ' ) and not conf . CheckLib ( ' lua51 ' ) :
2012-07-07 13:08:05 -05:00
print " liblua not found or not installed "
raise SystemExit ( 1 )
env = conf . Finish ( ) ;
2012-07-08 08:03:51 -05:00
env . Append ( CPPPATH = [ ' src/ ' , ' data/ ' , ' generated/ ' ] )
2012-07-07 13:08:05 -05:00
env . Append ( CCFLAGS = [ ' -w ' , ' -std=c99 ' , ' -fkeep-inline-functions ' ] )
2012-07-08 08:03:51 -05:00
env . Append ( LIBS = [ ' pthread ' , ' m ' , ' bz2 ' ] )
env . Append ( CPPDEFINES = { " _POSIX_C_SOURCE " : " 200112L " } )
env . Append ( CPPDEFINES = [ " USE_SDL " , " LUACONSOLE " , " GRAVFFT " , " _GNU_SOURCE " , " USE_STDINT " ] )
2012-07-07 13:08:05 -05:00
2012-07-11 15:11:13 -05:00
if GetOption ( " ptw32-static " ) :
env . Append ( CPPDEFINES = [ ' PTW32_STATIC_LIB ' ] ) ;
if ( GetOption ( ' static ' ) ) :
env . Append ( LINKFLAGS = [ ' -static-libgcc ' ] )
2012-07-07 13:08:05 -05:00
if ( GetOption ( ' win32 ' ) ) :
openGLLibs = [ ' opengl32 ' , ' glew32 ' ]
env . Prepend ( LIBS = [ ' mingw32 ' , ' ws2_32 ' , ' SDLmain ' , ' regex ' ] )
2012-07-11 15:11:13 -05:00
env . Append ( LIBS = [ ' winmm ' , ' gdi32 ' ] )
2012-07-07 13:08:05 -05:00
env . Append ( CPPDEFINES = [ " WIN32 " ] )
2012-07-11 15:11:13 -05:00
env . Append ( LINKFLAGS = [ ' -mwindows ' ] )
2012-07-29 10:55:26 -05:00
if ( GetOption ( ' lin ' ) :
2012-07-07 13:08:05 -05:00
openGLLibs = [ ' GL ' ]
env . Append ( LIBS = [ ' X11 ' , ' rt ' ] )
2012-07-29 10:55:26 -05:00
env . Append ( CPPDEFINES = [ " LIN " ] )
if GetOption ( ' _64bit ' ) :
env . Append ( CPPDEFINES = [ " _64BIT " ] )
env . Append ( LINKFAGS = [ ' -m64 ' ] )
env . Append ( CCFLAGS = [ ' -m64 ' ] )
else :
2012-07-08 13:26:31 -05:00
env . Append ( LINKFLAGS = [ ' -m32 ' ] )
2012-07-08 08:03:51 -05:00
env . Append ( CCFLAGS = [ ' -m32 ' ] )
2012-07-07 13:08:05 -05:00
2012-07-22 13:33:56 -05:00
if ( GetOption ( ' beta ' ) ) :
env . Append ( CPPDEFINES = ' BETA ' )
if ( GetOption ( ' snapshot ' ) ) :
env . Append ( CPPDEFINES = { ' SNAPSHOT_ID ' : GetOption ( ' snapshot ' ) } )
env . Append ( CPPDEFINES = ' SNAPSHOT ' )
2012-07-22 13:39:58 -05:00
else :
env . Append ( CPPDEFINES = { " SNAPSHOT_ID " : int ( time . time ( ) ) } )
2012-07-22 13:33:56 -05:00
if ( GetOption ( ' save-version ' ) ) :
env . Append ( CPPDEFINES = { ' SAVE_VERSION ' : GetOption ( ' major-version ' ) } )
if ( GetOption ( ' minor-version ' ) ) :
env . Append ( CPPDEFINES = { ' MINOR_VERSION ' : GetOption ( ' minor-version ' ) } )
2012-07-07 13:08:05 -05:00
if ( GetOption ( ' release ' ) ) :
2012-07-20 15:19:37 -05:00
env . Append ( CCFLAGS = [ ' -O3 ' , ' -ftree-vectorize ' , ' -funsafe-math-optimizations ' , ' -ffast-math ' , ' -fomit-frame-pointer ' , ' -funsafe-loop-optimizations ' , ' -Wunsafe-loop-optimizations ' ] )
if ( GetOption ( ' x86 ' ) ) :
env . Append ( CPPDEFINES = ' X86 ' )
2012-07-28 12:37:49 -05:00
if ( GetOption ( ' debug ' ) ) :
env . Append ( CPPDEFINES = ' DEBUG ' )
env . Append ( CCFLAGS = ' -g ' )
2012-07-20 15:19:37 -05:00
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 ' )
2012-07-07 13:08:05 -05:00
if ( GetOption ( ' opengl ' ) ) :
env . Append ( CPPDEFINES = [ " OGLI " , " PIX32OGL " ] )
env . Append ( LIBS = openGLLibs )
if ( GetOption ( ' opengl-renderer ' ) and GetOption ( ' opengl-renderer ' ) ) :
env . Append ( CPPDEFINES = [ " OGLR " ] )
elif ( GetOption ( ' opengl-renderer ' ) ) :
print " opengl-renderer requires opengl "
raise SystemExit ( 1 )
sources = Glob ( " src/*.cpp " )
if ( GetOption ( ' win32 ' ) ) :
2012-07-22 13:39:58 -05:00
sources + = env . RES ( ' resources/powder-res.rc ' )
2012-07-07 13:08:05 -05:00
sources + = Glob ( " src/*/*.cpp " )
sources + = Glob ( " src/simulation/elements/*.cpp " )
sources + = Glob ( " src/simulation/tools/*.cpp " )
2012-07-23 14:58:38 -05:00
sources + = Glob ( " generated/ToolClasses.cpp " )
sources + = Glob ( " generated/ElementClasses.cpp " )
2012-07-07 13:08:05 -05:00
SetupSpawn ( env )
2012-07-23 05:49:58 -05:00
programName = " powder "
2012-07-22 13:33:56 -05:00
if ( GetOption ( ' win32 ' ) ) :
2012-07-23 05:49:58 -05:00
programName = " Powder "
2012-07-29 10:55:26 -05:00
if ( GetOption ( ' _64bit ' ) ) :
2012-07-23 05:49:58 -05:00
programName + = " 64 "
if ( not ( GetOption ( ' sse2 ' ) or GetOption ( ' sse3 ' ) ) ) :
programName + = " -legacy "
if ( GetOption ( ' macosx ' ) ) :
programName + = " -x "
if ( GetOption ( ' win32 ' ) ) :
programName + = " .exe "
2012-07-23 14:58:38 -05:00
env . Command ( [ ' generated/ElementClasses.cpp ' , ' generated/ElementClasses.h ' ] , Glob ( ' src/simulation/elements/*.cpp ' ) , " python generator.py elements $TARGETS $SOURCES " )
2012-07-23 15:04:50 -05:00
env . Command ( [ ' generated/ToolClasses.cpp ' , ' generated/ToolClasses.h ' ] , Glob ( ' src/simulation/tools/*.cpp ' ) , " python generator.py tools $TARGETS $SOURCES " )
2012-07-23 05:49:58 -05:00
t = env . Program ( target = programName , source = sources )
2012-07-07 13:08:05 -05:00
Default ( t )
2012-07-22 14:17:58 -05:00
#if(GetOption('release')):
# StripExecutable(t);
2012-07-22 13:33:56 -05:00