SConscript (6163:92318648212f) SConscript (6168:ba6fe02228db)
1# -*- mode:python -*-
2
3# Copyright (c) 2009 The Hewlett-Packard Development Company
4# All rights reserved.
5#
6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions are
8# met: redistributions of source code must retain the above copyright
9# notice, this list of conditions and the following disclaimer;
10# redistributions in binary form must reproduce the above copyright
11# notice, this list of conditions and the following disclaimer in the
12# documentation and/or other materials provided with the distribution;
13# neither the name of the copyright holders nor the names of its
14# contributors may be used to endorse or promote products derived from
15# this software without specific prior written permission.
16#
17# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28#
29# Authors: Nathan Binkert
30
31import os
32import sys
33
34from os.path import basename, isdir, join as joinpath
35
36import SCons
37
38Import('*')
39
1# -*- mode:python -*-
2
3# Copyright (c) 2009 The Hewlett-Packard Development Company
4# All rights reserved.
5#
6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions are
8# met: redistributions of source code must retain the above copyright
9# notice, this list of conditions and the following disclaimer;
10# redistributions in binary form must reproduce the above copyright
11# notice, this list of conditions and the following disclaimer in the
12# documentation and/or other materials provided with the distribution;
13# neither the name of the copyright holders nor the names of its
14# contributors may be used to endorse or promote products derived from
15# this software without specific prior written permission.
16#
17# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28#
29# Authors: Nathan Binkert
30
31import os
32import sys
33
34from os.path import basename, isdir, join as joinpath
35
36import SCons
37
38Import('*')
39
40if not env['RUBY']:
41 Return()
42
40Source('init.cc')
41
42def do_embed_text(target, source, env):
43 """convert a text file into a file that can be embedded in C
44 using an #include statement, that defines a \"const char *\" pointing
45 to the same text.
46
47 This is useful to embed scripts and configuration files in object files.
48 """
49
50 escape = [ "\'", "\"", "\\", "\?" ]
51
52 # reads the text file in, line by line, converting it to a C string
53 fin = open(str(source[0]), 'r')
54 fout = open(str(target[0]), 'w' )
55 fout.write("static const char *%s =\n" % source[1].get_contents());
56 for l in fin:
57 # add escape sequences for the characters in escape
58 fout.write("\"")
59 for char in l:
60 if char == "\n":
61 break
62 if char in escape:
63 fout.write("\\")
64 fout.write(char)
65 else:
66 fout.write(char)
67 fout.write("\\n\"\n");
68 fout.write(";\n");
69 fin.close()
70 fout.close()
71
72def EmbedText(target, source, param):
73 env.Command(target, [source, Value(param)], do_embed_text)
74
75EmbedText('default_param.hh', 'config/rubyconfig.defaults',
76 'global_default_param')
77EmbedText('tester_param.hh', 'config/tester.defaults',
78 'global_default_tester_param')
79
80#
81# Link includes
82#
83generated_dir = Dir('../protocol')
84
85def MakeIncludeAction(target, source, env):
86 f = file(str(target[0]), 'w')
87 for s in source:
88 print >>f, '#include "%s"' % str(s.abspath)
89 f.close()
90
91def MakeInclude(source):
92 target = generated_dir.File(basename(source))
93 env.Command(target, source, MakeIncludeAction)
94
95MakeInclude('buffers/MessageBuffer.hh')
96MakeInclude('common/Address.hh')
97MakeInclude('common/DataBlock.hh')
98MakeInclude('common/NetDest.hh')
99MakeInclude('common/Set.hh')
100MakeInclude('slicc_interface/AbstractCacheEntry.hh')
101MakeInclude('slicc_interface/AbstractProtocol.hh')
102MakeInclude('slicc_interface/Message.hh')
103MakeInclude('slicc_interface/NetworkMessage.hh')
104MakeInclude('system/CacheMemory.hh')
105MakeInclude('system/DirectoryMemory.hh')
106MakeInclude('system/MachineID.hh')
107MakeInclude('system/MemoryControl.hh')
108MakeInclude('system/NodeID.hh')
109MakeInclude('system/NodePersistentTable.hh')
110MakeInclude('system/PerfectCacheMemory.hh')
111MakeInclude('system/PersistentTable.hh')
112MakeInclude('system/Sequencer.hh')
113MakeInclude('system/StoreBuffer.hh')
114MakeInclude('system/TBETable.hh')
115MakeInclude('system/TimerTable.hh')
43Source('init.cc')
44
45def do_embed_text(target, source, env):
46 """convert a text file into a file that can be embedded in C
47 using an #include statement, that defines a \"const char *\" pointing
48 to the same text.
49
50 This is useful to embed scripts and configuration files in object files.
51 """
52
53 escape = [ "\'", "\"", "\\", "\?" ]
54
55 # reads the text file in, line by line, converting it to a C string
56 fin = open(str(source[0]), 'r')
57 fout = open(str(target[0]), 'w' )
58 fout.write("static const char *%s =\n" % source[1].get_contents());
59 for l in fin:
60 # add escape sequences for the characters in escape
61 fout.write("\"")
62 for char in l:
63 if char == "\n":
64 break
65 if char in escape:
66 fout.write("\\")
67 fout.write(char)
68 else:
69 fout.write(char)
70 fout.write("\\n\"\n");
71 fout.write(";\n");
72 fin.close()
73 fout.close()
74
75def EmbedText(target, source, param):
76 env.Command(target, [source, Value(param)], do_embed_text)
77
78EmbedText('default_param.hh', 'config/rubyconfig.defaults',
79 'global_default_param')
80EmbedText('tester_param.hh', 'config/tester.defaults',
81 'global_default_tester_param')
82
83#
84# Link includes
85#
86generated_dir = Dir('../protocol')
87
88def MakeIncludeAction(target, source, env):
89 f = file(str(target[0]), 'w')
90 for s in source:
91 print >>f, '#include "%s"' % str(s.abspath)
92 f.close()
93
94def MakeInclude(source):
95 target = generated_dir.File(basename(source))
96 env.Command(target, source, MakeIncludeAction)
97
98MakeInclude('buffers/MessageBuffer.hh')
99MakeInclude('common/Address.hh')
100MakeInclude('common/DataBlock.hh')
101MakeInclude('common/NetDest.hh')
102MakeInclude('common/Set.hh')
103MakeInclude('slicc_interface/AbstractCacheEntry.hh')
104MakeInclude('slicc_interface/AbstractProtocol.hh')
105MakeInclude('slicc_interface/Message.hh')
106MakeInclude('slicc_interface/NetworkMessage.hh')
107MakeInclude('system/CacheMemory.hh')
108MakeInclude('system/DirectoryMemory.hh')
109MakeInclude('system/MachineID.hh')
110MakeInclude('system/MemoryControl.hh')
111MakeInclude('system/NodeID.hh')
112MakeInclude('system/NodePersistentTable.hh')
113MakeInclude('system/PerfectCacheMemory.hh')
114MakeInclude('system/PersistentTable.hh')
115MakeInclude('system/Sequencer.hh')
116MakeInclude('system/StoreBuffer.hh')
117MakeInclude('system/TBETable.hh')
118MakeInclude('system/TimerTable.hh')