SConscript revision 6157
112866Sgabeblack@google.com# -*- mode:python -*-
212866Sgabeblack@google.com
312866Sgabeblack@google.com# Copyright (c) 2009 The Hewlett-Packard Development Company
412866Sgabeblack@google.com# All rights reserved.
512866Sgabeblack@google.com#
612866Sgabeblack@google.com# Redistribution and use in source and binary forms, with or without
712866Sgabeblack@google.com# modification, are permitted provided that the following conditions are
812866Sgabeblack@google.com# met: redistributions of source code must retain the above copyright
912866Sgabeblack@google.com# notice, this list of conditions and the following disclaimer;
1012866Sgabeblack@google.com# redistributions in binary form must reproduce the above copyright
1112866Sgabeblack@google.com# notice, this list of conditions and the following disclaimer in the
1212866Sgabeblack@google.com# documentation and/or other materials provided with the distribution;
1312866Sgabeblack@google.com# neither the name of the copyright holders nor the names of its
1412866Sgabeblack@google.com# contributors may be used to endorse or promote products derived from
1512866Sgabeblack@google.com# this software without specific prior written permission.
1612866Sgabeblack@google.com#
1712866Sgabeblack@google.com# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1812866Sgabeblack@google.com# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1912866Sgabeblack@google.com# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
2012866Sgabeblack@google.com# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2112866Sgabeblack@google.com# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2212866Sgabeblack@google.com# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2312866Sgabeblack@google.com# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2412866Sgabeblack@google.com# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2512866Sgabeblack@google.com# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2612866Sgabeblack@google.com# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2712866Sgabeblack@google.com# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2812866Sgabeblack@google.com#
2912866Sgabeblack@google.com# Authors: Nathan Binkert
3012866Sgabeblack@google.com
3112866Sgabeblack@google.comimport os
3212866Sgabeblack@google.comimport sys
3312866Sgabeblack@google.com
3412866Sgabeblack@google.comfrom os.path import basename, isdir, join as joinpath
3512866Sgabeblack@google.com
3612866Sgabeblack@google.comimport SCons
3712866Sgabeblack@google.com
3812866Sgabeblack@google.comImport('*')
3912866Sgabeblack@google.com
4012866Sgabeblack@google.comSource('init.cc')
4112866Sgabeblack@google.com
4212866Sgabeblack@google.comdef do_embed_text(target, source, env):
4312866Sgabeblack@google.com    """convert a text file into a file that can be embedded in C
4412866Sgabeblack@google.com    using an #include statement, that defines a \"const char *\" pointing
4512866Sgabeblack@google.com    to the same text.
4612866Sgabeblack@google.com
4712866Sgabeblack@google.com    This is useful to embed scripts and configuration files in object files.
4812866Sgabeblack@google.com    """
4912866Sgabeblack@google.com
5012866Sgabeblack@google.com    escape = [ "\'", "\"", "\\", "\?" ]
5112866Sgabeblack@google.com
5212866Sgabeblack@google.com    # reads the text file in, line by line, converting it to a C string
5312866Sgabeblack@google.com    fin = open(str(source[0]), 'r')
5412866Sgabeblack@google.com    fout = open(str(target[0]), 'w' )
5512866Sgabeblack@google.com    fout.write("static const char *%s =\n" % source[1].get_contents());
5612866Sgabeblack@google.com    for l in fin:
5712866Sgabeblack@google.com        # add escape sequences for the characters in escape
5812866Sgabeblack@google.com        fout.write("\"")
5912866Sgabeblack@google.com        for char in l:
6012866Sgabeblack@google.com            if char == "\n":
6112866Sgabeblack@google.com                break
6212866Sgabeblack@google.com            if char in escape:
6312866Sgabeblack@google.com                fout.write("\\")
6412866Sgabeblack@google.com                fout.write(char)
6512869Sgabeblack@google.com            else:
6612866Sgabeblack@google.com                fout.write(char)
6712869Sgabeblack@google.com        fout.write("\\n\"\n");
6812866Sgabeblack@google.com    fout.write(";\n");
6912866Sgabeblack@google.com    fin.close()
7012866Sgabeblack@google.com    fout.close()
7112866Sgabeblack@google.com
7212866Sgabeblack@google.comdef EmbedText(target, source, param):
7312866Sgabeblack@google.com    env.Command(target, [source, Value(param)], do_embed_text)
7412866Sgabeblack@google.com
7512866Sgabeblack@google.comEmbedText('default_param.hh', 'config/rubyconfig.defaults',
7612866Sgabeblack@google.com          'global_default_param')
7712866Sgabeblack@google.comEmbedText('tester_param.hh', 'config/tester.defaults',
7812866Sgabeblack@google.com          'global_default_tester_param')
7912866Sgabeblack@google.com
8012866Sgabeblack@google.com#
8112866Sgabeblack@google.com# Link includes
8212869Sgabeblack@google.com#
8312869Sgabeblack@google.comgenerated_dir = Dir('../protocol')
8412869Sgabeblack@google.com
8512869Sgabeblack@google.comdef MakeIncludeAction(target, source, env):
8612869Sgabeblack@google.com    f = file(str(target[0]), 'w')
8712869Sgabeblack@google.com    for s in source:
8812869Sgabeblack@google.com        print >>f, '#include "%s"' % str(s.abspath)
8912869Sgabeblack@google.com    f.close()
9012866Sgabeblack@google.com
9112866Sgabeblack@google.comdef MakeInclude(source):
9212866Sgabeblack@google.com    target = generated_dir.File(basename(source))
9312866Sgabeblack@google.com    env.Command(target, source, MakeIncludeAction)
9412866Sgabeblack@google.com
9512866Sgabeblack@google.comMakeInclude('buffers/MessageBuffer.hh')
9612866Sgabeblack@google.comMakeInclude('common/Address.hh')
9712866Sgabeblack@google.comMakeInclude('common/DataBlock.hh')
9812866Sgabeblack@google.comMakeInclude('common/NetDest.hh')
9912866Sgabeblack@google.comMakeInclude('common/Set.hh')
10012866Sgabeblack@google.comMakeInclude('slicc_interface/AbstractCacheEntry.hh')
10112866Sgabeblack@google.comMakeInclude('slicc_interface/AbstractProtocol.hh')
10212866Sgabeblack@google.comMakeInclude('slicc_interface/Message.hh')
10312866Sgabeblack@google.comMakeInclude('slicc_interface/NetworkMessage.hh')
10412866Sgabeblack@google.comMakeInclude('system/CacheMemory.hh')
10512866Sgabeblack@google.comMakeInclude('system/DirectoryMemory.hh')
10612866Sgabeblack@google.comMakeInclude('system/GenericBloomFilter.hh')
10712866Sgabeblack@google.comMakeInclude('system/MachineID.hh')
10812866Sgabeblack@google.comMakeInclude('system/MemoryControl.hh')
10912866Sgabeblack@google.comMakeInclude('system/NodeID.hh')
11012866Sgabeblack@google.comMakeInclude('system/NodePersistentTable.hh')
11112866Sgabeblack@google.comMakeInclude('system/PerfectCacheMemory.hh')
11212866Sgabeblack@google.comMakeInclude('system/PersistentTable.hh')
11312866Sgabeblack@google.comMakeInclude('system/Sequencer.hh')
11412866Sgabeblack@google.comMakeInclude('system/StoreBuffer.hh')
11512866Sgabeblack@google.comMakeInclude('system/TBETable.hh')
11612866Sgabeblack@google.comMakeInclude('system/TimerTable.hh')
11712866Sgabeblack@google.com