From: Gabe Black Date: Wed, 25 Mar 2020 04:38:28 +0000 (-0700) Subject: util,scons: Generalize the aarch64 scons for the m5 util. X-Git-Tag: v20.0.0.0~194 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=8a46b6b6b4fb432152b60dc07289fcf2d545f909;p=gem5.git util,scons: Generalize the aarch64 scons for the m5 util. Slightly parameterize it so it can be used with the other versions of the utility. All build products for a given variant will now go under build/${VARIANT}. The primary build outputs will go under build/${VARIANT}/out so that they're easy to distinguish. Change-Id: Idd244cc2a6c08ec8e4d67de3d0bae604c0611220 Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/27217 Reviewed-by: Gabe Black Maintainer: Gabe Black Tested-by: Gem5 Cloud Project GCB service account <345032938727@cloudbuild.gserviceaccount.com> Tested-by: kokoro --- diff --git a/util/m5/SConstruct b/util/m5/SConstruct index c1cf193c6..83d46aa44 100644 --- a/util/m5/SConstruct +++ b/util/m5/SConstruct @@ -43,9 +43,6 @@ main.Append(CPPPATH=[ common_include ]) # Propogate the environment's PATH setting. main['ENV']['PATH'] = os.environ['PATH'] -# Cross compiler prefix. -main['CROSS_COMPILE'] = os.environ.get('CROSS_COMPILE', 'aarch64-linux-gnu-') - main['CC'] = '${CROSS_COMPILE}gcc' main['AS'] = '${CROSS_COMPILE}as' main['LD'] = '${CROSS_COMPILE}ld' @@ -62,6 +59,30 @@ main.SConsignFile(os.path.join(abspath(build_dir), 'sconsign')) # Use soft links instead of hard links when setting up a build directory. main.SetOption('duplicate', 'soft-copy') -env = main.Clone() -main.SConscript(src_dir.File('SConscript'), - variant_dir=build_dir, exports='env') +for root, dirs, files in os.walk(abspath(src_dir)): + # Each SConsopts file describes a variant of the m5 utility. + if 'SConsopts' in files: + env = main.Clone() + + # The user may override variant settings by setting environment + # variables of the form ${VARIANT}.${OPTION}. For instance, to set the + # CROSS_COMPILE prefix for variant foo to bar-, the user would set an + # environment variable foo.CROSS_COMPILE=bar-. + # + # This also considers scons command line settings which may look like + # environment variables, but are set after "scons" on the command line. + def get_variant_opt(name, default): + var_name = env.subst('${VARIANT}.%s' % name) + env[name] = os.environ.get( + var_name, ARGUMENTS.get(var_name, default)) + + # Process the variant's settings in the SConsopts file, storing them + # in a copy of the primary environment. + env.SConscript(Dir(root).File('SConsopts'), + exports=[ 'env', 'get_variant_opt' ]) + + # Once all the options have been configured, set up build targets for + # this variant. + variant_dir = build_dir.Dir(env.subst('${VARIANT}')) + env.SConscript(src_dir.File('SConscript'), + variant_dir=variant_dir, exports='env') diff --git a/util/m5/src/SConscript b/util/m5/src/SConscript index 752084199..8c4236397 100644 --- a/util/m5/src/SConscript +++ b/util/m5/src/SConscript @@ -29,7 +29,7 @@ Import('*') # Raw source files. m5_mmap = 'm5_mmap.c' -m5op = 'aarch64/m5op.S' +m5op = '${VARIANT}/m5op.S' m5 = 'm5.c' jni = 'jni_gem5Op.c' lua = 'lua_gem5Op.c' @@ -37,7 +37,7 @@ lua = 'lua_gem5Op.c' # # The m5 library for use in other C/C++ programs. # -libm5 = env.StaticLibrary('m5', [ m5op, m5_mmap ]) +libm5 = env.StaticLibrary('out/m5', [ m5op, m5_mmap ]) # @@ -45,7 +45,7 @@ libm5 = env.StaticLibrary('m5', [ m5op, m5_mmap ]) # m5_bin_env = env.Clone() m5_bin_env.Append(LINKFLAGS=[ '-static' ]) -m5_bin = m5_bin_env.Program('m5', [ m5, m5_mmap, libm5 ]) +m5_bin = m5_bin_env.Program('out/m5', [ m5, m5_mmap, libm5 ]) # The shared version of the m5 op call sights, used by mutliple targets below. @@ -60,13 +60,15 @@ if env['HAVE_JAVA']: # that the javah tool exists. Java has dropped that tool in favor of a -h # option on javac which the Java builder doesn't know how to use. To get # around this, we set up our own builder which does the "right thing" here. - java_env.Command([ 'jni_gem5Op.h', 'gem5OpJni.jar' ], 'jni/gem5Op.java', - [ '${JAVAC} ${JAVACFLAGS} -d ${CWD} ${SOURCES} -h ${CWD}', + java_env.Command([ 'jni_gem5Op.h', 'out/gem5OpJni.jar' ], + 'jni/gem5Op.java', + [ '${JAVAC} ${JAVACFLAGS} -d ${OUT} ${SOURCES} -h ${CWD}', '${JAR} cvf ${TARGETS[1]} ${JNI_DIR}/*.class' ], - JNI_DIR=Dir('jni'), CWD=Dir('.')) + JNI_DIR=Dir('out').Dir('jni'), + OUT=Dir('out'), CWD=Dir('.')) # Set include paths to the C headers from the JDK which scons found for us. java_env.Append(CPPPATH='${JAVAINCLUDES}') - java_env.SharedLibrary('gem5OpJni', [ jni, m5op_shared ]) + java_env.SharedLibrary('out/gem5OpJni', [ jni, m5op_shared ]) if env['HAVE_LUA51']: @@ -76,4 +78,4 @@ if env['HAVE_LUA51']: lua_env = env.Clone() # Extract the include paths needed for lua51 using pkg-config. lua_env.ParseConfig('pkg-config --cflags lua51') - lua_env.SharedLibrary('gem5OpLua', [ lua, m5op_shared, m5_mmap ]) + lib = lua_env.SharedLibrary('out/gem5OpLua', [ lua, m5op_shared, m5_mmap ]) diff --git a/util/m5/src/aarch64/SConsopts b/util/m5/src/aarch64/SConsopts new file mode 100644 index 000000000..12059f81f --- /dev/null +++ b/util/m5/src/aarch64/SConsopts @@ -0,0 +1,29 @@ +# Copyright 2020 Google, Inc. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer; +# redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution; +# neither the name of the copyright holders nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +Import('*') + +env['VARIANT'] = 'aarch64' +get_variant_opt('CROSS_COMPILE', 'aarch64-linux-gnu-')