cb0c61db466d93c2e3376c6f227aeead49b05926
[gem5.git] / ext / systemc / SConscript
1 # Copyright (c) 2017, TU Dresden
2 # Copyright (c) 2017, University of Kaiserslautern
3 # All rights reserved.
4
5 # Permission is hereby granted, free of charge, to any person obtaining a copy
6 # of this software and associated documentation files (the "Software"), to deal
7 # in the Software without restriction, including without limitation the rights
8 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 # copies of the Software, and to permit persons to whom the Software is
10 # furnished to do so, subject to the following conditions:
11 #
12 # The above copyright notice and this permission notice shall be included in
13 # all copies or substantial portions of the Software.
14 #
15 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 # SOFTWARE.
22 #
23 # Authors: Christian Menard
24 # Matthias Jung
25
26 from __future__ import print_function
27
28 import os
29 from m5.util.terminal import get_termcap
30
31 Import('main')
32 systemc = main.Clone()
33
34 build_root = Dir('.').abspath
35 src_root = Dir('.').srcdir.abspath
36
37 systemc.Prepend(CPPPATH=Dir('./src'))
38 systemc.Prepend(CPATH=Dir('./src'))
39
40 systemc.Prepend(CXXFLAGS=['-DSC_INCLUDE_FX'])
41 systemc.Prepend(CFLAGS=['-DSC_INCLUDE_FX'])
42
43 conf = Configure(systemc,
44 conf_dir = os.path.join(build_root, '.scons_config'),
45 log_file = os.path.join(build_root, 'scons_config.log'))
46
47 if systemc['PLATFORM'] == 'darwin':
48 systemc.Append(LINKFLAGS=['-undefined', 'dynamic_lookup'])
49
50 arch = None
51 systemc['COROUTINE_LIB'] = ''
52 if conf.CheckDeclaration('__i386__'):
53 systemc['COROUTINE_LIB'] = 'qt'
54 systemc['QT_ARCH'] = 'i386'
55 arch = 'i386'
56 elif conf.CheckDeclaration('__x86_64__'):
57 systemc['COROUTINE_LIB'] = 'qt'
58 systemc['QT_ARCH'] = 'iX86_64'
59 arch = 'x86_64'
60 else:
61 termcap = get_termcap(GetOption('use_colors'))
62 print(termcap.Yellow + termcap.Bold +
63 "Warning: Unrecognized architecture for systemc." + termcap.Normal)
64
65 conf.Finish()
66
67 if systemc['COROUTINE_LIB'] == 'pthreads':
68 systemc.Prepend(CXXFLAGS=['-DSC_USE_PTHREADS'])
69
70 systemc_files = []
71 def SystemCSource(*args):
72 for arg in args:
73 systemc_files.append(systemc.File(arg))
74
75 if arch:
76 for root, dirs, files in os.walk(src_root):
77 if 'SConscript.sc' in files:
78 build_dir = os.path.relpath(root, src_root)
79 systemc.SConscript(os.path.join(root, 'SConscript.sc'),
80 exports=['systemc', 'SystemCSource'],
81 variant_dir=os.path.join(build_root, build_dir))
82
83 systemc.Library('libsystemc', systemc_files)
84 systemc.SharedLibrary('libsystemc', systemc_files)
85