SConscript revision 11294:a368064a2ab5
1955SN/A# -*- mode:python -*-
2955SN/A
37816Ssteve.reinhardt@amd.com# Copyright (c) 2004-2005 The Regents of The University of Michigan
45871Snate@binkert.org# All rights reserved.
51762SN/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.
28955SN/A#
29955SN/A# Authors: Nathan Binkert
302665Ssaidi@eecs.umich.edu
312665Ssaidi@eecs.umich.eduimport os, subprocess
325863Snate@binkert.org
33955SN/AImport('main')
34955SN/A
35955SN/Afrom m5.util import compareVersions
36955SN/A
37955SN/Aelf_files = []
388878Ssteve.reinhardt@amd.comdef ElfFile(filename):
392632Sstever@eecs.umich.edu    elf_files.append(File(filename))
408878Ssteve.reinhardt@amd.com
412632Sstever@eecs.umich.eduElfFile('elf_begin.c')
42955SN/AElfFile('elf_cntl.c')
438878Ssteve.reinhardt@amd.comElfFile('elf_data.c')
442632Sstever@eecs.umich.eduElfFile('elf_end.c')
452761Sstever@eecs.umich.eduElfFile('elf_errmsg.c')
462632Sstever@eecs.umich.eduElfFile('elf_errno.c')
472632Sstever@eecs.umich.eduElfFile('elf_fill.c')
482632Sstever@eecs.umich.eduElfFile('elf_flag.c')
492761Sstever@eecs.umich.eduElfFile('elf_getarhdr.c')
502761Sstever@eecs.umich.eduElfFile('elf_getarsym.c')
512761Sstever@eecs.umich.eduElfFile('elf_getbase.c')
528878Ssteve.reinhardt@amd.comElfFile('elf_getident.c')
538878Ssteve.reinhardt@amd.comElfFile('elf_hash.c')
542761Sstever@eecs.umich.eduElfFile('elf_kind.c')
552761Sstever@eecs.umich.eduElfFile('elf_memory.c')
562761Sstever@eecs.umich.eduElfFile('elf_next.c')
572761Sstever@eecs.umich.eduElfFile('elf_phnum.c')
582761Sstever@eecs.umich.eduElfFile('elf_rand.c')
598878Ssteve.reinhardt@amd.comElfFile('elf_rawfile.c')
608878Ssteve.reinhardt@amd.comElfFile('elf_scn.c')
612632Sstever@eecs.umich.eduElfFile('elf_shnum.c')
622632Sstever@eecs.umich.eduElfFile('elf_shstrndx.c')
638878Ssteve.reinhardt@amd.comElfFile('elf_strptr.c')
648878Ssteve.reinhardt@amd.comElfFile('elf_update.c')
652632Sstever@eecs.umich.eduElfFile('elf_version.c')
66955SN/AElfFile('gelf_checksum.c')
67955SN/AElfFile('gelf_dyn.c')
68955SN/AElfFile('gelf_ehdr.c')
695863Snate@binkert.orgElfFile('gelf_fsize.c')
705863Snate@binkert.orgElfFile('gelf_getclass.c')
715863Snate@binkert.orgElfFile('gelf_phdr.c')
725863Snate@binkert.orgElfFile('gelf_rel.c')
735863Snate@binkert.orgElfFile('gelf_rela.c')
745863Snate@binkert.orgElfFile('gelf_shdr.c')
755863Snate@binkert.orgElfFile('gelf_sym.c')
765863Snate@binkert.orgElfFile('gelf_symshndx.c')
775863Snate@binkert.orgElfFile('gelf_xlate.c')
785863Snate@binkert.orgElfFile('libelf.c')
795863Snate@binkert.orgElfFile('libelf_align.c')
808878Ssteve.reinhardt@amd.comElfFile('libelf_allocate.c')
815863Snate@binkert.orgElfFile('libelf_ar.c')
825863Snate@binkert.orgElfFile('libelf_checksum.c')
835863Snate@binkert.orgElfFile('libelf_data.c')
845863Snate@binkert.orgElfFile('libelf_ehdr.c')
855863Snate@binkert.orgElfFile('libelf_extended.c')
865863Snate@binkert.orgElfFile('libelf_phdr.c')
875863Snate@binkert.orgElfFile('libelf_shdr.c')
885863Snate@binkert.orgElfFile('libelf_xlate.c')
895863Snate@binkert.org
905863Snate@binkert.orgElfFile('libelf_convert.c')
915863Snate@binkert.orgElfFile('libelf_fsize.c')
925863Snate@binkert.orgElfFile('libelf_msize.c')
935863Snate@binkert.org
945863Snate@binkert.orgm4env = main.Clone()
955863Snate@binkert.orgif m4env['GCC']:
968878Ssteve.reinhardt@amd.com    m4env.Append(CCFLAGS=['-Wno-pointer-sign',
975863Snate@binkert.org                          '-Wno-unused-but-set-variable',
985863Snate@binkert.org                          '-Wno-implicit-function-declaration',
995863Snate@binkert.org                          '-Wno-override-init'])
1006654Snate@binkert.orgif m4env['CLANG']:
101955SN/A    m4env.Append(CCFLAGS=['-Wno-initializer-overrides', '-Wno-pointer-sign'])
1025396Ssaidi@eecs.umich.edu    # clang defaults to c99 (while gcc defaults to gnu89) and there is a
1035863Snate@binkert.org    # difference in the handling of inlining functions which causes
1045863Snate@binkert.org    # linking problems with multiple definitions of the symbols in
1054202Sbinkertn@umich.edu    # sysmacros.h for older versions of glibc
1065863Snate@binkert.org    m4env.Append(CCFLAGS=['-std=gnu89'])
1075863Snate@binkert.orgm4env.Append(CCFLAGS=['-Wno-implicit'])
1085863Snate@binkert.orgdel m4env['CPPPATH']
1095863Snate@binkert.org
110955SN/A# If we have gm4 use it
1116654Snate@binkert.orgif m4env.Detect('gm4'):
1125273Sstever@gmail.com    m4env['M4'] = 'gm4'
1135871Snate@binkert.org
1145273Sstever@gmail.com# Check that m4 is available
1156655Snate@binkert.orgimport SCons.Tool.m4
1168878Ssteve.reinhardt@amd.comif not SCons.Tool.m4.exists(m4env):
1176655Snate@binkert.org   print "Error: Can't find version of M4 macro processor.  " + \
1186655Snate@binkert.org         "Please install M4 and try again."
1196655Snate@binkert.org   Exit(1)
1206655Snate@binkert.org
1215871Snate@binkert.orgm4env.Append(M4FLAGS=['-DSRCDIR=%s' % Dir('.').path])
1226654Snate@binkert.orgm4env['M4COM'] = '$M4 $M4FLAGS $SOURCES > $TARGET'
1238947Sandreas.hansson@arm.comm4env.M4(target=File('libelf_convert.c'),
1245396Ssaidi@eecs.umich.edu         source=[File('elf_types.m4'), File('libelf_convert.m4')])
1258120Sgblack@eecs.umich.edum4env.M4(target=File('libelf_fsize.c'),
1268120Sgblack@eecs.umich.edu         source=[File('elf_types.m4'), File('libelf_fsize.m4')])
1278120Sgblack@eecs.umich.edum4env.M4(target=File('libelf_msize.c'),
1288120Sgblack@eecs.umich.edu         source=[File('elf_types.m4'), File('libelf_msize.m4')])
1298120Sgblack@eecs.umich.edu
1308120Sgblack@eecs.umich.edu# Build libelf as a static library with PIC code so it can be linked
1318120Sgblack@eecs.umich.edu# into either m5 or the library
1328120Sgblack@eecs.umich.edum4env.Library('elf', [m4env.SharedObject(f) for f in elf_files])
1338879Ssteve.reinhardt@amd.com
1348879Ssteve.reinhardt@amd.commain.Prepend(CPPPATH=Dir('.'))
1358879Ssteve.reinhardt@amd.commain.Append(LIBS=['elf'])
1368879Ssteve.reinhardt@amd.commain.Prepend(LIBPATH=[Dir('.')])
1378879Ssteve.reinhardt@amd.com
1388879Ssteve.reinhardt@amd.com