SConscript revision 2139
1955SN/A# -*- mode:python -*-
2955SN/A
31762SN/A# Copyright (c) 2006 The Regents of The University of Michigan
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.orgimport os.path
30955SN/A
315522Snate@binkert.org# Import build environment variable from SConstruct.
326143Snate@binkert.orgImport('env')
334762Snate@binkert.org
345522Snate@binkert.org#
35955SN/A# ISA "switch header" generation.
365522Snate@binkert.org#
37955SN/A# Auto-generate arch headers that include the right ISA-specific
385522Snate@binkert.org# header based on the setting of THE_ISA preprocessor variable.
394202Sbinkertn@umich.edu
405742Snate@binkert.org# List of headers to generate
41955SN/Aisa_switch_hdrs = Split('''
424381Sbinkertn@umich.edu	isa_traits.hh
434381Sbinkertn@umich.edu        ''')
448334Snate@binkert.org
45955SN/A# Generate the header.  target[0] is the full path of the output
46955SN/A# header to generate.  'source' is a dummy variable, since we get the
474202Sbinkertn@umich.edu# list of ISAs from env['ALL_ISA_LIST'].
48955SN/Adef gen_switch_hdr(target, source, env):
494382Sbinkertn@umich.edu    fname = str(target[0])
504382Sbinkertn@umich.edu    basename = os.path.basename(fname)
514382Sbinkertn@umich.edu    f = open(fname, 'w')
526654Snate@binkert.org    f.write('#include "arch/isa_specific.hh"\n')
535517Snate@binkert.org    cond = '#if'
548614Sgblack@eecs.umich.edu    for isa in env['ALL_ISA_LIST']:
557674Snate@binkert.org        f.write('%s THE_ISA == %s_ISA\n#include "arch/%s/%s"\n'
566143Snate@binkert.org                % (cond, isa.upper(), isa, basename))
576143Snate@binkert.org        cond = '#elif'
586143Snate@binkert.org    f.write('#else\n#error "THE_ISA not set"\n#endif\n')
598233Snate@binkert.org    f.close()
608233Snate@binkert.org    return 0
618233Snate@binkert.org
628233Snate@binkert.org# String to print when generating header
638233Snate@binkert.orgdef gen_switch_hdr_string(target, source, env):
648334Snate@binkert.org    return "Generating ISA switch header " + str(target[0])
658334Snate@binkert.org
668233Snate@binkert.org# Build SCons Action object. 'varlist' specifies env vars that this
678233Snate@binkert.org# action depdnds on; when env['ALL_ISA_LIST'] changes these actions
688233Snate@binkert.org# should get re-executed.
698233Snate@binkert.orgswitch_hdr_action = Action(gen_switch_hdr, gen_switch_hdr_string,
708233Snate@binkert.org                           varlist=['ALL_ISA_LIST'])
718233Snate@binkert.org
726143Snate@binkert.org# Instantiate actions for each header
738233Snate@binkert.orgfor hdr in isa_switch_hdrs:
748233Snate@binkert.org    env.Command(hdr, [], switch_hdr_action)
758233Snate@binkert.org