SConscript revision 6157
1955SN/A# -*- mode:python -*- 2955SN/A 31762SN/A# Copyright (c) 2009 The Hewlett-Packard Development Company 4955SN/A# All rights reserved. 5955SN/A# 6955SN/A# Redistribution and use in source and binary forms, with or without 7955SN/A# modification, are permitted provided that the following conditions are 8955SN/A# met: redistributions of source code must retain the above copyright 9955SN/A# notice, this list of conditions and the following disclaimer; 10955SN/A# redistributions in binary form must reproduce the above copyright 11955SN/A# notice, this list of conditions and the following disclaimer in the 12955SN/A# documentation and/or other materials provided with the distribution; 13955SN/A# neither the name of the copyright holders nor the names of its 14955SN/A# contributors may be used to endorse or promote products derived from 15955SN/A# this software without specific prior written permission. 16955SN/A# 17955SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18955SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19955SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20955SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21955SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22955SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23955SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24955SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25955SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26955SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27955SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 282665Ssaidi@eecs.umich.edu# 294762Snate@binkert.org# Authors: Nathan Binkert 30955SN/A 315522Snate@binkert.orgimport os 326143Snate@binkert.orgimport sys 334762Snate@binkert.org 345522Snate@binkert.orgfrom os.path import basename, isdir, join as joinpath 35955SN/A 365522Snate@binkert.orgimport SCons 37955SN/A 385522Snate@binkert.orgImport('*') 394202Sbinkertn@umich.edu 405742Snate@binkert.orgSource('init.cc') 41955SN/A 424381Sbinkertn@umich.edudef do_embed_text(target, source, env): 434381Sbinkertn@umich.edu """convert a text file into a file that can be embedded in C 44955SN/A using an #include statement, that defines a \"const char *\" pointing 45955SN/A to the same text. 46955SN/A 474202Sbinkertn@umich.edu This is useful to embed scripts and configuration files in object files. 48955SN/A """ 494382Sbinkertn@umich.edu 504382Sbinkertn@umich.edu escape = [ "\'", "\"", "\\", "\?" ] 514382Sbinkertn@umich.edu 526108Snate@binkert.org # reads the text file in, line by line, converting it to a C string 535517Snate@binkert.org fin = open(str(source[0]), 'r') 546143Snate@binkert.org fout = open(str(target[0]), 'w' ) 556143Snate@binkert.org fout.write("static const char *%s =\n" % source[1].get_contents()); 566143Snate@binkert.org for l in fin: 576143Snate@binkert.org # add escape sequences for the characters in escape 586143Snate@binkert.org fout.write("\"") 596143Snate@binkert.org for char in l: 606143Snate@binkert.org if char == "\n": 616143Snate@binkert.org break 626143Snate@binkert.org if char in escape: 636143Snate@binkert.org fout.write("\\") 646143Snate@binkert.org fout.write(char) 656143Snate@binkert.org else: 666143Snate@binkert.org fout.write(char) 676143Snate@binkert.org fout.write("\\n\"\n"); 686143Snate@binkert.org fout.write(";\n"); 694762Snate@binkert.org fin.close() 706143Snate@binkert.org fout.close() 716143Snate@binkert.org 726143Snate@binkert.orgdef EmbedText(target, source, param): 736143Snate@binkert.org env.Command(target, [source, Value(param)], do_embed_text) 746143Snate@binkert.org 756143Snate@binkert.orgEmbedText('default_param.hh', 'config/rubyconfig.defaults', 766143Snate@binkert.org 'global_default_param') 776143Snate@binkert.orgEmbedText('tester_param.hh', 'config/tester.defaults', 786143Snate@binkert.org 'global_default_tester_param') 796143Snate@binkert.org 806143Snate@binkert.org# 816143Snate@binkert.org# Link includes 826143Snate@binkert.org# 836143Snate@binkert.orggenerated_dir = Dir('../protocol') 846143Snate@binkert.org 856143Snate@binkert.orgdef MakeIncludeAction(target, source, env): 866143Snate@binkert.org f = file(str(target[0]), 'w') 876143Snate@binkert.org for s in source: 886143Snate@binkert.org print >>f, '#include "%s"' % str(s.abspath) 896143Snate@binkert.org f.close() 906143Snate@binkert.org 916143Snate@binkert.orgdef MakeInclude(source): 926143Snate@binkert.org target = generated_dir.File(basename(source)) 936143Snate@binkert.org env.Command(target, source, MakeIncludeAction) 946143Snate@binkert.org 956143Snate@binkert.orgMakeInclude('buffers/MessageBuffer.hh') 966143Snate@binkert.orgMakeInclude('common/Address.hh') 976143Snate@binkert.orgMakeInclude('common/DataBlock.hh') 986143Snate@binkert.orgMakeInclude('common/NetDest.hh') 996143Snate@binkert.orgMakeInclude('common/Set.hh') 1006143Snate@binkert.orgMakeInclude('slicc_interface/AbstractCacheEntry.hh') 1016143Snate@binkert.orgMakeInclude('slicc_interface/AbstractProtocol.hh') 1026143Snate@binkert.orgMakeInclude('slicc_interface/Message.hh') 1036143Snate@binkert.orgMakeInclude('slicc_interface/NetworkMessage.hh') 1046143Snate@binkert.orgMakeInclude('system/CacheMemory.hh') 1056143Snate@binkert.orgMakeInclude('system/DirectoryMemory.hh') 1066143Snate@binkert.orgMakeInclude('system/GenericBloomFilter.hh') 1076143Snate@binkert.orgMakeInclude('system/MachineID.hh') 1086143Snate@binkert.orgMakeInclude('system/MemoryControl.hh') 1096143Snate@binkert.orgMakeInclude('system/NodeID.hh') 1106143Snate@binkert.orgMakeInclude('system/NodePersistentTable.hh') 1116143Snate@binkert.orgMakeInclude('system/PerfectCacheMemory.hh') 1126143Snate@binkert.orgMakeInclude('system/PersistentTable.hh') 1135522Snate@binkert.orgMakeInclude('system/Sequencer.hh') 1146143Snate@binkert.orgMakeInclude('system/StoreBuffer.hh') 1156143Snate@binkert.orgMakeInclude('system/TBETable.hh') 1166143Snate@binkert.orgMakeInclude('system/TimerTable.hh') 1176143Snate@binkert.org