On Thu, 2008-12-18 at 18:09 +0100, Michael Haubenwallner wrote:
> following up
> http://lists.gnu.org/archive/html/bug-libtool/2008-12/msg00006.html
> started at
> http://lists.gnu.org/archive/html/bug-libtool/2008-11/msg00082.html

> > > > > +     _LT_TAGVAR(lt_prog_compiler_shared_as_static, 
> > > > > $1)='${wl}-bstatic'
> > > > > +     _LT_TAGVAR(lt_prog_compiler_shared_as_shared, 
> > > > > $1)='${wl}-bdynamic'

> Have extracted the parts to statically link against shared libraries on
> AIX, although I don't have an idea how to get better readability for the
> additional tests in ltmain.m4sh.
> 
> This also applies to the test-cases, which really should utilize
> '-static' whenever possible.

Any update on this?

However, the same patch again, now including ChangeLog.

Thanks!

/haubi/
diff --git a/ChangeLog b/ChangeLog
index 5fe54d7..1616fe3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+2009-02-11  Michael Haubenwallner <[email protected]>
+
+	AIX can link statically against shared libraries.
+	* doc/notes.texi: Add note that this is done when requested.
+	* libltdl/config/ltmain.m4sh: Listen to new link_shared_as_static_flag/
+	link_shared_as_shared_flag.
+	* libltdl/m4/libtool.m4: Introduce lt_prog_compiler_shared_as_static/
+	lt_prog_compiler_shared_as_shared settings, initialize on AIX and map
+	them to new link_shared_as_static_flag/link_shared_as_shared_flag.
+	* tests/demo/configure.ac: Use '-static' also when statically linking
+	against shared libraries is possible.
+	* tests/depdemo/configure.ac: Likewise.
+	* tests/mdemo/configure.ac: Likewise.
+	* tests/mdemo2/configure.ac: Likewise.
+	* tests/pdemo/configure.ac: Likewise.
+
 2009-02-03  Ralf Wildenhues  <[email protected]>
 	    Kurt Roeckx <[email protected]>
 
diff --git a/doc/notes.texi b/doc/notes.texi
index 44b50d1..923c0f8 100644
--- a/doc/notes.texi
+++ b/doc/notes.texi
@@ -4,6 +4,13 @@
 You currently need GNU make to build the Libtool package itself.
 
 @item
+On AIX, everything is PIC, so there is no need to compile two separate objects
+for shared and static libraries. However, AIX can statically link against
+shared libraries (more specifically shared objects) using some linker flags.
+So libtool does not create the static library when shared-library-creation is
+active, but still links statically against the shared library when requested.
+
+...@item
 On AIX there are two different styles of shared linking, one in which symbols
 are bound at link-time and one in which symbols are bound at runtime only,
 similar to e...@.  In case of doubt use @code{LDFLAGS=-Wl,-brtl} for the latter style.
diff --git a/libltdl/config/ltmain.m4sh b/libltdl/config/ltmain.m4sh
index 49e07c3..f5ac92f 100644
--- a/libltdl/config/ltmain.m4sh
+++ b/libltdl/config/ltmain.m4sh
@@ -3850,8 +3850,10 @@ func_mode_link ()
 	  fi
 	  if test -n "$link_static_flag"; then
 	    dlopen_self=$dlopen_self_static
+	    prefer_static_libs=all
+	  else
+	    prefer_static_libs=yes
 	  fi
-	  prefer_static_libs=yes
 	  ;;
 	-static)
 	  if test -z "$pic_flag" && test -n "$link_static_flag"; then
@@ -5475,7 +5477,17 @@ func_mode_link ()
 	    fi
 	    if test "$linkmode" = prog; then
 	      test -n "$add_dir" && compile_deplibs="$add_dir $compile_deplibs"
+	      # AIX can link 'shared objects' statically:
+	      test "$use_static_libs" != no &&
+		test "$use_static_libs" != all &&
+		test -n "$link_shared_as_static_flag" &&
+		eval "compile_deplibs=\"$link_shared_as_static_flag \$compile_deplibs\""
 	      test -n "$add" && compile_deplibs="$add $compile_deplibs"
+	      # switch back to link 'shared objects' dynamically:
+	      test "$use_static_libs" != no &&
+		test "$use_static_libs" != all &&
+		test -n "$link_shared_as_shared_flag" &&
+		eval "compile_deplibs=\"$link_shared_as_shared_flag \$compile_deplibs\""
 	    else
 	      test -n "$add_dir" && deplibs="$add_dir $deplibs"
 	      test -n "$add" && deplibs="$add $deplibs"
