File: SConstruct

package info (click to toggle)
nsis 2.19-3
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 7,868 kB
  • ctags: 7,903
  • sloc: cpp: 31,925; ansic: 28,340; pascal: 1,365; python: 987; xml: 330; makefile: 63
file content (631 lines) | stat: -rwxr-xr-x 20,653 bytes parent folder | download
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
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
## TODO
#
#   * Write SConscript for NSIS Menu
#    - Use inheritance instead of current wxWidgets patches
#    - Compile for POSIX too? wxWidgets is cross platform after all...
#
##

EnsurePythonVersion(1,6)

try:
	EnsureSConsVersion(0,96,91)
except TypeError: # EnsureSConsVersion in older versions took only two parameters
	print 'SCons 0.96.91 or greater is required, but you have an older version'
	Exit(2)
	
stubs = [
	'bzip2',
	'lzma',
	'zlib'
]

plugins = [
	'AdvSplash',
	'Banner',
	'BgImage',
	'Dialer',
	'InstallOptions',
	'LangDLL',
	'Library/TypeLib',
	'Math',
	'nsExec',
	'NSISdl',
	'Splash',
	'StartMenu',
	'System',
	'UserInfo',
	'VPatch/Source/Plugin'
]

utils = [
	'Library/LibraryLocal',
	'Library/RegTool',
	'MakeLangId',
	'Makensisw',
	'NSIS Menu',
	'UIs',
	'VPatch/Source/GenPat',
	'zip2exe'
]

misc = [
	'Graphics',
	'Language files',
	'Modern UI',
	'VPatch'
]

doc = [
	'license.txt'
]

defenv = Environment()
Export('defenv')

######################################################################
#######  Includes                                                  ###
######################################################################

SConscript('SCons/utils.py')

######################################################################
#######  Options                                                   ###
######################################################################

import os
hhc = 'no'
if defenv.WhereIs('hhc', os.environ['PATH']):
	hhc = 'yes'

from time import strftime, gmtime
cvs_version = strftime('%d-%b-%Y.cvs', gmtime())

opts = Options()

install_dirs = {
	'win32': {
		'dest': '',
		'prefix': '',
		'conf': '$PREFIX',
		'bin': '$PREFIX',
		'data': '$PREFIX',
		'doc': '$PREFIX',
	},
	'default': {
		'dest': '',
		'prefix': '/usr/local',
		'conf': '$PREFIX/etc',
		'bin': '$PREFIX/bin',
		'data': '$PREFIX/share/nsis',
		'doc': '$PREFIX/share/doc/nsis',
	}
}

if defenv['PLATFORM'] in install_dirs:
	dirs = install_dirs[defenv['PLATFORM']]
else:
	dirs = install_dirs['default']

# version
opts.Add(('VERSION', 'Version of NSIS', cvs_version))
opts.Add(('VER_MAJOR', 'Major version of NSIS (recommended for dist-installer)', None))
opts.Add(('VER_MINOR', 'Minor version of NSIS (recommended for dist-installer)', None))
opts.Add(('VER_REVISION', 'Revision of NSIS (recommended for dist-installer)', None))
opts.Add(('VER_BUILD', 'Build version of NSIS (recommended for dist-installer)', None))
# installation
opts.Add(('PREFIX', 'Installation prefix', dirs['prefix']))
opts.Add(ListOption('SKIPSTUBS', 'A list of stubs that will not be built', 'none', stubs))
opts.Add(ListOption('SKIPPLUGINS', 'A list of plug-ins that will not be built', 'none', plugins))
opts.Add(ListOption('SKIPUTILS', 'A list of utilities that will not be built', 'none', utils))
opts.Add(ListOption('SKIPMISC', 'A list of plug-ins that will not be built', 'none', misc))
opts.Add(ListOption('SKIPDOC', 'A list of doc files that will not be built/installed', 'none', doc))
# build tools
opts.Add(BoolOption('MSTOOLKIT', 'Use Microsoft Visual C++ Toolkit', 'no'))
opts.Add(BoolOption('CHMDOCS', 'Build CHM documentation, requires hhc.exe', hhc))
opts.Add(PathOption('CPPPATH', 'Path to search for include files', None))
opts.Add(PathOption('LIBPATH', 'Path to search for libraries', None))
# build options
opts.Add(BoolOption('DEBUG', 'Build executables with debugging information', 'no'))
opts.Add(PathOption('CODESIGNER', 'A program used to sign executables', None))
# path related build options
opts.Add(('PREFIX_DEST', 'Intermediate installation prefix (extra install time prefix)', dirs['dest']))
opts.Add(('PREFIX_CONF', 'Path to install nsisconf.nsh to', dirs['conf']))
opts.Add(('PREFIX_BIN', 'Path to install native binaries to', dirs['bin']))
opts.Add(('PREFIX_DATA', 'Path to install nsis data to (plugins, includes, stubs, contrib, win32 binaries)', dirs['data']))
opts.Add(('PREFIX_DOC','Path to install nsis README / INSTALL / TODO files to.', dirs['doc']))

