SConscript revision 8946
112855Sgabeblack@google.com# -*- mode:python -*-
212855Sgabeblack@google.com
312855Sgabeblack@google.com# Copyright (c) 2004-2005 The Regents of The University of Michigan
412855Sgabeblack@google.com# All rights reserved.
512855Sgabeblack@google.com#
612855Sgabeblack@google.com# Redistribution and use in source and binary forms, with or without
712855Sgabeblack@google.com# modification, are permitted provided that the following conditions are
812855Sgabeblack@google.com# met: redistributions of source code must retain the above copyright
912855Sgabeblack@google.com# notice, this list of conditions and the following disclaimer;
1012855Sgabeblack@google.com# redistributions in binary form must reproduce the above copyright
1112855Sgabeblack@google.com# notice, this list of conditions and the following disclaimer in the
1212855Sgabeblack@google.com# documentation and/or other materials provided with the distribution;
1312855Sgabeblack@google.com# neither the name of the copyright holders nor the names of its
1412855Sgabeblack@google.com# contributors may be used to endorse or promote products derived from
1512855Sgabeblack@google.com# this software without specific prior written permission.
1612855Sgabeblack@google.com#
1712855Sgabeblack@google.com# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1812855Sgabeblack@google.com# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1912855Sgabeblack@google.com# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
2012855Sgabeblack@google.com# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2112855Sgabeblack@google.com# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2212855Sgabeblack@google.com# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2312855Sgabeblack@google.com# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2412855Sgabeblack@google.com# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2512855Sgabeblack@google.com# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2612855Sgabeblack@google.com# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2712855Sgabeblack@google.com# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2812855Sgabeblack@google.com#
2912855Sgabeblack@google.com# Authors: Nathan Binkert
3012855Sgabeblack@google.com
3112855Sgabeblack@google.comimport os, subprocess
3212855Sgabeblack@google.com
3312855Sgabeblack@google.comImport('main')
3412855Sgabeblack@google.com
3512855Sgabeblack@google.comfrom m5.util import compareVersions
3612855Sgabeblack@google.com
3712855Sgabeblack@google.comelf_files = []
3812855Sgabeblack@google.comdef ElfFile(filename):
3912855Sgabeblack@google.com    elf_files.append(File(filename))
4012855Sgabeblack@google.com
4112855Sgabeblack@google.comElfFile('elf_begin.c')
4212855Sgabeblack@google.comElfFile('elf_cntl.c')
4312855Sgabeblack@google.comElfFile('elf_data.c')
4412855Sgabeblack@google.comElfFile('elf_end.c')
4512855Sgabeblack@google.comElfFile('elf_errmsg.c')
4612855Sgabeblack@google.comElfFile('elf_errno.c')
4712855Sgabeblack@google.comElfFile('elf_fill.c')
4812855Sgabeblack@google.comElfFile('elf_flag.c')
4912855Sgabeblack@google.comElfFile('elf_getarhdr.c')
5012855Sgabeblack@google.comElfFile('elf_getarsym.c')
5112855Sgabeblack@google.comElfFile('elf_getbase.c')
5212855Sgabeblack@google.comElfFile('elf_getident.c')
5312855Sgabeblack@google.comElfFile('elf_hash.c')
5412855Sgabeblack@google.comElfFile('elf_kind.c')
5512855Sgabeblack@google.comElfFile('elf_memory.c')
5612855Sgabeblack@google.comElfFile('elf_next.c')
5712855Sgabeblack@google.comElfFile('elf_phnum.c')
5812855Sgabeblack@google.comElfFile('elf_rand.c')
5912855Sgabeblack@google.comElfFile('elf_rawfile.c')
6012855Sgabeblack@google.comElfFile('elf_scn.c')
6112855Sgabeblack@google.comElfFile('elf_shnum.c')
6212855Sgabeblack@google.comElfFile('elf_shstrndx.c')
6312855Sgabeblack@google.comElfFile('elf_strptr.c')
6412855Sgabeblack@google.comElfFile('elf_update.c')
6512855Sgabeblack@google.comElfFile('elf_version.c')
6612855Sgabeblack@google.comElfFile('gelf_checksum.c')
6712855Sgabeblack@google.comElfFile('gelf_dyn.c')
6812855Sgabeblack@google.comElfFile('gelf_ehdr.c')
6912855Sgabeblack@google.comElfFile('gelf_fsize.c')
70ElfFile('gelf_getclass.c')
71ElfFile('gelf_phdr.c')
72ElfFile('gelf_rel.c')
73ElfFile('gelf_rela.c')
74ElfFile('gelf_shdr.c')
75ElfFile('gelf_sym.c')
76ElfFile('gelf_symshndx.c')
77ElfFile('gelf_xlate.c')
78ElfFile('libelf.c')
79ElfFile('libelf_align.c')
80ElfFile('libelf_allocate.c')
81ElfFile('libelf_ar.c')
82ElfFile('libelf_checksum.c')
83ElfFile('libelf_data.c')
84ElfFile('libelf_ehdr.c')
85ElfFile('libelf_extended.c')
86ElfFile('libelf_phdr.c')
87ElfFile('libelf_shdr.c')
88ElfFile('libelf_xlate.c')
89
90ElfFile('libelf_convert.c')
91ElfFile('libelf_fsize.c')
92ElfFile('libelf_msize.c')
93
94m4env = main.Clone()
95if m4env['GCC']:
96    if compareVersions(m4env['GCC_VERSION'], '4') >= 0:
97        m4env.Append(CCFLAGS=['-Wno-pointer-sign'])
98    if compareVersions(m4env['GCC_VERSION'], '4.6') >= 0:
99        m4env.Append(CCFLAGS=['-Wno-unused-but-set-variable',
100                              '-Wno-implicit-function-declaration'])
101if m4env['CLANG']:
102    m4env.Append(CCFLAGS=['-Wno-initializer-overrides', '-Wno-pointer-sign'])
103m4env.Append(CCFLAGS=['-Wno-implicit'])
104del m4env['CPPPATH']
105
106# If we have gm4 use it
107if m4env.Detect('gm4'):
108    m4env['M4'] = 'gm4'
109
110# Check that m4 is available
111import SCons.Tool.m4
112if not SCons.Tool.m4.exists(m4env):
113   print "Error: Can't find version of M4 macro processor.  " + \
114         "Please install M4 and try again."
115   Exit(1)
116
117m4env.Append(M4FLAGS=['-DSRCDIR=%s' % Dir('.').path])
118m4env['M4COM'] = '$M4 $M4FLAGS $SOURCES > $TARGET'
119m4env.M4(target=File('libelf_convert.c'),
120         source=[File('elf_types.m4'), File('libelf_convert.m4')])
121m4env.M4(target=File('libelf_fsize.c'),
122         source=[File('elf_types.m4'), File('libelf_fsize.m4')])
123m4env.M4(target=File('libelf_msize.c'),
124         source=[File('elf_types.m4'), File('libelf_msize.m4')])
125
126# Build libelf as a static library with PIC code so it can be linked
127# into either m5 or the library
128m4env.Library('elf', [m4env.SharedObject(f) for f in elf_files])
129
130main.Prepend(CPPPATH=Dir('.'))
131main.Append(LIBS=['elf'])
132main.Prepend(LIBPATH=[Dir('.')])
133
134