-
Notifications
You must be signed in to change notification settings - Fork 0
/
SConstruct
178 lines (150 loc) · 6.88 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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# vi: syntax=python:et:ts=4
from os.path import join
from glob import glob
import os, sys, shutil
EnsureSConsVersion(0, 98, 0)
for dir in ["release", "debug"]:
if glob(os.path.join("build", dir, "*.cpp")):
shutil.rmtree(os.path.join("build", dir), True)
Decider("MD5-timestamp")
SetOption('implicit_cache', 1)
SConsignFile("build/sconsign.dblite")
sys.path.insert(0, "./scons")
from build_output import setup_build_output
from cross_compile import setup_cross_compile
opts = Options("options.cache")
opts.AddOptions(
("PREFIX", "Install prefix.", "/usr/local"),
("DESTDIR", "Directory of staged installation.", "/"),
("QT4DIR", "Root directory of Qt's installation.", ""),
BoolOption("use_frameworked_qt", "Use Qt frameworks on Mac", False),
("SDLDIR", "Root directory of SDL's installation.", "/usr/"),
("BOOSTDIR", "Root directory of boost installation.", "/usr/include"),
("BOOSTLIBS", "Directory where boost libs are located.", "/usr/lib"),
("BOOST_SUFFIX", "Suffix of the boost regex library.", ""),
("GTKDIR", "Directory where GTK SDK is located.", ""),
BoolOption("use_pango", "Use experimental pango based text renderer.", True),
BoolOption("AUDIO", "Whether sound support is enabled", False),
EnumOption("Build", "Build variant: debug or release", "release", ["debug", "release"], ignorecase=1),
("EXTRA_FLAGS_RELEASE", "Extra compiler/linker flags to use in release build variant.(e.g. \"-O3 -march=prescott\")", ""),
("EXTRA_FLAGS_DEBUG", "Extra compiler/linker flags to use in debug build variant.", ""),
BoolOption("VERBOSE_BUILD_OUTPUT", "If true, SCons will display full command lines of commands it's running.", False),
("HOST", "Cross-compile host.", ""),
BoolOption("STRICT", "Strict compilation (warnings are errors, etc..).", False)
)
env = Environment(tools = ["zip", "config_checks"], toolpath = ["scons"], options = opts)
env["Build"] = env["Build"].lower()
if env["PLATFORM"] == "win32":
env.Tool("mingw")
else:
env.Tool("default")
setup_cross_compile(env)
opts.Save("options.cache", env)
Help("""
Type "scons" to build the game.
"scons editor" - builds the editor.
"scons namegen" - namegen.
"scons version_finder" - version finder.
Additional options:
""")
Help(opts.GenerateHelpText(env))
if GetOption("help") : Return()
if env["PLATFORM"] == "win32": openal_lib = "openal32"
else: openal_lib = "openal"
env.Append(LIBPATH = "/usr/X11R6/lib")
conf = env.Configure(custom_tests = env["config_checks"], log_file="build/config.log", conf_dir="build/sconf_temp")
conf.CheckBoost("regex", "1.20") or Exit(1)
conf.Finish()
namegen_env = env.Clone()
conf = env.Configure(custom_tests = env["config_checks"])
conf.CheckBoost("program_options") and \
conf.CheckGLEW() and \
conf.CheckSDL(require_version = "1.2.9") and \
conf.CheckSDL("SDL_image") or Return()
if env["use_pango"]:
env["use_pango"] = conf.CheckPango("ft2")
if not env["use_pango"]:
conf.CheckSDL("SDL_ttf") or Return()
if env["AUDIO"]:
env["AUDIO"] = conf.CheckLibWithHeader(openal_lib, "AL/al.h", "C") and \
conf.CheckLibWithHeader("mpg123", "mpg123.h", "C")
HaveNSIS = conf.CheckMakeNSIS()
conf.Finish()
editor_env = env.Clone()
editor_env.Replace(QT4_UICDECLSUFFIX=".hpp", QT4_UICDECLPREFIX="", QT4_MOCIMPLPREFIX="", QT4_MOCIMPLSUFFIX=".moc")
editor_conf = editor_env.Configure(custom_tests = editor_env["config_checks"])
editor_env["HaveQt"] = editor_conf.CheckQt4Tools() and \
editor_conf.CheckQt4Libs(["QtCore", "QtGui", "QtOpenGL"])
editor_conf.Finish()
if "-mms-bitfields" in editor_env["CCFLAGS"]:
editor_env["CCFLAGS"].remove("-mms-bitfields")
if env["AUDIO"]:
env.Replace(CPPDEFINES = { "AUDIO" : None })
else:
env.Replace(CPPDEFINES = dict())
if "gcc" in env["TOOLS"]:
ccflags = Split("-Wall -Wno-sign-compare -Wno-switch -Wno-switch-enum")
if env["STRICT"]:
ccflags += Split("-Werror -ansi")
linkflags = []
if env["Build"] == "release":
ccflags.append("-O2")
if env["Build"] == "debug":
ccflags.append("-ggdb")
env.AppendUnique(CCFLAGS = ccflags, LINKFLAGS = linkflags)
editor_env.AppendUnique(CCFLAGS = ccflags, LINKFLAGS = linkflags)
env.MergeFlags(env["EXTRA_FLAGS_" + env["Build"].upper()], unique=0)
editor_env.MergeFlags(env["EXTRA_FLAGS_" + env["Build"].upper()], unique=0)
namegen = namegen_env.Program("utilities/names/namegen", "utilities/names/namegen.cpp")
Alias("namegen", namegen)
env.Program("version_finder", "utilities/versions/version_finder.cpp")
Export("env")
Export("editor_env")
if env["HOST"]: build = env["Build"] + "-" + env["HOST"]
else: build = env["Build"]
silvertree, editor = SConscript("src/SConscript", build_dir = join("build", build), duplicate = False)
if (not env["HOST"] or env["HOST"] == "mingw32") and env["Build"] == "release":
ExecutableSuffix = env["PROGSUFFIX"]
else:
ExecutableSuffix = "-" + build + env["PROGSUFFIX"]
env.Default(env.Alias("silvertreerpg", env.InstallAs("./silvertreerpg" + ExecutableSuffix, silvertree)))
if editor:
editor_env.Alias("editor", editor_env.InstallAs("./silvertreeedit" + ExecutableSuffix, editor))
executables = [silvertree]
if editor_env["HaveQt"]:
executables.append(editor)
executables += glob("*.dll")
datafiles = map(Dir, Split("data images model-sources music"))
datafiles += ["FreeSans.ttf"] + map(glob, Split("*.dae *.3ds *.3d"))
def prepend_destdir(env, path):
return join(env["DESTDIR"], path.lstrip("/"))
data_install_dir = join(env["PREFIX"], "share/silvertree-rpg")
data_stage_dir = prepend_destdir(env, data_install_dir)
install_executables = Install(prepend_destdir(env, join(env["PREFIX"], "bin")), executables)
install_data = Install(data_stage_dir, datafiles)
if not env["PLATFORM"] == "win32":
Alias("install", [install_executables, install_data])
env.AppendUnique(CPPDEFINES = { "DATADIR" : '\\"' + data_install_dir + '\\"' })
editor_env.Replace(CPPDEFINES = { "DATADIR" : '\\"' + data_install_dir + '\\"' })
bindistdir = env.Install("silvertree", Split("README LICENSE") + executables + datafiles)
bindistzip = env.Zip("silvertree.zip", bindistdir)
env.Alias("bindistzip", bindistzip)
if HaveNSIS:
env["INSTALLER_FILES"] = datafiles + executables + glob("*.dll")
env["INSTALLER_NAME"] = "SilverTree"
env["INSTALLER_VERSION"] = "0.2.1"
env["INSTALLER_SHORTCUTS"] = silvertree
installer = env.Installer(env["INSTALLER_NAME"] + "-" + env["INSTALLER_VERSION"], "installer.nsi.template")
env.Alias("installer", installer)
env.Command("tags",
Glob("src/*.cpp") + Glob("src/*.hpp") + Glob("src/*/*.cpp") + Glob("src/*/*.hpp"),
"ctags -o $TARGET $SOURCES"
)
setup_build_output([env, editor_env, namegen_env])
SConsignFile("sconsign")
if not GetOption("silent"):
print env.subst("""
Build variant: $Build
Text rendering backend: ${use_pango and 'pango' or 'sdl-ttf'}
Audio support: ${ AUDIO and 'enabled' or 'disabled' }
""")