SConscript revision 8483
14762Snate@binkert.org# -*- mode:python -*- 24762Snate@binkert.org 34762Snate@binkert.org# Copyright (c) 2009 The Hewlett-Packard Development Company 44762Snate@binkert.org# All rights reserved. 54762Snate@binkert.org# 64762Snate@binkert.org# Redistribution and use in source and binary forms, with or without 74762Snate@binkert.org# modification, are permitted provided that the following conditions are 84762Snate@binkert.org# met: redistributions of source code must retain the above copyright 94762Snate@binkert.org# notice, this list of conditions and the following disclaimer; 104762Snate@binkert.org# redistributions in binary form must reproduce the above copyright 114762Snate@binkert.org# notice, this list of conditions and the following disclaimer in the 124762Snate@binkert.org# documentation and/or other materials provided with the distribution; 134762Snate@binkert.org# neither the name of the copyright holders nor the names of its 144762Snate@binkert.org# contributors may be used to endorse or promote products derived from 154762Snate@binkert.org# this software without specific prior written permission. 164762Snate@binkert.org# 174762Snate@binkert.org# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 184762Snate@binkert.org# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 194762Snate@binkert.org# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 204762Snate@binkert.org# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 214762Snate@binkert.org# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 224762Snate@binkert.org# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 234762Snate@binkert.org# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 244762Snate@binkert.org# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 254762Snate@binkert.org# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 264762Snate@binkert.org# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 274762Snate@binkert.org# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 284762Snate@binkert.org# 294762Snate@binkert.org# Authors: Nathan Binkert 304762Snate@binkert.org 314762Snate@binkert.orgimport os 324762Snate@binkert.orgimport sys 334762Snate@binkert.org 344762Snate@binkert.orgfrom os.path import basename, isdir, join as joinpath 35 36import SCons 37 38Import('*') 39 40if env['TARGET_ISA'] == 'no': 41 Return() 42 43if not env['RUBY']: 44 Return() 45 46def do_embed_text(target, source, env): 47 """convert a text file into a file that can be embedded in C 48 using an #include statement, that defines a \"const char *\" pointing 49 to the same text. 50 51 This is useful to embed scripts and configuration files in object files. 52 """ 53 54 escape = [ "\'", "\"", "\\", "\?" ] 55 56 # reads the text file in, line by line, converting it to a C string 57 fin = open(str(source[0]), 'r') 58 fout = open(str(target[0]), 'w' ) 59 fout.write("static const char *%s =\n" % source[1].get_contents()); 60 for l in fin: 61 # add escape sequences for the characters in escape 62 fout.write("\"") 63 for char in l: 64 if char == "\n": 65 break 66 if char in escape: 67 fout.write("\\") 68 fout.write(char) 69 else: 70 fout.write(char) 71 fout.write("\\n\"\n"); 72 fout.write(";\n"); 73 fin.close() 74 fout.close() 75 76# 77# Link includes 78# 79generated_dir = Dir('../protocol') 80 81def MakeIncludeAction(target, source, env): 82 f = file(str(target[0]), 'w') 83 for s in source: 84 print >>f, '#include "%s"' % str(s.abspath) 85 f.close() 86 87def MakeInclude(source): 88 target = generated_dir.File(basename(source)) 89 include_action = MakeAction(MakeIncludeAction, Transform("MAKE INC", 1)) 90 env.Command(target, source, include_action) 91 92MakeInclude('slicc_interface/AbstractEntry.hh') 93MakeInclude('slicc_interface/AbstractCacheEntry.hh') 94MakeInclude('slicc_interface/AbstractProtocol.hh') 95MakeInclude('slicc_interface/Message.hh') 96MakeInclude('slicc_interface/NetworkMessage.hh') 97MakeInclude('slicc_interface/RubyRequest.hh') 98 99# External types 100MakeInclude('buffers/MessageBuffer.hh') 101MakeInclude('common/Address.hh') 102MakeInclude('common/DataBlock.hh') 103MakeInclude('common/NetDest.hh') 104MakeInclude('common/Set.hh') 105MakeInclude('filters/GenericBloomFilter.hh') 106MakeInclude('system/CacheMemory.hh') 107MakeInclude('system/DMASequencer.hh') 108MakeInclude('system/DirectoryMemory.hh') 109MakeInclude('system/MachineID.hh') 110MakeInclude('system/MemoryControl.hh') 111MakeInclude('system/WireBuffer.hh') 112MakeInclude('system/NodeID.hh') 113MakeInclude('system/PerfectCacheMemory.hh') 114MakeInclude('system/PersistentTable.hh') 115MakeInclude('system/Sequencer.hh') 116MakeInclude('system/TBETable.hh') 117MakeInclude('system/TimerTable.hh') 118