~chuckw20/widelands/New_barbarian_fisher_worker_and_modified_carrier_worker

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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
#!/usr/bin/python
# -*- coding: utf-8 -*-

import os, sys, string
sys.path.append("build/scons-tools")
import shutil, fnmatch, time, glob
import SCons
from SCons.Script.SConscript import SConsEnvironment

from ColorizeGcc import overwrite_spawn_function
from distcc import setup_distcc
from ccache import setup_ccache
from scons_configure import *
from Distribute import *

# Sanity checks
EnsurePythonVersion(2, 3)
EnsureSConsVersion(1, 0, 1)

# Speedup. If you have problems with inconsistent or wrong builds, look here first
SetOption('max_drift', 1)
SetOption('implicit_cache', 1)
Decider('MD5-timestamp')

# write only *one* signature file in a place where we don't care
SConsignFile('build/scons-signatures')

# Pretty output
print

########################################## simple glob that works across BUILDDIR

def simpleglob(pattern='*', directory='.', recursive=False):
        entries=[]

	for entry in os.listdir(Dir(directory).srcnode().abspath):
		if fnmatch.fnmatchcase(entry, pattern):
			entries.append(os.path.join(directory, entry))
		if recursive and os.path.isdir(os.path.join(directory, entry)):
                        entries+=(simpleglob(pattern, os.path.join(directory, entry), recursive))

	return entries

########################### Create a phony target (not (yet) a feature of scons)

# taken from scons' wiki
def PhonyTarget(alias, action):
	"""Returns an alias to a command that performs the
	   action.  This is implementated by a Command with a
	   nonexistant file target.  This command will run on every
	   build, and will never be considered 'up to date'. Acts
	   like a 'phony' target in make."""

	from tempfile import mktemp
	from os.path import normpath

	phony_file = normpath(mktemp(prefix="phony_%s_" % alias, dir="."))
	return Alias(alias, Command(target=phony_file, source=None, action=action))

############################## Functions for setting permissions when installing
# don't forget to set umask
try:
	os.umask(022)
except OSError:     # ignore on systems that don't support umask
	pass

def InstallPerm(env, dest, files, perm):
	obj = env.Install(dest, files)
	for i in obj:
		env.AddPostAction(i, env.Chmod(str(i), perm))

SConsEnvironment.InstallPerm = InstallPerm
SConsEnvironment.InstallProgram = lambda env, dest, files: InstallPerm(env, dest, files, 0755)
SConsEnvironment.InstallData = lambda env, dest, files: InstallPerm(env, dest, files, 0644)

################################################################################
# CLI options setup

def cli_options():
	opts=Variables('build/scons-config.py', ARGUMENTS)
	opts.Add('cc', 'use this compiler as default c compiler', '')
	opts.Add('cxx', 'use this compiler as default c++ compiler','')
	opts.Add('build', 'debug / profile / release(default)', 'debug')
	opts.Add('build_id', 'To get a default value (SVN revision), leave this empty', '') #change this before/after preparing a release
	opts.Add('sdlconfig', 'On some systems (e.g. BSD) this is called sdl12-config', 'sdl-config')
	opts.Add('pkgconfig', 'On some systems (e.g. BSD) this is called pkg-config13', 'pkg-config')
	opts.Add('paraguiconfig', '', 'paragui-config')
	opts.Add('install_prefix', '', '/usr/local')
	opts.Add('bindir', '(absolute or relative to install_prefix)', 'games')
	opts.Add('datadir', '(absolute or relative to install_prefix)', 'share/games/widelands')
	opts.Add('localedir', '(absolute or relative to install_prefix)', 'share/games/widelands/locale')
	opts.Add('extra_include_path', '', '')
	opts.Add('extra_lib_path', '', '')
	opts.Add('extra_compile_flags', '', '')
	opts.Add('extra_link_flags', '', '')
	opts.Add('check','Enable/Disable checks, DO NOT USE', True),
	opts.AddVariables(
		BoolVariable('distcc', 'use distcc to compile widelands on many computers', False),
		BoolVariable('ccache', 'use ccache to speedup compiling widelands', False),

		BoolVariable('enable_sdl_parachute', 'Enable SDL parachute?', False),
		BoolVariable('enable_efence', 'Use the efence memory debugger?', False),
		BoolVariable('enable_ggz', 'Use the GGZ Gamingzone?', True),
		BoolVariable('enable_opengl', 'use opengl for graphics', False),
		BoolVariable('prefer_localdata', 'Useful for developers. Use data and locales from ./ at runtime', True),
		BoolVariable('pretty_compile_output', 'Suppress link and compile commands, only print a very short info text and occurring errors and warnings.', True),
		BoolVariable('colored_compile_output', 'Show style warnings and (gcc) compile warnings in color. Disabled if output is not a tty', True),
		)
	return opts

################################################################################
# Environment setup
#
# Create configuration objects

opts=cli_options()

