-
Notifications
You must be signed in to change notification settings - Fork 41
/
configure.ac
275 lines (232 loc) · 7.52 KB
/
configure.ac
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
dnl Process this file with autoconf to produce a configure script.
AC_INIT(elf2flt.c)
AC_ARG_WITH(zlib-prefix,
AS_HELP_STRING([--with-zlib-prefix=<dir>], [path to installed zlib]),
[ ac_zlib_prefix=$withval ],
[ ac_zlib_prefix=NONE ]
)
AC_ARG_WITH(libbfd,
AS_HELP_STRING([--with-libbfd=<file>], [path to libbfd.a library to use]),
[ ac_libbfd=$withval ],
[ ac_libbfd=NONE ]
)
AC_ARG_WITH(libiberty,
AS_HELP_STRING([--with-libiberty=<file>], [path to libiberty.a library to use]),
[ ac_libiberty=$withval ],
[ ac_libiberty=NONE ]
)
AC_ARG_WITH(bfd-include-dir,
AS_HELP_STRING([--with-bfd-include-dir=<dir>], [include path for correct bfd.h]),
[ ac_bfd_include_dir=$withval ],
[ ac_bfd_include_dir=NONE ]
)
AC_ARG_WITH(binutils-include-dir,
AS_HELP_STRING([--with-binutils-include-dir=<dir>], [include path for binutils headers]),
[ ac_binutils_include_dir=$withval ],
[ ac_binutils_include_dir=NONE ]
)
AC_ARG_WITH(binutils-ldscript-dir,
AS_HELP_STRING([--with-binutils-ldscript-dir=<dir>], [path to install elf2flt.ld]),
[ ac_binutils_ldscript_dir=$withval ],
[ ac_binutils_ldscript_dir=NONE ]
)
AC_ARG_WITH(binutils-build-dir,
AS_HELP_STRING([--with-binutils-build-dir=<dir>], [path to compiled binutils tree]),
[ ac_binutils_build_dir=$withval ],
[ ac_binutils_build_dir=NONE ]
)
AC_ARG_ENABLE(ld-elf2flt-binary,
AS_HELP_STRING([--disable-ld-elf2flt-binary], [use ld-elf2flt shell script]),
[ use_ld_elf2flt_binary=$enableval ],
[ use_ld_elf2flt_binary=yes ]
)
if test "$use_ld_elf2flt_binary" != "yes"; then
AC_MSG_WARN([--disable-ld-elf2flt-binary is deprecated.
If you still need this, please let us know before we delete it.])
fi
dnl convert a yes/no variable to 1/0 for C code
var_yn_to_10() {
if eval test \"\$$1\" = yes ; then
eval $1=1
else
eval $1=0
fi
}
AC_ARG_ENABLE(werror,
AS_HELP_STRING([--disable-werror], [do not build with -Werror]),
[ werror=$enableval ],
[ werror=yes ]
)
var_yn_to_10 werror
AC_ARG_ENABLE(got-check,
AS_HELP_STRING([--disable-got-check], [disable check for GOT (needed on H8)]),
[ got_check=$enableval ],
[ got_check=yes ]
)
var_yn_to_10 got_check
AC_ARG_ENABLE(emit-relocs,
AS_HELP_STRING([--disable-emit-relocs], [don't use the --emit-relocs (-q) linker option]),
[ emit_relocs=$enableval ],
[ emit_relocs=yes ]
)
var_yn_to_10 emit_relocs
AC_ARG_ENABLE(emit-ctor-dtor,
AS_HELP_STRING([--enable-emit-ctor-dtor], [manually create ctor/dtor list]),
[ emit_ctor_dtor=$enableval ],
[ emit_ctor_dtor=no ]
)
var_yn_to_10 emit_ctor_dtor
AC_ARG_ENABLE(always-reloc-text,
AS_HELP_STRING([--enable-always-reloc-text], [always process text relocs ignoring pic/got (needed on Blackfin)]),
[ always_reloc_text=$enableval ],
[
case $target in
bfin*) always_reloc_text=yes;;
*) always_reloc_text=no;;
esac
]
)
var_yn_to_10 always_reloc_text
AC_CANONICAL_HOST
AC_CANONICAL_TARGET
dnl Checks for programs.
AC_PROG_CC
AC_USE_SYSTEM_EXTENSIONS
AC_PROG_INSTALL
if test "$ac_binutils_build_dir" != "NONE"; then
test "$ac_libbfd" = "NONE" && ac_libbfd="$ac_binutils_build_dir/bfd/libbfd.a"
test "$ac_libiberty" = "NONE" && ac_libiberty="$ac_binutils_build_dir/libiberty/libiberty.a"
test "$ac_bfd_include_dir" = "NONE" && ac_bfd_include_dir="$ac_binutils_build_dir/bfd"
test "$ac_binutils_include_dir" = "NONE" && ac_binutils_include_dir="$ac_binutils_build_dir/include"
fi
dnl Checks for libraries. Look for zlib before binutils libs in case they
dnl need zlib themselves.
if test "$ac_zlib_prefix" = "NONE"; then
AC_CHECK_LIB(z, deflate)
else
LIBS="-L$ac_zlib_prefix/lib -lz $LIBS"
fi
AC_CHECK_LIB(zstd, ZSTD_decompress)
if test "$ac_libiberty" = "NONE"; then
AC_CHECK_LIB(iberty, objalloc_create)
ac_libiberty=auto
else
LIBS="$ac_libiberty $LIBS"
fi
if test "$ac_libbfd" = "NONE"; then
AC_CHECK_LIB(bfd, bfd_openr)
ac_libbfd=auto
else
LIBS="$ac_libbfd $LIBS"
fi
bfd_include_dir=
if test "$ac_bfd_include_dir" != "NONE"; then
bfd_include_dir=$(cd "$ac_bfd_include_dir" && pwd)
fi
binutils_include_dir=
if test "$ac_binutils_include_dir" != "NONE"; then
binutils_include_dir=$(cd "$ac_binutils_include_dir" && pwd)
fi
zlib_include_dir=
if test "$ac_zlib_prefix" != "NONE"; then
zlib_include_dir="-I$ac_zlib_prefix/include"
fi
binutils_ldscript_dir=
if test "$ac_binutils_ldscript_dir" = "NONE"; then
ac_binutils_ldscript_dir="\${TOOLDIR}/../${target_alias}/lib"
fi
binutils_ldscript_dir="$ac_binutils_ldscript_dir"
if test "$ac_libbfd" = "NONE" -o "$ac_libiberty" = "NONE" ; then
AC_MSG_ERROR([
You need to specify the location of the libfd.a and libiberty.a
host libraries from the binutils package.
Run configure again specifying these options:
./configure --target=<ARCH> --with-bfd-include-dir=<dir> --with-libbfd=<libbfd.a> --with-libiberty=<libiberty.a>
])
fi
if test "$ac_bfd_include_dir" = "NONE" ; then
AC_MSG_ERROR([
You need to specify the location of the bfd.h header from a
configured/compiled version of the binutils package for your target.
Without this your elf2flt may crash as it will try to use the
systems bfd.h which may be from a different binutils package.
Run configure again specifying these options:
./configure --target=<ARCH> --with-bfd-include-dir=<dir> --with-libbfd=<libbfd.a> --with-libiberty=<libiberty.a>
])
fi
SYMBOL_PREFIX=
case $target in
bfin*)
SYMBOL_PREFIX=_
;;
esac
dnl Make sure we resolve system symbols before libiberty/libbfd ones.
dnl Otherwise, things like getopt get screwed up because the system headers
dnl redirect some functions to the system symbols, but other local symbols
dnl come from libiberty/libbfd.
dnl int getopt(int, char * const [], const char *) __asm("_" "getopt" "$UNIX2003");
AC_CHECK_LIB(c, malloc, LIBS="-lc $LIBS")
AC_CHECK_LIB(dl, dlopen, LIBS="$LIBS -ldl")
dnl Checks for header files.
AC_HEADER_STDC
AC_CHECK_HEADERS(fcntl.h unistd.h bfd.h)
dnl Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
HAVE_BFD_XTENSA_PDIFF_RELOCS=0
case $target in
xtensa*)
AS_VAR_COPY([OLD_CPPFLAGS], [CPPFLAGS])
AS_VAR_SET([CPPFLAGS], ["-I$bfd_include_dir -I$binutils_include_dir $CPPFLAGS"])
AC_CHECK_DECL([R_XTENSA_PDIFF8],
[HAVE_BFD_XTENSA_PDIFF_RELOCS=1],,
[#include "bfd.h"
#include "elf/xtensa.h"])
AS_VAR_COPY([CPPFLAGS], [OLD_CPPFLAGS])
;;
esac
dnl Checks for library functions.
AC_FUNC_VPRINTF
AC_CHECK_FUNCS([ \
dcgettext \
getline \
libintl_dgettext \
strsignal \
])
dnl Various bfd section macros and functions like bfd_section_size() have been
dnl modified starting with binutils >= 2.34.
dnl Check if the prototypes take a bfd argument.
if test "$binutils_include_dir" != "NONE"; then
CFLAGS="-I$binutils_include_dir -I$bfd_include_dir $CFLAGS"
fi
AC_TRY_COMPILE([#include <bfd.h>],
[const asection *sec; bfd_section_size(sec);],
bfd_section_api_takes_bfd=no,
bfd_section_api_takes_bfd=yes)
if test "$bfd_section_api_takes_bfd" = "yes" ; then
AC_DEFINE(HAVE_BFD_SECTION_API_TAKES_BFD, 1,
[define to 1 for binutils < 2.34])
fi
if test "$GCC" = yes ; then
CFLAGS="-Wall $CFLAGS"
if test "$werror" = 1 ; then
CFLAGS="-Werror -Wno-error=unused-label $CFLAGS"
fi
fi
dnl Subsitute values
AC_SUBST(target)
AC_SUBST(target_alias)
AC_SUBST(target_cpu)
AC_SUBST(target_os)
AC_SUBST(target_vendor)
AC_SUBST(bfd_include_dir)
AC_SUBST(binutils_include_dir)
AC_SUBST(zlib_include_dir)
AC_SUBST(binutils_ldscript_dir)
AC_SUBST(use_ld_elf2flt_binary)
AC_SUBST(got_check)
AC_SUBST(emit_relocs)
AC_SUBST(emit_ctor_dtor)
AC_SUBST(always_reloc_text)
AC_SUBST(SYMBOL_PREFIX)
AC_SUBST(HAVE_BFD_XTENSA_PDIFF_RELOCS)
AC_OUTPUT(ld-elf2flt.sh:ld-elf2flt.in Makefile elf2flt.ld)