Gabe Black has submitted this change. ( https://gem5-review.googlesource.com/c/public/gem5/+/27217 )

Change subject: util,scons: Generalize the aarch64 scons for the m5 util.
......................................................................

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 <gabebl...@google.com>
Maintainer: Gabe Black <gabebl...@google.com>
Tested-by: Gem5 Cloud Project GCB service account <345032938...@cloudbuild.gserviceaccount.com>
Tested-by: kokoro <noreply+kok...@google.com>
---
M util/m5/SConstruct
M util/m5/src/SConscript
A util/m5/src/aarch64/SConsopts
3 files changed, 66 insertions(+), 14 deletions(-)

Approvals:
  Gabe Black: Looks good to me, approved; Looks good to me, approved
  kokoro: Regressions pass
  Gem5 Cloud Project GCB service account: Regressions pass



diff --git a/util/m5/SConstruct b/util/m5/SConstruct
index c1cf193..83d46aa 100644
--- a/util/m5/SConstruct
+++ b/util/m5/SConstruct
@@ -43,9 +43,6 @@
 # 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 @@
 # 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 7520841..8c42363 100644
--- a/util/m5/src/SConscript
+++ b/util/m5/src/SConscript
@@ -29,7 +29,7 @@

 # 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 @@
 #
 # 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 @@
 #
 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 @@
# 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 @@
     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 0000000..12059f8
--- /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-')

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/27217
To unsubscribe, or for help writing mail filters, visit https://gem5-review.googlesource.com/settings

Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: Idd244cc2a6c08ec8e4d67de3d0bae604c0611220
Gerrit-Change-Number: 27217
Gerrit-PatchSet: 8
Gerrit-Owner: Gabe Black <gabebl...@google.com>
Gerrit-Reviewer: Bobby R. Bruce <bbr...@ucdavis.edu>
Gerrit-Reviewer: Daniel Carvalho <oda...@yahoo.com.br>
Gerrit-Reviewer: Earl Ou <shunhsin...@google.com>
Gerrit-Reviewer: Gabe Black <gabebl...@google.com>
Gerrit-Reviewer: Gem5 Cloud Project GCB service account <345032938...@cloudbuild.gserviceaccount.com>
Gerrit-Reviewer: Giacomo Travaglini <giacomo.travagl...@arm.com>
Gerrit-Reviewer: Jason Lowe-Power <power...@gmail.com>
Gerrit-Reviewer: Yu-hsin Wang <yuhsi...@google.com>
Gerrit-Reviewer: kokoro <noreply+kok...@google.com>
Gerrit-MessageType: merged
_______________________________________________
gem5-dev mailing list
gem5-dev@gem5.org
http://m5sim.org/mailman/listinfo/gem5-dev

Reply via email to