SConscript revision 2139
112904Sgabeblack@google.com# -*- mode:python -*- 212904Sgabeblack@google.com 312904Sgabeblack@google.com# Copyright (c) 2006 The Regents of The University of Michigan 412904Sgabeblack@google.com# All rights reserved. 512904Sgabeblack@google.com# 612904Sgabeblack@google.com# Redistribution and use in source and binary forms, with or without 712904Sgabeblack@google.com# modification, are permitted provided that the following conditions are 812904Sgabeblack@google.com# met: redistributions of source code must retain the above copyright 912904Sgabeblack@google.com# notice, this list of conditions and the following disclaimer; 1012904Sgabeblack@google.com# redistributions in binary form must reproduce the above copyright 1112935Sgabeblack@google.com# notice, this list of conditions and the following disclaimer in the 1212935Sgabeblack@google.com# documentation and/or other materials provided with the distribution; 1312935Sgabeblack@google.com# neither the name of the copyright holders nor the names of its 1412935Sgabeblack@google.com# contributors may be used to endorse or promote products derived from 1512935Sgabeblack@google.com# this software without specific prior written permission. 1612904Sgabeblack@google.com# 1712904Sgabeblack@google.com# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1813526Sgabeblack@google.com# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1913526Sgabeblack@google.com# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 2013526Sgabeblack@google.com# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2113526Sgabeblack@google.com# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2212904Sgabeblack@google.com# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2312904Sgabeblack@google.com# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2412904Sgabeblack@google.com# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2512904Sgabeblack@google.com# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2612906Sgabeblack@google.com# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2712910Sgabeblack@google.com# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2812906Sgabeblack@google.com 2912906Sgabeblack@google.comimport os.path 3012906Sgabeblack@google.com 3112906Sgabeblack@google.com# Import build environment variable from SConstruct. 3212936Sgabeblack@google.comImport('env') 3312936Sgabeblack@google.com 3412936Sgabeblack@google.com# 3512936Sgabeblack@google.com# ISA "switch header" generation. 3613050Sgabeblack@google.com# 3713050Sgabeblack@google.com# Auto-generate arch headers that include the right ISA-specific 3813050Sgabeblack@google.com# header based on the setting of THE_ISA preprocessor variable. 3913050Sgabeblack@google.com 4012936Sgabeblack@google.com# List of headers to generate 4112936Sgabeblack@google.comisa_switch_hdrs = Split(''' 4212936Sgabeblack@google.com isa_traits.hh 4312936Sgabeblack@google.com ''') 4412936Sgabeblack@google.com 4512936Sgabeblack@google.com# Generate the header. target[0] is the full path of the output 4612947Sgabeblack@google.com# header to generate. 'source' is a dummy variable, since we get the 4712947Sgabeblack@google.com# list of ISAs from env['ALL_ISA_LIST']. 4812947Sgabeblack@google.comdef gen_switch_hdr(target, source, env): 4912947Sgabeblack@google.com fname = str(target[0]) 5012947Sgabeblack@google.com basename = os.path.basename(fname) 5112947Sgabeblack@google.com f = open(fname, 'w') 5213266Sgabeblack@google.com f.write('#include "arch/isa_specific.hh"\n') 5313266Sgabeblack@google.com cond = '#if' 5413266Sgabeblack@google.com for isa in env['ALL_ISA_LIST']: 5513266Sgabeblack@google.com f.write('%s THE_ISA == %s_ISA\n#include "arch/%s/%s"\n' 5613266Sgabeblack@google.com % (cond, isa.upper(), isa, basename)) 5713266Sgabeblack@google.com cond = '#elif' 5813326Sgabeblack@google.com f.write('#else\n#error "THE_ISA not set"\n#endif\n') 5913326Sgabeblack@google.com f.close() 6013326Sgabeblack@google.com return 0 6113326Sgabeblack@google.com 6213326Sgabeblack@google.com# String to print when generating header 6312904Sgabeblack@google.comdef gen_switch_hdr_string(target, source, env): 6412904Sgabeblack@google.com return "Generating ISA switch header " + str(target[0]) 6512904Sgabeblack@google.com 66# Build SCons Action object. 'varlist' specifies env vars that this 67# action depdnds on; when env['ALL_ISA_LIST'] changes these actions 68# should get re-executed. 69switch_hdr_action = Action(gen_switch_hdr, gen_switch_hdr_string, 70 varlist=['ALL_ISA_LIST']) 71 72# Instantiate actions for each header 73for hdr in isa_switch_hdrs: 74 env.Command(hdr, [], switch_hdr_action) 75