summaryrefslogtreecommitdiff
path: root/SConscript
blob: f630027e375a0c234606c12648e64594d727a01f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
import os, sys, subprocess

##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.")
AddOption('--win32',dest="win32",action='store_true',default=False,help="32bit Windows target.")
AddOption('--lin32',dest="lin32",action='store_true',default=False,help="32bit Linux target")
AddOption('--lin64',dest="lin64",action='store_true',default=False,help="64bit Linux target")
AddOption('--release',dest="release",action='store_true',default=False,help="Enable optimisations (Will slow down compiling)")

luaLib = "lua5.1"
luaInclude = "lua5.1"
fftLib = "fftw3f"

if(GetOption('win32')):
    env = Environment(tools = ['mingw'], ENV = os.environ)
else:
    env = Environment(ENV = os.environ)

#Check for headers and libraries
conf = Configure(env)

#Find correct lua include dir
if conf.CheckCHeader('lua.h'):
    luaInclude = "/MinGW/include/"
elif conf.CheckCHeader('lua5.1/lua.h'):
    luaInclude = "/MinGW/include/lua5.1"
elif conf.CheckCHeader('lua51/lua.h'):
    luaInclude = "/MinGW/include/lua51"
elif conf.CheckCHeader('lua/lua.h'):
    luaInclude = "/MinGW/include/lua"
else:
    print "lua5.1 headers not found or not installed"
    raise SystemExit(1)

#Check for SDL headers
if not conf.CheckCHeader('SDL/SDL.h'):
    print "SDL headers not found or not installed"
    raise SystemExit(1)

#Check for SDL lib
if not conf.CheckLib('SDL'):
    print "libSDL not found or not installed"
    raise SystemExit(1)

#Check for FFT lib
if conf.CheckLib('fftw3f'):
	fftLib = "fftw3f"
elif conf.CheckLib('fftw3f-3'):
	fftLib = "fftw3f-3"
else:
    print "libfftw3f not found or not installed"
    raise SystemExit(1)

#Check for Lua lib
if conf.CheckLib('lua'):
    luaLib = 'lua'
elif conf.CheckLib('lua5.1'):
    luaLib = 'lua5.1'
elif conf.CheckLib('lua51'):
    luaLib = 'lua51'
else:
    print "liblua not found or not installed"
    raise SystemExit(1)

env = conf.Finish();

env.Append(CPPPATH=['src/', 'data/', 'generated/', luaInclude, '/MinGW/include/SDL/'])
env.Append(CCFLAGS=['-w', '-std=c99', '-fkeep-inline-functions'])
env.Append(LIBS=['pthread', fftLib, 'm', 'bz2', luaLib, 'SDL'])
env.Append(CPPDEFINES={"_POSIX_C_SOURCE":"200112L"})
env.Append(CPPDEFINES=["USE_SDL", "LUACONSOLE","GRAVFFT","_GNU_SOURCE","USE_STDINT"])


if(GetOption('win32')):
    openGLLibs = ['opengl32', 'glew32']
    env.Prepend(LIBS=['mingw32', 'ws2_32', 'SDLmain', 'regex'])
    env.Append(CPPDEFINES=["WIN32"])
if(GetOption('lin32') or GetOption('lin64')):
    openGLLibs = ['GL']
    env.Append(LIBS=['X11', 'rt'])
    if GetOption('lin32'):
        env.Append(CPPDEFINES=["LIN32"])
    else:
        env.Append(CPPDEFINES=["LIN64"])


if(GetOption('release')):
    ev.Append(CCFLAGS='-O3')

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')):
	sources += env.RES('resources/powder-res.rc')
sources+=Glob("src/*/*.cpp")
sources+=Glob("src/simulation/elements/*.cpp")
sources+=Glob("src/simulation/tools/*.cpp")
sources+=Glob("generated/*.cpp")

SetupSpawn(env)

t=env.Program(target='powder', source=sources)
Default(t)