scons: Fix libelf linking errors when using clang/llvm
[gem5.git] / ext / libelf / SConscript
1 # -*- mode:python -*-
2
3 # Copyright (c) 2004-2005 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 #
29 # Authors: Nathan Binkert
30
31 import os, subprocess
32
33 Import('main')
34
35 from m5.util import compareVersions
36
37 elf_files = []
38 def ElfFile(filename):
39 elf_files.append(File(filename))
40
41 ElfFile('elf_begin.c')
42 ElfFile('elf_cntl.c')
43 ElfFile('elf_data.c')
44 ElfFile('elf_end.c')
45 ElfFile('elf_errmsg.c')
46 ElfFile('elf_errno.c')
47 ElfFile('elf_fill.c')
48 ElfFile('elf_flag.c')
49 ElfFile('elf_getarhdr.c')
50 ElfFile('elf_getarsym.c')
51 ElfFile('elf_getbase.c')
52 ElfFile('elf_getident.c')
53 ElfFile('elf_hash.c')
54 ElfFile('elf_kind.c')
55 ElfFile('elf_memory.c')
56 ElfFile('elf_next.c')
57 ElfFile('elf_phnum.c')
58 ElfFile('elf_rand.c')
59 ElfFile('elf_rawfile.c')
60 ElfFile('elf_scn.c')
61 ElfFile('elf_shnum.c')
62 ElfFile('elf_shstrndx.c')
63 ElfFile('elf_strptr.c')
64 ElfFile('elf_update.c')
65 ElfFile('elf_version.c')
66 ElfFile('gelf_checksum.c')
67 ElfFile('gelf_dyn.c')
68 ElfFile('gelf_ehdr.c')
69 ElfFile('gelf_fsize.c')
70 ElfFile('gelf_getclass.c')
71 ElfFile('gelf_phdr.c')
72 ElfFile('gelf_rel.c')
73 ElfFile('gelf_rela.c')
74 ElfFile('gelf_shdr.c')
75 ElfFile('gelf_sym.c')
76 ElfFile('gelf_symshndx.c')
77 ElfFile('gelf_xlate.c')
78 ElfFile('libelf.c')
79 ElfFile('libelf_align.c')
80 ElfFile('libelf_allocate.c')
81 ElfFile('libelf_ar.c')
82 ElfFile('libelf_checksum.c')
83 ElfFile('libelf_data.c')
84 ElfFile('libelf_ehdr.c')
85 ElfFile('libelf_extended.c')
86 ElfFile('libelf_phdr.c')
87 ElfFile('libelf_shdr.c')
88 ElfFile('libelf_xlate.c')
89
90 ElfFile('libelf_convert.c')
91 ElfFile('libelf_fsize.c')
92 ElfFile('libelf_msize.c')
93
94 m4env = main.Clone()
95 if 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'])
101 if m4env['CLANG']:
102 m4env.Append(CCFLAGS=['-Wno-initializer-overrides', '-Wno-pointer-sign'])
103 # clang defaults to c99 (while gcc defaults to gnu89) and there is a
104 # difference in the handling of inlining functions which causes
105 # linking problems with multiple definitions of the symbols in
106 # sysmacros.h for older versions of glibc
107 m4env.Append(CCFLAGS=['-std=gnu89'])
108 m4env.Append(CCFLAGS=['-Wno-implicit'])
109 del m4env['CPPPATH']
110
111 # If we have gm4 use it
112 if m4env.Detect('gm4'):
113 m4env['M4'] = 'gm4'
114
115 # Check that m4 is available
116 import SCons.Tool.m4
117 if not SCons.Tool.m4.exists(m4env):
118 print "Error: Can't find version of M4 macro processor. " + \
119 "Please install M4 and try again."
120 Exit(1)
121
122 m4env.Append(M4FLAGS=['-DSRCDIR=%s' % Dir('.').path])
123 m4env['M4COM'] = '$M4 $M4FLAGS $SOURCES > $TARGET'
124 m4env.M4(target=File('libelf_convert.c'),
125 source=[File('elf_types.m4'), File('libelf_convert.m4')])
126 m4env.M4(target=File('libelf_fsize.c'),
127 source=[File('elf_types.m4'), File('libelf_fsize.m4')])
128 m4env.M4(target=File('libelf_msize.c'),
129 source=[File('elf_types.m4'), File('libelf_msize.m4')])
130
131 # Build libelf as a static library with PIC code so it can be linked
132 # into either m5 or the library
133 m4env.Library('elf', [m4env.SharedObject(f) for f in elf_files])
134
135 main.Prepend(CPPPATH=Dir('.'))
136 main.Append(LIBS=['elf'])
137 main.Prepend(LIBPATH=[Dir('.')])
138