@@ -5530,10 +5542,30 @@ func_mode_link ()
 
 	    if test "$linkmode" = prog; then
 	      test -n "$add_dir" && finalize_deplibs="$add_dir $finalize_deplibs"
+	      # AIX can link 'shared objects' statically:
+	      test "$use_static_libs" != no &&
+		test "$use_static_libs" != all &&
+		test -n "$link_shared_as_static_flag" &&
+		eval "finalize_deplibs=\"$link_shared_as_static_flag \$finalize_deplibs\""
 	      test -n "$add" && finalize_deplibs="$add $finalize_deplibs"
+	      # switch back to link 'shared objects' dynamically:
+	      test "$use_static_libs" != no &&
+		test "$use_static_libs" != all &&
+		test -n "$link_shared_as_shared_flag" &&
+		eval "finalize_deplibs=\"$link_shared_as_shared_flag \$finalize_deplibs\""
 	    else
 	      test -n "$add_dir" && deplibs="$add_dir $deplibs"
+	      # AIX can link 'shared objects' statically:
+	      test "$use_static_libs" != no &&
+		test "$use_static_libs" != all &&
+		test -n "$link_shared_as_static_flag" &&
+		eval "deplibs=\"$link_shared_as_static_flag \$deplibs\""
 	      test -n "$add" && deplibs="$add $deplibs"
+	      # switch back to link 'shared objects' dynamically:
+	      test "$use_static_libs" != no &&
+		test "$use_static_libs" != all &&
+		test -n "$link_shared_as_shared_flag" &&
+		eval "deplibs=\"$link_shared_as_shared_flag \$deplibs\""
 	    fi
 	  fi
 	elif test "$linkmode" = prog; then
@@ -5589,6 +5621,7 @@ func_mode_link ()
 	  if test -n "$dependency_libs" &&
 	     { test "$hardcode_into_libs" != yes ||
 	       test "$build_old_libs" = yes ||
+	       test -n "$link_shared_as_static_flag" ||
 	       test "$link_static" = yes; }; then
 	    # Extract -R from dependency_libs
 	    temp_deplibs=
@@ -6179,7 +6212,8 @@ func_mode_link ()
 	  *) finalize_rpath="$finalize_rpath $libdir" ;;
 	  esac
 	done
-	if test "$hardcode_into_libs" != yes || test "$build_old_libs" = yes; then
+	if test "$hardcode_into_libs" != yes || test "$build_old_libs" = yes ||
+	   test -n "$link_shared_as_static_flag"; then
 	  dependency_libs="$temp_xrpath $dependency_libs"
 	fi
       fi
