SConscript revision 10553
1955SN/A# -*- mode:python -*-
2955SN/A
31762SN/A# Copyright (c) 2004-2005 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.org# Authors: Nathan Binkert
30955SN/A
3112563Sgabeblack@google.comimport os, subprocess
3212563Sgabeblack@google.com
335522Snate@binkert.orgImport('main')
346143Snate@binkert.org
3512371Sgabeblack@google.comfrom m5.util import compareVersions
364762Snate@binkert.org
375522Snate@binkert.orgelf_files = []
38955SN/Adef ElfFile(filename):
395522Snate@binkert.org    elf_files.append(File(filename))
4011974Sgabeblack@google.com
41955SN/AElfFile('elf_begin.c')
425522Snate@binkert.orgElfFile('elf_cntl.c')
434202Sbinkertn@umich.eduElfFile('elf_data.c')
445742Snate@binkert.orgElfFile('elf_end.c')
45955SN/AElfFile('elf_errmsg.c')
464381Sbinkertn@umich.eduElfFile('elf_errno.c')
474381Sbinkertn@umich.eduElfFile('elf_fill.c')
4812246Sgabeblack@google.comElfFile('elf_flag.c')
4912246Sgabeblack@google.comElfFile('elf_getarhdr.c')
508334Snate@binkert.orgElfFile('elf_getarsym.c')
51955SN/AElfFile('elf_getbase.c')
52955SN/AElfFile('elf_getident.c')
534202Sbinkertn@umich.eduElfFile('elf_hash.c')
54955SN/AElfFile('elf_kind.c')
554382Sbinkertn@umich.eduElfFile('elf_memory.c')
564382Sbinkertn@umich.eduElfFile('elf_next.c')
574382Sbinkertn@umich.eduElfFile('elf_phnum.c')
586654Snate@binkert.orgElfFile('elf_rand.c')
595517Snate@binkert.orgElfFile('elf_rawfile.c')
608614Sgblack@eecs.umich.eduElfFile('elf_scn.c')
617674Snate@binkert.orgElfFile('elf_shnum.c')
626143Snate@binkert.orgElfFile('elf_shstrndx.c')
636143Snate@binkert.orgElfFile('elf_strptr.c')
646143Snate@binkert.orgElfFile('elf_update.c')
6512302Sgabeblack@google.comElfFile('elf_version.c')
6612302Sgabeblack@google.comElfFile('gelf_checksum.c')
6712302Sgabeblack@google.comElfFile('gelf_dyn.c')
6812371Sgabeblack@google.comElfFile('gelf_ehdr.c')
6912371Sgabeblack@google.comElfFile('gelf_fsize.c')
7012371Sgabeblack@google.comElfFile('gelf_getclass.c')
7112371Sgabeblack@google.comElfFile('gelf_phdr.c')
7212371Sgabeblack@google.comElfFile('gelf_rel.c')
7312371Sgabeblack@google.comElfFile('gelf_rela.c')
7412371Sgabeblack@google.comElfFile('gelf_shdr.c')
7512371Sgabeblack@google.comElfFile('gelf_sym.c')
7612371Sgabeblack@google.comElfFile('gelf_symshndx.c')
7712371Sgabeblack@google.comElfFile('gelf_xlate.c')
7812371Sgabeblack@google.comElfFile('libelf.c')
7912371Sgabeblack@google.comElfFile('libelf_align.c')
8012371Sgabeblack@google.comElfFile('libelf_allocate.c')
8112371Sgabeblack@google.comElfFile('libelf_ar.c')
8212371Sgabeblack@google.comElfFile('libelf_checksum.c')
8312371Sgabeblack@google.comElfFile('libelf_data.c')
8412371Sgabeblack@google.comElfFile('libelf_ehdr.c')
8512371Sgabeblack@google.comElfFile('libelf_extended.c')
8612371Sgabeblack@google.comElfFile('libelf_phdr.c')
8712371Sgabeblack@google.comElfFile('libelf_shdr.c')
8812371Sgabeblack@google.comElfFile('libelf_xlate.c')
8912371Sgabeblack@google.com
9012371Sgabeblack@google.comElfFile('libelf_convert.c')
9112371Sgabeblack@google.comElfFile('libelf_fsize.c')
9212371Sgabeblack@google.comElfFile('libelf_msize.c')
9312371Sgabeblack@google.com
9412371Sgabeblack@google.comm4env = main.Clone()
9512371Sgabeblack@google.comif m4env['GCC']:
9612371Sgabeblack@google.com    m4env.Append(CCFLAGS=['-Wno-pointer-sign'])
9712371Sgabeblack@google.com    if compareVersions(m4env['GCC_VERSION'], '4.6') >= 0:
9812371Sgabeblack@google.com        m4env.Append(CCFLAGS=['-Wno-unused-but-set-variable',
9912371Sgabeblack@google.com                              '-Wno-implicit-function-declaration'])
10012371Sgabeblack@google.comif m4env['CLANG']:
10112371Sgabeblack@google.com    m4env.Append(CCFLAGS=['-Wno-initializer-overrides', '-Wno-pointer-sign'])
10212371Sgabeblack@google.com    # clang defaults to c99 (while gcc defaults to gnu89) and there is a
10312371Sgabeblack@google.com    # difference in the handling of inlining functions which causes
10412371Sgabeblack@google.com    # linking problems with multiple definitions of the symbols in
10512371Sgabeblack@google.com    # sysmacros.h for older versions of glibc
10612371Sgabeblack@google.com    m4env.Append(CCFLAGS=['-std=gnu89'])
10712371Sgabeblack@google.comm4env.Append(CCFLAGS=['-Wno-implicit'])
10812371Sgabeblack@google.comdel m4env['CPPPATH']
10912371Sgabeblack@google.com
11012371Sgabeblack@google.com# If we have gm4 use it
11112371Sgabeblack@google.comif m4env.Detect('gm4'):
11212371Sgabeblack@google.com    m4env['M4'] = 'gm4'
11312371Sgabeblack@google.com
11412371Sgabeblack@google.com# Check that m4 is available
11512302Sgabeblack@google.comimport SCons.Tool.m4
11612371Sgabeblack@google.comif not SCons.Tool.m4.exists(m4env):
11712302Sgabeblack@google.com   print "Error: Can't find version of M4 macro processor.  " + \
11812371Sgabeblack@google.com         "Please install M4 and try again."
11912302Sgabeblack@google.com   Exit(1)
12012302Sgabeblack@google.com
12112371Sgabeblack@google.comm4env.Append(M4FLAGS=['-DSRCDIR=%s' % Dir('.').path])
12212371Sgabeblack@google.comm4env['M4COM'] = '$M4 $M4FLAGS $SOURCES > $TARGET'
12312371Sgabeblack@google.comm4env.M4(target=File('libelf_convert.c'),
12412371Sgabeblack@google.com         source=[File('elf_types.m4'), File('libelf_convert.m4')])
12512302Sgabeblack@google.comm4env.M4(target=File('libelf_fsize.c'),
12612371Sgabeblack@google.com         source=[File('elf_types.m4'), File('libelf_fsize.m4')])
12712371Sgabeblack@google.comm4env.M4(target=File('libelf_msize.c'),
12812371Sgabeblack@google.com         source=[File('elf_types.m4'), File('libelf_msize.m4')])
12912371Sgabeblack@google.com
13011983Sgabeblack@google.com# Build libelf as a static library with PIC code so it can be linked
1316143Snate@binkert.org# into either m5 or the library
1328233Snate@binkert.orgm4env.Library('elf', [m4env.SharedObject(f) for f in elf_files])
13312302Sgabeblack@google.com
1346143Snate@binkert.orgmain.Prepend(CPPPATH=Dir('.'))
1356143Snate@binkert.orgmain.Append(LIBS=['elf'])
13612302Sgabeblack@google.commain.Prepend(LIBPATH=[Dir('.')])
1374762Snate@binkert.org
1386143Snate@binkert.org