[PATCH v3] gold: Use autotools pthread macro
Joshua Watt
jpewhacker@gmail.com
Tue Jun 19 02:54:00 GMT 2018
The autotools library macro (AX_PTHREAD) is now used to detect if
pthreads is present and multi-threaded linking in gold is automatically
enabled if it is found. This enables multi-threaded gold on platforms
where pthreads is enabled via other methods than just -lpthread (e.g.
MinGW)
Signed-off-by: Joshua Watt <JPEWhacker@gmail.com>
---
gold/Makefile.am | 11 +++++------
gold/aclocal.m4 | 1 +
gold/configure.ac | 38 +++++++++++++++++++++++---------------
3 files changed, 29 insertions(+), 21 deletions(-)
diff --git a/gold/Makefile.am b/gold/Makefile.am
index 675deecb47..f87067aab4 100644
--- a/gold/Makefile.am
+++ b/gold/Makefile.am
@@ -31,8 +31,11 @@ ACLOCAL_AMFLAGS = -I ../bfd -I ../config
ZLIB = @zlibdir@ -lz
ZLIBINC = @zlibinc@
-AM_CFLAGS = $(WARN_CFLAGS) $(LFS_CFLAGS) $(RANDOM_SEED_CFLAGS) $(ZLIBINC)
-AM_CXXFLAGS = $(WARN_CXXFLAGS) $(LFS_CFLAGS) $(RANDOM_SEED_CFLAGS) $(ZLIBINC)
+THREADFLAGS = @PTHREAD_CFLAGS@
+THREADLIBS = @PTHREAD_LIBS@
+
+AM_CFLAGS = $(WARN_CFLAGS) $(LFS_CFLAGS) $(RANDOM_SEED_CFLAGS) $(ZLIBINC) $(THREADFLAGS)
+AM_CXXFLAGS = $(WARN_CXXFLAGS) $(LFS_CFLAGS) $(RANDOM_SEED_CFLAGS) $(ZLIBINC) $(THREADFLAGS)
AM_CPPFLAGS = \
-I$(srcdir) -I$(srcdir)/../include -I$(srcdir)/../elfcpp \
@@ -46,10 +49,6 @@ if PLUGINS
LIBDL = @DLOPEN_LIBS@
endif
-if THREADS
-THREADSLIB = -lpthread
-endif
-
AM_YFLAGS = -d
# Automake 1.10+ disables lex and yacc output file regeneration if
diff --git a/gold/aclocal.m4 b/gold/aclocal.m4
index 2a792230f4..5edbc17b40 100644
--- a/gold/aclocal.m4
+++ b/gold/aclocal.m4
@@ -1000,6 +1000,7 @@ AC_SUBST([am__tar])
AC_SUBST([am__untar])
]) # _AM_PROG_TAR
+m4_include([../config/ax_pthread.m4])
m4_include([../config/depstand.m4])
m4_include([../config/gettext-sister.m4])
m4_include([../config/lcmessage.m4])
diff --git a/gold/configure.ac b/gold/configure.ac
index 1ed6c0d45c..abf96c62c8 100644
--- a/gold/configure.ac
+++ b/gold/configure.ac
@@ -87,21 +87,6 @@ AC_ARG_ENABLE(gold,
AC_SUBST(install_as_default)
AC_SUBST(installed_linker)
-dnl For now threads are a configure time option.
-AC_ARG_ENABLE([threads],
-[ --enable-threads multi-threaded linking],
-[case "${enableval}" in
- yes | "") threads=yes ;;
- no) threads=no ;;
- *) threads=yes ;;
- esac],
-[threads=no])
-if test "$threads" = "yes"; then
- AC_DEFINE(ENABLE_THREADS, 1,
- [Define to do multi-threaded linking])
-fi
-AM_CONDITIONAL(THREADS, test "$threads" = "yes")
-
AC_PLUGINS
if test "$plugins" = "yes"; then
AC_DEFINE(ENABLE_PLUGINS, 1,
@@ -565,6 +550,29 @@ fi
# Link in zlib if we can. This allows us to write compressed sections.
AM_ZLIB
+
+AC_ARG_ENABLE([threads],
+[[ --enable-threads[=ARG] multi-threaded linking [ARG={auto,yes,no}]]],
+[case "${enableval}" in
+ yes | "") threads=yes ;;
+ no) threads=no ;;
+ auto) threads=auto ;;
+ *) threads=yes ;;
+ esac],
+[threads=auto])
+
+if test "$threads" = "yes"; then
+ AX_PTHREAD([thread=yes], AC_MSG_ERROR([pthread not found]))
+elif test "$threads" = "auto"; then
+ AX_PTHREAD([threads=yes], [threads=no])
+fi
+
+if test "$threads" = "yes"; then
+ AC_DEFINE(ENABLE_THREADS, 1,
+ [Define to do multi-threaded linking])
+fi
+AM_CONDITIONAL(THREADS, test "$threads" = "yes")
+
dnl We have to check these in C, not C++, because autoconf generates
dnl tests which have no type information, and current glibc provides
dnl multiple declarations of functions like basename when compiling
--
2.17.0
More information about the Binutils
mailing list