SConscript revision 2139
1# -*- mode:python -*- 2 3# Copyright (c) 2006 The Regents of The University of Michigan 4# All rights reserved. 5# 6# Redistribution and use in source and binary forms, with or without 7# modification, are permitted provided that the following conditions are 8# met: redistributions of source code must retain the above copyright 9# notice, this list of conditions and the following disclaimer; 10# redistributions in binary form must reproduce the above copyright 11# notice, this list of conditions and the following disclaimer in the 12# documentation and/or other materials provided with the distribution; 13# neither the name of the copyright holders nor the names of its 14# contributors may be used to endorse or promote products derived from 15# this software without specific prior written permission. 16# 17# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 29import os.path 30 31# Import build environment variable from SConstruct. 32Import('env') 33 34# 35# ISA "switch header" generation. 36# 37# Auto-generate arch headers that include the right ISA-specific 38# header based on the setting of THE_ISA preprocessor variable. 39 40# List of headers to generate 41isa_switch_hdrs = Split(''' 42 isa_traits.hh 43 ''') 44 45# Generate the header. target[0] is the full path of the output 46# header to generate. 'source' is a dummy variable, since we get the 47# list of ISAs from env['ALL_ISA_LIST']. 48def gen_switch_hdr(target, source, env): 49 fname = str(target[0]) 50 basename = os.path.basename(fname) 51 f = open(fname, 'w') 52 f.write('#include "arch/isa_specific.hh"\n') 53 cond = '#if' 54 for isa in env['ALL_ISA_LIST']: 55 f.write('%s THE_ISA == %s_ISA\n#include "arch/%s/%s"\n' 56 % (cond, isa.upper(), isa, basename)) 57 cond = '#elif' 58 f.write('#else\n#error "THE_ISA not set"\n#endif\n') 59 f.close() 60 return 0 61 62# String to print when generating header 63def gen_switch_hdr_string(target, source, env): 64 return "Generating ISA switch header " + str(target[0]) 65 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