SConscript (9982:b2bfc23f932c) SConscript (10196:be0e1724eb39)
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

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

144
145 def __lt__(self, other): return self.filename < other.filename
146 def __le__(self, other): return self.filename <= other.filename
147 def __gt__(self, other): return self.filename > other.filename
148 def __ge__(self, other): return self.filename >= other.filename
149 def __eq__(self, other): return self.filename == other.filename
150 def __ne__(self, other): return self.filename != other.filename
151
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

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

144
145 def __lt__(self, other): return self.filename < other.filename
146 def __le__(self, other): return self.filename <= other.filename
147 def __gt__(self, other): return self.filename > other.filename
148 def __ge__(self, other): return self.filename >= other.filename
149 def __eq__(self, other): return self.filename == other.filename
150 def __ne__(self, other): return self.filename != other.filename
151
152 @staticmethod
153 def done():
154 def disabled(cls, name, *ignored):
155 raise RuntimeError("Additional SourceFile '%s'" % name,\
156 "declared, but targets deps are already fixed.")
157 SourceFile.__init__ = disabled
158
159
152class Source(SourceFile):
153 '''Add a c/c++ source file to the build'''
154 def __init__(self, source, Werror=True, swig=False, **guards):
155 '''specify the source file, and any guards'''
156 super(Source, self).__init__(source, **guards)
157
158 self.Werror = Werror
159 self.swig = swig

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

872
873########################################################################
874#
875# Define binaries. Each different build type (debug, opt, etc.) gets
876# a slightly different build environment.
877#
878
879# List of constructed environments to pass back to SConstruct
160class Source(SourceFile):
161 '''Add a c/c++ source file to the build'''
162 def __init__(self, source, Werror=True, swig=False, **guards):
163 '''specify the source file, and any guards'''
164 super(Source, self).__init__(source, **guards)
165
166 self.Werror = Werror
167 self.swig = swig

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

880
881########################################################################
882#
883# Define binaries. Each different build type (debug, opt, etc.) gets
884# a slightly different build environment.
885#
886
887# List of constructed environments to pass back to SConstruct
880envList = []
881
882date_source = Source('base/date.cc', skip_lib=True)
883
888date_source = Source('base/date.cc', skip_lib=True)
889
890# Capture this directory for the closure makeEnv, otherwise when it is
891# called, it won't know what directory it should use.
892variant_dir = Dir('.').path
893def variant(*path):
894 return os.path.join(variant_dir, *path)
895def variantd(*path):
896 return variant(*path)+'/'
897
884# Function to create a new build environment as clone of current
885# environment 'env' with modified object suffix and optional stripped
886# binary. Additional keyword arguments are appended to corresponding
887# build environment vars.
898# Function to create a new build environment as clone of current
899# environment 'env' with modified object suffix and optional stripped
900# binary. Additional keyword arguments are appended to corresponding
901# build environment vars.
888def makeEnv(label, objsfx, strip = False, **kwargs):
902def makeEnv(env, label, objsfx, strip = False, **kwargs):
889 # SCons doesn't know to append a library suffix when there is a '.' in the
890 # name. Use '_' instead.
903 # SCons doesn't know to append a library suffix when there is a '.' in the
904 # name. Use '_' instead.
891 libname = 'gem5_' + label
892 exename = 'gem5.' + label
893 secondary_exename = 'm5.' + label
905 libname = variant('gem5_' + label)
906 exename = variant('gem5.' + label)
907 secondary_exename = variant('m5.' + label)
894
895 new_env = env.Clone(OBJSUFFIX=objsfx, SHOBJSUFFIX=objsfx + 's')
896 new_env.Label = label
897 new_env.Append(**kwargs)
898
899 swig_env = new_env.Clone()
900
901 # Both gcc and clang have issues with unused labels and values in

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

973 main_objs = [ make_obj(s, True) for s in Source.get(main=True) ]
974
975 for test in UnitTest.all:
976 flags = { test.target : True }
977 test_sources = Source.get(**flags)
978 test_objs = [ make_obj(s, static=True) for s in test_sources ]
979 if test.main:
980 test_objs += main_objs
908
909 new_env = env.Clone(OBJSUFFIX=objsfx, SHOBJSUFFIX=objsfx + 's')
910 new_env.Label = label
911 new_env.Append(**kwargs)
912
913 swig_env = new_env.Clone()
914
915 # Both gcc and clang have issues with unused labels and values in

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