opts.Update(defenv)

Help(opts.GenerateHelpText(defenv))

# build configuration
SConscript('SCons/config.py')

# add prefixes defines
if defenv['PLATFORM'] != 'win32':
	defenv.Append(NSIS_CPPDEFINES = [('PREFIX_CONF', '"%s"' % defenv.subst('$PREFIX_CONF'))])
	defenv.Append(NSIS_CPPDEFINES = [('PREFIX_DATA', '"%s"' % defenv.subst('$PREFIX_DATA'))])

# write configuration into sconf.h and defines.h
sconf_h = open(File('#Source/exehead/sconf.h').abspath, 'w')
defines_h = open(File('#Source/defines.h').abspath, 'w')
for i in defenv['NSIS_CPPDEFINES']:
	if type(i) is not str:
		sconf_h.write('#define %s %s\n' % (i[0], i[1]))
		if str(i[1])[0] != '"':
			defines_h.write('definedlist.add("%s", "%s");\n' % (i[0], i[1]))
		else:
			defines_h.write('definedlist.add("%s", %s);\n' % (i[0], i[1]))
	else:
		sconf_h.write('#define %s\n' % (i))
		defines_h.write('definedlist.add("%s");\n' % (i))
sconf_h.close()
defines_h.close()

# write version into version.h
f = open(File('#Source/version.h').abspath, 'w')
f.write('#define NSIS_VERSION "v%s"\n' % defenv['VERSION'])
f.close()

######################################################################
#######  Functions                                                 ###
######################################################################

defenv['ZIPDISTDIR'] = defenv.Dir('#nsis-$VERSION')
defenv['INSTDISTDIR'] = defenv.Dir('#.instdist')
defenv['TESTDISTDIR'] = defenv.Dir('#.test')
defenv['DISTSUFFIX'] = ''

if defenv.has_key('CODESIGNER'):
	defenv['DISTSUFFIX'] = '-signed'

defenv.Execute(Delete('$ZIPDISTDIR'))
defenv.Execute(Delete('$INSTDISTDIR'))
defenv.Execute(Delete('$TESTDISTDIR'))

def Distribute(files, names, component, path, subpath, alias, install_alias=None):
	if isinstance(files, (str, type(File('SConstruct')))):
		files = [files]
	files = map(File, files)

	if isinstance(names, str):
		names = [names]
	if not names:
		names = map(str, files)
		names = map(os.path.basename, names)

	for d in ('$ZIPDISTDIR', '$INSTDISTDIR', '$TESTDISTDIR'):
		paths = map(lambda file: os.path.join(d, path, subpath, file), names)
		defenv.InstallAs(paths, files)

	if defenv.has_key('PREFIX') and defenv['PREFIX']:
		prefix = '${PREFIX_DEST}${PREFIX_%s}' % component.upper()
		paths = map(lambda file: os.path.join(prefix, path, subpath, file), names)
		ins = defenv.InstallAs(paths, files)
	else:
		ins = []

	if ins:
		defenv.Alias('install', ins)
		defenv.Alias('install-%s' % component, ins)
		if alias:
			defenv.Alias(alias, ins)
		if install_alias:
			defenv.Alias('install-%s' % install_alias, ins)

		return ins

def DistributeBin(files, names=[], path='', alias=None):
	return defenv.Distribute(files, names, 'bin', '', path, alias)

def DistributeConf(files, names=[], path='', alias=None):
	return defenv.Distribute(files, names, 'conf', '', path, alias)

def DistributeW32Bin(files, names=[], path='', alias=None):
	return defenv.Distribute(files, names, 'data', 'Bin', path, alias, 'w32bin')

def DistributeStubs(files, names=[], path='', alias=None):
	return defenv.Distribute(files, names, 'data', 'Stubs', path, alias, 'stubs')

