From dc23a1fb9c20950fea87889026e6793f34b24ee5 Mon Sep 17 00:00:00 2001 From: Gabe Black Date: Tue, 24 Mar 2020 17:41:16 -0700 Subject: [PATCH] util,scons: Detect java and lua51 in the m5 utility scons files. These will enable or disable the java and lua51 m5 op wrappers depending on whether the required tools are available on the host system. Change-Id: I2b11a13a39b2dfd5d45a9ed57702d2e225ef7d2e Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/27214 Maintainer: Bobby R. Bruce Tested-by: kokoro Reviewed-by: Daniel Carvalho --- util/m5/SConstruct | 6 ++++++ util/m5/src/SConscript | 47 +++++++++++++++++++++--------------------- 2 files changed, 30 insertions(+), 23 deletions(-) diff --git a/util/m5/SConstruct b/util/m5/SConstruct index ab341123e..c1cf193c6 100644 --- a/util/m5/SConstruct +++ b/util/m5/SConstruct @@ -51,6 +51,12 @@ main['AS'] = '${CROSS_COMPILE}as' main['LD'] = '${CROSS_COMPILE}ld' main['AR'] = '${CROSS_COMPILE}ar' +# Detect some dependencies of some forms of the m5 utility/library. +main['HAVE_JAVA'] = all(key in main for key in ('JAVAC', 'JAR')) +main['HAVE_PKG_CONFIG'] = main.Detect('pkg-config') is not None +main['HAVE_LUA51'] = (main['HAVE_PKG_CONFIG'] and + os.system('pkg-config --exists lua51') == 0) + # 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. diff --git a/util/m5/src/SConscript b/util/m5/src/SConscript index a3f7a8f67..464da64c5 100644 --- a/util/m5/src/SConscript +++ b/util/m5/src/SConscript @@ -51,28 +51,29 @@ 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 ]) +if env['HAVE_JAVA']: + # + # 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 ]) +if env['HAVE_LUA51']: + # + # 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 ]) -- 2.30.2