util: Add a "writefile" unit test to the m5 utility.
[gem5.git] / util / m5 / src / SConscript
1 # Copyright 2020 Google, Inc.
2 #
3 # Redistribution and use in source and binary forms, with or without
4 # modification, are permitted provided that the following conditions are
5 # met: redistributions of source code must retain the above copyright
6 # notice, this list of conditions and the following disclaimer;
7 # redistributions in binary form must reproduce the above copyright
8 # notice, this list of conditions and the following disclaimer in the
9 # documentation and/or other materials provided with the distribution;
10 # neither the name of the copyright holders nor the names of its
11 # contributors may be used to endorse or promote products derived from
12 # this software without specific prior written permission.
13 #
14 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
15 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
16 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
17 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
18 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
19 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
20 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25
26 import os
27
28 Import('*')
29
30 env.Append(CPPPATH=Dir('.'))
31
32 # Raw source files.
33 args = 'args.cc'
34 call_type = 'call_type.cc'
35 command = 'command.cc'
36 m5 = 'm5.cc'
37 m5_mmap = 'm5_mmap.c'
38 usage = 'usage.cc'
39
40 jni = 'jni_gem5Op.c'
41 lua = 'lua_gem5Op.cc'
42
43 all_call_types = list(env['CALL_TYPE'].values())
44 call_types = list([ ct for ct in all_call_types if ct.enabled ])
45 m5ops = list([ 'abi/${ABI}/%s' % ct.impl_file for ct in call_types ])
46
47 default_call_type = list([ ct for ct in call_types if ct.default ])
48 assert len(default_call_type) == 1, \
49 'There should be exactly one default call type for %s, found %d' % \
50 (env['ABI'], len(default_call_type))
51 default_call_type = default_call_type[0]
52
53 static_env = env.Clone()
54 static_env.Append(LINKFLAGS=[ '-no-pie', '-static' ])
55
56 #
57 # The m5 library for use in other C/C++ programs.
58 #
59 libm5 = static_env.StaticLibrary('out/m5', [ m5_mmap ] + m5ops)
60
61 commands = env.SConscript('command/SConscript', exports={ "env": static_env })
62
63 #
64 # The m5 stand alone command line utility.
65 #
66 ct_support = []
67 for ct in call_types:
68 ct_env = static_env.Clone()
69 is_default = 'true' if ct.default else 'false'
70 ct_env.Append(CXXFLAGS=[ '-DCALL_TYPE_IS_DEFAULT=%s' % is_default ])
71 ct_support.extend(ct_env.StaticObject('call_type/%s.cc' % ct.name))
72 m5_bin = static_env.Program('out/m5', ct_support +
73 [ args, call_type, command, commands, m5, m5_mmap, libm5, usage ])
74
75
76 # The shared version of the m5 op call sights, used by mutliple targets below.
77 shared_env = env.Clone()
78 shared_env.Append(ASFLAGS='-DM5OP_PIC')
79 m5op_shared = shared_env.SharedObject(m5ops)
80
81 if env['HAVE_JAVA']:
82 #
83 # A wrapper to make the m5 ops available in Java through the JNI.
84 #
85 java_env = shared_env.Clone()
86 # SCons provides Java and JavaH builders, but the JavaH builder assumes
87 # that the javah tool exists. Java has dropped that tool in favor of a -h
88 # option on javac which the Java builder doesn't know how to use. To get
89 # around this, we set up our own builder which does the "right thing" here.
90 java_env.Command([ 'jni_gem5Op.h', 'out/gem5OpJni.jar' ],
91 'jni/gem5Op.java',
92 [ '${JAVAC} ${JAVACFLAGS} -d ${OUT} ${SOURCES} -h ${CWD}',
93 '${JAR} cvf ${TARGETS[1]} ${JNI_DIR}/*.class' ],
94 JNI_DIR=Dir('out').Dir('jni'),
95 OUT=Dir('out'), CWD=Dir('.'))
96 # Set include paths to the C headers from the JDK which scons found for us.
97 java_env.Append(CPPPATH='${JAVAINCLUDES}')
98 java_env.SharedLibrary('out/gem5OpJni', [ jni ] + m5op_shared)
99
100
101 if env['HAVE_LUA51']:
102 #
103 # A wrapper to make the m5 ops available in lua version 5.1.
104 #
105 lua_env = shared_env.Clone()
106 # Extract the include paths needed for lua51 using pkg-config.
107 lua_env.ParseConfig('pkg-config --cflags lua51')
108 lib = lua_env.SharedLibrary('out/gem5OpLua',
109 [ lua, m5_mmap ] + m5op_shared)