env=Environment(options=opts)

BUILDDIR=parse_cli(env, BUILD_TARGETS) # must parse CLI before anything else, PATH might get changed

env.Tool("ctags", toolpath=['build/scons-tools'])
env.Tool("PNGShrink", toolpath=['build/scons-tools'])
env.Tool("astyle", toolpath=['build/scons-tools'])
env.Tool("Distribute", toolpath=['build/scons-tools'])
env.Help(opts.GenerateHelpText(env))
if sys.platform == 'win32':
	Tool('mingw')(env)

opts.Save('build/scons-config.py',env)

conf=env.Configure(conf_dir='#/build/sconf_temp',log_file='#build/config.log',
		   custom_tests={
				'CheckPKGConfig' : CheckPKGConfig,
				'CheckPKG': CheckPKG,
				'CheckSDLConfig': CheckSDLConfig,
				'CheckSDLVersionAtLeast': CheckSDLVersionAtLeast,
				'CheckCompilerAttribute': CheckCompilerAttribute,
				'CheckCompilerFlag': CheckCompilerFlag,
				'CheckLinkerFlag': CheckLinkerFlag,
				#'CheckParaguiConfig': CheckParaguiConfig,
				'CheckBoostVersion': CheckBoostVersion
		   }
)

################################################################################
# Environment setup
#
# Parse commandline and autoconfigure

env.Append(CPPPATH=[os.path.join('#', BUILDDIR)])

print_build_info(env)

if env.enable_configuration:
	# Generate build_info.cc - scons itself will decide whether a recompile is needed
	Command(os.path.join(BUILDDIR, "build_info.cc"), [Value(get_build_id(env)),Value(env['build'])], generate_buildinfo_file)

	if (env['cxx'] != ''):
		env['CXX'] = env['cxx']
		print "Using compiler cxx=" + env['cxx']
	if (env['cc'] != ''):
		env['CC'] = env['cc']
		print "Using compiler cc=" + env['cc']
	num_cpu = 0
	if (env['distcc'] == True):
		setup_distcc(env)
		num_cpu = int(os.environ.get('NUM_CPU', 8))
	else:
		num_cpu = int(os.environ.get('NUM_CPU', 2))
	if (env['ccache'] == True):
			setup_ccache(env)

	SetOption('num_jobs', num_cpu)
	print "running with -j", GetOption('num_jobs')

	do_configure(conf, env)

	# Generate config.h - scons itself will decide whether a recompile is needed
	Command(os.path.join(BUILDDIR, "config.h"), [Value(generate_configh_content(env))], generate_configh_file)




env=conf.Finish()

# We only add this tool now, because it adds an emitter to Object which
# breaks configuration.
env.Tool("CodeCheck", toolpath=['build/scons-tools'])

# Setup pretty compile output
if env['pretty_compile_output']:
    env.Append(CXXCOMSTR="Compiling ==> '$TARGET'");
    env.Append(LINKCOMSTR="Linking ==> '$TARGET'");
    env.Append(ARCOMSTR="ar ==> '$TARGET'");
    env.Append(RANLIBCOMSTR="ranlib ==> '$TARGET'");
env["USE_COLOR"]=False
if env['colored_compile_output']:
    if not os.isatty(1): # No tty, no color. Sorry
        env["USE_COLOR"]=False
    elif "TERM" in os.environ:
        color_terms = ("xterm-color",)
        nocolor_terms = ("dumb",)

        # Try to get terminal settings from environment
        # Note: we do not use scons environment, since
        # we *really* want the users terminal here
        t = os.environ["TERM"]
        if t in nocolor_terms:
            env["USE_COLOR"] = False
        elif t in color_terms:
            env["USE_COLOR"] = True
        else:
            print "\nUnknown TERM. Disabling colors. Please add your TERM in SConstruct"
            env["USE_COLOR"] = True


# We now copy env to get our test Environment
# TODO Doing this after configuration means that all
# test exectutables are linked agains boots,SDL,... and
# have the DEFINES from config. That's bad.
testEnv = env.Clone()
testEnv.Tool("UnitTest", toolpath=['build/scons-tools'],
    LIBS=["boost_unit_test_framework-mt"])
testEnv.Append(CXXFLAGS=["-DBOOST_TEST_DYN_LINK"])

# Overwriting Spawn to provide some color output
overwrite_spawn_function(env)

print # Pretty output

#######################################################################

Export('env', 'testEnv', 'BUILDDIR', 'PhonyTarget', 'simpleglob')

SConscript('build/SConscript')
SConscript('campaigns/SConscript')
SConscript('doc/SConscript')
SConscript('fonts/SConscript')
SConscript('maps/SConscript')
SConscript('music/SConscript')
SConscript('pics/SConscript')
buildlocale=SConscript('po/SConscript')
SConscript('sound/SConscript')
SConscript('src/SConscript.dist')
thebinary=SConscript('src/SConscript', build_dir=BUILDDIR, duplicate=0)
SConscript('tribes/SConscript')
SConscript('txts/SConscript')
SConscript('utils/SConscript')
SConscript('worlds/SConscript')
SConscript('global/SConscript')

