905dbaf1c706361406b927409697346ebaa138d3
[external/binutils.git] / gold / configure.ac
1 dnl Process this file with autoconf to produce a configure script.
2
3 AC_PREREQ(2.59)
4
5 AC_INIT(gold, 0.1)
6 AC_CONFIG_SRCDIR(gold.cc)
7
8 AC_CANONICAL_TARGET
9
10 AM_INIT_AUTOMAKE([no-dist parallel-tests])
11
12 AM_CONFIG_HEADER(config.h:config.in)
13
14 AC_ARG_WITH(sysroot,
15 [  --with-sysroot[=DIR]    search for usr/lib et al within DIR],
16 [sysroot=$withval], [sysroot=no])
17
18 if test "$sysroot" = "yes"; then
19   sysroot='${exec_prefix}/${target_alias}/sys-root'
20 elif test "$sysroot" = "no"; then
21   sysroot=
22 fi
23
24 sysroot_relocatable=0
25 if test -n "$sysroot"; then
26   case "sysroot" in
27     "${prefix}" | "${prefix}/"* | \
28     "${exec_prefix}" | "${exec_prefix}/"* | \
29     '${prefix}' | '${prefix}/'*| \
30     '${exec_prefix}' | '${exec_prefix}/'*)
31       sysroot_relocatable=1
32       ;;
33   esac
34 fi
35
36 AC_DEFINE_UNQUOTED(TARGET_SYSTEM_ROOT, "$sysroot",
37   [System root for target files])
38 AC_DEFINE_UNQUOTED(TARGET_SYSTEM_ROOT_RELOCATABLE, $sysroot_relocatable,
39   [Whether the system root can be relocated])
40
41 dnl "install_as_default" is true if the linker to be installed as the
42 dnl default linker, ld.
43 dnl "installed_linker" is the installed gold linker name.
44
45 default_ld=
46 AC_ARG_ENABLE(ld,
47 [[  --enable-ld[=ARG]     build ld [ARG={default,yes,no}]]],
48 [case "${enableval}" in 
49   default)
50     default_ld=ld.bfd
51     ;;
52 esac])
53
54 AC_ARG_ENABLE(gold,
55 [[  --enable-gold[=ARG]     build gold [ARG={default,yes,no}]]],
56 [case "${enableval}" in
57  yes|default)
58    if test x${default_ld} = x; then
59      install_as_default=yes
60    fi
61    installed_linker=ld.gold
62    ;;
63  no)
64    ;;
65  *)
66    AC_MSG_ERROR([invalid --enable-gold argument])
67    ;;
68  esac],
69 [install_as_default=no
70  installed_linker=ld.gold])
71 AC_SUBST(install_as_default)
72 AC_SUBST(installed_linker)
73
74 dnl For now threads are a configure time option.
75 AC_ARG_ENABLE([threads],
76 [  --enable-threads        multi-threaded linking],
77 [case "${enableval}" in
78   yes | "") threads=yes ;;
79   no) threads=no ;;
80   *) threads=yes ;;
81  esac],
82 [threads=no])
83 if test "$threads" = "yes"; then
84   AC_DEFINE(ENABLE_THREADS, 1,
85             [Define to do multi-threaded linking])
86 fi
87 AM_CONDITIONAL(THREADS, test "$threads" = "yes")
88
89 AC_ARG_ENABLE([plugins],
90 [  --enable-plugins        linker plugins],
91 [case "${enableval}" in
92   yes | "") plugins=yes ;;
93   no) plugins=no ;;
94   *) plugins=yes ;;
95  esac],
96 [plugins=no])
97 if test "$plugins" = "yes"; then
98   AC_DEFINE(ENABLE_PLUGINS, 1,
99             [Define to enable linker plugins])
100 fi
101 AM_CONDITIONAL(PLUGINS, test "$plugins" = "yes")
102
103 AC_ARG_ENABLE([targets],
104 [  --enable-targets        alternative target configurations],
105 [case "${enableval}" in
106   yes | "")
107     AC_MSG_ERROR([--enable-targets option must specify target names or 'all'])
108     ;;
109   no)
110     enable_targets=
111     ;;
112   *)
113     enable_targets=$enableval
114     ;;
115 esac],
116 [# For now, enable all targets by default
117  enable_targets=all
118 ])
119
120 # Canonicalize the enabled targets.
121 if test -n "$enable_targets"; then
122   for targ in `echo $enable_targets | sed -e 's/,/ /g'`; do
123     result=`$ac_config_sub $targ 2>/dev/null`
124     if test -n "$result"; then
125       canon_targets="$canon_targets $result"
126     else
127       # Permit unrecognized target names, like "all".
128       canon_targets="$canon_targets $targ"
129     fi
130   done
131 fi
132
133 # See which specific instantiations we need.
134 targetobjs=
135 all_targets=
136 default_machine=
137 default_size=
138 default_big_endian=
139 default_osabi=ELFOSABI_NONE
140 targ_32_little=
141 targ_32_big=
142 targ_64_little=
143 targ_64_big=
144 for targ in $target $canon_targets; do
145   if test "$targ" = "all"; then
146     targ_32_little=yes
147     targ_32_big=yes
148     targ_64_little=yes
149     targ_64_big=yes
150     all_targets=yes
151   else
152     . ${srcdir}/configure.tgt
153
154     if test "$targ_obj" = "UNKNOWN"; then
155       AC_MSG_ERROR("unsupported target $targ")
156     else
157       targetobjs="$targetobjs ${targ_obj}.\$(OBJEXT)"
158       if test "$targ_extra_obj" != ""; then
159         targetobjs="$targetobjs ${targ_extra_obj}.\$(OBJEXT)"
160       fi
161       if test "$targ_size" = "32" -o "$targ_extra_size" = "32"; then
162           if test "$targ_big_endian" = "true" \
163               -o "$targ_extra_big_endian" = "true"; then
164               targ_32_big=yes
165           fi
166           if test "$targ_big_endian" = "false" \
167               -o "$targ_extra_big_endian" = "false"; then
168               targ_32_little=yes
169           fi
170       fi
171       if test "$targ_size" = "64" -o "$targ_extra_size" = "64"; then
172           if test "$targ_big_endian" = "true" \
173               -o "$targ_extra_big_endian" = "true"; then
174               targ_64_big=yes
175           fi
176           if test "$targ_big_endian" = "false" \
177               -o "$targ_extra_big_endian" = "false"; then
178               targ_64_little=yes
179           fi
180       fi
181
182       if test "$target" = "$targ"; then
183         default_machine=$targ_machine
184         default_size=$targ_size
185         default_big_endian=$targ_big_endian
186         default_osabi=$targ_osabi
187
188         AM_CONDITIONAL(DEFAULT_TARGET_ARM, test "$targ_obj" = "arm")
189         AM_CONDITIONAL(DEFAULT_TARGET_I386, test "$targ_obj" = "i386")
190         AM_CONDITIONAL(DEFAULT_TARGET_POWERPC, test "$targ_obj" = "powerpc")
191         AM_CONDITIONAL(DEFAULT_TARGET_SPARC, test "$targ_obj" = "sparc")
192         AM_CONDITIONAL(DEFAULT_TARGET_X86_64, test "$targ_obj" = "x86_64")
193       fi
194     fi
195   fi
196 done
197
198 # Remove any duplicates.
199 to=""
200 for t in $targetobjs; do
201   case " $to " in
202   *" $t "*) ;;
203   *) to="$to $t" ;;
204   esac
205 done
206 targetobjs=$to
207
208 if test -n "$targ_32_little"; then
209   AC_DEFINE(HAVE_TARGET_32_LITTLE, 1,
210               [Define to support 32-bit little-endian targets])
211 fi
212 if test -n "$targ_32_big"; then
213   AC_DEFINE(HAVE_TARGET_32_BIG, 1,
214               [Define to support 32-bit big-endian targets])
215 fi
216 if test -n "$targ_64_little"; then
217   AC_DEFINE(HAVE_TARGET_64_LITTLE, 1,
218               [Define to support 64-bit little-endian targets])
219 fi
220 if test -n "$targ_64_big"; then
221   AC_DEFINE(HAVE_TARGET_64_BIG, 1,
222               [Define to support 64-bit big-endian targets])
223 fi
224
225 if test -n "$all_targets"; then
226   TARGETOBJS='$(ALL_TARGETOBJS)'
227 else
228   TARGETOBJS="$targetobjs"
229 fi
230 AC_SUBST(TARGETOBJS)
231
232 AC_DEFINE_UNQUOTED(GOLD_DEFAULT_MACHINE, $default_machine,
233                    [Default machine code])
234 AC_DEFINE_UNQUOTED(GOLD_DEFAULT_SIZE, $default_size,
235                    [Default size (32 or 64)])
236 AC_DEFINE_UNQUOTED(GOLD_DEFAULT_BIG_ENDIAN, $default_big_endian,
237                    [Default big endian (true or false)])
238 AC_DEFINE_UNQUOTED(GOLD_DEFAULT_OSABI, $default_osabi,
239                    [Default OSABI code])
240
241 AC_CHECK_TOOL(NM, nm)
242
243 AC_PROG_CC
244 AC_PROG_CXX
245 AC_PROG_YACC
246 AC_PROG_RANLIB
247 AC_PROG_INSTALL
248 AC_PROG_LN_S
249
250 AC_GNU_SOURCE
251
252 ZW_GNU_GETTEXT_SISTER_DIR
253 AM_PO_SUBDIRS
254
255 AC_C_BIGENDIAN
256
257 AC_EXEEXT
258
259 AM_CONDITIONAL(NATIVE_LINKER,
260   test "x$target_alias" = "x" -o "x$host_alias" = "x$target_alias")
261 AM_CONDITIONAL(GCC, test "$GCC" = yes)
262
263 AM_CONDITIONAL(NATIVE_OR_CROSS_LINKER,
264   test "x$target_alias" = "x" -o "x$host_alias" = "x$target_alias" -o "x$host_alias" = "x$build_alias")
265
266 dnl Test for whether static linking is supported.  Some systems do not
267 dnl install static libraries.  This only affects the set of tests that
268 dnl we run.
269 AC_CACHE_CHECK([whether static linking works], [gold_cv_lib_static],
270 [LDFLAGS_hold=$LDFLAGS
271 LDFLAGS="$LDFLAGS -static"
272 AC_LINK_IFELSE([
273 AC_LANG_PROGRAM([[void f() { }]])],
274 [gold_cv_lib_static=yes], [gold_cv_lib_static=no])
275 LDFLAGS=$LDFLAGS_hold])
276 AM_CONDITIONAL(HAVE_STATIC, test "$gold_cv_lib_static" = "yes")
277
278 dnl Some architectures do not support taking pointers of functions
279 dnl defined in shared libraries except in -fPIC mode.  We need to
280 dnl tell the unittest framework if we're compiling for one of those
281 dnl targets, so it doesn't try to run the tests that do that.
282 AM_CONDITIONAL(FN_PTRS_IN_SO_WITHOUT_PIC, [
283   case $target_cpu in
284     i?86) true;;
285     x86_64) false;;
286     sparc64) false;;
287     *) true;;
288   esac])
289
290 dnl Test for gcc 4.1 or later.  Full support for -mcmodel=medium is
291 dnl only available in gcc 4.1.
292 AC_CACHE_CHECK([for gcc >= 4.1], [gold_cv_prog_gcc41],
293 [AC_COMPILE_IFELSE([
294 #if !defined __GNUC__
295 error
296 #elif __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 1)
297 error
298 #endif
299 ], [gold_cv_prog_gcc41=yes], [gold_cv_prog_gcc41=no])])
300
301 dnl Whether we can test -mcmodel=medium.
302 AM_CONDITIONAL(MCMODEL_MEDIUM,
303 [test "$target_cpu" = "x86_64" -a "$gold_cv_prog_gcc41" = "yes"])
304
305 dnl Test for __thread support.
306 AC_CACHE_CHECK([for thread support], [gold_cv_c_thread],
307 [AC_COMPILE_IFELSE([__thread int i = 1;],
308 [gold_cv_c_thread=yes], [gold_cv_c_thread=no])])
309
310 AM_CONDITIONAL(TLS, test "$gold_cv_c_thread" = "yes")
311
312 dnl On GNU/Linux TLS in static programs only works when using glibc
313 dnl 2.4 or later.
314 AC_CACHE_CHECK([for glibc >= 2.4], [gold_cv_lib_glibc24],
315 [AC_COMPILE_IFELSE([
316 #include <features.h>
317 #if !defined __GLIBC__
318 error
319 #elif __GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 4)
320 error
321 #endif
322 ], [gold_cv_lib_glibc24=yes], [gold_cv_lib_glibc24=no])])
323
324 AM_CONDITIONAL(STATIC_TLS, test "$gold_cv_lib_glibc24" = "yes")
325
326 dnl Test for #pragma omp threadprivate
327 AC_CACHE_CHECK([for omp support], [gold_cv_c_threadprivate],
328 [save_CFLAGS="$CFLAGS"
329 CFLAGS="$CFLAGS -fopenmp"
330 AC_COMPILE_IFELSE([
331 #include <omp.h>
332 int i;
333 #pragma omp threadprivate (i)
334 ], [gold_cv_c_threadprivate=yes], [gold_cv_c_threadprivate=no])
335 CFLAGS="$save_CFLAGS"])
336 if test "$gold_cv_c_threadprivate" = "yes"; then
337   AC_DEFINE(HAVE_OMP_SUPPORT, 1,
338             [Define if compiler supports #pragma omp threadprivate])
339 fi
340 AM_CONDITIONAL(OMP_SUPPORT, test "$gold_cv_c_threadprivate" = "yes")
341
342 dnl Test for the -ftls-dialect=gnu2 option.
343 save_CFLAGS="$CFLAGS"
344 CFLAGS="$CFLAGS -mtls-dialect=gnu2"
345 AC_COMPILE_IFELSE([int i;], [have_tls_gnu2=yes], [have_tls_gnu2=no])
346 CFLAGS="$save_CFLAGS"
347 AM_CONDITIONAL(TLS_GNU2_DIALECT, test "$have_tls_gnu2" = "yes")
348
349 dnl On GNU/Linux TLS descriptors are supported by the dynamic loader
350 dnl only with glibc 2.9 or later.
351 AC_CACHE_CHECK([for glibc >= 2.9], [gold_cv_lib_glibc29],
352 [AC_COMPILE_IFELSE([
353 #include <features.h>
354 #if !defined __GLIBC__
355 error
356 #elif __GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 9)
357 error
358 #endif
359 ], [gold_cv_lib_glibc29=yes], [gold_cv_lib_glibc29=no])])
360
361 AM_CONDITIONAL(TLS_DESCRIPTORS, test "$gold_cv_lib_glibc29" = "yes")
362
363 dnl Test for the -frandom-seed option.
364 AC_CACHE_CHECK([for -frandom-seed support], [gold_cv_c_random_seed],
365 [save_CFLAGS="$CFLAGS"
366 CFLAGS="$CFLAGS -frandom-seed=foo"
367 AC_COMPILE_IFELSE([int i;], [gold_cv_c_random_seed=yes],
368 [gold_cv_c_random_seed=no])
369 CFLAGS="$save_CFLAGS"])
370 if test "$gold_cv_c_random_seed" = "yes"; then
371   # In Makefile, '$@' will be expanded to be the name of the file
372   # being built, providing a unique seed for each file.
373   RANDOM_SEED_CFLAGS=-frandom-seed=\$@
374 fi
375 AC_SUBST(RANDOM_SEED_CFLAGS)
376
377 dnl On GNU/Linux ifunc is supported by the dynamic linker in glibc
378 dnl 2.11 or later, and by binutils 2.20.1 or later.
379 AC_CACHE_CHECK([for glibc ifunc support], [gold_cv_lib_glibc_ifunc],
380 [save_LDFLAGS="$LDFLAGS"
381 LDFLAGS="$LDFLAGS -static"
382 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
383 #include <features.h>
384 #if !defined __GLIBC__
385 error
386 #elif __GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 11)
387 error
388 #endif
389 void func (void) { }
390 void invoke (void);
391 __asm__(".type invoke, %gnu_indirect_function");
392 typedef void (*funcptr) (void);
393 funcptr dispatch (void) __asm__ ("invoke");
394 funcptr dispatch (void) { return &func; }]],
395 [[invoke();]])
396 ], [
397 if ${NM} conftest$EXEEXT | grep "__rela\?_iplt_start" >/dev/null 2>&1; then
398   gold_cv_lib_glibc_ifunc=both
399 else
400   gold_cv_lib_glibc_ifunc=dyn
401 fi], [gold_cv_lib_glibc_ifunc=no])
402 LDFLAGS="$save_LDFLAGS"])
403
404 AM_CONDITIONAL(IFUNC, test "$gold_cv_lib_glibc_ifunc" != "no")
405 AM_CONDITIONAL(IFUNC_STATIC, test "$gold_cv_lib_glibc_ifunc" = "both")
406
407 AM_BINUTILS_WARNINGS
408
409 WARN_CXXFLAGS=`echo ${WARN_CFLAGS} | sed -e 's/-Wstrict-prototypes//' -e 's/-Wmissing-prototypes//' -e 's/-Wshadow//'`
410 AC_SUBST(WARN_CXXFLAGS)
411
412 AC_ARG_WITH(gold-ldflags,
413 [  --with-gold-ldflags=FLAGS  additional link flags for gold],
414 [if test "$withval" = "no" -o "$withval" = "yes"; then
415    GOLD_LDFLAGS=
416  else
417    GOLD_LDFLAGS=$withval
418  fi],
419 [GOLD_LDFLAGS=])
420 AC_SUBST(GOLD_LDFLAGS)
421
422 AC_ARG_WITH(gold-ldadd,
423 [  --with-gold-ldadd=LIBS     additional libraries for gold],
424 [if test "$withval" = "no" -o "$withval" = "yes"; then
425    GOLD_LDADD=
426  else
427    GOLD_LDADD=$withval
428  fi],
429 [GOLD_LDADD=])
430 AC_SUBST(GOLD_LDADD)
431
432 dnl Force support for large files by default.  This may need to be
433 dnl host dependent.  If build == host, we can check getconf LFS_CFLAGS.
434 LFS_CFLAGS="-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64"
435 AC_SUBST(LFS_CFLAGS)
436
437 AC_CHECK_HEADERS(sys/mman.h)
438 AC_CHECK_FUNCS(chsize mmap)
439 AC_REPLACE_FUNCS(pread ftruncate ffsll)
440
441 AC_CACHE_CHECK([mremap with MREMAP_MAYMOVE], [gold_cv_lib_mremap_maymove],
442 [AC_LINK_IFELSE([
443 AC_LANG_PROGRAM([[
444 #include <sys/mman.h>
445 void f() { mremap (0, 0, 0, MREMAP_MAYMOVE); }
446 ]])], [gold_cv_lib_mremap_maymove=yes], [gold_cv_lib_mremap_maymove=no])])
447 if test "$gold_cv_lib_mremap_maymove" = "yes"; then
448   AC_DEFINE(HAVE_MREMAP, 1,
449     [Define to 1 if you have the mremap function with MREMAP_MAYMOVE support])
450 else
451   AC_LIBOBJ(mremap)
452 fi
453
454 # Link in zlib if we can.  This allows us to write compressed sections.
455 AC_SEARCH_LIBS(zlibVersion, z, [AC_CHECK_HEADERS(zlib.h)])
456 AM_CONDITIONAL(HAVE_ZLIB, test "$ac_cv_search_zlibVersion" != "no")
457
458 dnl We have to check these in C, not C++, because autoconf generates
459 dnl tests which have no type information, and current glibc provides
460 dnl multiple declarations of functions like basename when compiling
461 dnl with C++.
462 AC_CHECK_DECLS([basename, ffs, asprintf, vasprintf, snprintf, vsnprintf, strverscmp])
463
464 AC_LANG_PUSH(C++)
465
466 AC_CHECK_HEADERS(tr1/unordered_set tr1/unordered_map)
467 AC_CHECK_HEADERS(ext/hash_map ext/hash_set)
468 AC_CHECK_HEADERS(byteswap.h)
469 AC_CHECK_FUNCS(mallinfo posix_fallocate readv sysconf times)
470 AC_CHECK_DECLS([basename, ffs, asprintf, vasprintf, snprintf, vsnprintf, strverscmp, strndup, memmem])
471
472 # Use of ::std::tr1::unordered_map::rehash causes undefined symbols
473 # at link time with some versions of GCC.
474 AC_CACHE_CHECK([whether ::std::tr1::unordered_map::rehash is usable.],
475 [gold_cv_unordered_map_rehash],
476 [AC_LINK_IFELSE([AC_LANG_PROGRAM([[
477 #include <tr1/unordered_map>
478 void bar() { ::std::tr1::unordered_map<int, int> x; x.rehash(10); }
479 ]])], [gold_cv_unordered_map_rehash=yes], [gold_cv_unordered_map_rehash=no])])
480 if test "$gold_cv_unordered_map_rehash" = "yes"; then
481   AC_DEFINE(HAVE_TR1_UNORDERED_MAP_REHASH, 1,
482             [Define if ::std::tr1::unordered_map::rehash is usable])
483 fi
484
485 # gcc 4.3.0 doesn't recognize the printf attribute on a template
486 # function.  Check for that.  This is gcc bug 35546.  This test can
487 # probably be removed after the bug has been fixed for a while.
488 AC_CACHE_CHECK([whether we can use attributes with template functions],
489 [gold_cv_template_attribute],
490 [AC_COMPILE_IFELSE([
491 template<typename T> extern void foo(const char*, ...)
492   __attribute__ ((__format__ (__printf__, 1, 2)));
493 template<typename T> void foo(const char* format, ...) {}
494 void bar() { foo<int>("%s\n", "foo"); }
495 ], [gold_cv_template_attribute=yes], [gold_cv_template_attribute=no])])
496 if test "$gold_cv_template_attribute" = "yes"; then
497   AC_DEFINE(HAVE_TEMPLATE_ATTRIBUTES, 1,
498             [Define if attributes work on C++ templates])
499 fi
500
501 dnl Check if the system has struct stat::st_mtim.
502 AC_CACHE_CHECK([for struct stat::st_mtim.],
503 [gold_cv_stat_st_mtim],
504 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
505 #include <sys/stat.h>
506 long bar() { struct stat s; return (long)(s.st_mtim.tv_sec + s.st_mtim.tv_sec);}
507 ]])], [gold_cv_stat_st_mtim=yes], [gold_cv_stat_st_mtim=no])])
508 if test "$gold_cv_stat_st_mtim" = "yes"; then
509   AC_DEFINE(HAVE_STAT_ST_MTIM, 1,
510             [Define if struct stat has a field st_mtim with timespec for mtime])
511 fi
512
513 AC_LANG_POP(C++)
514
515 AM_MAINTAINER_MODE
516
517 AC_OUTPUT(Makefile testsuite/Makefile po/Makefile.in:po/Make-in)