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