Default(thebinary)
if env['build']=='release':
	Default(buildlocale)

# Also build tests by default
if (env['build'] == 'debug' or env['build'] == 'profile') and not env['PLATFORM'] == 'win32': # FIXME: on win32 economytest is linked to SDL libs which breaks linking
    Default("test")

########################################################################### tags
# Tags
all_code_files=simpleglob('*.h', 'src', recursive=True)+simpleglob('*.cc', 'src', recursive=True)
all_code_files.sort()
Alias('tags', env.ctags(source=all_code_files))

################################################################ C++ style-check
if (env['build'] == 'debug' or env['build'] == 'profile') and env['PLATFORM'] != 'darwin' and env['check'] == True:
        Alias('old-stylecheck', env.Execute('sh utils/spurious_source_code/detect'))

# Style Checks
PhonyTarget('stylecheck',
    Action('./build/scons-tools/codecheck/CodeCheck.py %s %s' %
        ('-c' if env["USE_COLOR"] else '',
         ' '.join(all_code_files)), lambda *Silence: None)
)

################################################################## PNG shrinking

# finding files takes quite long, so don't execute it if it's unneccessary
if ('shrink' in BUILD_TARGETS):
	print "Assembling file list for image compactification..."
	Alias('shrink', env.PNGShrink(simpleglob('*.png', '.', recursive=True)))

########################################################## Install and uninstall

instadd(env, 'ChangeLog', 'doc')
instadd(env, 'COPYING', 'doc')
instadd(env, 'CREDITS', 'doc')
instadd(env, 'VERSION', '.')
instadd(env, 'widelands', filetype='binary')

install=env.Install('installtarget', 'COPYING') # the second argument is a (neccessary) dummy
Alias('install', install)
AlwaysBuild(install)
#env.AddPreAction(install, Action("scons buildlocale"))


uninstall=env.Uninstall('uninstalltarget', 'COPYING') # the second argument is a (neccessary) dummy
Alias('uninstall', uninstall)
Alias('uninst', uninstall)
AlwaysBuild(uninstall)

########################
#version file

print ("GENERATING VERSION FILE")
version_file=open("VERSION","w")
version_file.write(get_build_id(env))
version_file.write('\n\0')
version_file.close()


##################################################################### Distribute

distadd(env, 'ChangeLog')
distadd(env, 'COPYING')
distadd(env, 'CREDITS')
distadd(env, 'Makefile')
distadd(env, 'SConstruct')

dist=env.DistPackage('widelands-'+get_build_id(env), 'COPYING') # the second argument is a (neccessary) dummy
Alias('dist', dist)
AlwaysBuild(dist)

###################################################################### longlines

longlines=PhonyTarget("longlines", 'python utils/count-longlines.py')

###################################################################### precommit

#Alias('precommit', 'indent')
Alias('precommit', 'longlines')

################################################################## Documentation

PhonyTarget('doc', 'doxygen doc/Doxyfile')

########################################################################## Clean

distcleanactions=[
	Delete('build/native-debug'),
	Delete('build/native-profile'),
	Delete('build/native-release'),
	Delete('build/sconf_temp'),
	Delete('build/scons-config.py'),
	Delete('build/config.log'),
	Delete('build/scons-tools/scons_configure.pyc'),
	Delete('build/scons-tools/detect_revision.pyc'),
	Delete('build/scons-tools/Distribute.pyc'),
	Delete('build/scons-tools/ctags.pyc'),
	Delete('build/scons-tools/astyle.pyc'),
	Delete('build/scons-tools/distcc.pyc'),
	Delete('build/scons-tools/ccache.pyc'),
	Delete('build/scons-tools/CodeCheck.pyc'),
	Delete('build/scons-tools/PNGShrink.pyc'),
	Delete('build/scons-signatures.dblite'), #have to delete this or problems occur
	Touch('build/scons-signatures.dblite'), #we need this to make scons exit nicely
	Delete('utils/buildcat.pyc'),
	Delete('utils/confgettext.pyc'),
	Delete('tags'),
	Delete('widelands'),
	Delete('locale/cs'),
	Delete('locale/da'),
	Delete('locale/de'),
	Delete('locale/es'),
	Delete('locale/eu'),
	Delete('locale/fi'),
	Delete('locale/fr'),
	Delete('locale/gl'),
	Delete('locale/he'),
	Delete('locale/hu'),
	Delete('locale/it'),
	Delete('locale/nl'),
	Delete('locale/pl'),
	Delete('locale/ru'),
	Delete('locale/sk'),
	Delete('locale/sv'),
	Delete('VERSION')
]

distclean=PhonyTarget("distclean", distcleanactions)