Debian Codegraph @

SConstruct

raw
1 import platform; print("Using Python " + platform.python_version())
2 EnsureSConsVersion(1,2)
3 EnsurePythonVersion(2,7)
4
5 stubs = [
6 'bzip2',
7 'lzma',
8 'zlib'
9 ]
10
11 plugin_libs = [
12 'ExDLL'
13 ]
14
15 plugins = [
16 'AdvSplash',
17 'Banner',
18 'BgImage',
19 'Dialer',
20 'InstallOptions',
21 'LangDLL',
22 'Library/TypeLib',
23 'Math',
24 'nsDialogs',
25 'nsExec',
26 'NSISdl',
27 'Splash',
28 'StartMenu',
29 'System',
30 'UserInfo',
31 'VPatch/Source/Plugin',
32 ]
33
34 utils = [
35 'Library/RegTool',
36 'MakeLangId',
37 'Makensisw',
38 'NSIS Menu',
39 'UIs',
40 'SubStart',
41 'VPatch/Source/GenPat',
42 'zip2exe'
43 ]
44
45 misc = [
46 'Graphics',
47 'Language files',
48 'MultiUser',
49 'Modern UI',
50 'Modern UI 2',
51 'VPatch'
52 ]
53
54 doc = [
55 'COPYING'
56 ]
57
58 doctypes = [
59 'chm',
60 'html',
61 'htmlsingle',
62 'web',
63 ]
64
65 ######################################################################
66 ####### Build Environment ###
67 ######################################################################
68
69 import os
70 path = ARGUMENTS.get('PATH', '')
71 toolset = ARGUMENTS.get('TOOLSET', '')
72
73 defenv = {
74 'TARGET_ARCH': ARGUMENTS.get('TARGET_ARCH', 'x86'),
75 'ENV': {}
76 }
77
78 if path: defenv['ENV']['PATH'] = path
79 if toolset: defenv['TOOLS'] = toolset.split(',') + ['zip']
80
81 if len(defenv['ENV']) == 0: del defenv['ENV']
82 defenv = Environment(**defenv)
83 Export('defenv')
84
85 ######################################################################
86 ####### Includes ###
87 ######################################################################
88
89 SConscript('SCons/utils.py')
90 Import('GetOptionOrEnv')
91
92 ######################################################################
93 ####### Options ###
94 ######################################################################
95
96 default_doctype = 'html'
97 if defenv.WhereIs('hhc', os.environ['PATH']):
98 default_doctype = 'chm'
99
100 import time
101 cvs_version = time.strftime('%d-%b-%Y.cvs', time.gmtime(int(os.environ.get('SOURCE_DATE_EPOCH', time.time()))))
102
103 opts = Variables()
104
105 # load configuration options
106 # it's important this will be done here so NSIS_CONFIG_CONST_DATA_PATH
107 # will be available for the next few lines and so `dirs` can be set
108 SConscript('SCons/config.py')
109
110 opts.Update(defenv)
111 Help(opts.GenerateHelpText(defenv))
112
113 #Fix ListVariable to generate comma separated (quoted if required) list of allowed names:
114 org_ListVariable = ListVariable
115 def ListVariable(key, help, default, names, map={}):
116 r = list(org_ListVariable(key, help, default, names, map))
117 if len(r) == 5 and isinstance(r[1], str):
118 fmt = 'allowed names: %s'
119 repl = fmt % ', '.join( ((' ' in s) and ('"%s"' % s) or s) for s in names )
120 r[1] = r[1].replace(fmt % ' '.join(names), repl)
121 return r
122
123
124 install_dirs = {
125 'relocatable': {
126 'dest': '',
127 'prefix': '',
128 'conf': '$PREFIX',
129 'bin': '$PREFIX',
130 'data': '$PREFIX',
131 'doc': '$PREFIX'
132 },
133 'static': {
134 'dest': '',
135 'prefix': '/usr/local',
136 'conf': '$PREFIX/etc',
137 'bin': '$PREFIX/bin',
138 'data': '$PREFIX/share/nsis',
139 'doc': '$PREFIX/share/doc/nsis'
140 }
141 }
142
143 if 'NSIS_CONFIG_CONST_DATA_PATH' in defenv['NSIS_CPPDEFINES']:
144 dirs = install_dirs['static']
145 else:
146 dirs = install_dirs['relocatable']
147
148 if defenv['PLATFORM'] == 'win32':
149 ignore_tests = 'none'
150 else:
151 ignore_tests = ','.join(Split("""
152 Examples/makensis.nsi"""))
153
154 # version
155 opts.Add(('VERSION', 'Version of NSIS', cvs_version))
156 opts.Add(('VER_MAJOR', 'Major version of NSIS (recommended for dist-installer)', None))
157 opts.Add(('VER_MINOR', 'Minor version of NSIS (recommended for dist-installer)', None))
158 opts.Add(('VER_REVISION', 'Revision of NSIS', None))
159 opts.Add(('VER_BUILD', 'Build version of NSIS', None))
160 opts.Add(('VER_PACKED', 'Packed version of NSIS in 0xMMmmmrrb format, used for feature detection in scripts (recommended if VER_MAJOR and VER_MINOR are not set)', None))
161 # installation
162 opts.Add(('PREFIX', 'Installation prefix', dirs['prefix']))
163 opts.Add(ListVariable('SKIPSTUBS', 'A list of stubs that will not be built', 'none', stubs))
164 opts.Add(ListVariable('SKIPPLUGINS', 'A list of plug-ins that will not be built', 'none', plugin_libs + plugins))
165 opts.Add(ListVariable('SKIPUTILS', 'A list of utilities that will not be built', 'NSIS Menu', utils))
166 opts.Add(ListVariable('SKIPMISC', 'A list of plug-ins that will not be built', 'none', misc))
167 opts.Add(ListVariable('SKIPDOC', 'A list of doc files that will not be built/installed', 'none', doc))
168 opts.Add(('SKIPTESTS', 'A comma-separated list of test files that will not be ran', 'none'))
169 opts.Add(('IGNORETESTS', 'A comma-separated list of test files that will be ran but ignored', ignore_tests))
170 # build tools
171 opts.Add(('PATH', 'A colon-separated list of system paths instead of the default - TEMPORARY AND MAY DEPRECATE', None))
172 opts.Add(('TOOLSET', 'A comma-separated list of specific tools used for building instead of the default', None))
173 opts.Add(BoolVariable('MSTOOLKIT', 'Use Microsoft Visual C++ Toolkit', 'no'))
174 opts.Add(EnumVariable('MSVS_VERSION', 'MS Visual C++ version', os.environ.get('MSVS_VERSION'), allowed_values=('6.0', '7.0', '7.1', '8.0', '8.0Exp', '9.0', '9.0Exp', '10.0', '10.0Exp')))
175 opts.Add(EnumVariable('TARGET_ARCH', 'Target processor architecture', 'x86', allowed_values=('x86', 'amd64', 'arm64')))
176 opts.Add(ListVariable('DOCTYPES', 'A list of document types that will be built', default_doctype, doctypes))
177 opts.Add(('CC', 'Override C compiler', None))
178 opts.Add(('CXX', 'Override C++ compiler', None))
179 opts.Add(PathVariable('APPEND_CPPPATH', 'Additional paths to search for include files', None))
180 opts.Add(PathVariable('APPEND_LIBPATH', 'Additional paths to search for libraries', None))
181 opts.Add(('APPEND_CCFLAGS', 'Additional C/C++ compiler flags'))
182 opts.Add(('APPEND_LINKFLAGS', 'Additional linker flags'))
183 opts.Add(PathVariable('WXWIN', 'Path to wxWindows library folder (e.g. C:\\Dev\\wxWidgets-2.8.10)', os.environ.get('WXWIN')))
184 opts.Add(PathVariable('ZLIB_W32', 'Path to Win32 zlib library folder (e.g. C:\\Dev\\zlib-1.2.3)', os.environ.get('ZLIB_W32')))
185 # build options
186 opts.Add(BoolVariable('UNICODE', 'Build the Unicode version of the compiler and tools', 'yes'))
187 opts.Add(BoolVariable('DEBUG', 'Build executables with debugging information', 'no'))
188 opts.Add(PathVariable('CODESIGNER', 'A program used to sign executables', None))
189 opts.Add(BoolVariable('STRIP', 'Strips executables of any unrequired data such as symbols', 'yes'))
190 opts.Add(BoolVariable('STRIP_CP', 'Strips cross-platform executables of any unrequired data such as symbols', 'yes'))
191 opts.Add(BoolVariable('STRIP_W32', 'Strips Win32 executables of any unrequired data such as symbols', 'yes'))
192 # path related build options
193 opts.Add(('PREFIX_DEST', 'Intermediate installation prefix (extra install time prefix)', dirs['dest']))
194 opts.Add(('PREFIX_CONF', 'Path to install nsisconf.nsh to', dirs['conf']))
195 opts.Add(('PREFIX_BIN', 'Path to install native binaries to', dirs['bin']))
196 opts.Add(('PREFIX_DATA', 'Path to install nsis data to (plugins, includes, stubs, contrib, win32 binaries)', dirs['data']))
197 opts.Add(('PREFIX_DOC','Path to install nsis README / INSTALL / TODO files to.', dirs['doc']))
198 opts.Add(('PREFIX_PLUGINAPI_INC','Path to install plugin API headers to.', None))
199 opts.Add(('PREFIX_PLUGINAPI_LIB','Path to install plugin static library to.', None))
200 # reproducible builds
201 opts.Add(('SOURCE_DATE_EPOCH', 'UNIX timestamp (in seconds)', os.environ.get('SOURCE_DATE_EPOCH')))
202
203 opts.Update(defenv)
204 Help(opts.GenerateHelpText(defenv))
205
206 if defenv['TARGET_ARCH'] != 'x86':
207 defenv['UNICODE'] = True
208
209 if defenv['DEBUG']:
210 defenv.Append(CPPDEFINES = ['DEBUG'])
211
212 # add prefixes defines
213 if 'NSIS_CONFIG_CONST_DATA_PATH' in defenv['NSIS_CPPDEFINES']:
214 defenv.Append(NSIS_CPPDEFINES = [('PREFIX_CONF', '"%s"' % defenv.subst('$PREFIX_CONF'))])
215 defenv.Append(NSIS_CPPDEFINES = [('PREFIX_DATA', '"%s"' % defenv.subst('$PREFIX_DATA'))])
216 defenv.Append(NSIS_CPPDEFINES = [('PREFIX_DOC', '"%s"' % defenv.subst('$PREFIX_DOC'))])
217
218 if defenv.get('SOURCE_DATE_EPOCH','') != '':
219 if defenv.get('SOURCE_DATE_EPOCH','').lower() == 'now':
220 import time
221 defenv['SOURCE_DATE_EPOCH'] = str(int(time.time()))
222 defenv['ENV']['SOURCE_DATE_EPOCH'] = defenv['SOURCE_DATE_EPOCH'] = int(defenv['SOURCE_DATE_EPOCH'], 0) # Normalize and apply to ENV for child processes
223 defenv.Append(NSIS_CPPDEFINES = [('NSIS_SOURCE_DATE_EPOCH', '%s' % defenv['SOURCE_DATE_EPOCH'])]) # Display in /HDRINFO
224
225 # Need this early for the config header files to be placed in
226 if defenv['UNICODE']:
227 if defenv['DEBUG']:
228 defenv.Replace(BUILD_PREFIX = 'build/udebug')
229 else:
230 defenv.Replace(BUILD_PREFIX = 'build/urelease')
231 else:
232 if defenv['DEBUG']:
233 defenv.Replace(BUILD_PREFIX = 'build/debug')
234 else:
235 defenv.Replace(BUILD_PREFIX = 'build/release')
236
237 defenv.Replace(BUILD_CONFIG = defenv.subst('$BUILD_PREFIX/config'))
238
239 # ensure the config directory exists
240 if not Dir(defenv.Dir('#$BUILD_CONFIG')).exists():
241 defenv.Execute(Mkdir(defenv.Dir('#$BUILD_CONFIG')))
242
243 # write configuration into sconf.h and defines.h
244 sconf_h = open(defenv.File('#$BUILD_CONFIG/nsis-sconf.h').abspath, 'w')
245 sconf_h.write('// This file is automatically generated by SCons\n// DO NOT EDIT THIS FILE\n')
246
247 defines_h = open(defenv.File('#$BUILD_CONFIG/nsis-defines.h').abspath, 'w')
248 defines_h.write('// This file is automatically generated by SCons\n// DO NOT EDIT THIS FILE\n')
249
250 for i in defenv['NSIS_CPPDEFINES']:
251 if type(i) is not str:
252 sconf_h.write('#define %s %s\n' % (i[0], i[1]))
253 if str(i[1])[0] != '"':
254 defines_h.write('definedlist.add(_T("%s"), _T("%s"));\n' % (i[0], i[1]))
255 else:
256 defines_h.write('definedlist.add(_T("%s"), _T(%s));\n' % (i[0], i[1]))
257 else:
258 sconf_h.write('#define %s\n' % (i))
259 defines_h.write('definedlist.add(_T("%s"));\n' % (i))
260 sconf_h.close()
261 defines_h.close()
262
263 # write version into version.h
264 f = open(defenv.File('#$BUILD_CONFIG/nsis-version.h').abspath, 'w')
265 f.write('// This file is automatically generated by SCons\n// DO NOT EDIT THIS FILE\n')
266 f.write('#include "%s"\n' % File('#/Source/tchar.h').abspath)
267
268 if (not 'VER_PACKED' in defenv) and 'VER_MAJOR' in defenv and 'VER_MINOR' in defenv:
269 packed_r = int(defenv.get('VER_REVISION','0'))
270 packed_b = int(defenv.get('VER_BUILD','0'))
271 defenv['VER_PACKED'] = '0x%0.2i%0.3i%0.2i%0.1i' % (int(defenv['VER_MAJOR']), int(defenv['VER_MINOR']), packed_r, packed_b)
272 if not 'VER_PACKED' in defenv:
273 import re
274 found = None
275 for v in re.compile(r'^\\H\{[v]?(\S+)\}', re.M).finditer(File('#/Docs/src/history.but').get_contents().decode()): # Try to parse the Halibut history file
276 if v and not found:
277 v = v.group(1).split('.')
278 if len(v) >= 2:
279 mi = int(re.search(r'\d+', v[1]).group())
280 if mi < 1: mi = 1 # Make sure we can subtract 1 from the minor number so trunk stays below the next release
281 defenv['VER_PACKED'] = '0x%0.2i%0.3i%0.2i%0.1i' % (int(re.search(r'\d+', v[0]).group()), mi - 1, 66, 6)
282 if int(defenv['VER_PACKED'], 0) >= int('0x03000000', 0):
283 found = v
284 if not found:
285 defenv['VER_PACKED'] = '0x%0.2i%0.3i%0.2i%0.1i' % (3, 3, 42, 0) # Default to a version number we never used
286 print('WARNING: VER_PACKED not set, defaulting to %s!' % defenv['VER_PACKED'])
287 if int(defenv['VER_PACKED'], 0) < int('0x03000000', 0) or int(defenv['VER_PACKED'], 0) >= int('0x04000000', 0):
288 print('ERROR: Invalid VER_PACKED value!')
289 Exit(1)
290 f.write('#define NSIS_PACKEDVERSION _T("%s")\n' % defenv['VER_PACKED'])
291
292 if defenv.get('VERSION','') == '' and 'VER_MAJOR' in defenv:
293 defenv['VERSION'] = defenv['VER_MAJOR']
294 if 'VER_MINOR' in defenv:
295 defenv['VERSION'] += '.' + defenv['VER_MINOR']
296 if 'VER_REVISION' in defenv:
297 defenv['VERSION'] += '.' + defenv['VER_REVISION']
298 if defenv.get('VERSION','') == '' and int(defenv['VER_PACKED'], 0) > int('0x02000000', 0):
299 defenv['VERSION'] = '%i.%i.%i' % (int(defenv['VER_PACKED'][2:][:2]), int(defenv['VER_PACKED'][4:][:3]), int(defenv['VER_PACKED'][7:][:2]))
300 print('WARNING: VERSION not set, defaulting to %s!' % defenv['VERSION'])
301 f.write('#define NSIS_VERSION _T("v%s")\n' % defenv['VERSION'])
302
303 f.close()
304
305 ######################################################################
306 ####### Common Functions ###
307 ######################################################################
308
309 def GetArcCPU(env):
310 if (not 'TARGET_ARCH' in env) or env['TARGET_ARCH'] == 'x86':
311 return 'x86'
312 return env['TARGET_ARCH']
313
314 def GetArcSuffix(env, unicode = None):
315 if unicode is None:
316 unicode = 'UNICODE' in env['CPPDEFINES']
317 suff = '-unicode'
318 if not unicode:
319 suff = '-ansi'
320 return GetArcCPU(env) + suff
321
322 def GetTargetMinOSVersion(env):
323 if GetArcCPU(defenv) == 'arm64':
324 return (6, 4)
325 if not GetArcCPU(defenv) == 'x86':
326 return (5, 1)
327 return (4, 0)
328
329
330 def SafeFile(f):
331 from types import StringType
332
333 if isinstance(f, StringType):
334 return File(f)
335
336 return f
337
338 def MakeFileList(files):
339 return Flatten(File(files))
340
341 def AddEnvStandardFlags(env, defines=None, flags=None, libs=None, entry=None, nodeflib=None):
342 if defines:
343 env.Append(CPPDEFINES = defines)
344 if flags:
345 env.Append(CCFLAGS = flags)
346 if libs:
347 env.Append(LIBS = libs)
348
349 if entry:
350 unicodestr = "None"
351 if 'UNICODE' in env['CPPDEFINES']:
352 unicodestr = "True"
353 env.Append(LINKFLAGS = ['${ENTRY_FLAG("%s",%s)}' % (entry,unicodestr)])
354
355 if nodeflib:
356 env.Append(LINKFLAGS = ['$NODEFLIBS_FLAG']) # no default libraries
357
358 def AppendRES(env, source, res, resources):
359 if res:
360 target = MakeFileList(res)[0].name.replace('.rc', '-rc')
361 target_res = env.RES(target, res)
362 if resources:
363 env.Depends(target_res, resources)
364 source.append(target_res)
365
366 def CleanMap(env, target, target_name):
367 env.Clean(target, File(target_name + '.map'))
368
369
370 ######################################################################
371 ####### Functions ###
372 ######################################################################
373
374 defenv['ZIPDISTDIR'] = defenv.Dir('#nsis-$VERSION')
375 defenv['INSTDISTDIR'] = defenv.Dir('#.instdist')
376 defenv['TESTDISTDIR'] = defenv.Dir('#.test')
377 defenv['DISTSUFFIX'] = ''
378
379 if GetArcCPU(defenv) != 'x86':
380 defenv['DISTSUFFIX'] += GetArcCPU(defenv)
381 if 'CODESIGNER' in defenv:
382 defenv['DISTSUFFIX'] += '-signed'
383
384 defenv.Execute(Delete('$ZIPDISTDIR'))
385 defenv.Execute(Delete('$INSTDISTDIR'))
386 defenv.Execute(Delete('$TESTDISTDIR'))
387
388 def Distribute(files, names, component, path, subpath, alias, install_alias=None):
389 files = MakeFileList(files)
390
391 names = names or list(map(lambda x: x.name, files))
392 if isinstance(names, str):
393 names = [names]
394
395 for d in ('$ZIPDISTDIR', '$INSTDISTDIR', '$TESTDISTDIR'):
396 paths = list(map(lambda file: os.path.join(d, path, subpath, file), names))
397 defenv.InstallAs(paths, files)
398
399 if ('PREFIX' in defenv and defenv['PREFIX']) or ('PREFIX_DEST' in defenv and defenv['PREFIX_DEST']) :
400 prefix = '${PREFIX_DEST}${PREFIX_%s}' % component.upper()
401 paths = list(map(lambda file: os.path.join(prefix, path, subpath, file), names))
402 ins = defenv.InstallAs(paths, files)
403 else:
404 ins = []
405
406 if ins:
407 defenv.Alias('install', ins)
408 defenv.Alias('install-%s' % component, ins)
409 if alias:
410 defenv.Alias(alias, ins)
411 if install_alias:
412 defenv.Alias('install-%s' % install_alias, ins)
413
414 return ins
415
416 def DistributeBin(files, names=[], path='', alias=None):
417 return defenv.Distribute(files, names, 'bin', '', path, alias)
418
419 def DistributeConf(files, names=[], path='', alias=None):
420 return defenv.Distribute(files, names, 'conf', '', path, alias)
421
422 def DistributeW32Bin(files, names=[], path='', alias=None):
423 return defenv.Distribute(files, names, 'data', 'Bin', path, alias, 'w32bin')
424
425 def DistributeStubs(files, names=[], path='', alias=None):
426 return defenv.Distribute(files, names, 'data', 'Stubs', path, alias, 'stubs')
427
428 def DistributePlugin(files, names=[], arcsubpath='', alias=None):
429 return defenv.Distribute(files, names, 'data', 'Plugins', arcsubpath, alias, 'plugins')
430
431 def DistributeContrib(files, names=[], path='', alias=None):
432 return defenv.Distribute(files, names, 'data', 'Contrib', path, alias, 'contrib')
433
434 def DistributeMenu(files, names=[], path='', alias=None):
435 return defenv.Distribute(files, names, 'data', 'Menu', path, alias, 'menu')
436
437 def DistributeInclude(files, names=[], path='', alias=None):
438 return defenv.Distribute(files, names, 'data', 'Include', path, alias, 'includes')
439
440 def DistributeDoc(files, names=[], path='', alias=None, basepath='', install_alias='docs'):
441 return defenv.Distribute(files, names, 'doc', path=basepath, subpath=path, alias=alias, install_alias=install_alias)
442
443 def DistributeDocs(files, names=[], path='', alias=None, basepath='Docs', install_alias='docs'):
444 return defenv.Distribute(files, names, 'doc', path=basepath, subpath=path, alias=alias, install_alias=install_alias)
445
446 def DistributeExamples(files, names=[], path='', alias=None):
447 return defenv.Distribute(files, names, 'doc', 'Examples', path, alias, 'examples')
448
449 def FindMakeNSIS(env, path):
450 exename = 'makensis_not_found'
451 file = env.FindFile('makensis$PROGSUFFIX',
452 [os.path.join(path, '.'), os.path.join(path, 'Bin')])
453 if file:
454 exename = str(file)
455 return exename
456
457 def Sign(targets):
458 if 'CODESIGNER' in defenv:
459 for t in targets:
460 a = defenv.Action('$CODESIGNER "%s"' % t.path)
461 defenv.AddPostAction(t, a)
462
463 Import('SilentActionEcho IsPEExecutable SetPESecurityFlagsWorker SetPEMinOS MakeReproducibleAction')
464 def SetPESecurityFlagsAction(target, source, env):
465 for t in target:
466 SetPESecurityFlagsWorker(t.path)
467 g_pesecflagsecho = {}
468 def SetPESecurityFlagsActionEcho(target, source, env):
469 for t in target:
470 if t.name[-4:].lower() == '.dll' and IsPEExecutable(t.path) and not t.path in g_pesecflagsecho:
471 g_pesecflagsecho[t.path] = 1
472 print('Setting PE flags on %s' % t.name)
473 def SetPESecurityFlags(targets):
474 for t in targets:
475 a = defenv.Action(SetPESecurityFlagsAction, strfunction=SetPESecurityFlagsActionEcho)
476 defenv.AddPostAction(t, a)
477
478 def SetTargetPEMinOS(target, source=None, env=None):
479 for t in target:
480 if source is None:
481 defenv.AddPostAction(t, defenv.Action(SetTargetPEMinOS, strfunction=SilentActionEcho))
482 else:
483 ver = GetTargetMinOSVersion(env)
484 SetPEMinOS(t.path, ver[0], ver[1], ver[0], ver[1])
485
486 def MakeReproducible(targets):
487 for t in targets:
488 defenv.AddPostAction(t, defenv.Action(MakeReproducibleAction, strfunction=SilentActionEcho))
489
490 def TestScript(scripts):
491 defenv.Install('$TESTDISTDIR/Tests', scripts)
492
493 defenv.Distribute = Distribute
494 defenv.DistributeBin = DistributeBin
495 defenv.DistributeConf = DistributeConf
496 defenv.DistributeW32Bin = DistributeW32Bin
497 defenv.DistributeStubs = DistributeStubs
498 defenv.DistributePlugin = DistributePlugin
499 defenv.DistributeContrib = DistributeContrib
500 defenv.DistributeMenu = DistributeMenu
501 defenv.DistributeInclude = DistributeInclude
502 defenv.DistributeDoc = DistributeDoc
503 defenv.DistributeDocs = DistributeDocs
504 defenv.DistributeExamples = DistributeExamples
505 defenv.Sign = Sign
506 defenv.SetPESecurityFlags = SetPESecurityFlags
507 defenv.SetTargetPEMinOS = SetTargetPEMinOS
508 defenv.MakeReproducible = MakeReproducible
509 defenv.TestScript = TestScript
510
511 def DistributeExtras(env, target, examples, docs):
512 if examples:
513 env.DistributeExamples(examples, path=target)
514 if docs:
515 env.DistributeDocs(docs, path=target)
516
517 ######################################################################
518 ####### Environments ###
519 ######################################################################
520
521 if defenv['MSTOOLKIT']:
522 if GetOptionOrEnv('MSVC_USE_SCRIPT', '!') != '!':
523 defenv['MSVC_USE_SCRIPT'] = GetOptionOrEnv('MSVC_USE_SCRIPT')
524 defenv.Tool('mstoolkit', toolpath = [Dir('SCons/Tools').rdir()])
525
526 defenv.Append(CCFLAGS = Split('$APPEND_CCFLAGS'))
527 defenv.Append(LINKFLAGS = Split('$APPEND_LINKFLAGS'))
528 defenv.Append(CPPPATH = Split('$APPEND_CPPPATH'))
529 defenv.Append(LIBPATH = Split('$APPEND_LIBPATH'))
530
531 defenv.Default('$BUILD_PREFIX')
532
533 if 'ZLIB_W32' in defenv:
534 defenv['ZLIB_W32_INC'] = os.path.dirname(str(
535 defenv.FindFile('zlib.h',
536 [
537 defenv['ZLIB_W32'],
538 os.path.join(defenv['ZLIB_W32'], 'include')
539 ]
540 )
541 ))
542 # Search for import library of zlib for mingw or VisualC
543 for importlib in ['libzdll.a', 'libz.dll.a', 'zdll.lib']:
544 defenv['ZLIB_W32_LIB'] = os.path.dirname(str(
545 defenv.FindFile(importlib,
546 [
547 defenv['ZLIB_W32'],
548 os.path.join(defenv['ZLIB_W32'], 'lib')
549 ]
550 )
551 ))
552 if defenv['ZLIB_W32_LIB']:
553 break
554 defenv['ZLIB_W32_DLL'] = defenv.FindFile('zlib1.dll',
555 [defenv['ZLIB_W32'], defenv['ZLIB_W32_LIB']])
556 defenv['ZLIB_W32_NEW_DLL'] = defenv.FindFile('zlib.dll',
557 [defenv['ZLIB_W32'], defenv['ZLIB_W32_LIB']])
558
559 tools = defenv['TOOLS']
560
561 envs = []
562
563 if 'msvc' in tools or 'mstoolkit' in tools:
564 envs = SConscript('SCons/Config/ms')
565 elif 'gcc' in tools:
566 envs = SConscript('SCons/Config/gnu')
567 elif 'hpc++' in tools:
568 envs = SConscript('SCons/Config/hpc++')
569 else:
570 envs = SConscript('SCons/Config/default')
571
572 stub_env = envs[0]
573 makensis_env = envs[1]
574 plugin_env = envs[2]
575 util_env = envs[3]
576 cp_util_env = envs[4]
577 test_env = envs[5]
578 stub_uenv = envs[6]
579 plugin_uenv = envs[7]
580
581 Export('plugin_env plugin_uenv')
582
583 ######################################################################
584 ####### Distribution ###
585 ######################################################################
586
587 if defenv['PLATFORM'] == 'win32':
588 def build_nsis_menu_for_zip(target, source, env):
589 cmdline = FindMakeNSIS(env, str(env['ZIPDISTDIR']))
590 if Execute('''"{}" "{}" /X"OutFile '{}'" '''.format(cmdline, source[0].abspath, target[0].abspath)):
591 Exit(1)
592
593 nsis_menu_target = defenv.Command(
594 os.path.join('$ZIPDISTDIR', 'NSIS.exe'),
595 os.path.join('$ZIPDISTDIR', 'Examples', 'NSISMenu.nsi'),
596 build_nsis_menu_for_zip
597 )
598 defenv.Depends(nsis_menu_target, r'$ZIPDISTDIR\makensis.exe')
599 defenv.Depends(nsis_menu_target, r'$ZIPDISTDIR\Stubs')
600 defenv.Depends(nsis_menu_target, r'$ZIPDISTDIR\Plugins')
601 defenv.MakeReproducible(nsis_menu_target)
602 defenv.Sign(nsis_menu_target)
603
604 dist_zip = 'nsis-${VERSION}${DISTSUFFIX}.zip'
605 zip_target = defenv.Zip(dist_zip, '$ZIPDISTDIR')
606 defenv.Alias('dist-zip', zip_target)
607
608 AlwaysBuild(defenv.AddPostAction(zip_target, Delete('$ZIPDISTDIR')))
609
610 if defenv['PLATFORM'] == 'win32':
611 optchar = '/'
612 else:
613 optchar = '-'
614
615 defenv['INSTVER'] = '%sDVERSION=$VERSION' % optchar
616 if 'VER_MAJOR' in defenv and 'VER_MINOR' in defenv \
617 and 'VER_REVISION' in defenv and 'VER_BUILD' in defenv:
618 defenv['INSTVER'] += ' %sDVER_MAJOR=$VER_MAJOR' % optchar
619 defenv['INSTVER'] += ' %sDVER_MINOR=$VER_MINOR' % optchar
620 defenv['INSTVER'] += ' %sDVER_REVISION=$VER_REVISION' % optchar
621 defenv['INSTVER'] += ' %sDVER_BUILD=$VER_BUILD' % optchar
622
623 inst_env = {}
624 inst_env['NSISDIR'] = os.path.abspath(str(defenv['INSTDISTDIR']))
625 inst_env['NSISCONFDIR'] = os.path.abspath(str(defenv['INSTDISTDIR']))
626
627 def build_installer(target, source, env):
628 cmdline = FindMakeNSIS(env, str(env['INSTDISTDIR'])) + ' %sDOUTFILE=%s %s' % (optchar, target[0].abspath, env['INSTVER'])
629 if 'ZLIB_W32_NEW_DLL' in env and env['ZLIB_W32_NEW_DLL']:
630 cmdline += ' %sDUSE_NEW_ZLIB' % optchar
631 cmd = env.Command(None, source, cmdline + ' $SOURCE')
632 AlwaysBuild(cmd)
633 # Comment out the following if you want to see the installation directory
634 # after the build is finished.
635 #AlwaysBuild(env.AddPostAction(cmd, Delete('$INSTDISTDIR')))
636 env.Alias('dist-installer', cmd)
637
638 installer_target = defenv.Command('nsis-${VERSION}-setup${DISTSUFFIX}.exe',
639 os.path.join('$INSTDISTDIR', 'Examples', 'makensis.nsi'),
640 build_installer,
641 ENV = inst_env)
642 defenv.Depends(installer_target, '$INSTDISTDIR')
643 defenv.Sign(installer_target)
644 defenv.Alias('dist-installer', installer_target)
645
646 defenv.Alias('dist', ['dist-zip', 'dist-installer'])
647
648 ######################################################################
649 ####### Distribute Basics ###
650 ######################################################################
651
652 for d in doc:
653 if d in defenv['SKIPDOC']:
654 continue
655 defenv.DistributeDoc(d)
656
657 defenv.DistributeConf('nsisconf.nsh')
658
659 ######################################################################
660 ####### Stubs ###
661 ######################################################################
662
663 def BuildStub(compression, solid, unicode):
664
665 suffix = ''
666 if solid:
667 suffix = '_solid'
668 if unicode:
669 env = stub_uenv.Clone()
670 else:
671 env = stub_env.Clone()
672
673 suffix = suffix + '-' + GetArcSuffix(env, unicode)
674
675 AddEnvStandardFlags(env, entry='NSISWinMainNOCRT')
676
677 build_dir = '$BUILD_PREFIX/stub_%s%s' % (compression, suffix)
678
679 exports = { 'env' : env, 'compression' : compression, 'solid_compression' : solid }
680
681 target = defenv.SConscript(dirs = 'Source/exehead', variant_dir = build_dir, duplicate = False, exports = exports)
682 env.SideEffect('%s/stub_%s.map' % (build_dir, stub), target)
683
684 env.SetTargetPEMinOS(target)
685 env.MakeReproducible(target)
686 env.DistributeStubs(target, names=compression+suffix)
687
688 defenv.Alias(compression, target)
689 defenv.Alias('stubs', target)
690
691 for stub in stubs:
692 if stub in defenv['SKIPSTUBS']:
693 continue
694
695 if defenv['UNICODE']:
696 BuildStub(stub, False, True)
697 BuildStub(stub, True, True)
698
699 if GetArcCPU(defenv)=='x86':
700 BuildStub(stub, False, False)
701 BuildStub(stub, True, False)
702 # BUGBUG64: Should build x86 stubs on x64?
703
704 defenv.DistributeStubs('Source/exehead/uninst.ico',names='uninst')
705
706 ######################################################################
707 ####### makensis ###
708 ######################################################################
709
710 build_dir = '$BUILD_PREFIX/makensis'
711 exports = { 'env' : makensis_env }
712
713 makensis = defenv.SConscript(dirs = 'Source', variant_dir = build_dir, duplicate = False, exports = exports)
714
715 makensis_env.SideEffect('%s/makensis.map' % build_dir, makensis)
716
717 defenv.MakeReproducible(makensis)
718 defenv.Alias('makensis', makensis)
719
720 if defenv['PLATFORM'] == 'win32':
721 defenv.DistributeW32Bin(makensis, alias='install-compiler')
722 else:
723 defenv.DistributeBin(makensis, alias='install-compiler')
724
725 ######################################################################
726 ####### Plug-ins ###
727 ######################################################################
728
729 def PerformPluginExtrasDistOperationOnce(env, unicode):
730 #SCons does not like it if you install the same file multiple times
731 return GetArcCPU(defenv)==GetArcCPU(env) and (defenv['UNICODE']==unicode)
732
733 def BuildPluginWorker(target, source, libs, examples = None, docs = None,
734 entry = 'DllMain', res = None, resources = None,
735 defines = None, flags = None, nodeflib = True,
736 cppused = False, unicode = False):
737 basename = target
738 if unicode:
739 env = plugin_uenv.Clone()
740 else:
741 env = plugin_env.Clone()
742
743 if cppused and env['CPP_REQUIRES_STDLIB']:
744 nodeflib = False
745
746 AddEnvStandardFlags(env, defines, flags, libs, entry, nodeflib)
747
748 AppendRES(env, source, res, resources)
749
750 plugin = env.SharedLibrary(target, source)
751 defenv.Alias(target, plugin)
752 defenv.Alias('plugins', plugin)
753
754 defenv.SetTargetPEMinOS(plugin)
755 defenv.SetPESecurityFlags(plugin)
756 defenv.MakeReproducible(plugin)
757 defenv.Sign(plugin)
758
759 CleanMap(env, plugin, target)
760
761 for i in plugin:
762 if str(i)[-4:].lower() == '.dll':
763 plugin = i
764 break
765 env.DistributePlugin(plugin, arcsubpath = GetArcSuffix(env, unicode))
766
767 if PerformPluginExtrasDistOperationOnce(env, unicode): # only distribute extras once
768 DistributeExtras(env, basename, examples, docs)
769
770 def BuildPlugin(target, source, libs, examples = None, docs = None,
771 entry = 'DllMain', res = None, resources = None,
772 defines = None, flags = None, nodeflib = True,
773 cppused = False):
774 unicodetarget = 'UNICODE' in exports['env']['CPPDEFINES']
775 BuildPluginWorker(target, source, libs, examples, docs, entry, res, resources, defines, flags, nodeflib, cppused, unicodetarget)
776
777
778 for plugin in plugin_libs + plugins:
779 if plugin in defenv['SKIPPLUGINS']:
780 continue
781
782 srcpath = 'Contrib/' + plugin
783 build_dir = '$BUILD_PREFIX/' + plugin
784 pvariants = []
785 if GetArcCPU(defenv) == 'x86':
786 pvariants += [{'e':plugin_env.Clone()}]
787 if defenv['UNICODE']:
788 pvariants += [{'e':plugin_uenv.Clone()}]
789 for pvariant in pvariants:
790 exports = {
791 'env' : pvariant['e'],
792 'BuildPlugin' : BuildPlugin, 'GetArcSuffix' : GetArcSuffix,
793 'PerformPluginExtrasDistOperationOnce' : PerformPluginExtrasDistOperationOnce
794 }
795 vdir = build_dir + '/' + GetArcSuffix(pvariant['e'])
796 defenv.SConscript(dirs = srcpath, variant_dir = vdir, duplicate = False, exports = exports)
797
798
799
800 ######################################################################
801 ####### Utilities ###
802 ######################################################################
803
804 Import('AddZLib')
805
806 def BuildUtilEnv(defines = None, flags = None, libs = None,
807 entry = None, nodeflib = None,
808 cross_platform = False, cli = False):
809 if not cross_platform:
810 env = util_env.Clone()
811 platform = 'win32'
812 else:
813 env = cp_util_env.Clone()
814 platform = env['PLATFORM']
815
816 if libs and 'z' in libs:
817 libs.remove('z')
818 AddZLib(env, platform)
819
820 if platform == 'win32':
821 if cli:
822 env.Append(LINKFLAGS = env['SUBSYS_CON'])
823 else:
824 env.Append(LINKFLAGS = env['SUBSYS_WIN'])
825
826 AddEnvStandardFlags(env, defines, flags, libs, entry, nodeflib)
827
828 return env
829
830 def BuildUtil(target, source, libs, entry = None, res = None,
831 resources = None, defines = None, flags = None,
832 nodeflib = False, file_name = '', path='', contrib = False,
833 examples = None, docs = None, cross_platform = False,
834 root_util = False, cli = False, noinstall = False):
835 env = BuildUtilEnv(defines, flags, libs, entry, nodeflib, cross_platform, cli)
836
837 AppendRES(env, source, res, resources)
838
839 if file_name != '':
840 target = "%s/%s" % (target, file_name)
841
842 # make sure the environment suffix fits
843 if env['PROGSUFFIX'] not in target:
844 if '.' in target:
845 env['PROGSUFFIX'] = target[target.rindex('.'):]
846
847 util = env.Program(target, source)
848 defenv.Alias(target, util)
849 defenv.Alias('utils', util)
850
851 if (str(target)[:7]).lower() == 'RegTool'.lower():
852 defenv.SetTargetPEMinOS(util)
853 defenv.MakeReproducible(util)
854 defenv.Sign(util)
855
856 CleanMap(env, util, target)
857
858 if not noinstall:
859 if contrib:
860 ins = env.DistributeContrib(util, path=path, alias='install-utils')
861 elif cross_platform and not env['PLATFORM'] == 'win32' or root_util and env['PLATFORM'] == 'win32':
862 ins = env.DistributeBin(util, path=path, alias='install-utils')
863 else:
864 ins = env.DistributeW32Bin(util, path=path, alias='install-utils')
865
866 DistributeExtras(env, target, examples, docs)
867
868 return util
869
870 for util in utils:
871 if util in defenv['SKIPUTILS']:
872 continue
873
874 path = 'Contrib/' + util
875 build_dir = '$BUILD_PREFIX/' + util
876 exports = {'BuildUtil' : BuildUtil, 'BuildUtilEnv' : BuildUtilEnv, 'env' : util_env, 'GetArcCPU' : GetArcCPU}
877
878 defenv.SConscript(dirs = path, variant_dir = build_dir, duplicate = False, exports = exports)
879
880 ######################################################################
881 ####### Documentation ###
882 ######################################################################
883
884 halibut = defenv.SConscript(
885 dirs = 'Docs/src/bin/halibut',
886 variant_dir = '$BUILD_PREFIX/halibut',
887 duplicate = False,
888 exports = {'env' : defenv.Clone()}
889 )
890
891 for doctype in defenv['DOCTYPES']:
892
893 defenv.SConscript(
894 dirs = 'Docs/src',
895 variant_dir = '$BUILD_PREFIX/Docs/' + doctype,
896 duplicate = False,
897 exports = {'halibut' : halibut, 'env' : defenv.Clone(), 'build_doctype' : doctype}
898 )
899
900 ######################################################################
901 ####### Examples ###
902 ######################################################################
903
904 defenv.SConscript(
905 dirs = 'Examples',
906 exports = {'env': defenv.Clone()}
907 )
908
909 ######################################################################
910 ####### Includes ###
911 ######################################################################
912
913 defenv.SConscript(
914 dirs = 'Include',
915 exports = {'env': defenv.Clone()}
916 )
917
918 ######################################################################
919 ####### Miscellaneous ###
920 ######################################################################
921
922 for i in misc:
923 if i in defenv['SKIPMISC']:
924 continue
925
926 defenv.SConscript(dirs = 'Contrib/%s' % i)
927
928 ######################################################################
929 ####### Tests ###
930 ######################################################################
931
932 # test code
933
934 build_dir = '$BUILD_PREFIX/tests'
935 exports = {'env' : test_env.Clone()}
936
937 defenv.SConscript(
938 dirs = 'Source/Tests',
939 duplicate = False,
940 exports = exports,
941 variant_dir = build_dir
942 )
943
944 defenv.Ignore('$BUILD_PREFIX', '$BUILD_PREFIX/tests')
945
946 # test scripts
947
948 test_scripts_env = defenv.Clone(ENV = os.environ) # env needed for some scripts
949 test_scripts_env['ENV']['NSISDIR'] = os.path.abspath(str(defenv['TESTDISTDIR']))
950 test_scripts_env['ENV']['NSISCONFDIR'] = os.path.abspath(str(defenv['TESTDISTDIR']))
951 test_scripts_env.PrependENVPath('PATH', os.path.abspath(str(defenv['TESTDISTDIR'])))
952
953 def test_scripts(target, source, env):
954 from os import walk, sep
955
956 instdir = source[0].path
957
958 tdlen = len(env.subst('$TESTDISTDIR'))
959 skipped_tests = env['SKIPTESTS'].split(',')
960 ignored_tests = env['IGNORETESTS'].split(',')
961 skipped_tests += ['Examples' + sep + 'AppGen.nsi'] # Never test this, not a real installer
962
963 compiler = FindMakeNSIS(env, env.subst('$TESTDISTDIR'))
964
965 for root, dirs, files in walk(instdir):
966 for file in files:
967 if file[-4:] == '.nsi':
968 nsi = root + sep + file
969 nsif = nsi[tdlen + 1:]
970
971 if nsif in skipped_tests:
972 continue
973
974 if nsif in ignored_tests:
975 cmd = env.Command(None, nsi, '-' + compiler + ' $SOURCE')
976 else:
977 cmd = env.Command(None, nsi, compiler + ' $SOURCE')
978 AlwaysBuild(cmd)
979 env.Alias('test-scripts', cmd)
980
981 return None
982
983 test = test_scripts_env.Command('test-scripts.log', '$TESTDISTDIR', test_scripts)
984 test_scripts_env.Alias('test-scripts', test)
985
986 # test all
987
988 defenv.Alias('test', ['test-code', 'test-scripts'])