987 main_objs = [ make_obj(s, True) for s in Source.get(main=True) ]
988
989 for test in UnitTest.all:
990 flags = { test.target : True }
991 test_sources = Source.get(**flags)
992 test_objs = [ make_obj(s, static=True) for s in test_sources ]
993 if test.main:
994 test_objs += main_objs
981 testname = "unittest/%s.%s" % (test.target, label)
982 new_env.Program(testname, test_objs + static_objs)
995 path = variant('unittest/%s.%s' % (test.target, label))
996 new_env.Program(path, test_objs + static_objs)
983
984 progname = exename
985 if strip:
986 progname += '.unstripped'
987
988 targets = new_env.Program(progname, main_objs + static_objs)
989
990 if strip:
991 if sys.platform == 'sunos5':
992 cmd = 'cp $SOURCE $TARGET; strip $TARGET'
993 else:
994 cmd = 'strip $SOURCE -o $TARGET'
995 targets = new_env.Command(exename, progname,
996 MakeAction(cmd, Transform("STRIP")))
997
998 new_env.Command(secondary_exename, exename,
999 MakeAction('ln $SOURCE $TARGET', Transform("HARDLINK")))
1000
1001 new_env.M5Binary = targets[0]
997
998 progname = exename
999 if strip:
1000 progname += '.unstripped'
1001
1002 targets = new_env.Program(progname, main_objs + static_objs)
1003
1004 if strip:
1005 if sys.platform == 'sunos5':
1006 cmd = 'cp $SOURCE $TARGET; strip $TARGET'
1007 else:
1008 cmd = 'strip $SOURCE -o $TARGET'
1009 targets = new_env.Command(exename, progname,
1010 MakeAction(cmd, Transform("STRIP")))
1011
1012 new_env.Command(secondary_exename, exename,
1013 MakeAction('ln $SOURCE $TARGET', Transform("HARDLINK")))
1014
1015 new_env.M5Binary = targets[0]
1002 envList.append(new_env)
1016 return new_env
1003
1004# Start out with the compiler flags common to all compilers,
1005# i.e. they all use -g for opt and -g -pg for prof
1006ccflags = {'debug' : [], 'opt' : ['-g'], 'fast' : [], 'prof' : ['-g', '-pg'],
1007 'perf' : ['-g']}
1008
1009# Start out with the linker flags common to all linkers, i.e. -pg for
1010# prof, and -lprofiler for perf. The -lprofile flag is surrounded by

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

1060 if match and match.group(1) in target_types:
1061 return match.group(1)
1062 return 'all'
1063
1064needed_envs = [identifyTarget(target) for target in BUILD_TARGETS]
1065if 'all' in needed_envs:
1066 needed_envs += target_types
1067
1017
1018# Start out with the compiler flags common to all compilers,
1019# i.e. they all use -g for opt and -g -pg for prof
1020ccflags = {'debug' : [], 'opt' : ['-g'], 'fast' : [], 'prof' : ['-g', '-pg'],
1021 'perf' : ['-g']}
1022
1023# Start out with the linker flags common to all linkers, i.e. -pg for
1024# prof, and -lprofiler for perf. The -lprofile flag is surrounded by

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

