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
if env['PLATFORM'] == 'win32':
81
env.Append(CPPPATH = [".", "drivers/win/", "drivers/common/", "drivers/", "drivers/win/zlib", "drivers/win/directx", "drivers/win/lua/include"])
82
env.Append(CPPDEFINES = ["PSS_STYLE=2", "WIN32", "_USE_SHARED_MEMORY_", "NETWORK", "FCEUDEF_DEBUGGER", "NOMINMAX", "NEED_MINGW_HACKS", "_WIN32_IE=0x0600"])
83
env.Append(LIBS = ["rpcrt4", "comctl32", "vfw32", "winmm", "ws2_32", "comdlg32", "ole32", "gdi32", "htmlhelp"])
86
# If libdw is available, compile in backward-cpp support
87
if conf.CheckLib('dw'):
88
conf.env.Append(CCFLAGS = "-DBACKWARD_HAS_DW=1")
89
conf.env.Append(LINKFLAGS = "-ldw")
90
if conf.CheckFunc('asprintf'):
91
conf.env.Append(CCFLAGS = "-DHAVE_ASPRINTF")
92
if env['SYSTEM_MINIZIP']:
93
assert conf.CheckLibWithHeader('minizip', 'minizip/unzip.h', 'C', 'unzOpen;', 1), "please install: libminizip"
94
assert conf.CheckLibWithHeader('z', 'zlib.h', 'c', 'inflate;', 1), "please install: zlib"
95
env.Append(CPPDEFINES=["_SYSTEM_MINIZIP"])
97
assert conf.CheckLibWithHeader('z', 'zlib.h', 'c', 'inflate;', 1), "please install: zlib"
99
if not conf.CheckLib('SDL2'):
100
print 'Did not find libSDL2 or SDL2.lib, exiting!'
102
env.Append(CPPDEFINES=["_SDL2"])
103
env.ParseConfig('pkg-config sdl2 --cflags --libs')
105
if not conf.CheckLib('SDL'):
106
print 'Did not find libSDL or SDL.lib, exiting!'
108
env.ParseConfig('sdl-config --cflags --libs')
110
if not conf.CheckLib('gtk-x11-2.0'):
111
print 'Could not find libgtk-2.0, exiting!'
113
# Add compiler and linker flags from pkg-config
114
config_string = 'pkg-config --cflags --libs gtk+-2.0'
115
if env['PLATFORM'] == 'darwin':
116
config_string = 'PKG_CONFIG_PATH=/opt/X11/lib/pkgconfig/ ' + config_string
117
env.ParseConfig(config_string)
118
env.Append(CPPDEFINES=["_GTK2"])
119
env.Append(CCFLAGS = ["-D_GTK"])
121
# Add compiler and linker flags from pkg-config
122
config_string = 'pkg-config --cflags --libs gtk+-3.0'
123
if env['PLATFORM'] == 'darwin':
124
config_string = 'PKG_CONFIG_PATH=/opt/X11/lib/pkgconfig/ ' + config_string
125
env.ParseConfig(config_string)
126
env.Append(CPPDEFINES=["_GTK3"])
127
env.Append(CCFLAGS = ["-D_GTK"])
129
### Lua platform defines
130
### Applies to all files even though only lua needs it, but should be ok
132
env.Append(CPPDEFINES=["_S9XLUA_H"])
133
if env['PLATFORM'] == 'darwin':
134
# Define LUA_USE_MACOSX otherwise we can't bind external libs from lua
135
env.Append(CCFLAGS = ["-DLUA_USE_MACOSX"])
136
if env['PLATFORM'] == 'posix':
137
# If we're POSIX, we use LUA_USE_LINUX since that combines usual lua posix defines with dlfcn calls for dynamic library loading.
138
# Should work on any *nix
139
env.Append(CCFLAGS = ["-DLUA_USE_LINUX"])
140
lua_available = False
141
if conf.CheckLib('lua5.1'):
142
env.Append(LINKFLAGS = ["-ldl", "-llua5.1"])
143
env.Append(CCFLAGS = ["-I/usr/include/lua5.1"])
145
elif conf.CheckLib('lua'):
146
env.Append(LINKFLAGS = ["-ldl", "-llua"])
147
env.Append(CCFLAGS = ["-I/usr/include/lua"])
149
if lua_available == False:
150
print 'Could not find liblua, exiting!'
152
# "--as-needed" no longer available on OSX (probably BSD as well? TODO: test)
153
if env['PLATFORM'] != 'darwin':
154
env.Append(LINKFLAGS=['-Wl,--as-needed'])
156
### Search for gd if we're not in Windows
157
if env['PLATFORM'] != 'win32' and env['PLATFORM'] != 'cygwin' and env['CREATE_AVI'] and env['LOGO']:
158
gd = conf.CheckLib('gd', autoadd=1)
161
print 'Did not find libgd, you won\'t be able to create a logo screen for your avis.'
163
if env['OPENGL'] and conf.CheckLibWithHeader('GL', 'GL/gl.h', 'c', autoadd=1):
164
conf.env.Append(CCFLAGS = "-DOPENGL")
165
conf.env.Append(CPPDEFINES = ['PSS_STYLE=1'])
169
if sys.byteorder == 'little' or env['PLATFORM'] == 'win32':
170
env.Append(CPPDEFINES = ['LSB_FIRST'])
173
env.Append(CPPDEFINES = ['FRAMESKIP'])
175
print "base CPPDEFINES:",env['CPPDEFINES']
176
print "base CCFLAGS:",env['CCFLAGS']
179
env.Append(CPPDEFINES=["_DEBUG"], CCFLAGS = ['-g', '-O0'])
181
env.Append(CCFLAGS = ['-O2'])
183
if env['PLATFORM'] != 'win32' and env['PLATFORM'] != 'cygwin' and env['CREATE_AVI']:
184
env.Append(CPPDEFINES=["CREATE_AVI"])
189
fceux = SConscript('src/SConscript')
190
env.Program(target="fceux-net-server", source=["fceux-server/server.cpp", "fceux-server/md5.cpp", "fceux-server/throttle.cpp"])
194
prefix = "/usr/local"
197
if env['PLATFORM'] == 'win32':
200
fceux_src = 'src/fceux' + exe_suffix
201
fceux_dst = 'bin/fceux' + exe_suffix
203
fceux_net_server_src = 'fceux-net-server' + exe_suffix
204
fceux_net_server_dst = 'bin/fceux-net-server' + exe_suffix
206
auxlib_src = 'src/auxlib.lua'
207
auxlib_dst = 'bin/auxlib.lua'
208
auxlib_inst_dst = prefix + '/share/fceux/auxlib.lua'
210
fceux_h_src = 'output/fceux.chm'
211
fceux_h_dst = 'bin/fceux.chm'
213
env.Command(fceux_h_dst, fceux_h_src, [Copy(fceux_h_dst, fceux_h_src)])
214
env.Command(fceux_dst, fceux_src, [Copy(fceux_dst, fceux_src)])
215
env.Command(fceux_net_server_dst, fceux_net_server_src, [Copy(fceux_net_server_dst, fceux_net_server_src)])
216
env.Command(auxlib_dst, auxlib_src, [Copy(auxlib_dst, auxlib_src)])
218
man_src = 'documentation/fceux.6'
219
man_net_src = 'documentation/fceux-net-server.6'
220
man_dst = prefix + '/share/man/man6/fceux.6'
221
man_net_dst = prefix + '/share/man/man6/fceux-net-server.6'
223
share_src = 'output/'
224
share_dst = prefix + '/share/fceux/'
226
image_src = 'fceux.png'
227
image_dst = prefix + '/share/pixmaps'
229
desktop_src = 'fceux.desktop'
230
desktop_dst = prefix + '/share/applications/'
232
env.Install(prefix + "/bin/", fceux)
233
env.Install(prefix + "/bin/", "fceux-net-server")
234
# TODO: Where to put auxlib on "scons install?"
235
env.Alias('install', env.Command(auxlib_inst_dst, auxlib_src, [Copy(auxlib_inst_dst, auxlib_src)]))
236
env.Alias('install', env.Command(share_dst, share_src, [Copy(share_dst, share_src)]))
237
env.Alias('install', env.Command(man_dst, man_src, [Copy(man_dst, man_src)]))
238
env.Alias('install', env.Command(man_net_dst, man_net_src, [Copy(man_net_dst, man_net_src)]))
239
env.Alias('install', env.Command(image_dst, image_src, [Copy(image_dst, image_src)]))
240
env.Alias('install', env.Command(desktop_dst, desktop_src, [Copy(desktop_dst, desktop_src)]))
241
env.Alias('install', (prefix + "/bin/"))