Hi,

over the last months, there were multiple discussions on the libtool
mailing list about the need for building static-only or shared-only
libraries on a per target basis.  Up to now, libtool has a -static
flag for compile and link mode but its meaning is not consistent.
In compile mode, -static forces building of an .o file but also
builds a .lo file if the host system supports shared libraries, and
libtool was configured with --enable-shared.  In link mode, on the
other hand, -static forces building a static library but does not
build a shared library even if building a shared library is supported
or configured.  Adding the -static flag for compile mode is IMHO only
meaningful when using -static for link mode, too.  Therefore -static
must not build a .lo file in compile mode.

While the -static flag allows a package maintainer to explicitly build
a static-only library, libtool has no option for building a shared-only
library.  Below is a patch against libtool CVS from 2003-07-31 together
with a ChangeLog entry.  It adds a -shared flag to libtool and changes
the behavior of -static in compile mode as described above.  I've also
attached a tiny demo project for testing.

2003-08-03  Ralph Schleicher  <[EMAIL PROTECTED]>

        * doc/libtool.texi (Link mode): Document new -shared option.
        (Compile mode): Document new -shared option, and be more specific
        about the effect of the -static option.
        * ltmain.in: Implement it.

diff -c2d libtool-20030731/doc/libtool.texi.orig libtool-20030731/doc/libtool.texi
*** libtool-20030731/doc/libtool.texi.orig	Tue Apr 22 18:01:21 2003
--- libtool-20030731/doc/libtool.texi	Sun Aug  3 05:57:10 2003
***************
*** 1154,1159 ****
  and @samp{-Xcompiler @var{flag}}.
  
! If the @samp{-static} option is given, then a @samp{.o} file is built,
! even if libtool was configured with @samp{--disable-static}.
  
  Note that the @samp{-o} option is now fully supported.  It is emulated
--- 1154,1164 ----
  and @samp{-Xcompiler @var{flag}}.
  
! If the @samp{-static} option is given, then only a @samp{.o} file is
! built, even if libtool was configured with @samp{--disable-static}.
! 
! If the @samp{-shared} option is given, then no @samp{.o} file is built,
! even if libtool was configured with @samp{--enable-static}.  Libtool
! will signal an error if it was configured with @samp{--disable-shared},
! or if the host does not support shared libraries.
  
  Note that the @samp{-o} option is now fully supported.  It is emulated
***************
*** 1297,1300 ****
--- 1302,1313 ----
  program, @var{libdir} will be added to its run-time path.
  
+ @item -shared
+ If @var{output-file} is a program, then link it against any
+ uninstalled shared libtool libraries (this is the default behavior).
+ If @var{output-file} is a library, then only create a shared library.
+ In the later case, libtool will signal an error if it was configured
+ with @samp{--disable-shared}, or if the host does not support shared
+ libraries.
+ 
  @item -static
  If @var{output-file} is a program, then do not link it against any
diff -c2d libtool-20030731/ltmain.in.orig libtool-20030731/ltmain.in
*** libtool-20030731/ltmain.in.orig	Tue Jul 15 18:01:59 2003
--- libtool-20030731/ltmain.in	Sun Aug  3 07:15:33 2003
***************
*** 401,405 ****
--- 401,416 ----
  	  ;;
  
+ 	-shared)
+ 	  if test "$build_libtool_libs" != yes; then
+ 	    $echo "$modename: can not build a shared library" 1>&2
+ 	    $echo "Fatal configuration error." 1>&2
+ 	    exit 1
+ 	  fi
+ 	  build_old_libs=no
+ 	  continue
+ 	  ;;
+ 
  	-static)
+ 	  build_libtool_libs=no
  	  build_old_libs=yes
  	  continue
***************
*** 885,888 ****
--- 896,908 ----
      do
        case $arg in
+       -shared)
+ 	if test "$build_libtool_libs" != yes; then
+ 	  $echo "$modename: can not build a shared library" 1>&2
+ 	  $echo "Fatal configuration error." 1>&2
+ 	  exit 1
+ 	fi
+ 	build_old_libs=no
+ 	break
+ 	;;
        -all-static | -static)
  	if test "X$arg" = "X-all-static"; then
***************
*** 892,895 ****
--- 912,918 ----
  	  if test -n "$link_static_flag"; then
  	    dlopen_self=$dlopen_self_static
+ 	    # See comment for -static flag below, for more details.
+ 	    compile_command="$compile_command $link_static_flag"
+ 	    finalize_command="$finalize_command $link_static_flag"
  	  fi
  	else
***************
*** 1161,1168 ****
        case $arg in
        -all-static)
! 	if test -n "$link_static_flag"; then
! 	  compile_command="$compile_command $link_static_flag"
! 	  finalize_command="$finalize_command $link_static_flag"
! 	fi
  	continue
  	;;
--- 1184,1188 ----
        case $arg in
        -all-static)
! 	# The effects of -all-static are defined in a previous loop.
  	continue
  	;;
***************
*** 1384,1387 ****
--- 1404,1412 ----
  	;;
  
+       -shared)
+ 	# The effects of -shared are defined in a previous loop.
+ 	continue
+ 	;;
+ 
        -static)
  	# The effects of -static are defined in a previous loop.
***************
*** 6143,6147 ****
    -prefer-pic       try to building PIC objects only
    -prefer-non-pic   try to building non-PIC objects only
!   -static           always build a \`.o' file suitable for static linking
  
  COMPILE-COMMAND is a command to be used in creating a \`standard' object file
--- 6168,6173 ----
    -prefer-pic       try to building PIC objects only
    -prefer-non-pic   try to building non-PIC objects only
!   -shared           do not build a \`.o' file suitable for static linking
!   -static           only build a \`.o' file suitable for static linking
  
  COMPILE-COMMAND is a command to be used in creating a \`standard' object file
***************
*** 6230,6233 ****
--- 6256,6260 ----
    -rpath LIBDIR     the created library will eventually be installed in LIBDIR
    -R[ ]LIBDIR       add LIBDIR to the runtime path of programs and libraries
+   -shared           only do dynamic linking of libtool libraries
    -static           do not do any dynamic linking of libtool libraries
    -version-info CURRENT[:REVISION[:AGE]]

Attachment: libtool-demo.shar
Description: Binary data

Best regards,

-- 
Ralph
_______________________________________________
Libtool mailing list
[EMAIL PROTECTED]
http://mail.gnu.org/mailman/listinfo/libtool

Reply via email to