Deleted Added
sdiff udiff text old ( 5518:70caf53d9d7c ) new ( 5522:e56c3d89be79 )
full compact
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

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

23# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
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: Nathan Binkert
30
31import imp
32import os
33import py_compile
34import sys
35import zipfile
36
37from os.path import basename, exists, isdir, isfile, join as joinpath
38
39import SCons
40
41# This file defines how to build a particular configuration of M5
42# based on variable settings in the 'env' build environment.
43

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

53 if isinstance(_list, list):
54 _list = _list[:]
55 else:
56 _list = list(_list)
57 _list.sort()
58 return _list
59
60class PySourceFile(object):
61 def __init__(self, package, source):
62 filename = str(source)
63 pyname = basename(filename)
64 assert pyname.endswith('.py')
65 name = pyname[:-3]
66 path = package.split('.')
67 modpath = path
68 if name != '__init__':
69 modpath += [name]
70 modpath = '.'.join(modpath)
71
72 arcpath = package.split('.') + [ pyname + 'c' ]
73 arcname = joinpath(*arcpath)
74
75 self.source = source
76 self.pyname = pyname
77 self.srcpath = source.srcnode().abspath
78 self.package = package
79 self.modpath = modpath
80 self.arcname = arcname
81 self.filename = filename
82 self.compiled = File(filename + 'c')
83
84########################################################################
85# Code for adding source files of various types
86#
87cc_sources = []
88def Source(source):
89 '''Add a C/C++ source file to the build'''
90 if not isinstance(source, SCons.Node.FS.File):
91 source = File(source)
92
93 cc_sources.append(source)
94
95py_sources = []
96def PySource(package, source):
97 '''Add a python source file to the named package'''
98 if not isinstance(source, SCons.Node.FS.File):
99 source = File(source)
100
101 source = PySourceFile(package, source)
102 py_sources.append(source)

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

124 '''Add a swig file to build'''
125 if not isinstance(source, SCons.Node.FS.File):
126 source = File(source)
127 val = source,package
128 swig_sources.append(val)
129
130# Children should have access
131Export('Source')
132Export('PySource')
133Export('SimObject')
134Export('SwigSource')
135
136########################################################################
137#
138# Trace Flags
139#

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

254 mod.__file__ = srcfile
255
256 exec file(srcfile, 'r') in mod.__dict__
257
258 return mod
259
260py_modules = {}
261for source in py_sources:
262 py_modules[source.modpath] = source.srcpath
263
264# install the python importer so we can grab stuff from the source
265# tree itself. We can't have SimObjects added after this point or
266# else we won't know about them for the rest of the stuff.
267sim_objects_fixed = True
268importer = DictImporter(py_modules)
269sys.meta_path[0:0] = [ importer ]
270

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

546
547# Generate the main swig init file
548def makeSwigInit(target, source, env):
549 f = file(str(target[0]), 'w')
550 print >>f, 'extern "C" {'
551 for module in source:
552 print >>f, ' void init_%s();' % module.get_contents()
553 print >>f, '}'
554 print >>f, 'void init_swig() {'
555 for module in source:
556 print >>f, ' init_%s();' % module.get_contents()
557 print >>f, '}'
558 f.close()
559
560env.Command('swig/init.cc', swig_modules, makeSwigInit)
561Source('swig/init.cc')
562
563# Generate traceflags.py
564def traceFlagsPy(target, source, env):
565 assert(len(target) == 1)
566
567 f = file(str(target[0]), 'w')
568
569 allFlags = []

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

792 print "in except"
793 gen_file(target, "Unknown", "Unknown", "Unknown")
794 mercurial.demandimport.disable()
795
796env.Command('base/program_info.cc',
797 Value(str(SCons.Node.FS.default_fs.SConstruct_dir)),
798 programInfo)
799
800# Build the zip file
801def compilePyFile(target, source, env):
802 '''Action function to compile a .py into a .pyc'''
803 py_compile.compile(str(source[0]), str(target[0]))
804
805def buildPyZip(target, source, env):
806 '''Action function to build the zip archive. Uses the
807 PyZipFile module included in the standard Python library.'''
808
809 py_compiled = {}
810 for s in py_sources:
811 compname = str(s.compiled)
812 assert compname not in py_compiled
813 py_compiled[compname] = s
814
815 zf = zipfile.ZipFile(str(target[0]), 'w')
816 for s in source:
817 zipname = str(s)
818 arcname = py_compiled[zipname].arcname
819 zf.write(zipname, arcname)
820 zf.close()
821
822py_compiled = []
823py_zip_depends = []
824for source in py_sources:
825 env.Command(source.compiled, source.source, compilePyFile)
826 py_compiled.append(source.compiled)
827
828 # make the zipfile depend on the archive name so that the archive
829 # is rebuilt if the name changes
830 py_zip_depends.append(Value(source.arcname))
831
832# Add the zip file target to the environment.
833m5zip = File('m5py.zip')
834env.Command(m5zip, py_compiled, buildPyZip)
835env.Depends(m5zip, py_zip_depends)
836
837########################################################################
838#
839# Define binaries. Each different build type (debug, opt, etc.) gets
840# a slightly different build environment.
841#
842
843# List of constructed environments to pass back to SConstruct
844envList = []

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

868# Function to create a new build environment as clone of current
869# environment 'env' with modified object suffix and optional stripped
870# binary. Additional keyword arguments are appended to corresponding
871# build environment vars.
872def makeEnv(label, objsfx, strip = False, **kwargs):
873 newEnv = env.Copy(OBJSUFFIX=objsfx)
874 newEnv.Label = label
875 newEnv.Append(**kwargs)
876 exe = 'm5.' + label # final executable
877 bin = exe + '.bin' # executable w/o appended Python zip archive
878 newEnv.Program(bin, make_objs(cc_sources, newEnv))
879 if strip:
880 stripped_bin = bin + '.stripped'
881 if sys.platform == 'sunos5':
882 cmd = 'cp $SOURCE $TARGET; strip $TARGET'
883 else:
884 cmd = 'strip $SOURCE -o $TARGET'
885 newEnv.Command(stripped_bin, bin, cmd)
886 bin = stripped_bin
887 targets = newEnv.Concat(exe, [bin, 'm5py.zip'])
888 newEnv.M5Binary = targets[0]
889 envList.append(newEnv)
890
891# Debug binary
892ccflags = {}
893if env['GCC']:
894 if sys.platform == 'sunos5':
895 ccflags['debug'] = '-gstabs+'

--- 40 unchanged lines hidden ---