1074 if match and match.group(1) in target_types:
1075 return match.group(1)
1076 return 'all'
1077
1078needed_envs = [identifyTarget(target) for target in BUILD_TARGETS]
1079if 'all' in needed_envs:
1080 needed_envs += target_types
1081
1068# Debug binary
1069if 'debug' in needed_envs:
1070 makeEnv('debug', '.do',
1071 CCFLAGS = Split(ccflags['debug']),
1072 CPPDEFINES = ['DEBUG', 'TRACING_ON=1'],
1073 LINKFLAGS = Split(ldflags['debug']))
1082gem5_root = Dir('.').up().up().abspath
1083def makeEnvirons(target, source, env):
1084 # cause any later Source() calls to be fatal, as a diagnostic.
1085 Source.done()
1074
1086
1075# Optimized binary
1076if 'opt' in needed_envs:
1077 makeEnv('opt', '.o',
1078 CCFLAGS = Split(ccflags['opt']),
1079 CPPDEFINES = ['TRACING_ON=1'],
1080 LINKFLAGS = Split(ldflags['opt']))
1087 envList = []
1081
1088
1082# "Fast" binary
1083if 'fast' in needed_envs:
1084 makeEnv('fast', '.fo', strip = True,
1085 CCFLAGS = Split(ccflags['fast']),
1086 CPPDEFINES = ['NDEBUG', 'TRACING_ON=0'],
1087 LINKFLAGS = Split(ldflags['fast']))
1089 # Debug binary
1090 if 'debug' in needed_envs:
1091 envList.append(
1092 makeEnv(env, 'debug', '.do',
1093 CCFLAGS = Split(ccflags['debug']),
1094 CPPDEFINES = ['DEBUG', 'TRACING_ON=1'],
1095 LINKFLAGS = Split(ldflags['debug'])))
1088
1096
1089# Profiled binary using gprof
1090if 'prof' in needed_envs:
1091 makeEnv('prof', '.po',
1092 CCFLAGS = Split(ccflags['prof']),
1093 CPPDEFINES = ['NDEBUG', 'TRACING_ON=0'],
1094 LINKFLAGS = Split(ldflags['prof']))
1097 # Optimized binary
1098 if 'opt' in needed_envs:
1099 envList.append(
1100 makeEnv(env, 'opt', '.o',
1101 CCFLAGS = Split(ccflags['opt']),
1102 CPPDEFINES = ['TRACING_ON=1'],
1103 LINKFLAGS = Split(ldflags['opt'])))
1095
1104
1096# Profiled binary using google-pprof
1097if 'perf' in needed_envs:
1098 makeEnv('perf', '.gpo',
1099 CCFLAGS = Split(ccflags['perf']),
1100 CPPDEFINES = ['NDEBUG', 'TRACING_ON=0'],
1101 LINKFLAGS = Split(ldflags['perf']))
1105 # "Fast" binary
1106 if 'fast' in needed_envs:
1107 envList.append(
1108 makeEnv(env, 'fast', '.fo', strip = True,
1109 CCFLAGS = Split(ccflags['fast']),
1110 CPPDEFINES = ['NDEBUG', 'TRACING_ON=0'],
1111 LINKFLAGS = Split(ldflags['fast'])))
1102
1112
1103Return('envList')
1113 # Profiled binary using gprof
1114 if 'prof' in needed_envs:
1115 envList.append(
1116 makeEnv(env, 'prof', '.po',
1117 CCFLAGS = Split(ccflags['prof']),
1118 CPPDEFINES = ['NDEBUG', 'TRACING_ON=0'],
1119 LINKFLAGS = Split(ldflags['prof'])))
1120
1121 # Profiled binary using google-pprof
1122 if 'perf' in needed_envs:
1123 envList.append(
1124 makeEnv(env, 'perf', '.gpo',
1125 CCFLAGS = Split(ccflags['perf']),
1126 CPPDEFINES = ['NDEBUG', 'TRACING_ON=0'],
1127 LINKFLAGS = Split(ldflags['perf'])))
1128
1129 # Set up the regression tests for each build.
1130 for e in envList:
1131 SConscript(os.path.join(gem5_root, 'tests', 'SConscript'),
1132 variant_dir = variantd('tests', e.Label),
1133 exports = { 'env' : e }, duplicate = False)
1134
1135# The MakeEnvirons Builder defers the full dependency collection until
1136# after processing the ISA definition (due to dynamically generated
1137# source files). Add this dependency to all targets so they will wait
1138# until the environments are completely set up. Otherwise, a second
1139# process (e.g. -j2 or higher) will try to compile the requested target,
1140# not know how, and fail.
1141env.Append(BUILDERS = {'MakeEnvirons' :
1142 Builder(action=MakeAction(makeEnvirons,
1143 Transform("ENVIRONS", 1)))})
1144
1145isa_target = env['PHONY_BASE'] + '-deps'
1146environs = env['PHONY_BASE'] + '-environs'
1147env.Depends('#all-deps', isa_target)
1148env.Depends('#all-environs', environs)
1149env.ScanISA(isa_target, File('arch/%s/generated/inc.d' % env['TARGET_ISA']))
1150envSetup = env.MakeEnvirons(environs, isa_target)
1151
1152# make sure no -deps targets occur before all ISAs are complete
1153env.Depends(isa_target, '#all-isas')
1154# likewise for -environs targets and all the -deps targets
1155env.Depends(environs, '#all-deps')