--- /dev/null
+# 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 os
+
+main = Environment()
+
+# Includes which are shared with gem5 itself.
+common_include = Dir('..').Dir('..').Dir('include')
+
+src_dir = Dir('src')
+build_dir = Dir('build')
+
+def abspath(d):
+ return os.path.abspath(str(d))
+
+# Universal settings.
+main.Append(CCFLAGS=[ '-O2' ])
+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'
+main['AR'] = '${CROSS_COMPILE}ar'
+
+# Put the sconsign file in the build dir so everything can be deleted at once.
+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')
--- /dev/null
+# 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 os
+
+Import('*')
+
+# Raw source files.
+m5_mmap = 'm5_mmap.c'
+m5op = 'm5op_arm_A64.S'
+m5 = 'm5.c'
+jni = 'jni_gem5Op.c'
+lua = 'lua_gem5Op.c'
+
+#
+# The m5 library for use in other C/C++ programs.
+#
+libm5 = env.StaticLibrary('m5', [ m5op, m5_mmap ])
+
+
+#
+# The m5 stand alone command line utility.
+#
+m5_bin_env = env.Clone()
+m5_bin_env.Append(LINKFLAGS=[ '-static' ])
+m5_bin = m5_bin_env.Program('m5', [ m5, m5_mmap, libm5 ])
+
+
+# The shared version of the m5 op call sights, used by mutliple targets below.
+m5op_shared = env.SharedObject(m5op)
+
+
+#
+# A wrapper to make the m5 ops available in Java through the JNI.
+#
+java_env = env.Clone()
+# SCons provides Java and JavaH builders, but the JavaH builder assumes 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} ',
+ '${JAR} cvf ${TARGETS[1]} ${JNI_DIR}/*.class' ],
+ JNI_DIR=Dir('jni'), 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 ])
+
+
+#
+# A wrapper to make the m5 ops available in lua version 5.1.
+#
+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 ])