~widelands-dev/widelands/trunk

1030 by bedouin
- SCons build system
1
import os
1046 by bedouin
- new target "shrink: reduce size of PNGs
2
import shutil
1030 by bedouin
- SCons build system
3
import fnmatch
4
import SCons
1042 by bedouin
- simplify construction of phony targets
5
import time
1046 by bedouin
- new target "shrink: reduce size of PNGs
6
import glob
1030 by bedouin
- SCons build system
7
from SCons.Script.SConscript import SConsEnvironment
1062 by bedouin
- fix sdl-config parsing
8
import string
1030 by bedouin
- SCons build system
9
1155 by bedouin
- remove target "up" which called "cvs up"
10
import sys
11
sys.path.append("build/scons-tools")
12
from scons_configure import *
1955 by bedouin
- enable in-place compression inside distribution tarballs (eg. for campaigns)
13
from Distribute import *
2031 by bedouin
- automagically detect subversion revision number
14
from detect_revision import *
1155 by bedouin
- remove target "up" which called "cvs up"
15
1030 by bedouin
- SCons build system
16
#Speedup. If you have problems with inconsistent or wrong builds, look here first
17
SetOption('max_drift', 1)
18
SetOption('implicit_cache', 1)
19
1149 by bedouin
- pretty printing
20
# Pretty output
21
print
22
1062 by bedouin
- fix sdl-config parsing
23
########################################################################### Glob
1155 by bedouin
- remove target "up" which called "cvs up"
24
# glob.glob does not work with BuildDir(), so use the following replacement from
25
# http://www.scons.org/cgi-bin/wiki/BuildDirGlob?highlight=%28glob%29
26
# which I modified slightly to return a list of filenames instead of nodes
1030 by bedouin
- SCons build system
27
def Glob(match):
1155 by bedouin
- remove target "up" which called "cvs up"
28
	"""Similar to glob.glob, except globs SCons nodes, and thus sees
29
	generated files and files from build directories.  Basically, it sees
30
	anything SCons knows about.  A key subtlety is that since this function
31
	operates on generated nodes as well as source nodes on the filesystem,
32
	it needs to be called after builders that generate files you want to
33
	include.
34
	"""
35
36
	def fn_filter(node):
37
		fn = str(node)
38
		return fnmatch.fnmatch(os.path.basename(fn), match)
39
40
	here = Dir('.')
41
42
	children = here.all_children()
43
	nodes = map(File, filter(fn_filter, children))
44
	node_srcs = [n.srcnode() for n in nodes]
45
	filenames=[]
46
47
	src = here.srcnode()
48
	if src is not here:
49
		src_children = map(File, filter(fn_filter, src.all_children()))
50
		for s in src_children:
51
			 if s not in node_srcs:
52
			 	filenames.append(os.path.basename(str(s)))
53
54
	return filenames
1046 by bedouin
- new target "shrink: reduce size of PNGs
55
1955 by bedouin
- enable in-place compression inside distribution tarballs (eg. for campaigns)
56
######################################################### find $ROOT -name $GLOB
1046 by bedouin
- new target "shrink: reduce size of PNGs
57
1155 by bedouin
- remove target "up" which called "cvs up"
58
def find(root, glob):
1046 by bedouin
- new target "shrink: reduce size of PNGs
59
	files=[]
60
	for file in os.listdir(root):
61
		file=os.path.join(root, file)
62
		if fnmatch.fnmatch(file, glob):
63
			files.append(file)
1155 by bedouin
- remove target "up" which called "cvs up"
64
		if os.path.isdir(file):
65
			files+=find(file, glob)
1046 by bedouin
- new target "shrink: reduce size of PNGs
66
	return files