def DistributePlugin(files, names=[], path='', alias=None):
	return defenv.Distribute(files, names, 'data', 'Plugins', path, alias, 'plugins')

def DistributeContrib(files, names=[], path='', alias=None):
	return defenv.Distribute(files, names, 'data', 'Contrib', path, alias, 'contrib')

def DistributeMenu(files, names=[], path='', alias=None):
	return defenv.Distribute(files, names, 'data', 'Menu', path, alias, 'menu')

def DistributeInclude(files, names=[], path='', alias=None):
	return defenv.Distribute(files, names, 'data', 'Include', path, alias, 'includes')

def DistributeDoc(files, names=[], path='', alias=None):
	return defenv.Distribute(files, names, 'doc', '', path, alias)

def DistributeDocs(files, names=[], path='', alias=None):
	return defenv.Distribute(files, names, 'doc', 'Docs', path, alias, 'docs')

def DistributeExamples(files, names=[], path='', alias=None):
	return defenv.Distribute(files, names, 'doc', 'Examples', path, alias, 'examples')

def Sign(targets):
	if defenv.has_key('CODESIGNER'):
		for t in targets:
			a = defenv.Action('$CODESIGNER "%s"' % t.path)
			defenv.AddPostAction(t, a)

def TestScript(scripts):
	defenv.Install('$TESTDISTDIR/Tests', scripts)

defenv.Distribute = Distribute
defenv.DistributeBin = DistributeBin
defenv.DistributeConf = DistributeConf
defenv.DistributeW32Bin = DistributeW32Bin
defenv.DistributeStubs = DistributeStubs
defenv.DistributePlugin = DistributePlugin
defenv.DistributeContrib = DistributeContrib
defenv.DistributeMenu = DistributeMenu
defenv.DistributeInclude = DistributeInclude
defenv.DistributeDoc = DistributeDoc
defenv.DistributeDocs = DistributeDocs
defenv.DistributeExamples = DistributeExamples
defenv.Sign = Sign
defenv.TestScript = TestScript

######################################################################
#######  Environments                                              ###
######################################################################

if defenv['DEBUG']:
	defenv.Replace(BUILD_PREFIX = 'build/debug')
else:
	defenv.Replace(BUILD_PREFIX = 'build/release')

if defenv['MSTOOLKIT']:
	defenv.Tool('mstoolkit', toolpath = ['SCons/Tools'])

defenv.Default('$BUILD_PREFIX')

tools = defenv['TOOLS']

envs = []

if 'msvc' in tools or 'mstoolkit' in tools:
	envs = SConscript('SCons/Config/ms')
elif 'gcc' in tools:
	envs = SConscript('SCons/Config/gnu')
else:
	envs = SConscript('SCons/Config/default')

stub_env = envs[0]
makensis_env = envs[1]
plugin_env = envs[2]
util_env = envs[3]
cp_util_env = envs[4]
test_env = envs[5]

######################################################################
#######  Distribution                                              ###
######################################################################

dist_zip = 'nsis-${VERSION}${DISTSUFFIX}.zip'
zip_target = defenv.Zip(dist_zip, '$ZIPDISTDIR')
defenv.Alias('dist-zip', zip_target)

AlwaysBuild(defenv.AddPostAction(zip_target, Delete('$ZIPDISTDIR')))

if defenv['PLATFORM'] == 'win32':
	optchar = '/'
else:
	optchar = '-'

defenv['INSTVER'] = '%sDVERSION=$VERSION' % optchar
if defenv.has_key('VER_MAJOR') and defenv.has_key('VER_MINOR') \
    and defenv.has_key('VER_REVISION') and defenv.has_key('VER_BUILD'):
	defenv['INSTVER'] += ' %sDVER_MAJOR=$VER_MAJOR' % optchar
	defenv['INSTVER'] += ' %sDVER_MINOR=$VER_MINOR' % optchar
	defenv['INSTVER'] += ' %sDVER_REVISION=$VER_REVISION' % optchar
	defenv['INSTVER'] += ' %sDVER_BUILD=$VER_BUILD' % optchar

inst_env = {}
inst_env['NSISDIR'] = os.path.abspath(str(defenv['INSTDISTDIR']))
inst_env['NSISCONFDIR'] = os.path.abspath(str(defenv['INSTDISTDIR']))

