SConscript (4381:d1e914d47111) SConscript (4382:b35e75e1b890)
1# -*- mode:python -*-
2
3# Copyright (c) 2004-2005 The Regents of The University of Michigan
4# All rights reserved.
5#
6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions are
8# met: redistributions of source code must retain the above copyright

--- 16 unchanged lines hidden (view full) ---

25# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28#
29# Authors: Steve Reinhardt
30
31import os
32import sys
1# -*- mode:python -*-
2
3# Copyright (c) 2004-2005 The Regents of The University of Michigan
4# All rights reserved.
5#
6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions are
8# met: redistributions of source code must retain the above copyright

--- 16 unchanged lines hidden (view full) ---

25# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28#
29# Authors: Steve Reinhardt
30
31import os
32import sys
33import zipfile
33
34
35from os.path import basename
34from os.path import join as joinpath
35
36import SCons
37
38# This file defines how to build a particular configuration of M5
39# based on variable settings in the 'env' build environment.
40
41Import('*')
42
36from os.path import join as joinpath
37
38import SCons
39
40# This file defines how to build a particular configuration of M5
41# based on variable settings in the 'env' build environment.
42
43Import('*')
44
45# Children need to see the environment
46Export('env')
47
48########################################################################
49# Code for adding source files
50#
43sources = []
44def Source(source):
45 if isinstance(source, SCons.Node.FS.File):
46 sources.append(source)
47 else:
48 sources.append(File(source))
49
51sources = []
52def Source(source):
53 if isinstance(source, SCons.Node.FS.File):
54 sources.append(source)
55 else:
56 sources.append(File(source))
57
50Export('env')
58# Children should have access
51Export('Source')
52
59Export('Source')
60
61########################################################################
62# Code for adding python objects
63#
64py_sources = []
65py_source_packages = {}
66def PySource(package, source):
67 if not isinstance(source, SCons.Node.FS.File):
68 source = File(source)
69 py_source_packages[source] = package
70 py_sources.append(source)
71
72sim_objects = []
73def SimObject(source):
74 if not isinstance(source, SCons.Node.FS.File):
75 source = File(source)
76 PySource('m5.objects', source)
77 modname = basename(str(source))
78 sim_objects.append(modname)
79
80swig_sources = []
81swig_source_packages = {}
82def SwigSource(package, source):
83 if not isinstance(source, SCons.Node.FS.File):
84 source = File(source)
85 swig_source_packages[source] = package
86 swig_sources.append(source)
87
88# Children should have access
89Export('PySource')
90Export('SimObject')
91Export('SwigSource')
92
93########################################################################
94#
95# Set some compiler variables
96#
97
53# Include file paths are rooted in this directory. SCons will
54# automatically expand '.' to refer to both the source directory and
55# the corresponding build directory to pick up generated include
56# files.
57env.Append(CPPPATH=Dir('.'))
58
59# Add a flag defining what THE_ISA should be for all compilation
60env.Append(CPPDEFINES=[('THE_ISA','%s_ISA' % env['TARGET_ISA'].upper())])
61
98# Include file paths are rooted in this directory. SCons will
99# automatically expand '.' to refer to both the source directory and
100# the corresponding build directory to pick up generated include
101# files.
102env.Append(CPPPATH=Dir('.'))
103
104# Add a flag defining what THE_ISA should be for all compilation
105env.Append(CPPDEFINES=[('THE_ISA','%s_ISA' % env['TARGET_ISA'].upper())])
106
107########################################################################
62# Walk the tree and execute all SConscripts
108# Walk the tree and execute all SConscripts
109#
63scripts = []
64srcdir = env['SRCDIR']
65for root, dirs, files in os.walk(srcdir, topdown=True):
66 if root == srcdir:
67 # we don't want to recurse back into this SConscript
68 continue
69
70 if 'SConscript' in files:
71 # strip off the srcdir part since scons will try to find the
72 # script in the build directory
73 base = root[len(srcdir) + 1:]
74 SConscript(joinpath(base, 'SConscript'))
75
76for opt in env.ExportOptions:
77 env.ConfigFile(opt)
78
110scripts = []
111srcdir = env['SRCDIR']
112for root, dirs, files in os.walk(srcdir, topdown=True):
113 if root == srcdir:
114 # we don't want to recurse back into this SConscript
115 continue
116
117 if 'SConscript' in files:
118 # strip off the srcdir part since scons will try to find the
119 # script in the build directory
120 base = root[len(srcdir) + 1:]
121 SConscript(joinpath(base, 'SConscript'))
122
123for opt in env.ExportOptions:
124 env.ConfigFile(opt)
125
126########################################################################
127#
128# Deal with python/swig, object code. Collect .py files and
129# generating a zip archive that is appended to the m5 binary.
130#
131
132# Generate Python file that contains a dict specifying the current
133# build_env flags.
134def MakeDefinesPyFile(target, source, env):
135 f = file(str(target[0]), 'w')
136 print >>f, "m5_build_env = ", source[0]
137 f.close()
138
139optionDict = dict([(opt, env[opt]) for opt in env.ExportOptions])
140env.Command('python/m5/defines.py', Value(optionDict), MakeDefinesPyFile)
141PySource('m5', 'python/m5/defines.py')
142
143def MakeInfoPyFile(target, source, env):
144 f = file(str(target[0]), 'w')
145 for src in source:
146 data = ''.join(file(src.srcnode().abspath, 'r').xreadlines())
147 print >>f, "%s = %s" % (src, repr(data))
148 f.close()
149
150env.Command('python/m5/info.py',
151 [ '#/AUTHORS', '#/LICENSE', '#/README', '#/RELEASE_NOTES' ],
152 MakeInfoPyFile)
153PySource('m5', 'python/m5/info.py')
154
155def MakeObjectsInitFile(target, source, env):
156 f = file(str(target[0]), 'w')
157 print >>f, 'from m5.SimObject import *'
158 for src_path in source:
159 src_file = basename(src_path.get_contents())
160 assert(src_file.endswith('.py'))
161 src_module = src_file[:-3]
162 print >>f, 'from %s import *' % src_module
163 f.close()
164
165env.Command('python/m5/objects/__init__.py',
166 [ Value(o) for o in sim_objects],
167 MakeObjectsInitFile)
168PySource('m5.objects', 'python/m5/objects/__init__.py')
169
170swig_modules = []
171for source in swig_sources:
172 source.rfile() # Hack to cause the symlink to the .i file to be created
173 package = swig_source_packages[source]
174 filename = str(source)
175 module = basename(filename)
176
177 assert(module.endswith('.i'))
178 module = module[:-2]
179 cc_file = 'swig/%s_wrap.cc' % module
180 py_file = 'm5/internal/%s.py' % module
181
182 env.Command([cc_file, py_file], source,
183 '$SWIG $SWIGFLAGS -outdir ${TARGETS[1].dir} '
184 '-o ${TARGETS[0]} $SOURCES')
185 env.Depends(py_file, source)
186 env.Depends(cc_file, source)
187
188 swig_modules.append(Value(module))
189 Source(cc_file)
190 PySource(package, py_file)
191
192def MakeSwigInit(target, source, env):
193 f = file(str(target[0]), 'w')
194 print >>f, 'extern "C" {'
195 for module in source:
196 print >>f, ' void init_%s();' % module.get_contents()
197 print >>f, '}'
198 print >>f, 'void init_swig() {'
199 for module in source:
200 print >>f, ' init_%s();' % module.get_contents()
201 print >>f, '}'
202 f.close()
203env.Command('python/swig/init.cc', swig_modules, MakeSwigInit)
204
205def CompilePyFile(target, source, env):
206 import py_compile
207 py_compile.compile(str(source[0]), str(target[0]))
208
209py_compiled = []
210py_arcname = {}
211py_zip_depends = []
212for source in py_sources:
213 filename = str(source)
214 package = py_source_packages[source]
215 arc_path = package.split('.') + [ basename(filename) + 'c' ]
216 zip_path = [ 'zip' ] + arc_path
217 arcname = joinpath(*arc_path)
218 zipname = joinpath(*zip_path)
219 f = File(zipname)
220
221 env.Command(f, source, CompilePyFile)
222 py_compiled.append(f)
223 py_arcname[f] = arcname
224
225 # make the zipfile depend on the archive name so that the archive
226 # is rebuilt if the name changes
227 py_zip_depends.append(Value(arcname))
228
229# Action function to build the zip archive. Uses the PyZipFile module
230# included in the standard Python library.
231def buildPyZip(target, source, env):
232 zf = zipfile.ZipFile(str(target[0]), 'w')
233 for s in source:
234 arcname = py_arcname[s]
235 zipname = str(s)
236 zf.write(zipname, arcname)
237 zf.close()
238
239# Add the zip file target to the environment.
240env.Command('m5py.zip', py_compiled, buildPyZip)
241env.Depends('m5py.zip', py_zip_depends)
242
243########################################################################
244#
245# Define binaries. Each different build type (debug, opt, etc.) gets
246# a slightly different build environment.
247#
248
249# List of constructed environments to pass back to SConstruct
250envList = []
251
79# This function adds the specified sources to the given build
80# environment, and returns a list of all the corresponding SCons
81# Object nodes (including an extra one for date.cc). We explicitly
82# add the Object nodes so we can set up special dependencies for
83# date.cc.
84def make_objs(sources, env):
85 objs = [env.Object(s) for s in sources]
86 # make date.cc depend on all other objects so it always gets
87 # recompiled whenever anything else does
88 date_obj = env.Object('base/date.cc')
89 env.Depends(date_obj, objs)
90 objs.append(date_obj)
91 return objs
92
252# This function adds the specified sources to the given build
253# environment, and returns a list of all the corresponding SCons
254# Object nodes (including an extra one for date.cc). We explicitly
255# add the Object nodes so we can set up special dependencies for
256# date.cc.
257def make_objs(sources, env):
258 objs = [env.Object(s) for s in sources]
259 # make date.cc depend on all other objects so it always gets
260 # recompiled whenever anything else does
261 date_obj = env.Object('base/date.cc')
262 env.Depends(date_obj, objs)
263 objs.append(date_obj)
264 return objs
265
93###################################################
94#
95# Define binaries. Each different build type (debug, opt, etc.) gets
96# a slightly different build environment.
97#
98###################################################
99
100# List of constructed environments to pass back to SConstruct
101envList = []
102
103# Function to create a new build environment as clone of current
104# environment 'env' with modified object suffix and optional stripped
105# binary. Additional keyword arguments are appended to corresponding
106# build environment vars.
107def makeEnv(label, objsfx, strip = False, **kwargs):
108 newEnv = env.Copy(OBJSUFFIX=objsfx)
109 newEnv.Label = label
110 newEnv.Append(**kwargs)
111 exe = 'm5.' + label # final executable
112 bin = exe + '.bin' # executable w/o appended Python zip archive
113 newEnv.Program(bin, make_objs(sources, newEnv))
114 if strip:
115 stripped_bin = bin + '.stripped'
116 if sys.platform == 'sunos5':
117 newEnv.Command(stripped_bin, bin, 'cp $SOURCE $TARGET; strip $TARGET')
118 else:
119 newEnv.Command(stripped_bin, bin, 'strip $SOURCE -o $TARGET')
120 bin = stripped_bin
266# Function to create a new build environment as clone of current
267# environment 'env' with modified object suffix and optional stripped
268# binary. Additional keyword arguments are appended to corresponding
269# build environment vars.
270def makeEnv(label, objsfx, strip = False, **kwargs):
271 newEnv = env.Copy(OBJSUFFIX=objsfx)
272 newEnv.Label = label
273 newEnv.Append(**kwargs)
274 exe = 'm5.' + label # final executable
275 bin = exe + '.bin' # executable w/o appended Python zip archive
276 newEnv.Program(bin, make_objs(sources, newEnv))
277 if strip:
278 stripped_bin = bin + '.stripped'
279 if sys.platform == 'sunos5':
280 newEnv.Command(stripped_bin, bin, 'cp $SOURCE $TARGET; strip $TARGET')
281 else:
282 newEnv.Command(stripped_bin, bin, 'strip $SOURCE -o $TARGET')
283 bin = stripped_bin
121 targets = newEnv.Concat(exe, [bin, 'python/m5py.zip'])
284 targets = newEnv.Concat(exe, [bin, 'm5py.zip'])
122 newEnv.M5Binary = targets[0]
123 envList.append(newEnv)
124
125# Debug binary
126ccflags = {}
127if env['GCC']:
128 if sys.platform == 'sunos5':
129 ccflags['debug'] = '-gstabs+'

--- 40 unchanged lines hidden ---
285 newEnv.M5Binary = targets[0]
286 envList.append(newEnv)
287
288# Debug binary
289ccflags = {}
290if env['GCC']:
291 if sys.platform == 'sunos5':
292 ccflags['debug'] = '-gstabs+'

--- 40 unchanged lines hidden ---