diff --git a/libltdl/m4/libtool.m4 b/libltdl/m4/libtool.m4
index b75a55a..0805d20 100644
--- a/libltdl/m4/libtool.m4
+++ b/libltdl/m4/libtool.m4
@@ -3479,6 +3479,8 @@ m4_defun([_LT_COMPILER_PIC],
 _LT_TAGVAR(lt_prog_compiler_wl, $1)=
 _LT_TAGVAR(lt_prog_compiler_pic, $1)=
 _LT_TAGVAR(lt_prog_compiler_static, $1)=
+_LT_TAGVAR(lt_prog_compiler_shared_as_static, $1)=
+_LT_TAGVAR(lt_prog_compiler_shared_as_shared, $1)=
 
 AC_MSG_CHECKING([for $compiler option to produce PIC])
 m4_if([$1], [CXX], [
@@ -3493,6 +3495,9 @@ m4_if([$1], [CXX], [
       if test "$host_cpu" = ia64; then
 	# AIX 5 now supports IA64 processor
 	_LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+      else
+	_LT_TAGVAR(lt_prog_compiler_shared_as_static, $1)='${wl}-bstatic'
+	_LT_TAGVAR(lt_prog_compiler_shared_as_shared, $1)='${wl}-bdynamic'
       fi
       ;;
 
@@ -3570,6 +3575,8 @@ m4_if([$1], [CXX], [
 	  _LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
 	else
 	  _LT_TAGVAR(lt_prog_compiler_static, $1)='-bnso -bI:/lib/syscalls.exp'
+	  _LT_TAGVAR(lt_prog_compiler_shared_as_static, $1)='-bstatic'
+	  _LT_TAGVAR(lt_prog_compiler_shared_as_shared, $1)='-bdynamic'
 	fi
 	;;
       chorus*)
@@ -3799,6 +3806,9 @@ m4_if([$1], [CXX], [
       if test "$host_cpu" = ia64; then
 	# AIX 5 now supports IA64 processor
 	_LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
+      else
+	_LT_TAGVAR(lt_prog_compiler_shared_as_static, $1)='${wl}-bstatic'
+	_LT_TAGVAR(lt_prog_compiler_shared_as_shared, $1)='${wl}-bdynamic'
       fi
       ;;
 
@@ -3888,6 +3898,8 @@ m4_if([$1], [CXX], [
 	_LT_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
       else
 	_LT_TAGVAR(lt_prog_compiler_static, $1)='-bnso -bI:/lib/syscalls.exp'
+	_LT_TAGVAR(lt_prog_compiler_shared_as_static, $1)='-bstatic'
+	_LT_TAGVAR(lt_prog_compiler_shared_as_shared, $1)='-bdynamic'
       fi
       ;;
 
@@ -4092,6 +4104,10 @@ _LT_LINKER_OPTION([if $compiler static flag $lt_tmp_static_flag works],
   [_LT_TAGVAR(lt_prog_compiler_static, $1)=])
 _LT_TAGDECL([link_static_flag], [lt_prog_compiler_static], [1],
 	[Compiler flag to prevent dynamic linking])
+_LT_TAGDECL([link_shared_as_static_flag], [lt_prog_compiler_shared_as_static], [1],
+	[Compiler flag to link subsequent shared objects statically - AIX can do that])
+_LT_TAGDECL([link_shared_as_shared_flag], [lt_prog_compiler_shared_as_shared], [1],
+	[Compiler flag to link subsequent shared objects dynamically])
 ])# _LT_COMPILER_PIC
 
 
diff --git a/tests/demo/configure.ac b/tests/demo/configure.ac
index ccfc6fb..6880d40 100644
--- a/tests/demo/configure.ac
+++ b/tests/demo/configure.ac
@@ -51,7 +51,7 @@ LT_INIT([dlopen win32-dll])
 AC_SUBST([LIBTOOL_DEPS])
 
 STATIC=
-test "X$enable_static" = Xyes && STATIC=-static
+test "X$enable_static" = Xyes -o "X$lt_lt_prog_compiler_shared_as_static" != X && STATIC=-static
 AC_SUBST([STATIC])
 
 case $lt_cv_sys_global_symbol_pipe in
diff --git a/tests/depdemo/configure.ac b/tests/depdemo/configure.ac
index 31231f3..95d7c25 100644
--- a/tests/depdemo/configure.ac
+++ b/tests/depdemo/configure.ac
@@ -53,6 +53,7 @@ AC_SUBST([LIBTOOL_DEPS])
 ## depdemo specific configuration. ##
 ## ------------------------------- ##
 STATIC="\`${CONFIG_SHELL} ./libtool --features | ${SED} -n -e '/enable static/s/^.*\$\$/-static/p'\`"
+test "X$lt_lt_prog_compiler_shared_as_static" != X && STATIC=-static
 AC_SUBST([STATIC])
 
 ## ------------------------------ ##
diff --git a/tests/mdemo/configure.ac b/tests/mdemo/configure.ac
index c1a88f2..ee90537 100644
--- a/tests/mdemo/configure.ac
+++ b/tests/mdemo/configure.ac
@@ -55,7 +55,7 @@ LT_INIT([dlopen win32-dll])
 AC_SUBST(LIBTOOL_DEPS)
 
 STATIC=""
-test "X$enable_static" = Xyes && STATIC="-static"
+test "X$enable_static" = Xyes -o "X$lt_lt_prog_compiler_shared_as_static" != X && STATIC="-static"
 AC_SUBST([STATIC])
 
 
diff --git a/tests/mdemo2/configure.ac b/tests/mdemo2/configure.ac
index c73ae5f..52c0e0b 100644
--- a/tests/mdemo2/configure.ac
+++ b/tests/mdemo2/configure.ac
@@ -51,7 +51,7 @@ LT_INIT([dlopen])
 AC_SUBST(LIBTOOL_DEPS)
 
 STATIC=""
-test "X$enable_static" = Xyes && STATIC="-static"
+test "X$enable_static" = Xyes -o "X$lt_lt_prog_compiler_shared_as_static" != X && STATIC="-static"
 AC_SUBST([STATIC])
 
 
diff --git a/tests/pdemo/configure.ac b/tests/pdemo/configure.ac
index 83cb5d4..a9c12d4 100644
--- a/tests/pdemo/configure.ac
+++ b/tests/pdemo/configure.ac
@@ -51,7 +51,7 @@ LT_INIT([dlopen])
 AC_SUBST([LIBTOOL_DEPS])
 
 STATIC=
-test "X$enable_static" = Xyes && STATIC=-static
+test "X$enable_static" = Xyes -o "X$lt_lt_prog_compiler_shared_as_static" != X && STATIC=-static
 AC_SUBST([STATIC])
 
 case $lt_cv_sys_global_symbol_pipe in

Reply via email to