installer_target = defenv.Command('nsis-${VERSION}-setup${DISTSUFFIX}.exe',
                                  '$INSTDISTDIR' + os.sep + 'Examples' + os.sep + 'makensis.nsi',
                                  '$INSTDISTDIR' + os.sep + 'makensis$PROGSUFFIX ' +
                                  '%sDOUTFILE=$TARGET.abspath $INSTVER $SOURCE' % optchar,
                                  ENV = inst_env)
defenv.Depends(installer_target, '$INSTDISTDIR')
defenv.Sign(installer_target)
defenv.Alias('dist-installer', installer_target)

AlwaysBuild(defenv.AddPostAction(installer_target, Delete('$INSTDISTDIR')))

defenv.Alias('dist', ['dist-zip', 'dist-installer'])

######################################################################
#######  Distribute Basics                                         ###
######################################################################

for d in doc:
	if d in defenv['SKIPDOC']:
		continue
	defenv.DistributeDoc(d)

defenv.DistributeConf('nsisconf.nsh')

######################################################################
#######  Stubs                                                     ###
######################################################################

def BuildStub(compression, solid):
	env = stub_env.Copy()

	suffix = ''
	if solid:
		suffix = '_solid'

	build_dir = '$BUILD_PREFIX/stub_%s%s' % (compression, suffix)

	exports = { 'env' : env, 'compression' : compression, 'solid_compression' : solid }

	target = defenv.SConscript(dirs = 'Source/exehead', build_dir = build_dir, duplicate = False, exports = exports)
	env.SideEffect('%s/stub_%s.map' % (build_dir, stub), target)

	env.DistributeStubs(target, names=compression+suffix)

	defenv.Alias(compression, target)
	defenv.Alias('stubs', target)

for stub in stubs:
	if stub in defenv['SKIPSTUBS']:
		continue

	BuildStub(stub, False)
	BuildStub(stub, True)

defenv.DistributeStubs('Source/exehead/uninst.ico',names='uninst')

######################################################################
#######  makensis                                                  ###
######################################################################

build_dir = '$BUILD_PREFIX/makensis'
exports = { 'env' : makensis_env }

makensis = defenv.SConscript(dirs = 'Source', build_dir = build_dir, duplicate = False, exports = exports)

makensis_env.SideEffect('%s/makensis.map' % build_dir, makensis)

defenv.Alias('makensis', makensis)

ins = defenv.DistributeBin(makensis,alias='install-compiler')

######################################################################
#######  Common Functions                                          ###
######################################################################

def AddEnvStandardFlags(env, defines, flags, entry, nodeflib):
	if defines:
		env.Append(CPPDEFINES = defines)
	if flags:
		env.Append(CCFLAGS = flags)

	if entry:
		env.Append(LINKFLAGS = '${ENTRY_FLAG("%s")}' % entry)

	if nodeflib:
		env.Append(LINKFLAGS = '$NODEFLIBS_FLAG') # no default libraries

def AppendRES(env, source, res, resources, target_name = None):
	if res:
		target_res = env.RES(target_name, res)
		if resources:
			env.Depends(target_res, resources)
		source.append(target_res)

def CleanMap(env, target, target_name):
	env.Clean(target, File(target_name + '.map'))

def DistributeExtras(env, target, examples, docs):
	if examples:
		env.DistributeExamples(examples, path=target)
	if docs:
		env.DistributeDocs(docs, path=target)

######################################################################
#######  Plug-ins                                                  ###
######################################################################

def BuildPlugin(target, source, libs, examples = None, docs = None,
                entry = 'DllMain', res = None, res_target = None,
                resources = None, defines = None, flags = None, 
                nodeflib = True, cppused = False):
	env = plugin_env.Copy()

	if cppused and env['CPP_REQUIRES_STDLIB']:
		nodeflib = False

	AddEnvStandardFlags(env, defines, flags, entry, nodeflib)

	AppendRES(env, source, res, resources, res_target)

	plugin = env.SharedLibrary(target, source, LIBS = libs)
	defenv.Alias(target, plugin)
	defenv.Alias('plugins', plugin)

	defenv.Sign(plugin)

	CleanMap(env, plugin, target)

	for i in plugin:
		if str(i)[-4:].lower() == '.dll':
			plugin = i
			break
	env.DistributePlugin(plugin)

	DistributeExtras(env, target, examples, docs)

for plugin in plugins:
	if plugin in defenv['SKIPPLUGINS']:
		continue

	path = 'Contrib/' + plugin
	build_dir = '$BUILD_PREFIX/' + plugin
	exports = {'BuildPlugin' : BuildPlugin, 'env' : plugin_env.Copy()}

	defenv.SConscript(dirs = path, build_dir = build_dir, duplicate = False, exports = exports)