1051 by bedouin
- added astyle target for sourcecode formatting (change because
67
1955 by bedouin
- enable in-place compression inside distribution tarballs (eg. for campaigns)
68
########################### Create a phony target (not (yet) a feature of scons)
1042 by bedouin
- simplify construction of phony targets
69
70
# taken from scons' wiki
71
def PhonyTarget(alias, action):
72
	"""Returns an alias to a command that performs the
73
	   action.  This is implementated by a Command with a
74
	   nonexistant file target.  This command will run on every
75
	   build, and will never be considered 'up to date'. Acts
76
	   like a 'phony' target in make."""
1051 by bedouin
- added astyle target for sourcecode formatting (change because
77
1042 by bedouin
- simplify construction of phony targets
78
	from tempfile import mktemp
79
	from os.path import normpath
1051 by bedouin
- added astyle target for sourcecode formatting (change because
80
1042 by bedouin
- simplify construction of phony targets
81
	phony_file = normpath(mktemp(prefix="phony_%s_" % alias, dir="."))
82
	return Alias(alias, Command(target=phony_file, source=None, action=action))
83
1955 by bedouin
- enable in-place compression inside distribution tarballs (eg. for campaigns)
84
############################## Functions for setting permissions when installing
1030 by bedouin
- SCons build system
85
# don't forget to set umask
86
try:
87
	os.umask(022)
88
except OSError:     # ignore on systems that don't support umask
89
	pass
90
91
def InstallPerm(env, dest, files, perm):
92
	obj = env.Install(dest, files)
93
	for i in obj:
94
		env.AddPostAction(i, env.Chmod(str(i), perm))
95
96
SConsEnvironment.InstallPerm = InstallPerm
97
SConsEnvironment.InstallProgram = lambda env, dest, files: InstallPerm(env, dest, files, 0755)
98
SConsEnvironment.InstallData = lambda env, dest, files: InstallPerm(env, dest, files, 0644)
99
1155 by bedouin
- remove target "up" which called "cvs up"
100
################################################################################
101
# CLI options setup
102
103
def cli_options():
104
	opts=Options('build/scons-config.py', ARGUMENTS)
2175 by bedouin
- move filesystem code into it's own subdirectory
105
	opts.Add('build', 'debug-no-parachute / debug-slow / debug-efence / debug(default) / release / profile', 'debug')
2031 by bedouin
- automagically detect subversion revision number
106
	opts.Add('build_id', 'To get a default value (SVN revision), leave this empty', '')
1155 by bedouin
- remove target "up" which called "cvs up"
107
	opts.Add('sdlconfig', 'On some systems (e.g. BSD) this is called sdl12-config', 'sdl-config')
1185 by bedouin
- fold WLApplication init/shutdown int ctor/dtor
108
	opts.Add('paraguiconfig', '', 'paragui-config')
1155 by bedouin
- remove target "up" which called "cvs up"
109
	opts.Add('install_prefix', '', '/usr/local')
1967 by bedouin
- implement new targets scons install and scons uninstall using commandline
110
	opts.Add('bindir', '(relative to install_prefix)', 'games')
111
	opts.Add('datadir', '(relative to install_prefix)', 'share/games/widelands')
1155 by bedouin
- remove target "up" which called "cvs up"
112
	opts.Add('extra_include_path', '', '')
113
	opts.Add('extra_lib_path', '', '')
114
	opts.AddOptions(
115
		BoolOption('use_ggz', 'Use the GGZ Gamingzone?', 0),
116
		BoolOption('cross', 'Is this a cross compile? (developer use only)', 0)
117
		)
118
	return opts
119
120
################################################################################
121
# Environment setup
122
#
123
# Create configuration objects
124
125
opts=cli_options()
1051 by bedouin
- added astyle target for sourcecode formatting (change because
126
1030 by bedouin
- SCons build system
127
env=Environment(options=opts)
1155 by bedouin
- remove target "up" which called "cvs up"
128
env.Help(opts.GenerateHelpText(env))
129
130
conf=env.Configure(conf_dir='#/build/sconf_temp',log_file='#build/config.log',
131
		   custom_tests={
132
				'CheckPKGConfig' : CheckPKGConfig,
133
				'CheckPKG': CheckPKG,
134
				'CheckSDLConfig': CheckSDLConfig,
1185 by bedouin
- fold WLApplication init/shutdown int ctor/dtor
135
				'CheckSDLVersionAtLeast': CheckSDLVersionAtLeast,
2013 by bedouin
- check for a working C++ compiler
136
				'CheckCompilerAttribute': CheckCompilerAttribute,
1905 by bedouin
- bugfixes for debug-efence target
137
				'CheckCompilerFlag': CheckCompilerFlag,
138
				'CheckLinkerFlag': CheckLinkerFlag,
1185 by bedouin
- fold WLApplication init/shutdown int ctor/dtor
139
				'CheckParaguiConfig': CheckParaguiConfig
1155 by bedouin
- remove target "up" which called "cvs up"
140
		   }
141
)
142
143
################################################################################
144
# Environment setup
145
#
146
# Register tools
147
148
env.Tool("ctags", toolpath=['build/scons-tools'])
149
env.Tool("PNGShrink", toolpath=['build/scons-tools'])
150
env.Tool("astyle", toolpath=['build/scons-tools'])
1955 by bedouin
- enable in-place compression inside distribution tarballs (eg. for campaigns)
151
env.Tool("Distribute", toolpath=['build/scons-tools'])
1155 by bedouin
- remove target "up" which called "cvs up"
152
153
################################################################################
154
# Environment setup
155
#
156
# Initial debug info
157
1167 by bedouin
- fix bug where libpaths got output incorrectly
158
#This makes LIBPATH work correctly - I just don't know why :-(
159
#Obviously, env.LIBPATH must be forced to be a list instead of a string. Is this
160
#a scons problem? Or rather our problem???
161
env.Append(LIBPATH=[])
1217 by bedouin
- treat lists as what they are, not as strings :-$
162
env.Append(CPPPATH=[])
163
env.Append(PATH=[])
1167 by bedouin
- fix bug where libpaths got output incorrectly
164
1149 by bedouin
- pretty printing
165
print 'Platform:         ', env['PLATFORM']
166
print 'Build type:       ', env['build']
1059 by bedouin
- library autodetection fixes
167
1901 by bedouin
- new build target "scons dist" that creates a distribution tarball
168
#TODO: should be detected automagically
1088 by bedouin
- improved sdl-config detection
169
if env['PLATFORM']!='win32':
1217 by bedouin
- treat lists as what they are, not as strings :-$
170
	env.Append(PATH=['/usr/bin', '/usr/local/bin'])
1088 by bedouin
- improved sdl-config detection
171
1901 by bedouin
- new build target "scons dist" that creates a distribution tarball
172
#TODO: should be detected automagically
1059 by bedouin
- library autodetection fixes
173
if env['PLATFORM']=='darwin':
174
	# this is where DarwinPorts puts stuff by default
1217 by bedouin
- treat lists as what they are, not as strings :-$
175
	env.Append(CPPPATH='/opt/local/include')
176
	env.Append(LIBPATH='/opt/local/lib')
177
	env.Append(PATH='/opt/local/bin')
1099 by bedouin
- on darwin, use fink paths too
178
	# and here's for fink
1217 by bedouin
- treat lists as what they are, not as strings :-$
179
	env.Append(CPPPATH='/sw/include')
180
	env.Append(LIBPATH='/sw/lib')
181
	env.Append(PATH='/sw/bin')
1059 by bedouin
- library autodetection fixes
182
1155 by bedouin
- remove target "up" which called "cvs up"
183
################################################################################
184
# Autoconfiguration
185
#
186
# Parse build type
187
1030 by bedouin
- SCons build system
188
DEBUG=0
189
PROFILE=0
190
OPTIMIZE=0
191
SDL_PARACHUTE=1
1952 by sigra
Fix broken debug builds. Make sure that they are not stripped (which would remove the debug information).
192
STRIP=0
1904 by bedouin
- new build target "debug-efence" will use efence memory
193
EFENCE=0
1030 by bedouin
- SCons build system
194
if env['build']=='debug-no-parachute':
195
	DEBUG=1
196
	OPTIMIZE=1
197
	SDL_PARACHUTE=0
198
199
if env['build']=='debug-slow':
200
	DEBUG=1
201
202
if env['build']=='debug':
203
	DEBUG=1
204
	OPTIMIZE=1
205
1904 by bedouin
- new build target "debug-efence" will use efence memory
206
if env['build']=='debug-efence':
207
	DEBUG=1
208
	OPTIMIZE=1
209
	EFENCE=1
210
1030 by bedouin
- SCons build system
211
if env['build']=='profile':
212
	DEBUG=1
1905 by bedouin
- bugfixes for debug-efence target
213
	OPTIMIZE=1
1030 by bedouin
- SCons build system
214
	PROFILE=1
215
216
if env['build']=='release':
217
	OPTIMIZE=1
1952 by sigra
Fix broken debug builds. Make sure that they are not stripped (which would remove the debug information).
218
	STRIP=1
1030 by bedouin
- SCons build system
219
220
if DEBUG:
1905 by bedouin
- bugfixes for debug-efence target
221
	env.debug=1
222
	env.Append(CCFLAGS='-DDEBUG')
1030 by bedouin
- SCons build system
223
else:
1905 by bedouin
- bugfixes for debug-efence target
224
	env.debug=0
1217 by bedouin
- treat lists as what they are, not as strings :-$
225
	env.Append(CCFLAGS='-DNDEBUG')
1030 by bedouin
- SCons build system
226
227
if PROFILE:
1905 by bedouin
- bugfixes for debug-efence target
228
	env.profile=1
229
else:
230
	env.profile=0
1030 by bedouin
- SCons build system
231
232
if OPTIMIZE:
1905 by bedouin
- bugfixes for debug-efence target
233
	env.optimize=1
1030 by bedouin
- SCons build system
234
else:
1905 by bedouin
- bugfixes for debug-efence target
235
	env.optimize=0
1030 by bedouin
- SCons build system
236
1904 by bedouin
- new build target "debug-efence" will use efence memory
237
if EFENCE:
238
	env.efence=1
239
else:
240
	env.efence=0
241
1030 by bedouin
- SCons build system
242
if not SDL_PARACHUTE:
1217 by bedouin
- treat lists as what they are, not as strings :-$
243
	env.Append(CCFLAGS='-DNOPARACHUTE')
1030 by bedouin
- SCons build system
244
1952 by sigra
Fix broken debug builds. Make sure that they are not stripped (which would remove the debug information).
245
if STRIP:
246
	env.strip=1
247
else:
248
	env.strip=0
249
1155 by bedouin
- remove target "up" which called "cvs up"
250
################################################################################
251
252
TARGET=parse_cli(env)
253
254
env.Append(CPPPATH=env['extra_include_path'])
255
env.Append(LIBPATH=env['extra_lib_path'])
1030 by bedouin
- SCons build system
256
1046 by bedouin
- new target "shrink: reduce size of PNGs
257
BINDIR= os.path.join(env['install_prefix'], env['bindir'])
258
DATADIR=os.path.join(env['install_prefix'], env['datadir'])
259
1155 by bedouin
- remove target "up" which called "cvs up"
260
#TODO: make sure that build type is valid !!!
261
262
################################################################################
1042 by bedouin
- simplify construction of phony targets
263
2172 by bedouin
- bring back accidental deletion of scons' "memory" of previous build options
264
#build_id must be saved *before* it might be set to a fixed date
265
opts.Save('build/scons-config.py',env)
266
2031 by bedouin
- automagically detect subversion revision number
267
#This is just a default, don't change it here in the code.
268
#Use the commandline option 'build_id' instead
269
if env['build_id']=='':
270
	env['build_id']='svn'+detect_revision()
1149 by bedouin
- pretty printing
271
print 'Build ID:          '+env['build_id']
1155 by bedouin
- remove target "up" which called "cvs up"
272
273
config_h=write_configh_header()
274
do_configure(config_h, conf, env)
275
write_configh_footer(config_h, env['install_prefix'], BINDIR, DATADIR)
2031 by bedouin
- automagically detect subversion revision number
276
write_buildid(env['build_id'])
1051 by bedouin
- added astyle target for sourcecode formatting (change because
277
1030 by bedouin
- SCons build system
278
env=conf.Finish()
279
1155 by bedouin
- remove target "up" which called "cvs up"
280
# Pretty output
281
print
282
1955 by bedouin
- enable in-place compression inside distribution tarballs (eg. for campaigns)
283
######################################################## Use distcc if available
1030 by bedouin
- SCons build system
284
285
# not finished yet
286
#if os.path.exists('/usr/lib/distcc/bin'):
287
#	env['ENV']['DISTCC_HOSTS'] = os.environ['DISTCC_HOSTS']
288
#	env['ENV']['PATH'] = '/usr/lib/distcc/bin:'+env['ENV']['PATH']
289
#	env['ENV']['HOME'] = os.environ['HOME']
290
1955 by bedouin
- enable in-place compression inside distribution tarballs (eg. for campaigns)
291
################################################################### Build things
1046 by bedouin
- new target "shrink: reduce size of PNGs
292
1030 by bedouin
- SCons build system
293
SConsignFile('build/scons-signatures')
1155 by bedouin
- remove target "up" which called "cvs up"
294
BUILDDIR='build/'+TARGET+'-'+env['build']
295
Export('env', 'Glob', 'BUILDDIR', 'PhonyTarget')
1046 by bedouin
- new target "shrink: reduce size of PNGs
296
2189 by bedouin
- patch by Antonio Trueba: improve locale handling for coders and translators
297
####################################################################### 
1126 by bedouin
- new target "precommit" will call "indent" and "buildcat"
298
1955 by bedouin
- enable in-place compression inside distribution tarballs (eg. for campaigns)
299
SConscript('build/SConscript')
300
SConscript('campaigns/SConscript')
301
SConscript('doc/SConscript')
1967 by bedouin
- implement new targets scons install and scons uninstall using commandline
302
SConscript('fonts/SConscript')
303
SConscript('game_server/SConscript')
1955 by bedouin
- enable in-place compression inside distribution tarballs (eg. for campaigns)
304
SConscript('maps/SConscript')
1967 by bedouin
- implement new targets scons install and scons uninstall using commandline
305
SConscript('music/SConscript')
306
SConscript('pics/SConscript')
2189 by bedouin
- patch by Antonio Trueba: improve locale handling for coders and translators
307
(buildlocale, buildcat)=SConscript('po/SConscript')
1967 by bedouin
- implement new targets scons install and scons uninstall using commandline
308
SConscript('sound/SConscript')
2033 by bedouin
- add the sourcecode to scons dist :-$
309
SConscript('src/SConscript.dist')
310
thebinary=SConscript('src/SConscript', build_dir=BUILDDIR, duplicate=0)
1967 by bedouin
- implement new targets scons install and scons uninstall using commandline
311
SConscript('tribes/SConscript')
312
SConscript('txts/SConscript')
1955 by bedouin
- enable in-place compression inside distribution tarballs (eg. for campaigns)
313
SConscript('utils/SConscript')
1967 by bedouin
- implement new targets scons install and scons uninstall using commandline
314
SConscript('worlds/SConscript')
1959 by bedouin
- new target scons snapshot to create tarballs without any packing/compression
315
316
Default(thebinary)
2189 by bedouin
- patch by Antonio Trueba: improve locale handling for coders and translators
317
if env['build']=='release':
318
	Default(buildlocale)
1955 by bedouin
- enable in-place compression inside distribution tarballs (eg. for campaigns)
319
320
########################################################################### tags
1046 by bedouin
- new target "shrink: reduce size of PNGs
321
1051 by bedouin
- added astyle target for sourcecode formatting (change because
322
S=find('src', '*.h')
323
S+=find('src', '*.cc')
1046 by bedouin
- new target "shrink: reduce size of PNGs
324
Alias('tags', env.ctags(source=S, target='tags'))
2189 by bedouin
- patch by Antonio Trueba: improve locale handling for coders and translators
325
Default('tags')
1046 by bedouin
- new target "shrink: reduce size of PNGs
326
1955 by bedouin
- enable in-place compression inside distribution tarballs (eg. for campaigns)
327
################################################################## PNG shrinking
1046 by bedouin
- new target "shrink: reduce size of PNGs
328
329
# findfiles takes quite long, so don't execute it if it's unneccessary
1901 by bedouin
- new build target "scons dist" that creates a distribution tarball
330
if ('shrink' in BUILD_TARGETS):
331
	print "Assembling file list for image compactification..."
1046 by bedouin
- new target "shrink: reduce size of PNGs
332
	shrink=env.PNGShrink(find('.', '*.png'))
333
	Alias("shrink", shrink)
334
1955 by bedouin
- enable in-place compression inside distribution tarballs (eg. for campaigns)
335
########################################################## Install and uninstall
1046 by bedouin
- new target "shrink: reduce size of PNGs
336
1967 by bedouin
- implement new targets scons install and scons uninstall using commandline
337
instadd(env, 'ChangeLog', 'doc')
338
instadd(env, 'COPYING', 'doc')
339
instadd(env, 'CREDITS', 'doc')
340
instadd(env, 'widelands', filetype='binary')
341
342
install=env.Install('installtarget', '')
1965 by bedouin
- revert rev1968 which, as Erik rightly remarked, does not speed up things
343
Alias('install', install)
344
AlwaysBuild(install)
2189 by bedouin
- patch by Antonio Trueba: improve locale handling for coders and translators
345
env.AddPreAction(install, Action(buildlocale))
1965 by bedouin
- revert rev1968 which, as Erik rightly remarked, does not speed up things
346
1967 by bedouin
- implement new targets scons install and scons uninstall using commandline
347
uninstall=env.Uninstall('uninstalltarget', '')
348
Alias('uninstall', uninstall)
349
AlwaysBuild(uninstall)
1046 by bedouin
- new target "shrink: reduce size of PNGs
350
1955 by bedouin
- enable in-place compression inside distribution tarballs (eg. for campaigns)
351
##################################################################### Distribute
352
353
distadd(env, 'ChangeLog')
354
distadd(env, 'COPYING')
355
distadd(env, 'CREDITS')
356
distadd(env, 'Doxyfile')
357
distadd(env, 'Makefile')
358
distadd(env, 'README-compiling.txt')
359
distadd(env, 'README.developers')
360
distadd(env, 'SConstruct')
361
distadd(env, 'build-widelands.sh')
362
distadd(env, 'macos')
363
2031 by bedouin
- automagically detect subversion revision number
364
dist=env.DistPackage('widelands-'+env['build_id'], '')
1955 by bedouin
- enable in-place compression inside distribution tarballs (eg. for campaigns)
365
Alias('dist', dist)
366
AlwaysBuild(dist)
367
368
###################################################################### longlines
1145 by bedouin
- make count-longlines.py output useful
369
1156 by bedouin
- fix broken default target
370
longlines=PhonyTarget("longlines", 'utils/count-longlines.py')
1145 by bedouin
- make count-longlines.py output useful
371
1955 by bedouin
- enable in-place compression inside distribution tarballs (eg. for campaigns)
372
###################################################################### precommit
1126 by bedouin
- new target "precommit" will call "indent" and "buildcat"
373
1941 by sigra
Comment out broken astyle (see [https://sourceforge.net/tracker/index.php?func=detail&aid=1642489&group_id=2319&atid=102319]). When astyle releases a new version, we check if the bug has been fixed. If it has, we implement a version check. If the found astyle version is >= the fixed version, astyle is enabled.
374
#Alias('precommit', 'indent')
1155 by bedouin
- remove target "up" which called "cvs up"
375
Alias('precommit', buildcat)
376
Alias('precommit', 'longlines')
1046 by bedouin
- new target "shrink: reduce size of PNGs
377
1955 by bedouin
- enable in-place compression inside distribution tarballs (eg. for campaigns)
378
################################################################## Documentation
1046 by bedouin
- new target "shrink: reduce size of PNGs
379
1042 by bedouin
- simplify construction of phony targets
380
PhonyTarget('doc', 'doxygen Doxyfile')