comparison SConstruct @ 0:4a0efb7baf70

* Datasets becomes the new trunk and retires after that :-)
author mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
date Sun, 29 Jun 2008 18:44:17 +0000
parents
children d2f1e81fbe2c
comparison
equal deleted inserted replaced
-1:000000000000 0:4a0efb7baf70
1 import os, sys
2 from utils.util_scripts.path import path as upath
3
4 opts = Options('options.py', ARGUMENTS)
5 opts.Add(BoolOption('debug', 'Build with debuginfos and without optimisations', 1))
6 opts.Add(BoolOption('tests', 'Build testcases in unit_tests', 0))
7 opts.Add(BoolOption('noengine', 'Prevents building of engine, use e.g. for util/test tweaking', 0))
8 opts.Add(BoolOption('opengl', 'Compile OpenGL support', 1))
9 opts.Add(EnumOption('script', 'Selects generated scripting language bindings', 'python', allowed_values=('python', 'lua')))
10 opts.Add(BoolOption('profile', 'Build with profiling information', 0))
11 opts.Add(BoolOption('projectfiles_only', "Creates IDE project files only. If defined, won't build code. " +
12 "Note that normal builds generate these files also automatically.", 0))
13 opts.Add(BoolOption('utils', 'Build utilities', 0))
14 opts.Add(BoolOption('ext', 'Build external dependencies', 0))
15 opts.Add(BoolOption('docs', "Generates static analysis documentation into doc-folder. If defined, won't build code", 0))
16 opts.Add(BoolOption('zip', 'Enable ZIP archive support', 1))
17 opts.Add(BoolOption('log', 'Enables logging for the engine', 1))
18
19 opts.Add(BoolOption('rend_camzone', 'Enables camera zone renderer', 0))
20 opts.Add(BoolOption('rend_grid', 'Enables grid renderer', 0))
21
22 # Platform-specific prefix directories
23 if sys.platform == 'linux2':
24 opts.Add(PathOption('PREFIX', 'Directory to install under', '/usr'))
25
26 env = Environment(options = opts, ENV = {'PATH' : os.environ['PATH']})
27 env.Replace(SCONS_ROOT_PATH=str(upath('.').abspath()))
28 rootp = env['SCONS_ROOT_PATH']
29
30 Help(opts.GenerateHelpText(env))
31
32 # helper functions
33 def tryConfigCommand(context, cmd):
34 ret = context.TryAction(cmd)[0]
35 context.Result(ret)
36 if ret:
37 context.env.ParseConfig(cmd)
38 return ret
39
40 def importConfig(config):
41 module = __import__(config)
42 parts = config.split('.')
43 for part in parts[1:]:
44 module = getattr(module, part)
45 return module
46
47 def getPlatformConfig():
48 pathparts = ('build', '%s-config' % sys.platform)
49 filename = os.path.join(*pathparts)
50 sconsfilename = '.'.join(pathparts)
51 if os.path.exists(filename + '.py'):
52 return importConfig(sconsfilename)
53 else:
54 print 'no custom platform-config found (searched: %s.py)' % filename
55 filename += '-dist'
56 sconsfilename += '-dist'
57 if os.path.exists(filename + '.py'):
58 return importConfig(sconsfilename)
59 print 'no platform-config found (searched: %s.py)' % filename
60 Exit(1)
61
62 # custom checks
63 def checkPKG(context, name):
64 context.Message('Checking for %s (using pkg-config)... ' % name)
65 return tryConfigCommand(context, 'pkg-config --libs --cflags \'%s\'' % name)
66
67 def checkConf(context, name):
68 binary = '%s-config' % name.lower()
69 context.Message('Checking for %s (using %s)... ' % (name, binary))
70 configcall = '%s --libs --cflags' %binary
71 return tryConfigCommand(context, configcall)
72
73 def checkSimpleLib(context, liblist, header = '', lang = 'c', required = 1):
74 for lib in liblist:
75 ret = checkPKG(context, lib)
76 if ret:
77 return ret
78
79 ret = checkConf(context, lib)
80 if ret:
81 return ret
82
83 if len(header):
84 ret = conf.CheckLibWithHeader(lib, header, lang)
85 else:
86 ret = conf.CheckLib(lib)
87
88 if ret:
89 # print "ret: " + ret
90 if not lib in conf.env['LIBS']:
91 conf.env.Append(LIBS = [lib])
92 return ret
93
94 if required:
95 print 'required lib %s not found :(' % lib
96 Exit(1)
97
98 return False
99
100 if env['projectfiles_only']:
101 Export('env')
102 SConscript(['engine/SConscript'])
103 elif env['docs']:
104 _jp = os.path.join
105 # should prolly be done using scons builders...
106 try:
107 print "removing old documentation directories"
108 upath('doc/doxygen/html').rmtree()
109 except OSError:
110 pass
111 print "generating new doxygen documentation"
112 os.system('doxygen ' + _jp('doc', 'doxygen', 'doxyfile'))
113 print "doxygen documentation created succesfully"
114
115 elif env['ext']:
116 Export('env')
117 SConscript('ext/SConscript')
118 else:
119 platformConfig = getPlatformConfig()
120 env = platformConfig.initEnvironment(env)
121 conf = Configure(env,
122 custom_tests = {'checkConf': checkConf, 'checkPKG': checkPKG, 'checkSimpleLib': checkSimpleLib},
123 conf_dir = '#/build/.sconf_temp',
124 log_file = '#/build/config.log')
125
126 platformConfig.addExtras(conf)
127 env = conf.Finish()
128
129 if sys.platform == "win32":
130 env.Append(CPPFLAGS = ['-Wall'])
131 else:
132 env.Append(CPPFLAGS = ['-Wall']) # removed old style cast warnings for now (swig creates these)
133
134 if env['debug'] == 1:
135 env.Append(CPPFLAGS = ['-ggdb', '-O0'])
136 else:
137 if os.getenv('CXXFLAGS'):
138 env.Append(CPPFLAGS = Split(os.environ['CXXFLAGS']))
139 else:
140 env.Append(CPPFLAGS = ['-O2'])
141
142 if env['profile']:
143 env.Append(CPPFLAGS = ['-pg'])
144 env.Append(LINKFLAGS = ['-pg'])
145
146 definemap = {
147 'opengl': 'HAVE_OPENGL',
148 'zip': 'HAVE_ZIP',
149 'log': 'LOG_ENABLED',
150 'rend_camzone': 'RENDER_CAMZONES',
151 'rend_grid': 'RENDER_GRID',
152 }
153 for k, v in definemap.items():
154 if env[k]:
155 env.Append(CPPDEFINES = [v])
156
157 Export('env')
158
159 if not env['noengine']:
160 SConscript('engine/SConscript')
161
162 env.Append(LIBPATH = ['#/engine'])
163
164 if env['tests']:
165 SConscript('tests/core_tests/SConscript')
166
167 if env['utils']:
168 SConscript([str(p) for p in upath('utils').walkfiles('SConscript')])
169
170 # vim: set filetype=python: