-
Notifications
You must be signed in to change notification settings - Fork 2
/
SConstruct
executable file
·140 lines (124 loc) · 4.58 KB
/
SConstruct
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
136
137
138
139
140
# vim:filetype=python
import os
import sys
import re
from subprocess import Popen, PIPE
client_name = 'treacherous-terrain'
server_name = client_name + '-server'
CCFS_ROOT = 'assets/fs'
def find_dirs_under(path):
dirs = [path]
for ent in os.listdir(path):
ent_path = '%s/%s' % (path, ent)
if os.path.isdir(ent_path):
dirs += find_dirs_under(ent_path)
return dirs
def find_sources_under(path):
sources = []
for ent in os.listdir(path):
ent_path = '%s/%s' % (path, ent)
if re.search('\.cc?$', ent):
sources.append(ent_path)
elif os.path.isdir(ent_path):
sources += find_sources_under(ent_path)
return sources
# determine our build platform
platform = 'windows' if sys.platform == 'cygwin' else 'unix'
# common environment settings
BIN_DIR = 'bin'
CXX = 'g++'
CC = 'gcc'
CXXFLAGS = ['-Wall', '-O0', '-g']
LINKFLAGS = []
LIBS_client = []
LIBS_server = []
libs_to_copy = []
SFML_PATH = '/c/apps/SFML-2.0' if platform == 'windows' else '/opt/SFML'
SFGUI_PATH = '/c/apps/SFGUI-0.1.0' if platform == 'windows' else '/opt/SFGUI'
if 'SFML_PATH' in os.environ:
SFML_PATH = os.environ['SFML_PATH']
if 'SFGUI_PATH' in os.environ:
SFGUI_PATH = os.environ['SFGUI_PATH']
LIBPATH = ['%s/lib' % SFGUI_PATH, '%s/lib' % SFML_PATH]
CPPFLAGS = []
CPPFLAGS += map(lambda x: '-I' + x, find_dirs_under('src/common'))
CPPFLAGS += ['-I%s/include' % SFGUI_PATH, '-I%s/include' % SFML_PATH]
CPPFLAGS_client = ['-DGL_INCLUDE_FILE=\\"GL3/gl3w.h\\"']
CPPFLAGS_client += map(lambda x: '-I' + x, find_dirs_under('src/client'))
CPPFLAGS_server = map(lambda x: '-I' + x, find_dirs_under('src/server'))
if platform == 'windows':
# Windows-specific environment settings
CXX = 'i686-pc-mingw32-g++'
CC = 'i686-pc-mingw32-gcc'
MINGW_DIR = '/usr/i686-pc-mingw32/sys-root/mingw/bin'
LIBS_client += ['sfml-graphics-s', 'sfml-window-s', 'sfml-network-s',
'sfml-system-s', 'opengl32', 'glu32', 'mingw32']
LIBS_server += ['sfml-network-s', 'sfml-system-s', 'mingw32']
LINKFLAGS.append('-static-libstdc++')
libs_to_copy.append('%s/libgcc_s_dw2-1.dll' % MINGW_DIR)
CPPFLAGS.append('-DSFML_STATIC')
else:
LIBS_client += ['sfgui', 'sfml-network', 'sfml-window', 'sfml-graphics',
'sfml-system', 'GL', 'GLU']
LIBS_server += ['sfml-system','sfml-network']
LINKFLAGS.append('-Wl,-R%s/lib' % SFGUI_PATH)
LINKFLAGS.append('-Wl,-R%s/lib' % SFML_PATH)
# our sources
sources_client = (find_sources_under('src/common') +
find_sources_under('src/client'))
if 'src/common/ccfs.cc' not in sources_client:
sources_client.append('src/common/ccfs.cc')
sources_server = (find_sources_under('src/common') +
find_sources_under('src/server'))
if 'src/common/ccfs.cc' not in sources_server:
sources_server.append('src/common/ccfs.cc')
# create the scons environments
env_ccfs = Environment()
env_client = Environment(
CC = CC,
CXX = CXX,
CPPFLAGS = CPPFLAGS + CPPFLAGS_client,
CXXFLAGS = CXXFLAGS,
LINKFLAGS = LINKFLAGS,
LIBPATH = LIBPATH,
LIBS = LIBS_client)
env_server = Environment(
OBJSUFFIX = '-server.o',
CC = CC,
CXX = CXX,
CPPFLAGS = CPPFLAGS + CPPFLAGS_server,
CXXFLAGS = CXXFLAGS,
LINKFLAGS = LINKFLAGS,
LIBPATH = LIBPATH,
LIBS = LIBS_server)
# CCFS builder
def get_all_files(prefix):
files = []
for ent in os.listdir(prefix):
if ent.startswith('.'):
next
full_path = '%s/%s' % (prefix, ent)
if os.path.isdir(full_path):
files += get_all_files(full_path)
else:
files.append(full_path)
return files
def CCFS(target, source, env):
source_list = []
for s in source:
source_fname = str(s)
source_fname = source_fname.replace(CCFS_ROOT + '/', '')
source_list.append(source_fname)
Popen(['./ccfs_gen.py', '--root', 'assets/fs', str(target[0])] + source_list).wait()
return None
def CCFS_emitter(target, source, env):
target.append(re.sub(r'\..*$', '.h', str(target[0])))
env.Depends(target, 'ccfs_gen.py')
return target, source
env_ccfs.Append(BUILDERS = {'CCFS' : Builder(action = CCFS, emitter = CCFS_emitter)})
env_ccfs.CCFS('src/common/ccfs.cc', get_all_files(CCFS_ROOT))
for lib_path in libs_to_copy:
installed_libs = env_client.Install(BIN_DIR, lib_path)
env_client.Depends('%s/%s' % (BIN_DIR, client_name), installed_libs)
env_client.Program('%s/%s' % (BIN_DIR, client_name), sources_client)
env_server.Program('%s/%s' % (BIN_DIR, server_name), sources_server)