SConscript revision 4123:9c80390ea1bb
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
9# notice, this list of conditions and the following disclaimer;
10# redistributions in binary form must reproduce the above copyright
11# notice, this list of conditions and the following disclaimer in the
12# documentation and/or other materials provided with the distribution;
13# neither the name of the copyright holders nor the names of its
14# contributors may be used to endorse or promote products derived from
15# this software without specific prior written permission.
16#
17# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
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: Steve Reinhardt
30
31import os
32import sys
33from os.path import isfile, join as joinpath
34
35# This file defines how to build a particular configuration of M5
36# based on variable settings in the 'env' build environment.
37
38# Import build environment variable from SConstruct.
39Import('env')
40
41###################################################
42#
43# Define needed sources.
44#
45###################################################
46
47# Base sources used by all configurations.
48
49base_sources = Split('''
50	base/annotate.cc
51	base/circlebuf.cc
52	base/cprintf.cc
53	base/fast_alloc.cc
54	base/fifo_buffer.cc
55	base/hostinfo.cc
56	base/hybrid_pred.cc
57	base/inifile.cc
58	base/intmath.cc
59	base/match.cc
60	base/misc.cc
61	base/output.cc
62	base/pollevent.cc
63	base/range.cc
64	base/random.cc
65	base/remote_gdb.cc
66	base/sat_counter.cc
67	base/socket.cc
68	base/statistics.cc
69	base/str.cc
70	base/time.cc
71	base/trace.cc
72	base/traceflags.cc
73	base/userinfo.cc
74	base/compression/lzss_compression.cc
75	base/loader/aout_object.cc
76	base/loader/ecoff_object.cc
77	base/loader/elf_object.cc
78	base/loader/raw_object.cc
79	base/loader/object_file.cc
80	base/loader/symtab.cc
81	base/stats/events.cc
82        base/stats/output.cc
83	base/stats/statdb.cc
84	base/stats/visit.cc
85	base/stats/text.cc
86
87        cpu/activity.cc
88	cpu/base.cc
89	cpu/cpuevent.cc
90	cpu/exetrace.cc
91        cpu/func_unit.cc
92        cpu/op_class.cc
93	cpu/pc_event.cc
94        cpu/quiesce_event.cc
95	cpu/static_inst.cc
96        cpu/simple_thread.cc
97        cpu/thread_state.cc
98
99        mem/bridge.cc
100        mem/bus.cc
101        mem/dram.cc
102        mem/mem_object.cc
103        mem/packet.cc
104        mem/physical.cc
105        mem/port.cc
106        mem/tport.cc
107
108        mem/cache/base_cache.cc
109        mem/cache/cache.cc
110        mem/cache/coherence/coherence_protocol.cc
111        mem/cache/coherence/uni_coherence.cc
112        mem/cache/miss/blocking_buffer.cc
113        mem/cache/miss/miss_buffer.cc
114        mem/cache/miss/miss_queue.cc
115        mem/cache/miss/mshr.cc
116        mem/cache/miss/mshr_queue.cc
117        mem/cache/prefetch/base_prefetcher.cc
118        mem/cache/prefetch/ghb_prefetcher.cc
119        mem/cache/prefetch/stride_prefetcher.cc
120        mem/cache/prefetch/tagged_prefetcher.cc
121        mem/cache/tags/base_tags.cc
122        mem/cache/tags/fa_lru.cc
123        mem/cache/tags/iic.cc
124        mem/cache/tags/lru.cc
125        mem/cache/tags/repl/gen.cc
126        mem/cache/tags/repl/repl.cc
127        mem/cache/tags/split.cc
128        mem/cache/tags/split_lifo.cc
129        mem/cache/tags/split_lru.cc
130
131        mem/cache/cache_builder.cc
132
133        python/swig/init.cc
134        python/swig/core_wrap.cc
135        python/swig/debug_wrap.cc
136        python/swig/event_wrap.cc
137        python/swig/random_wrap.cc
138        python/swig/sim_object_wrap.cc
139        python/swig/stats_wrap.cc
140        python/swig/trace_wrap.cc
141        python/swig/pyevent.cc
142        python/swig/pyobject.cc
143
144        sim/async.cc
145	sim/builder.cc
146        sim/core.cc
147	sim/debug.cc
148	sim/eventq.cc
149	sim/faults.cc
150	sim/main.cc
151	sim/param.cc
152	sim/root.cc
153	sim/serialize.cc
154	sim/sim_events.cc
155	sim/sim_object.cc
156        sim/simulate.cc
157	sim/startup.cc
158	sim/stat_control.cc
159	sim/system.cc
160        ''')
161
162trace_reader_sources = Split('''
163        cpu/trace/reader/mem_trace_reader.cc
164        cpu/trace/reader/ibm_reader.cc
165        cpu/trace/reader/itx_reader.cc
166        cpu/trace/reader/m5_reader.cc
167        cpu/trace/opt_cpu.cc
168        cpu/trace/trace_cpu.cc
169        ''')
170
171
172
173# MySql sources
174mysql_sources = Split('''
175	base/mysql.cc
176	base/stats/mysql.cc
177        ''')
178
179# Full-system sources
180full_system_sources = Split('''
181	base/crc.cc
182	base/inet.cc
183
184	cpu/intr_control.cc
185        cpu/profile.cc
186
187	dev/uart.cc
188	dev/uart8250.cc
189
190        mem/vport.cc
191
192	sim/pseudo_inst.cc
193        ''')
194	#dev/sinic.cc
195        #dev/i8254xGBe.cc
196
197if env['TARGET_ISA'] == 'alpha':
198    full_system_sources += Split('''
199	kern/tru64/dump_mbuf.cc
200	kern/tru64/printf.cc
201	kern/tru64/tru64_events.cc
202	kern/tru64/tru64_syscalls.cc
203        ''')
204
205# Syscall emulation (non-full-system) sources
206syscall_emulation_sources = Split('''
207        mem/translating_port.cc
208        mem/page_table.cc
209	sim/process.cc
210	sim/syscall_emul.cc
211        ''')
212
213#if env['TARGET_ISA'] == 'alpha':
214#    syscall_emulation_sources += Split('''
215#        kern/tru64/tru64.cc
216#        ''')
217
218memtest_sources = Split('''
219	cpu/memtest/memtest.cc
220        ''')
221
222# Include file paths are rooted in this directory.  SCons will
223# automatically expand '.' to refer to both the source directory and
224# the corresponding build directory to pick up generated include
225# files.
226env.Append(CPPPATH=Dir('.'))
227
228# Add a flag defining what THE_ISA should be for all compilation
229env.Append(CPPDEFINES=[('THE_ISA','%s_ISA' % env['TARGET_ISA'].upper())])
230
231arch_sources = SConscript(os.path.join('arch', 'SConscript'), exports = 'env')
232
233cpu_sources = SConscript(os.path.join('cpu', 'SConscript'), exports = 'env')
234
235if env['FULL_SYSTEM']:
236    dev_sources = SConscript(os.path.join('dev', 'SConscript'),
237                             exports = 'env')
238    full_system_sources += dev_sources
239
240    kern_sources = SConscript(os.path.join('kern', 'SConscript'),
241                              exports = 'env')
242    full_system_sources += kern_sources
243
244# Set up complete list of sources based on configuration.
245sources = base_sources + arch_sources + cpu_sources
246
247# encumbered should be last because we're adding to some of the other groups
248if isfile(joinpath(env['SRCDIR'], 'encumbered/SConscript')):
249    sources += SConscript('encumbered/SConscript', exports = 'env')
250
251
252if env['FULL_SYSTEM']:
253    sources += full_system_sources
254else:
255    sources += syscall_emulation_sources
256
257if env['USE_MYSQL']:
258    sources += mysql_sources
259
260for opt in env.ExportOptions:
261    env.ConfigFile(opt)
262
263###################################################
264#
265# Special build rules.
266#
267###################################################
268
269# base/traceflags.{cc,hh} are generated from base/traceflags.py.
270# $TARGET.base will expand to "<build-dir>/base/traceflags".
271env.Command(Split('base/traceflags.hh base/traceflags.cc'),
272            'base/traceflags.py',
273            'python $SOURCE $TARGET.base')
274
275SConscript('python/SConscript', exports = ['env'])
276
277# This function adds the specified sources to the given build
278# environment, and returns a list of all the corresponding SCons
279# Object nodes (including an extra one for date.cc).  We explicitly
280# add the Object nodes so we can set up special dependencies for
281# date.cc.
282def make_objs(sources, env):
283    objs = [env.Object(s) for s in sources]
284    # make date.cc depend on all other objects so it always gets
285    # recompiled whenever anything else does
286    date_obj = env.Object('base/date.cc')
287    env.Depends(date_obj, objs)
288    objs.append(date_obj)
289    return objs
290
291###################################################
292#
293# Define binaries.  Each different build type (debug, opt, etc.) gets
294# a slightly different build environment.
295#
296###################################################
297
298# List of constructed environments to pass back to SConstruct
299envList = []
300
301# Function to create a new build environment as clone of current
302# environment 'env' with modified object suffix and optional stripped
303# binary.  Additional keyword arguments are appended to corresponding
304# build environment vars.
305def makeEnv(label, objsfx, strip = False, **kwargs):
306    newEnv = env.Copy(OBJSUFFIX=objsfx)
307    newEnv.Label = label
308    newEnv.Append(**kwargs)
309    exe = 'm5.' + label  # final executable
310    bin = exe + '.bin'   # executable w/o appended Python zip archive
311    newEnv.Program(bin, make_objs(sources, newEnv))
312    if strip:
313        stripped_bin = bin + '.stripped'
314        if sys.platform == 'sunos5':
315            newEnv.Command(stripped_bin, bin, 'cp $SOURCE $TARGET; strip $TARGET')
316        else:
317            newEnv.Command(stripped_bin, bin, 'strip $SOURCE -o $TARGET')
318        bin = stripped_bin
319    targets = newEnv.Concat(exe, [bin, 'python/m5py.zip'])
320    newEnv.M5Binary = targets[0]
321    envList.append(newEnv)
322
323# Debug binary
324ccflags = {}
325if env['GCC']:
326    if sys.platform == 'sunos5':
327        ccflags['debug'] = '-gstabs+'
328    else:
329        ccflags['debug'] = '-ggdb3'
330    ccflags['opt'] = '-g -O3'
331    ccflags['fast'] = '-O3'
332    ccflags['prof'] = '-O3 -g -pg'
333elif env['SUNCC']:
334    ccflags['debug'] = '-g0'
335    ccflags['opt'] = '-g -O'
336    ccflags['fast'] = '-fast'
337    ccflags['prof'] = '-fast -g -pg'
338elif env['ICC']:
339    ccflags['debug'] = '-g -O0'
340    ccflags['opt'] = '-g -O'
341    ccflags['fast'] = '-fast'
342    ccflags['prof'] = '-fast -g -pg'
343else:
344    print 'Unknown compiler, please fix compiler options'
345    Exit(1)    
346
347makeEnv('debug', '.do',
348        CCFLAGS = Split(ccflags['debug']),
349        CPPDEFINES = ['DEBUG', 'TRACING_ON=1'])
350
351# Optimized binary
352makeEnv('opt', '.o',
353        CCFLAGS = Split(ccflags['opt']),
354        CPPDEFINES = ['TRACING_ON=1'])
355
356# "Fast" binary
357makeEnv('fast', '.fo', strip = True,
358        CCFLAGS = Split(ccflags['fast']),
359        CPPDEFINES = ['NDEBUG', 'TRACING_ON=0'])
360
361# Profiled binary
362makeEnv('prof', '.po',
363        CCFLAGS = Split(ccflags['prof']),
364        CPPDEFINES = ['NDEBUG', 'TRACING_ON=0'],
365        LINKFLAGS = '-pg')
366
367Return('envList')
368