SConscript (11974:006d830b4a4e) SConscript (11983:40e0c3829cfe)
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

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

67# skip_no_python -- do not put this file into a no_python library
68# as it embeds compiled Python
69# <unittest> -- unit tests use filters based on the unit test name
70#
71# A parent can now be specified for a source file and default filter
72# values will be retrieved recursively from parents (children override
73# parents).
74#
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

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

67# skip_no_python -- do not put this file into a no_python library
68# as it embeds compiled Python
69# <unittest> -- unit tests use filters based on the unit test name
70#
71# A parent can now be specified for a source file and default filter
72# values will be retrieved recursively from parents (children override
73# parents).
74#
75def guarded_source_iterator(sources, **guards):
76 '''Iterate over a set of sources, gated by a set of guards.'''
77 for src in sources:
78 for flag,value in guards.iteritems():
79 # if the flag is found and has a different value, skip
80 # this file
81 if src.all_guards.get(flag, False) != value:
82 break
83 else:
84 yield src
85
75class SourceMeta(type):
76 '''Meta class for source files that keeps track of all files of a
77 particular type and has a get function for finding all functions
78 of a certain type that match a set of guards'''
79 def __init__(cls, name, bases, dict):
80 super(SourceMeta, cls).__init__(name, bases, dict)
81 cls.all = []
82
83 def get(cls, **guards):
84 '''Find all files that match the specified guards. If a source
85 file does not specify a flag, the default is False'''
86class SourceMeta(type):
87 '''Meta class for source files that keeps track of all files of a
88 particular type and has a get function for finding all functions
89 of a certain type that match a set of guards'''
90 def __init__(cls, name, bases, dict):
91 super(SourceMeta, cls).__init__(name, bases, dict)
92 cls.all = []
93
94 def get(cls, **guards):
95 '''Find all files that match the specified guards. If a source
96 file does not specify a flag, the default is False'''
86 for src in cls.all:
87 for flag,value in guards.iteritems():
88 # if the flag is found and has a different value, skip
89 # this file
90 if src.all_guards.get(flag, False) != value:
91 break
92 else:
93 yield src
97 for s in guarded_source_iterator(cls.all, **guards):
98 yield s
94
95class SourceFile(object):
96 '''Base object that encapsulates the notion of a source file.
97 This includes, the source node, target node, various manipulations
98 of those. A source file also specifies a set of guards which
99 describing which builds the source file applies to. A parent can
100 also be specified to get default guards from'''
101 __metaclass__ = SourceMeta

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

156 def done():
157 def disabled(cls, name, *ignored):
158 raise RuntimeError("Additional SourceFile '%s'" % name,\
159 "declared, but targets deps are already fixed.")
160 SourceFile.__init__ = disabled
161
162
163class Source(SourceFile):
99
100class SourceFile(object):
101 '''Base object that encapsulates the notion of a source file.
102 This includes, the source node, target node, various manipulations
103 of those. A source file also specifies a set of guards which
104 describing which builds the source file applies to. A parent can
105 also be specified to get default guards from'''
106 __metaclass__ = SourceMeta

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

161 def done():
162 def disabled(cls, name, *ignored):
163 raise RuntimeError("Additional SourceFile '%s'" % name,\
164 "declared, but targets deps are already fixed.")
165 SourceFile.__init__ = disabled
166
167
168class Source(SourceFile):
169 current_group = None
170 source_groups = { None : [] }
171
172 @classmethod
173 def set_group(cls, group):
174 if not group in Source.source_groups:
175 Source.source_groups[group] = []
176 Source.current_group = group
177
164 '''Add a c/c++ source file to the build'''
165 def __init__(self, source, Werror=True, swig=False, **guards):
166 '''specify the source file, and any guards'''
167 super(Source, self).__init__(source, **guards)
168
169 self.Werror = Werror
170 self.swig = swig
171
178 '''Add a c/c++ source file to the build'''
179 def __init__(self, source, Werror=True, swig=False, **guards):
180 '''specify the source file, and any guards'''
181 super(Source, self).__init__(source, **guards)
182
183 self.Werror = Werror
184 self.swig = swig
185
186 Source.source_groups[Source.current_group].append(self)
187
172class PySource(SourceFile):
173 '''Add a python source file to the named package'''
174 invalid_sym_char = re.compile('[^A-z0-9_]')
175 modules = {}
176 tnodes = {}
177 symnames = {}
178
179 def __init__(self, package, source, **guards):

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

1160
1161 lib_guards = {'main': False, 'skip_lib': False}
1162
1163 # Without Python, leave out all SWIG and Python content from the
1164 # library builds. The option doesn't affect gem5 built as a program
1165 if GetOption('without_python'):
1166 lib_guards['skip_no_python'] = False
1167
188class PySource(SourceFile):
189 '''Add a python source file to the named package'''
190 invalid_sym_char = re.compile('[^A-z0-9_]')
191 modules = {}
192 tnodes = {}
193 symnames = {}
194
195 def __init__(self, package, source, **guards):

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

1176
1177 lib_guards = {'main': False, 'skip_lib': False}
1178
1179 # Without Python, leave out all SWIG and Python content from the
1180 # library builds. The option doesn't affect gem5 built as a program
1181 if GetOption('without_python'):
1182 lib_guards['skip_no_python'] = False
1183
1168 static_objs = [ make_obj(s, True) for s in Source.get(**lib_guards) ]
1169 shared_objs = [ make_obj(s, False) for s in Source.get(**lib_guards) ]
1184 static_objs = []
1185 shared_objs = []
1186 for s in guarded_source_iterator(Source.source_groups[None], **lib_guards):
1187 static_objs.append(make_obj(s, True))
1188 shared_objs.append(make_obj(s, False))
1170
1189
1190 partial_objs = []
1191 for group, all_srcs in Source.source_groups.iteritems():
1192 # If these are the ungrouped source files, skip them.
1193 if not group:
1194 continue
1195
1196 # Get a list of the source files compatible with the current guards.
1197 srcs = [ s for s in guarded_source_iterator(all_srcs, **lib_guards) ]
1198 # If there aren't any left, skip this group.
1199 if not srcs:
1200 continue
1201
1202 # Set up the static partially linked objects.
1203 source_objs = [ make_obj(s, True) for s in srcs ]
1204 file_name = new_env.subst("${OBJPREFIX}lib${OBJSUFFIX}.partial")
1205 target = File(joinpath(group, file_name))
1206 partial = env.PartialStatic(target=target, source=source_objs)
1207 static_objs.append(partial)
1208
1209 # Set up the shared partially linked objects.
1210 source_objs = [ make_obj(s, False) for s in srcs ]
1211 file_name = new_env.subst("${SHOBJPREFIX}lib${SHOBJSUFFIX}.partial")
1212 target = File(joinpath(group, file_name))
1213 partial = env.PartialShared(target=target, source=source_objs)
1214 shared_objs.append(partial)
1215
1171 static_date = make_obj(date_source, static=True, extra_deps=static_objs)
1172 static_objs.append(static_date)
1173
1174 shared_date = make_obj(date_source, static=False, extra_deps=shared_objs)
1175 shared_objs.append(shared_date)
1176
1177 # First make a library of everything but main() so other programs can
1178 # link against m5.

--- 183 unchanged lines hidden ---
1216 static_date = make_obj(date_source, static=True, extra_deps=static_objs)
1217 static_objs.append(static_date)
1218
1219 shared_date = make_obj(date_source, static=False, extra_deps=shared_objs)
1220 shared_objs.append(shared_date)
1221
1222 # First make a library of everything but main() so other programs can
1223 # link against m5.

--- 183 unchanged lines hidden ---