0ab684
From bb3db69e2a0c210cc3a63940622db96a97eb7947 Mon Sep 17 00:00:00 2001
0ab684
From: nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>
0ab684
Date: Fri, 2 Mar 2018 01:37:53 +0000
0ab684
Subject: [PATCH] configure.ac: library options to MAINLIBS
0ab684
0ab684
* configure.ac (MAINLIBS): moved library options for main program
0ab684
  and static libruby, and append MAINLIBS to LIBRUBYARG_STATIC, as
0ab684
  these libraries are not needed for linking to shared libruby.
0ab684
  [ruby-core:85882] [Bug #14422]
0ab684
0ab684
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62627 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
0ab684
---
0ab684
 configure.ac        | 33 +++++++++++++++------------------
0ab684
 template/ruby.pc.in |  1 +
0ab684
 win32/Makefile.sub  |  6 ++++--
0ab684
 3 files changed, 20 insertions(+), 20 deletions(-)
0ab684
0ab684
diff --git a/configure.ac b/configure.ac
0ab684
index aebbae1969a5..733a0c992fd7 100644
0ab684
--- a/configure.ac
0ab684
+++ b/configure.ac
0ab684
@@ -10,6 +10,7 @@ AC_DISABLE_OPTION_CHECKING
0ab684
 AC_ARG_VAR([cflags], [additional CFLAGS])
0ab684
 AC_ARG_VAR([cppflags], [additional CPPFLAGS])
0ab684
 AC_ARG_VAR([cxxflags], [additional CXXFLAGS])
0ab684
+ORIG_LIBS=$LIBS
0ab684
 
0ab684
 AC_DEFUN([RUBY_RM_RECURSIVE], [
0ab684
 m4_version_prereq([2.70], [-1], [
3aa0f2
@@ -2939,13 +2940,11 @@ AS_IF([test x"$enable_pthread" = xyes], [
0ab684
 	AC_DEFINE(_THREAD_SAFE)
0ab684
 	AC_DEFINE(HAVE_LIBPTHREAD)
0ab684
 	AC_CHECK_HEADERS(pthread_np.h, [], [], [@%:@include <pthread.h>])
0ab684
-	AS_CASE([$pthread_lib],
0ab684
-	[c],    [],
0ab684
-	[root], [],
0ab684
-	[c_r],  [MAINLIBS="-pthread $MAINLIBS"],
0ab684
-	        [AS_CASE(["$target_os"],
0ab684
-		    [openbsd*|mirbsd*], [LIBS="-pthread $LIBS"],
0ab684
-		    [LIBS="-l$pthread_lib $LIBS"])])
0ab684
+	AS_CASE(["$pthread_lib:$target_os"],
0ab684
+		[c:*], [],
0ab684
+		[root:*], [],
0ab684
+		[c_r:*|*:openbsd*|*:mirbsd*],  [LIBS="-pthread $LIBS"],
0ab684
+		[LIBS="-l$pthread_lib $LIBS"])
0ab684
     ], [
0ab684
 	AC_MSG_WARN("Don't know how to find pthread library on your system -- thread support disabled")
0ab684
     ])
3aa0f2
@@ -3624,7 +3623,7 @@ LIBRUBY_A='lib$(RUBY_SO_NAME)-static.a'
0ab684
 LIBRUBY='$(LIBRUBY_A)'
0ab684
 LIBRUBYARG_STATIC='-l$(RUBY_SO_NAME)-static'
0ab684
 LIBRUBYARG='$(LIBRUBYARG_STATIC)'
0ab684
-SOLIBS=
0ab684
+SOLIBS='$(MAINLIBS)'
0ab684
 
0ab684
 AS_CASE(["$target_os"],
0ab684
   [cygwin*|mingw*|haiku*|darwin*], [
3aa0f2
@@ -3690,9 +3689,6 @@ AS_CASE("$enable_shared", [yes], [
0ab684
   LIBRUBY_RELATIVE=no
0ab684
   test -z "$CCDLFLAGS" || CFLAGS="$CFLAGS $CCDLFLAGS"
0ab684
   ENABLE_SHARED=yes
0ab684
-  AS_IF([test "$rb_cv_binary_elf" = yes], [
0ab684
-    SOLIBS='$(LIBS)'
0ab684
-  ])
0ab684
 
0ab684
   # libdir can be overridden in config.site file (on OpenSUSE at least).
0ab684
   libdir_basename=lib
3aa0f2
@@ -3727,7 +3723,6 @@ AS_CASE("$enable_shared", [yes], [
0ab684
 	])
0ab684
 	],
0ab684
     [freebsd*|dragonfly*], [
0ab684
-	SOLIBS='$(LIBS)'
0ab684
 	LIBRUBY_SO='lib$(RUBY_SO_NAME).$(SOEXT).$(MAJOR)$(MINOR)'
0ab684
 	LIBRUBY_SONAME='$(LIBRUBY_SO)'
0ab684
 	AS_IF([test "$rb_cv_binary_elf" != "yes" ], [
3aa0f2
@@ -3736,7 +3731,6 @@ AS_CASE("$enable_shared", [yes], [
0ab684
 	])
0ab684
 	],
0ab684
     [netbsd*], [
0ab684
-	SOLIBS='$(LIBS)'
0ab684
 	LIBRUBY_SONAME='lib$(RUBY_SO_NAME).$(SOEXT).$(MAJOR)$(MINOR)'
0ab684
 	LIBRUBY_SO="${LIBRUBY_SONAME}"'.$(TEENY)'
0ab684
 	RUBY_APPEND_OPTIONS(LIBRUBY_DLDFLAGS, ['-Wl,-soname,$(LIBRUBY_SONAME)' "$LDFLAGS_OPTDIR"])
3aa0f2
@@ -3747,11 +3741,9 @@ AS_CASE("$enable_shared", [yes], [
0ab684
 	])
0ab684
 	],
0ab684
     [openbsd*|mirbsd*], [
0ab684
-	SOLIBS='$(LIBS)'
0ab684
 	LIBRUBY_SO='lib$(RUBY_SO_NAME).$(SOEXT).$(MAJOR).'`expr ${MINOR} \* 10 + ${TEENY}`
0ab684
 	],
0ab684
     [solaris*], [
0ab684
-	SOLIBS='$(LIBS)'
0ab684
 	LIBRUBY_SO='lib$(RUBY_SO_NAME).$(SOEXT).$(MAJOR)'
0ab684
 	LIBRUBY_SONAME='lib$(RUBY_SO_NAME).$(SOEXT).$(RUBY_PROGRAM_VERSION)'
0ab684
 	LIBRUBY_ALIASES='$(LIBRUBY_SONAME) lib$(RUBY_SO_NAME).$(SOEXT)'
3aa0f2
@@ -3769,7 +3761,7 @@ AS_CASE("$enable_shared", [yes], [
0ab684
     [aix*], [
0ab684
 	RUBY_APPEND_OPTIONS(LIBRUBY_DLDFLAGS, ["${linker_flag}-bnoentry" "$XLDFLAGS" "$LDFLAGS_OPTDIR"])
0ab684
 	LIBRUBYARG_SHARED='-L${libdir} -l${RUBY_SO_NAME}'
0ab684
-	SOLIBS='-lm -lc'
0ab684
+	LIBS="$LIBS -lm -lc"
0ab684
 	],
0ab684
     [darwin*], [
0ab684
 	LIBRUBY_LDSHARED='$(CC) -dynamiclib'
3aa0f2
@@ -3789,7 +3781,6 @@ AS_CASE("$enable_shared", [yes], [
0ab684
 	LIBRUBY_SO='lib$(RUBY_SO_NAME).$(SOEXT)'
0ab684
 	LIBRUBY_SONAME='lib$(RUBY_BASE_NAME).$(RUBY_API_VERSION).$(SOEXT)'
0ab684
 	LIBRUBY_ALIASES='$(LIBRUBY_SONAME) lib$(RUBY_INSTALL_NAME).$(SOEXT)'
0ab684
-	SOLIBS='$(LIBS)'
0ab684
 	],
0ab684
     [interix*], [
0ab684
 	LIBRUBYARG_SHARED='-L. -L${libdir} -l$(RUBY_SO_NAME)'
3aa0f2
@@ -4032,7 +4023,6 @@ AS_CASE(["$target_os"],
0ab684
 	    ])
0ab684
 	LIBRUBY_ALIASES=''
0ab684
 	FIRSTMAKEFILE=GNUmakefile:cygwin/GNUmakefile.in
0ab684
-	SOLIBS='$(LIBS)'
0ab684
 	AS_IF([test x"$enable_shared" = xyes], [
0ab684
 	    LIBRUBY='lib$(RUBY_SO_NAME).dll.a'
0ab684
 	], [
3aa0f2
@@ -4132,6 +4122,13 @@ AS_IF([test "${universal_binary-no}" = yes ], [
0ab684
 		[rb_cv_architecture_available=yes], [rb_cv_architecture_available=no]))
0ab684
 ])
0ab684
 
0ab684
+MAINLIBS="$LIBS"
0ab684
+LIBS=$ORIG_LIBS
0ab684
+AS_IF([test -n "${LIBS}"], [
0ab684
+    libspat=`echo "${LIBS}" | sed 's/[[][|.*$^]]/\\&/;;s/^  */ /;s/^  *$/ /'`
0ab684
+    MAINFLAGS=`echo " $MAINLIBS " | sed "s|$libspat"'||;s/^ *//;s/ *$//'`
0ab684
+])
0ab684
+LIBRUBYARG_STATIC="${LIBRUBYARG_STATIC} \$(MAINLIBS)"
0ab684
 CPPFLAGS="$CPPFLAGS "'$(DEFS)'
0ab684
 test -z "$CPPFLAGS" || CPPFLAGS="$CPPFLAGS "; CPPFLAGS="$CPPFLAGS"'${cppflags}'
0ab684
 AS_IF([test -n "${cflags+set}"], [
0ab684
diff --git a/template/ruby.pc.in b/template/ruby.pc.in
0ab684
index d874f92c3b20..7ce4461c05df 100644
0ab684
--- a/template/ruby.pc.in
0ab684
+++ b/template/ruby.pc.in
0ab684
@@ -39,6 +39,7 @@ sitehdrdir=@sitehdrdir@
0ab684
 rubyarchhdrdir=@rubyarchhdrdir@
0ab684
 vendorarchhdrdir=@vendorarchhdrdir@
0ab684
 sitearchhdrdir=@sitearchhdrdir@
0ab684
+MAINLIBS=@MAINLIBS@
0ab684
 SOEXT=@SOEXT@
0ab684
 LIBPATH=@LIBPATH@
0ab684
 LIBRUBY_A=@LIBRUBY_A@
0ab684
diff --git a/win32/Makefile.sub b/win32/Makefile.sub
0ab684
index 8673c121641e..f8316cccb68e 100644
0ab684
--- a/win32/Makefile.sub
0ab684
+++ b/win32/Makefile.sub
0ab684
@@ -279,6 +279,7 @@ MJIT_DEBUGFLAGS = $(DEBUGFLAGS)
0ab684
 CPPFLAGS = $(DEFS) $(ARCHDEFS) $(CPPFLAGS)
0ab684
 
0ab684
 DLDFLAGS = $(LDFLAGS) -dll
0ab684
+MAINLIBS = $(LIBS)
0ab684
 SOLIBS =
0ab684
 RCFILES = $(RUBY_INSTALL_NAME).rc $(RUBYW_INSTALL_NAME).rc $(RUBY_SO_NAME).rc
0ab684
 !ifndef RCFLAGS
0ab684
@@ -821,7 +822,8 @@ s,@CPPFLAGS@,$(CPPFLAGS),;t t
0ab684
 s,@CXXFLAGS@,$(CXXFLAGS),;t t
0ab684
 s,@FFLAGS@,$(FFLAGS),;t t
0ab684
 s,@LDFLAGS@,$(LDFLAGS),;t t
0ab684
-s,@LIBS@,$(LIBS),;t t
0ab684
+s,@LIBS@,,;t t
0ab684
+s,@MAINLIBS@,$(MAINLIBS),;t t
0ab684
 s,@exec_prefix@,$${prefix},;t t
0ab684
 s,@prefix@,$(prefix),;t t
0ab684
 s,@program_transform_name@,s,.*,$(PROGRAM_PREFIX)&$(PROGRAM_SUFFIX),,;t t
0ab684
@@ -909,7 +911,7 @@ s,@LIBRUBY_SO@,$$(RUBY_SO_NAME).dll,;t t
0ab684
 s,@LIBRUBY_ALIASES@,$(LIBRUBY_ALIASES),;t t
0ab684
 s,@LIBRUBY@,$$(RUBY_SO_NAME).lib,;t t
0ab684
 s,@LIBRUBYARG@,$$(LIBRUBYARG_SHARED),;t t
0ab684
-s,@LIBRUBYARG_STATIC@,$$(LIBRUBY_A),;t t
0ab684
+s,@LIBRUBYARG_STATIC@,$$(LIBRUBY_A) $$(MAINLIBS),;t t
0ab684
 s,@LIBRUBYARG_SHARED@,$$(LIBRUBY),;t t
0ab684
 s,@SOLIBS@,$(SOLIBS),;t t
0ab684
 s,@DLDLIBS@,$(DLDLIBS),;t t