SConscript revision 9016
16145Snate@binkert.org# -*- mode:python -*-
26145Snate@binkert.org
36145Snate@binkert.org# Copyright (c) 2009 The Hewlett-Packard Development Company
46145Snate@binkert.org# All rights reserved.
56145Snate@binkert.org#
66145Snate@binkert.org# Redistribution and use in source and binary forms, with or without
76145Snate@binkert.org# modification, are permitted provided that the following conditions are
86145Snate@binkert.org# met: redistributions of source code must retain the above copyright
96145Snate@binkert.org# notice, this list of conditions and the following disclaimer;
106145Snate@binkert.org# redistributions in binary form must reproduce the above copyright
116145Snate@binkert.org# notice, this list of conditions and the following disclaimer in the
126145Snate@binkert.org# documentation and/or other materials provided with the distribution;
136145Snate@binkert.org# neither the name of the copyright holders nor the names of its
146145Snate@binkert.org# contributors may be used to endorse or promote products derived from
156145Snate@binkert.org# this software without specific prior written permission.
166145Snate@binkert.org#
176145Snate@binkert.org# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
186145Snate@binkert.org# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
196145Snate@binkert.org# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
206145Snate@binkert.org# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
216145Snate@binkert.org# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
226145Snate@binkert.org# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
236145Snate@binkert.org# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
246145Snate@binkert.org# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
256145Snate@binkert.org# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
266145Snate@binkert.org# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
276145Snate@binkert.org# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
286145Snate@binkert.org#
297039Snate@binkert.org# Authors: Nathan Binkert
307039Snate@binkert.org
316145Snate@binkert.orgimport os
327039Snate@binkert.orgimport sys
337039Snate@binkert.org
3410301Snilay@cs.wisc.edufrom os.path import basename, isdir, join as joinpath
357039Snate@binkert.org
3610301Snilay@cs.wisc.eduimport SCons
376145Snate@binkert.org
386145Snate@binkert.orgImport('*')
396145Snate@binkert.org
407039Snate@binkert.orgif env['TARGET_ISA'] == 'no':
4111025Snilay@cs.wisc.edu    Return()
426145Snate@binkert.org
437039Snate@binkert.orgif env['PROTOCOL'] == 'None':
446145Snate@binkert.org    Return()
456145Snate@binkert.org
4611308Santhony.gutierrez@amd.comdef do_embed_text(target, source, env):
4711308Santhony.gutierrez@amd.com    """convert a text file into a file that can be embedded in C
4811308Santhony.gutierrez@amd.com    using an #include statement, that defines a \"const char *\" pointing
4911308Santhony.gutierrez@amd.com    to the same text.
5011308Santhony.gutierrez@amd.com
5111308Santhony.gutierrez@amd.com    This is useful to embed scripts and configuration files in object files.
526145Snate@binkert.org    """
536145Snate@binkert.org
547039Snate@binkert.org    escape = [ "\'", "\"", "\\", "\?" ]
5511025Snilay@cs.wisc.edu
566145Snate@binkert.org    # reads the text file in, line by line, converting it to a C string
577039Snate@binkert.org    fin = open(str(source[0]), 'r')
587039Snate@binkert.org    fout = open(str(target[0]), 'w' )
597039Snate@binkert.org    fout.write("static const char *%s =\n" % source[1].get_contents());
606145Snate@binkert.org    for l in fin:
616145Snate@binkert.org        # add escape sequences for the characters in escape
6211308Santhony.gutierrez@amd.com        fout.write("\"")
6311308Santhony.gutierrez@amd.com        for char in l:
6411308Santhony.gutierrez@amd.com            if char == "\n":
6511308Santhony.gutierrez@amd.com                break
6611308Santhony.gutierrez@amd.com            if char in escape:
6711308Santhony.gutierrez@amd.com                fout.write("\\")
6811308Santhony.gutierrez@amd.com                fout.write(char)
6911308Santhony.gutierrez@amd.com            else:
7011308Santhony.gutierrez@amd.com                fout.write(char)
7111308Santhony.gutierrez@amd.com        fout.write("\\n\"\n");
7211308Santhony.gutierrez@amd.com    fout.write(";\n");
7311308Santhony.gutierrez@amd.com    fin.close()
7411308Santhony.gutierrez@amd.com    fout.close()
7511308Santhony.gutierrez@amd.com
7611308Santhony.gutierrez@amd.com#
7711308Santhony.gutierrez@amd.com# Link includes
787039Snate@binkert.org#
797039Snate@binkert.orggenerated_dir = Dir('../protocol')
806843Sdrh5@cs.wisc.edu
817039Snate@binkert.orgdef MakeIncludeAction(target, source, env):
8210005Snilay@cs.wisc.edu    f = file(str(target[0]), 'w')
837039Snate@binkert.org    for s in source:
847039Snate@binkert.org        print >>f, '#include "%s"' % str(s.abspath)
857039Snate@binkert.org    f.close()
867039Snate@binkert.org
876843Sdrh5@cs.wisc.edudef MakeInclude(source):
886843Sdrh5@cs.wisc.edu    target = generated_dir.File(basename(source))
897039Snate@binkert.org    include_action = MakeAction(MakeIncludeAction, Transform("MAKE INC", 1))
9011025Snilay@cs.wisc.edu    env.Command(target, source, include_action)
9110005Snilay@cs.wisc.edu
926467Sdrh5@cs.wisc.eduMakeInclude('slicc_interface/AbstractEntry.hh')
937039Snate@binkert.orgMakeInclude('slicc_interface/AbstractCacheEntry.hh')
947039Snate@binkert.orgMakeInclude('slicc_interface/AbstractProtocol.hh')
9510005Snilay@cs.wisc.eduMakeInclude('slicc_interface/Message.hh')
9610005Snilay@cs.wisc.eduMakeInclude('slicc_interface/NetworkMessage.hh')
9711025Snilay@cs.wisc.eduMakeInclude('slicc_interface/RubyRequest.hh')
9810005Snilay@cs.wisc.edu
996468Sdrh5@cs.wisc.edu# External types
1006467Sdrh5@cs.wisc.eduMakeInclude('buffers/MessageBuffer.hh')
1016467Sdrh5@cs.wisc.eduMakeInclude('common/Address.hh')
1027039Snate@binkert.orgMakeInclude('common/DataBlock.hh')
1037039Snate@binkert.orgMakeInclude('common/NetDest.hh')
1046145Snate@binkert.orgMakeInclude('common/Set.hh')
1057039Snate@binkert.orgMakeInclude('filters/GenericBloomFilter.hh')
1066145Snate@binkert.orgMakeInclude('system/CacheMemory.hh')
1076145Snate@binkert.orgMakeInclude('system/DMASequencer.hh')
1087039Snate@binkert.orgMakeInclude('system/DirectoryMemory.hh')
1097039Snate@binkert.orgMakeInclude('system/MachineID.hh')
1106145Snate@binkert.orgMakeInclude('system/MemoryControl.hh')
1117039Snate@binkert.orgMakeInclude('system/WireBuffer.hh')
1126145Snate@binkert.orgMakeInclude('system/PerfectCacheMemory.hh')
1136145Snate@binkert.orgMakeInclude('system/PersistentTable.hh')
1147039Snate@binkert.orgMakeInclude('system/Sequencer.hh')
1157039Snate@binkert.orgMakeInclude('system/TBETable.hh')
1167039Snate@binkert.orgMakeInclude('system/TimerTable.hh')
1176926SBrad.Beckmann@amd.com