SConscript revision 11208
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.comDebugFlag('ProtocolTrace') 4112866Sgabeblack@google.comDebugFlag('RubyCache') 4212866Sgabeblack@google.comDebugFlag('RubyCacheTrace') 4312866Sgabeblack@google.comDebugFlag('RubyDma') 4412866Sgabeblack@google.comDebugFlag('RubyGenerated') 4512866Sgabeblack@google.comDebugFlag('RubyMemory') 4612866Sgabeblack@google.comDebugFlag('RubyNetwork') 4712866Sgabeblack@google.comDebugFlag('RubyPort') 4812866Sgabeblack@google.comDebugFlag('RubyPrefetcher') 4912866Sgabeblack@google.comDebugFlag('RubyQueue') 5012866Sgabeblack@google.comDebugFlag('RubySequencer') 5112866Sgabeblack@google.comDebugFlag('RubySlicc') 5212866Sgabeblack@google.comDebugFlag('RubySystem') 5312866Sgabeblack@google.comDebugFlag('RubyTester') 5412866Sgabeblack@google.comDebugFlag('RubyStats') 5512866Sgabeblack@google.comDebugFlag('RubyResourceStalls') 5612866Sgabeblack@google.com 5712866Sgabeblack@google.comCompoundFlag('Ruby', [ 'RubyQueue', 'RubyNetwork', 'RubyTester', 5812866Sgabeblack@google.com 'RubyGenerated', 'RubySlicc', 'RubySystem', 'RubyCache', 5912866Sgabeblack@google.com 'RubyMemory', 'RubyDma', 'RubyPort', 'RubySequencer', 'RubyCacheTrace', 6012866Sgabeblack@google.com 'RubyPrefetcher']) 6112866Sgabeblack@google.com 6212866Sgabeblack@google.comif env['PROTOCOL'] == 'None': 6312866Sgabeblack@google.com Return() 6412866Sgabeblack@google.com 6512866Sgabeblack@google.comdef do_embed_text(target, source, env): 6612866Sgabeblack@google.com """convert a text file into a file that can be embedded in C 6712866Sgabeblack@google.com using an #include statement, that defines a \"const char *\" pointing 6812866Sgabeblack@google.com to the same text. 6912866Sgabeblack@google.com 7012866Sgabeblack@google.com This is useful to embed scripts and configuration files in object files. 7112866Sgabeblack@google.com """ 7212866Sgabeblack@google.com 7312866Sgabeblack@google.com escape = [ "\'", "\"", "\\", "\?" ] 7412866Sgabeblack@google.com 7512866Sgabeblack@google.com # reads the text file in, line by line, converting it to a C string 7612866Sgabeblack@google.com fin = open(str(source[0]), 'r') 7712866Sgabeblack@google.com fout = open(str(target[0]), 'w' ) 7812866Sgabeblack@google.com fout.write("static const char *%s =\n" % source[1].get_contents()); 7912866Sgabeblack@google.com for l in fin: 8012866Sgabeblack@google.com # add escape sequences for the characters in escape 8112866Sgabeblack@google.com fout.write("\"") 8212866Sgabeblack@google.com for char in l: 8312866Sgabeblack@google.com if char == "\n": 8412866Sgabeblack@google.com break 8512866Sgabeblack@google.com if char in escape: 8612866Sgabeblack@google.com fout.write("\\") 8712866Sgabeblack@google.com fout.write(char) 8812866Sgabeblack@google.com else: 8912866Sgabeblack@google.com fout.write(char) 9012866Sgabeblack@google.com fout.write("\\n\"\n"); 9112866Sgabeblack@google.com fout.write(";\n"); 9212866Sgabeblack@google.com fin.close() 9312866Sgabeblack@google.com fout.close() 9412866Sgabeblack@google.com 9512866Sgabeblack@google.com# 9612866Sgabeblack@google.com# Link includes 9712866Sgabeblack@google.com# 9812866Sgabeblack@google.comgenerated_dir = Dir('../protocol') 9912866Sgabeblack@google.com 10012866Sgabeblack@google.comdef MakeIncludeAction(target, source, env): 10112866Sgabeblack@google.com f = file(str(target[0]), 'w') 10212866Sgabeblack@google.com for s in source: 10312866Sgabeblack@google.com print >>f, '#include "%s"' % str(s.abspath) 10412866Sgabeblack@google.com f.close() 10512866Sgabeblack@google.com 10612866Sgabeblack@google.comdef MakeInclude(source): 10712866Sgabeblack@google.com target = generated_dir.File(basename(source)) 10812866Sgabeblack@google.com include_action = MakeAction(MakeIncludeAction, Transform("MAKE INC", 1)) 10912866Sgabeblack@google.com env.Command(target, source, include_action) 11012866Sgabeblack@google.com 11112866Sgabeblack@google.comMakeInclude('slicc_interface/AbstractEntry.hh') 11212866Sgabeblack@google.comMakeInclude('slicc_interface/AbstractCacheEntry.hh') 11312866Sgabeblack@google.comMakeInclude('slicc_interface/Message.hh') 11412866Sgabeblack@google.comMakeInclude('slicc_interface/RubyRequest.hh') 11512866Sgabeblack@google.com 11612866Sgabeblack@google.com# External types 11712866Sgabeblack@google.comMakeInclude('common/Address.hh') 11812866Sgabeblack@google.comMakeInclude('common/BoolVec.hh') 11912866Sgabeblack@google.comMakeInclude('common/DataBlock.hh') 12012866Sgabeblack@google.comMakeInclude('common/MachineID.hh') 12112866Sgabeblack@google.comMakeInclude('common/NetDest.hh') 12212866Sgabeblack@google.comMakeInclude('common/Set.hh') 12312866Sgabeblack@google.comMakeInclude('filters/AbstractBloomFilter.hh') 12412866Sgabeblack@google.comMakeInclude('network/MessageBuffer.hh') 12512866Sgabeblack@google.comMakeInclude('structures/Prefetcher.hh') 12612866Sgabeblack@google.comMakeInclude('structures/CacheMemory.hh') 12712866Sgabeblack@google.comMakeInclude('system/DMASequencer.hh') 12812866Sgabeblack@google.comMakeInclude('structures/DirectoryMemory.hh') 12912866Sgabeblack@google.comMakeInclude('structures/WireBuffer.hh') 13012866Sgabeblack@google.comMakeInclude('structures/PerfectCacheMemory.hh') 13112866Sgabeblack@google.comMakeInclude('structures/PersistentTable.hh') 13212866Sgabeblack@google.comMakeInclude('system/Sequencer.hh') 13312866Sgabeblack@google.comMakeInclude('structures/TBETable.hh') 13412866Sgabeblack@google.comMakeInclude('structures/TimerTable.hh') 13512866Sgabeblack@google.com