SConscript revision 4045:43eb54e807d1
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/statdb.cc
83	base/stats/visit.cc
84	base/stats/text.cc
85
86        cpu/activity.cc
87	cpu/base.cc
88	cpu/cpuevent.cc
89	cpu/exetrace.cc
90        cpu/func_unit.cc
91        cpu/op_class.cc
92	cpu/pc_event.cc
93        cpu/quiesce_event.cc
94	cpu/static_inst.cc
95        cpu/simple_thread.cc
96        cpu/thread_state.cc
97
98        mem/bridge.cc
99        mem/bus.cc
100        mem/dram.cc
101        mem/mem_object.cc
102        mem/packet.cc
103        mem/physical.cc
104        mem/port.cc
105        mem/tport.cc
106
107        mem/cache/base_cache.cc
108        mem/cache/cache.cc
109        mem/cache/coherence/coherence_protocol.cc
110        mem/cache/coherence/uni_coherence.cc
111        mem/cache/miss/blocking_buffer.cc
112        mem/cache/miss/miss_buffer.cc
113        mem/cache/miss/miss_queue.cc
114        mem/cache/miss/mshr.cc
115        mem/cache/miss/mshr_queue.cc
116        mem/cache/prefetch/base_prefetcher.cc
117        mem/cache/prefetch/ghb_prefetcher.cc
118        mem/cache/prefetch/stride_prefetcher.cc
119        mem/cache/prefetch/tagged_prefetcher.cc
120        mem/cache/tags/base_tags.cc
121        mem/cache/tags/fa_lru.cc
122        mem/cache/tags/iic.cc
123        mem/cache/tags/lru.cc
124        mem/cache/tags/repl/gen.cc
125        mem/cache/tags/repl/repl.cc
126        mem/cache/tags/split.cc
127        mem/cache/tags/split_lifo.cc
128        mem/cache/tags/split_lru.cc
129
130        mem/cache/cache_builder.cc
131
132        python/swig/init.cc
133        python/swig/debug_wrap.cc
134        python/swig/main_wrap.cc
135        python/swig/event_wrap.cc
136        python/swig/random_wrap.cc
137        python/swig/trace_wrap.cc
138        python/swig/pyevent.cc
139
140	sim/builder.cc
141	sim/debug.cc
142	sim/eventq.cc
143	sim/faults.cc
144	sim/main.cc
145	sim/param.cc
146	sim/root.cc
147	sim/serialize.cc
148	sim/sim_events.cc
149	sim/sim_object.cc
150	sim/startup.cc
151	sim/stat_context.cc
152	sim/stat_control.cc
153	sim/system.cc
154        sim/trace_control.cc
155        ''')
156
157trace_reader_sources = Split('''
158        cpu/trace/reader/mem_trace_reader.cc
159        cpu/trace/reader/ibm_reader.cc
160        cpu/trace/reader/itx_reader.cc
161        cpu/trace/reader/m5_reader.cc
162        cpu/trace/opt_cpu.cc
163        cpu/trace/trace_cpu.cc
164        ''')
165
166
167
168# MySql sources
169mysql_sources = Split('''
170	base/mysql.cc
171	base/stats/mysql.cc
172        ''')
173
174# Full-system sources
175full_system_sources = Split('''
176	base/crc.cc
177	base/inet.cc
178
179	cpu/intr_control.cc
180        cpu/profile.cc
181
182	dev/uart.cc
183	dev/uart8250.cc
184
185        mem/vport.cc
186
187	sim/pseudo_inst.cc
188        ''')
189	#dev/sinic.cc
190        #dev/i8254xGBe.cc
191
192if env['TARGET_ISA'] == 'alpha':
193    full_system_sources += Split('''
194	kern/tru64/dump_mbuf.cc
195	kern/tru64/printf.cc
196	kern/tru64/tru64_events.cc
197	kern/tru64/tru64_syscalls.cc
198        ''')
199
200# Syscall emulation (non-full-system) sources
201syscall_emulation_sources = Split('''
202        mem/translating_port.cc
203        mem/page_table.cc
204	sim/process.cc
205	sim/syscall_emul.cc
206        ''')
207
208#if env['TARGET_ISA'] == 'alpha':
209#    syscall_emulation_sources += Split('''
210#        kern/tru64/tru64.cc
211#        ''')
212
213memtest_sources = Split('''
214	cpu/memtest/memtest.cc
215        ''')
216
217# Include file paths are rooted in this directory.  SCons will
218# automatically expand '.' to refer to both the source directory and
219# the corresponding build directory to pick up generated include
220# files.
221env.Append(CPPPATH=Dir('.'))
222
223# Add a flag defining what THE_ISA should be for all compilation
224env.Append(CPPDEFINES=[('THE_ISA','%s_ISA' % env['TARGET_ISA'].upper())])
225
226arch_sources = SConscript(os.path.join('arch', 'SConscript'), exports = 'env')
227
228cpu_sources = SConscript(os.path.join('cpu', 'SConscript'), exports = 'env')
229
230if env['FULL_SYSTEM']:
231    dev_sources = SConscript(os.path.join('dev', 'SConscript'),
232                             exports = 'env')
233    full_system_sources += dev_sources
234
235    kern_sources = SConscript(os.path.join('kern', 'SConscript'),
236                              exports = 'env')
237    full_system_sources += kern_sources
238
239# Set up complete list of sources based on configuration.
240sources = base_sources + arch_sources + cpu_sources
241
242# encumbered should be last because we're adding to some of the other groups
243if isfile(joinpath(env['SRCDIR'], 'encumbered/SConscript')):
244    sources += SConscript('encumbered/SConscript', exports = 'env')
245
246
247if env['FULL_SYSTEM']:
248    sources += full_system_sources
249else:
250    sources += syscall_emulation_sources
251
252if env['USE_MYSQL']:
253    sources += mysql_sources
254
255for opt in env.ExportOptions:
256    env.ConfigFile(opt)
257
258###################################################
259#
260# Special build rules.
261#
262###################################################
263
264# base/traceflags.{cc,hh} are generated from base/traceflags.py.
265# $TARGET.base will expand to "<build-dir>/base/traceflags".
266env.Command(Split('base/traceflags.hh base/traceflags.cc'),
267            'base/traceflags.py',
268            'python $SOURCE $TARGET.base')
269
270SConscript('python/SConscript', exports = ['env'])
271
272# This function adds the specified sources to the given build
273# environment, and returns a list of all the corresponding SCons
274# Object nodes (including an extra one for date.cc).  We explicitly
275# add the Object nodes so we can set up special dependencies for
276# date.cc.
277def make_objs(sources, env):
278    objs = [env.Object(s) for s in sources]
279    # make date.cc depend on all other objects so it always gets
280    # recompiled whenever anything else does
281    date_obj = env.Object('base/date.cc')
282    env.Depends(date_obj, objs)
283    objs.append(date_obj)
284    return objs
285
286###################################################
287#
288# Define binaries.  Each different build type (debug, opt, etc.) gets
289# a slightly different build environment.
290#
291###################################################
292
293# List of constructed environments to pass back to SConstruct
294envList = []
295
296# Function to create a new build environment as clone of current
297# environment 'env' with modified object suffix and optional stripped
298# binary.  Additional keyword arguments are appended to corresponding
299# build environment vars.
300def makeEnv(label, objsfx, strip = False, **kwargs):
301    newEnv = env.Copy(OBJSUFFIX=objsfx)
302    newEnv.Label = label
303    newEnv.Append(**kwargs)
304    exe = 'm5.' + label  # final executable
305    bin = exe + '.bin'   # executable w/o appended Python zip archive
306    newEnv.Program(bin, make_objs(sources, newEnv))
307    if strip:
308        stripped_bin = bin + '.stripped'
309        if sys.platform == 'sunos5':
310            newEnv.Command(stripped_bin, bin, 'cp $SOURCE $TARGET; strip $TARGET')
311        else:
312            newEnv.Command(stripped_bin, bin, 'strip $SOURCE -o $TARGET')
313        bin = stripped_bin
314    targets = newEnv.Concat(exe, [bin, 'python/m5py.zip'])
315    newEnv.M5Binary = targets[0]
316    envList.append(newEnv)
317
318# Debug binary
319ccflags = {}
320if env['GCC']:
321    if sys.platform == 'sunos5':
322        ccflags['debug'] = '-gstabs+'
323    else:
324        ccflags['debug'] = '-ggdb3'
325    ccflags['opt'] = '-g -O3'
326    ccflags['fast'] = '-O3'
327    ccflags['prof'] = '-O3 -g -pg'
328elif env['SUNCC']:
329    ccflags['debug'] = '-g0'
330    ccflags['opt'] = '-g -O'
331    ccflags['fast'] = '-fast'
332    ccflags['prof'] = '-fast -g -pg'
333elif env['ICC']:
334    ccflags['debug'] = '-g -O0'
335    ccflags['opt'] = '-g -O'
336    ccflags['fast'] = '-fast'
337    ccflags['prof'] = '-fast -g -pg'
338else:
339    print 'Unknown compiler, please fix compiler options'
340    Exit(1)    
341
342makeEnv('debug', '.do',
343        CCFLAGS = Split(ccflags['debug']),
344        CPPDEFINES = ['DEBUG', 'TRACING_ON=1'])
345
346# Optimized binary
347makeEnv('opt', '.o',
348        CCFLAGS = Split(ccflags['opt']),
349        CPPDEFINES = ['TRACING_ON=1'])
350
351# "Fast" binary
352makeEnv('fast', '.fo', strip = True,
353        CCFLAGS = Split(ccflags['fast']),
354        CPPDEFINES = ['NDEBUG', 'TRACING_ON=0'])
355
356# Profiled binary
357makeEnv('prof', '.po',
358        CCFLAGS = Split(ccflags['prof']),
359        CPPDEFINES = ['NDEBUG', 'TRACING_ON=0'],
360        LINKFLAGS = '-pg')
361
362Return('envList')
363