######################################################################
#######  Utilities                                                 ###
######################################################################

def BuildUtil(target, source, libs, entry = None, res = None, 
              resources = None, defines = None, flags = None,
              nodeflib = False, file_name = '', path='', contrib = False,
              examples = None, docs = None, cross_platform = False,
							root_util = False):
	if not cross_platform:
		env = util_env.Copy()
	else:
		env = cp_util_env.Copy()

	AddEnvStandardFlags(env, defines, flags, entry, nodeflib)

	AppendRES(env, source, res, resources)

	if file_name != '':
		target = "%s/%s" % (target, file_name)

	util = env.Program(target, source, LIBS = libs)
	defenv.Alias(target, util)
	defenv.Alias('utils', util)

	defenv.Sign(util)

	CleanMap(env, util, target)

	if contrib:
		ins = env.DistributeContrib(util, path=path, alias='install-utils')
	elif cross_platform and not env['PLATFORM'] == 'win32' or root_util and env['PLATFORM'] == 'win32':
		ins = env.DistributeBin(util, path=path, alias='install-utils')
	else:
		ins = env.DistributeW32Bin(util, path=path, alias='install-utils')

	DistributeExtras(env, target, examples, docs)

	return util

for util in utils:
	if util in defenv['SKIPUTILS']:
		continue

	path = 'Contrib/' + util
	build_dir = '$BUILD_PREFIX/' + util
	exports = {'BuildUtil' : BuildUtil, 'env' : util_env.Copy()}

	defenv.SConscript(dirs = path, build_dir = build_dir, duplicate = False, exports = exports)

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

halibut = defenv.SConscript(
	dirs = 'Docs/src/bin/halibut',
	build_dir = '$BUILD_PREFIX/halibut',
	duplicate = False,
	exports = {'env' : defenv.Copy()}
)

if defenv['CHMDOCS']:
	defenv.SConscript(
		dirs = 'Docs/src',
		build_dir = '$BUILD_PREFIX/Docs/chm',
		duplicate = False,
		exports = {'halibut' : halibut, 'env' : defenv.Copy(), 'build_chm' : True}
	)
else:
	defenv.SConscript(
		dirs = 'Docs/src',
		build_dir = '$BUILD_PREFIX/Docs/html',
		duplicate = False,
		exports = {'halibut' : halibut, 'env' : defenv.Copy(), 'build_chm' : False}
	)

######################################################################
#######  Examples                                                  ###
######################################################################

defenv.SConscript(
	dirs = 'Examples',
	exports = {'env': defenv.Copy()}
)

######################################################################
#######  Includes                                                  ###
######################################################################

defenv.SConscript(
	dirs = 'Include',
	exports = {'env': defenv.Copy()}
)

######################################################################
#######  Miscellaneous                                             ###
######################################################################

for i in misc:
	if i in defenv['SKIPMISC']:
		continue

	defenv.SConscript(dirs = 'Contrib/%s' % i)

######################################################################
#######  Tests                                                     ###
######################################################################

# test code

build_dir = '$BUILD_PREFIX/tests'
exports = {'env' : test_env.Copy()}

defenv.SConscript(
	dirs = 'Source/Tests',
	duplicate = False,
	exports = exports,
	build_dir = build_dir
)

defenv.Ignore('$BUILD_PREFIX', '$BUILD_PREFIX/tests')

# test scripts

test_scripts_env = defenv.Copy(ENV = os.environ) # env needed for some scripts
test_scripts_env['ENV']['NSISDIR'] = os.path.abspath(str(defenv['TESTDISTDIR']))
test_scripts_env['ENV']['NSISCONFDIR'] = os.path.abspath(str(defenv['TESTDISTDIR']))

def test_scripts(target, source, env):
	from os import walk, sep

	instdir = source[0].path

	makensis = instdir + sep + 'makensis'

	for root, dirs, files in walk(instdir):
		for file in files:
			if file[-4:] == '.nsi':
				nsi = root + sep + file
				cmd = env.Command(None, nsi, '%s $SOURCE' % makensis)
				AlwaysBuild(cmd)
				env.Alias('test-scripts', cmd)

	return None

test = test_scripts_env.Command('test-scripts.log', '$TESTDISTDIR', test_scripts)
test_scripts_env.Alias('test-scripts', test)

# test all

defenv.Alias('test', ['test-code', 'test-scripts'])