2
# SConstruct - build script for the SDL port of fceux
4
# You can adjust the BoolVariables below to include/exclude features
5
# at compile-time. You may also use arguments to specify the parameters.
6
# ie: scons RELEASE=1 GTK3=1
8
# Use "scons" to compile and "scons install" to install.
15
opts = Variables(None, ARGUMENTS)
17
BoolVariable('DEBUG', 'Build with debugging symbols', 0),
18
BoolVariable('RELEASE', 'Set to 1 to build for release', 1),
19
BoolVariable('FRAMESKIP', 'Enable frameskipping', 1),
20
BoolVariable('OPENGL', 'Enable OpenGL support', 1),
21
BoolVariable('LUA', 'Enable Lua support', 1),
22
BoolVariable('GTK', 'Enable GTK2 GUI (SDL only)', 1),
23
BoolVariable('GTK3', 'Enable GTK3 GUI (SDL only)', 0),
24
BoolVariable('NEWPPU', 'Enable new PPU core', 1),
25
BoolVariable('CREATE_AVI', 'Enable avi creation support (SDL only)', 1),
26
BoolVariable('LOGO', 'Enable a logoscreen when creating avis (SDL only)', 1),
27
BoolVariable('SYSTEM_LUA','Use system lua instead of static lua provided with fceux', 1),
28
BoolVariable('SYSTEM_MINIZIP', 'Use system minizip instead of static minizip provided with fceux', 0),
29
BoolVariable('LSB_FIRST', 'Least signficant byte first (non-PPC)', 1),
30
BoolVariable('CLANG', 'Compile with llvm-clang instead of gcc', 0),
31
BoolVariable('SDL2', 'Compile using SDL2 instead of SDL 1.2 (experimental/non-functional)', 0)
33
AddOption('--prefix', dest='prefix', type='string', nargs=1, action='store', metavar='DIR', help='installation prefix')
35
prefix = GetOption('prefix')
36
env = Environment(options = opts)
39
env.Append(CPPDEFINES=["PUBLIC_RELEASE"])
42
# LSB_FIRST must be off for PPC to compile
43
if platform.system == "ppc":
46
# Default compiler flags:
47
env.Append(CCFLAGS = ['-Wall', '-Wno-write-strings', '-Wno-sign-compare'])
49
if os.environ.has_key('PLATFORM'):
50
env.Replace(PLATFORM = os.environ['PLATFORM'])
51
if os.environ.has_key('CC'):
52
env.Replace(CC = os.environ['CC'])
53
if os.environ.has_key('CXX'):
54
env.Replace(CXX = os.environ['CXX'])
55
if os.environ.has_key('WINDRES'):
56
env.Replace(WINDRES = os.environ['WINDRES'])
57
if os.environ.has_key('CFLAGS'):
58
env.Append(CCFLAGS = os.environ['CFLAGS'].split())
59
if os.environ.has_key('CXXFLAGS'):
60
env.Append(CXXFLAGS = os.environ['CXXFLAGS'].split())
61
if os.environ.has_key('CPPFLAGS'):
62
env.Append(CPPFLAGS = os.environ['CPPFLAGS'].split())
63
if os.environ.has_key('LDFLAGS'):
64
env.Append(LINKFLAGS = os.environ['LDFLAGS'].split())
66
print "platform: ", env['PLATFORM']
70
env.Replace(CC='clang')
71
env.Replace(CXX='clang++')
73
# special flags for cygwin
74
# we have to do this here so that the function and lib checks will go through mingw
75
if env['PLATFORM'] == 'cygwin':
76
env.Append(CCFLAGS = " -mno-cygwin")
77
env.Append(LINKFLAGS = " -mno-cygwin")
78
env['LIBS'] = ['wsock32'];
80
# tell g++ to support c++0x, used for static_assert()
81
if env['CXX'] == 'g++':
82
env.Append(CXXFLAGS = "-std=c++0x")
84
if env['PLATFORM'] == 'win32':
85
env.Append(CPPPATH = [".", "drivers/win/", "drivers/common/", "drivers/", "drivers/win/zlib", "drivers/win/directx", "drivers/win/lua/include"])
86
env.Append(CPPDEFINES = ["PSS_STYLE=2", "WIN32", "_USE_SHARED_MEMORY_", "NETWORK", "FCEUDEF_DEBUGGER", "NOMINMAX", "NEED_MINGW_HACKS", "_WIN32_IE=0x0600"])
87
env.Append(LIBS = ["rpcrt4", "comctl32", "vfw32", "winmm", "ws2_32", "comdlg32", "ole32", "gdi32", "htmlhelp"])
90
# If libdw is available, compile in backward-cpp support
91
if conf.CheckLib('dw'):
92
conf.env.Append(CCFLAGS = "-DBACKWARD_HAS_DW=1")
93
conf.env.Append(LINKFLAGS = "-ldw")
94
if conf.CheckFunc('asprintf'):
95
conf.env.Append(CCFLAGS = "-DHAVE_ASPRINTF")
96
if env['SYSTEM_MINIZIP']:
97
assert conf.CheckLibWithHeader('minizip', 'minizip/unzip.h', 'C', 'unzOpen;', 1), "please install: libminizip"
98
assert conf.CheckLibWithHeader('z', 'zlib.h', 'c', 'inflate;', 1), "please install: zlib"
99
env.Append(CPPDEFINES=["_SYSTEM_MINIZIP"])
101
assert conf.CheckLibWithHeader('z', 'zlib.h', 'c', 'inflate;', 1), "please install: zlib"
103
if not conf.CheckLib('SDL2'):
104
print 'Did not find libSDL2 or SDL2.lib, exiting!'
106
env.Append(CPPDEFINES=["_SDL2"])
107
env.ParseConfig('pkg-config sdl2 --cflags --libs')
109
if not conf.CheckLib('SDL'):
110
print 'Did not find libSDL or SDL.lib, exiting!'
112
env.ParseConfig('sdl-config --cflags --libs')
114
if not conf.CheckLib('gtk-x11-2.0'):
115
print 'Could not find libgtk-2.0, exiting!'
117
# Add compiler and linker flags from pkg-config
118
config_string = 'pkg-config --cflags --libs gtk+-2.0'
119
if env['PLATFORM'] == 'darwin':
120
config_string = 'PKG_CONFIG_PATH=/opt/X11/lib/pkgconfig/ ' + config_string
121
env.ParseConfig(config_string)
122
env.Append(CPPDEFINES=["_GTK2"])
123
env.Append(CCFLAGS = ["-D_GTK"])
125
# Add compiler and linker flags from pkg-config
126
config_string = 'pkg-config --cflags --libs gtk+-3.0'
127
if env['PLATFORM'] == 'darwin':
128
config_string = 'PKG_CONFIG_PATH=/opt/X11/lib/pkgconfig/ ' + config_string
129
env.ParseConfig(config_string)
130
env.Append(CPPDEFINES=["_GTK3"])
131
env.Append(CCFLAGS = ["-D_GTK"])
133
### Lua platform defines
134
### Applies to all files even though only lua needs it, but should be ok
136
env.Append(CPPDEFINES=["_S9XLUA_H"])
137
if env['PLATFORM'] == 'darwin':
138
# Define LUA_USE_MACOSX otherwise we can't bind external libs from lua
139
env.Append(CCFLAGS = ["-DLUA_USE_MACOSX"])
140
if env['PLATFORM'] == 'posix':
141
# If we're POSIX, we use LUA_USE_LINUX since that combines usual lua posix defines with dlfcn calls for dynamic library loading.
142
# Should work on any *nix
143
env.Append(CCFLAGS = ["-DLUA_USE_LINUX"])
144
lua_available = False
145
if conf.CheckLib('lua5.1'):
146
env.Append(LINKFLAGS = ["-ldl", "-llua5.1"])
147
env.Append(CCFLAGS = ["-I/usr/include/lua5.1"])
149
elif conf.CheckLib('lua'):
150
env.Append(LINKFLAGS = ["-ldl", "-llua"])
151
env.Append(CCFLAGS = ["-I/usr/include/lua"])
153
if lua_available == False:
154
print 'Could not find liblua, exiting!'
156
# "--as-needed" no longer available on OSX (probably BSD as well? TODO: test)
157
if env['PLATFORM'] != 'darwin':
158
env.Append(LINKFLAGS=['-Wl,--as-needed'])
160
### Search for gd if we're not in Windows
161
if env['PLATFORM'] != 'win32' and env['PLATFORM'] != 'cygwin' and env['CREATE_AVI'] and env['LOGO']:
162
gd = conf.CheckLib('gd', autoadd=1)
165
print 'Did not find libgd, you won\'t be able to create a logo screen for your avis.'
167
if env['OPENGL'] and conf.CheckLibWithHeader('GL', 'GL/gl.h', 'c', autoadd=1):
168
conf.env.Append(CCFLAGS = "-DOPENGL")
169
conf.env.Append(CPPDEFINES = ['PSS_STYLE=1'])
173
if sys.byteorder == 'little' or env['PLATFORM'] == 'win32':
174
env.Append(CPPDEFINES = ['LSB_FIRST'])
177
env.Append(CPPDEFINES = ['FRAMESKIP'])
179
print "base CPPDEFINES:",env['CPPDEFINES']
180
print "base CCFLAGS:",env['CCFLAGS']
183
env.Append(CPPDEFINES=["_DEBUG"], CCFLAGS = ['-g', '-O0'])
185
env.Append(CCFLAGS = ['-O2'])
187
if env['PLATFORM'] != 'win32' and env['PLATFORM'] != 'cygwin' and env['CREATE_AVI']:
188
env.Append(CPPDEFINES=["CREATE_AVI"])
193
fceux = SConscript('src/SConscript')
194
env.Program(target="fceux-net-server", source=["fceux-server/server.cpp", "fceux-server/md5.cpp", "fceux-server/throttle.cpp"])
198
prefix = "/usr/local"
201
if env['PLATFORM'] == 'win32':
204
fceux_src = 'src/fceux' + exe_suffix
205
fceux_dst = 'bin/fceux' + exe_suffix
207
fceux_net_server_src = 'fceux-net-server' + exe_suffix
208
fceux_net_server_dst = 'bin/fceux-net-server' + exe_suffix
210
auxlib_src = 'src/auxlib.lua'
211
auxlib_dst = 'bin/auxlib.lua'
213
fceux_h_src = 'output/fceux.chm'
214
fceux_h_dst = 'bin/fceux.chm'
216
env.Command(fceux_h_dst, fceux_h_src, [Copy(fceux_h_dst, fceux_h_src)])
217
env.Command(fceux_dst, fceux_src, [Copy(fceux_dst, fceux_src)])
218
env.Command(fceux_net_server_dst, fceux_net_server_src, [Copy(fceux_net_server_dst, fceux_net_server_src)])
219
env.Command(auxlib_dst, auxlib_src, [Copy(auxlib_dst, auxlib_src)])
221
man_src = 'documentation/fceux.6'
222
man_net_src = 'documentation/fceux-net-server.6'
224
share_src = 'output/'
226
image_src = 'fceux.png'
228
desktop_src = 'fceux.desktop'
230
env.Install(prefix + "/bin/", [fceux, fceux_net_server_src])
231
env.InstallAs(prefix + '/share/fceux/', share_src)
232
env.Install(prefix + '/share/fceux/', auxlib_src)
233
env.Install(prefix + '/share/pixmaps/', image_src)
234
env.Install(prefix + '/share/applications/', desktop_src)
235
env.Install(prefix + "/share/man/man6/", [man_src, man_net_src])
236
env.Alias('install', prefix)