Guys,

This preliminary patch aims to add better support for a shared libparrot library (don't apply it yet!).

* First I've added config/inter/libparrot.pl to interactively prompt for whether a shared library should be built. This can be defaulted by platform hints (defaulting off for now, with cygwin on)

* I've split out the config variable for the directory blib/lib from the library name and believe that I've fixed its use everywhere

 * mkdir'ing blib/lib can now be performed on a variable

 * The names for static/shared libraries are assigned to make variables

 * LIBPARROT is set by Configure to be the appropriate target to be used

* When linking, I'm using '-L blib/lib -l parrot' which assumes that only one library exists. While it is possible to explicitly link with blib/lib/libparrot.so, this causes problems locating the library when not in the top-level directory

Now for the bit I'd appreciate some thoughts on... parrot needs help locating the shared library pre-installation. There seem to be three standard ways to do this:

* LD_LIBRARY_PATH: This is guaranteed to work, but is really a user variable. It can of course be used for short periods 'LD_LIBRARY_PATH=blib/lib ./parrot ...' with some shells

* A wrapper script: This can be used to set LD_LIBRARY_PATH, but needs us to do some more work

* -rpath: I don't know how well supported across platforms this is, is it specific to the GNU toolchain?

 * [On cygwin it's located using the PATH!]

This problem only really arises during building, as once installed the library can be found system-wide. What I suggest for now is that we try to use -rpath if supported, and failing that request that the developer set LD_LIBRARY_PATH. I'm currently using -rpath on miniparrot, parrot, the parrot utilities (pdb, pbc_merge etc.) but not installable_parrot. The parrot utilities probably need relinking before installing system-wide (as libtool would) but there would more likely currently be run in the build environment.

I'm not suggesting we apply this yet, but if you run a non-Linux platform, particularly on Windows, can you let me know of any breakage before we cause problems for a wider audience.

Check that the static case works, and then either set libparrot_build_shared to 1 in config/init/data.pl and reconfigure, or just run Configure with --ask. Then remove the blib directory and remake. -rpath will undoubtably be supplied to compilers that don't support it, so configure will need to be made somewhat smarter.

Any feedback appreciated,

Cheers,

Nick

=== MANIFEST
==================================================================
--- MANIFEST    (revision 9306)
+++ MANIFEST    (local)
@@ -312,6 +312,7 @@
 config/inter/shlibs.pl                            []
 config/inter/progs.pl                             []
 config/inter/types.pl                             []
+config/inter/libparrot.pl                         []
 docs/ROADMAP                                      [devel]doc
 docs/compiler_faq.pod                             [devel]doc
 docs/configuration.pod                            [devel]doc
=== config/gen/makefiles/root.in
==================================================================
--- config/gen/makefiles/root.in        (revision 9306)
+++ config/gen/makefiles/root.in        (local)
@@ -87,8 +87,7 @@
 TOUCH      = $(PERL) -MExtUtils::Command -e touch
 YACC       = ${yacc}
 LEX        = ${lex}
-# do not die when dir already exits
-MKDIR      = $(PERL) -e ${PQ}-d or mkdir $$_,0777 or die foreach @ARGV${PQ}
+MKDIR      = $(PERL) -MExtUtils::Command -e mkpath
 CC         = ${cc}
 CC_INC     = ${cc_inc}
 CFLAGS     = ${ccflags} ${cc_debug} ${ccwarn} $(CC_INC) ${cc_hasjit} 
${cg_flag} ${gc_flag}
@@ -99,6 +98,7 @@
 LINKFLAGS  = ${linkflags} ${link_debug} ${ld_debug}
 LD         = ${ld}
 LDFLAGS    = ${ldflags} ${ld_debug}
+RPATH_BLIB = ${rpath_blib}
 
 LINT       = splint
 # note: +distinctinternalnames with +externalnamelen at 8 characters
@@ -457,7 +457,6 @@
 PARROT            = $(CUR_DIR)/${test_prog}$(EXE)
 MINIPARROT        = $(CUR_DIR)/miniparrot$(EXE)
 INSTALLABLEPARROT = $(CUR_DIR)/installable_parrot$(EXE)
-PARROT_SO         = $(CUR_DIR)/${test_prog}_so$(EXE)
 DIS               = $(CUR_DIR)/disassemble$(EXE)
 PDUMP             = $(CUR_DIR)/pdump$(EXE)
 PINFO             = $(CUR_DIR)/pbc_info$(EXE)
@@ -465,9 +464,11 @@
 PDB               = $(CUR_DIR)/pdb$(EXE)
 
 # libs
-LIBPARROT         = ${blib_lib_libparrot_a}
-#CONDITIONED_LINE(has_icu):ICU_SHARED      = ${icu_shared}
-ALL_PARROT_LIBS   = $(LIBPARROT) $(ICU_SHARED) $(C_LIBS)
+LIBPARROT_STATIC  = ${blib_lib}${slash}${libparrot_a}
+LIBPARROT_SHARED  = ${blib_lib}${slash}${libparrot_so}
+LIBPARROT         = ${libparrot}
+#CONDITIONED_LINE(has_icu):ICU_SHARED  = ${icu_shared}
+ALL_PARROT_LIBS   = -L ${blib_lib} -lparrot $(ICU_SHARED) $(C_LIBS)
 
 # dynamic extensions
 DYNEXT_DIR        = runtime/parrot/dynext
@@ -671,14 +672,14 @@
 $(PARROT) : $(IMCC_DIR)/main$(O) $(GEN_HEADERS) $(LIBPARROT) \
                lib/Parrot/OpLib/core.pm $(SRC_DIR)/parrot_config$(O) \
                $(MINIPARROT) ${parrot_exe_def}
-       $(LINK) ${ld_out}$(PARROT) $(LINKFLAGS) $(LINK_DYNAMIC) 
${ld_parrot_exe_def} \
+       $(LINK) ${ld_out}$(PARROT) $(LINKFLAGS) $(LINK_DYNAMIC) $(RPATH_BLIB) 
${ld_parrot_exe_def} \
          $(IMCC_DIR)/main$(O) $(ALL_PARROT_LIBS) $(SRC_DIR)/parrot_config$(O)
 #
 # TODO build the real miniparrot
 #
 $(MINIPARROT) : $(IMCC_DIR)/main$(O) $(GEN_HEADERS) $(LIBPARROT) \
                lib/Parrot/OpLib/core.pm $(SRC_DIR)/null_config$(O)
-       $(LINK) ${ld_out}$(MINIPARROT) $(LINKFLAGS) $(IMCC_DIR)/main$(O) \
+       $(LINK) ${ld_out}$(MINIPARROT) $(LINKFLAGS) $(RPATH_BLIB) 
$(IMCC_DIR)/main$(O) \
            $(ALL_PARROT_LIBS) $(SRC_DIR)/null_config$(O)
 
 $(INSTALLABLEPARROT) : $(IMCC_DIR)/main$(O) $(GEN_HEADERS) $(LIBPARROT) \
@@ -729,29 +730,25 @@
 #
 ###############################################################################
 
-shared : $(GEN_HEADERS) blib/lib/libparrot$(SHARE_EXT) $(LIBPARROT)
-static : $(GEN_HEADERS) $(LIBPARROT)
+shared : $(GEN_HEADERS) $(LIBPARROT_SHARED)
+static : $(GEN_HEADERS) $(LIBPARROT_STATIC)
 
 # XXX changes don't always propagate into libparrot
 # e.g. when I change debug:fataly to xfataly, nm still shows the old symbol
 # and parrot builds fine (except for the unproto warning
 # so always delete the lib -leo
 
-$(LIBPARROT) : $(O_FILES)
+$(LIBPARROT_STATIC) : $(O_FILES)
        $(RM_F) $@
-       $(MKDIR) blib blib/lib
+       $(MKDIR) ${blib_lib}
        $(AR_CR) ${ar_out}$@ ${ar_extra} $(O_FILES)
        $(RANLIB) $@
 
-blib/lib/libparrot$(SHARE_EXT) : $(O_FILES)
-       $(MKDIR) blib blib/lib
-       $(LD) $(LD_SHARE_FLAGS) $(LDFLAGS) 
${ld_out}blib/lib/libparrot$(SHARE_EXT) $(O_FILES) $(C_LIBS) $(LIBICUCORE) 
$(LIBICUDATA)
+$(LIBPARROT_SHARED) : $(O_FILES)
+       $(MKDIR) ${blib_lib}
+       $(LD) $(LD_SHARE_FLAGS) $(LDFLAGS) ${ld_out}$@ $(O_FILES) $(C_LIBS) \
+       $(LIBICUCORE) $(LIBICUDATA)
 
-$(PARROT_SO) : $(IMCC_DIR)/main$(O) blib/lib/libparrot$(SHARE_EXT) 
lib/Parrot/OpLib/core.pm
-       $(LINK) $(LINKFLAGS) ${ld_out}$(PARROT) $(IMCC_DIR)/main$(O) \
-       $(SRC_DIR)/parrot_config$(O) -Lblib/lib -lparrot \
-       $(C_LIBS) $(ICU_SHARED)
-
 #
 # Parrot Debugger
 #
@@ -761,6 +758,7 @@
 $(PDB) : $(SRC_DIR)/pdb$(O) $(LIBPARROT)
        $(LINK) ${ld_out}$(PDB) \
        $(SRC_DIR)/pdb$(O) \
+       $(RPATH_BLIB) \
        $(SRC_DIR)/null_config$(O) \
        $(LINKFLAGS) $(ALL_PARROT_LIBS)
 
@@ -773,6 +771,7 @@
 $(DIS) : $(SRC_DIR)/disassemble$(O) $(LIBPARROT)
        $(LINK) ${ld_out}$(DIS) \
        $(SRC_DIR)/disassemble$(O) \
+       $(RPATH_BLIB) \
        $(SRC_DIR)/null_config$(O) \
        $(LINKFLAGS) $(ALL_PARROT_LIBS)
 
@@ -783,6 +782,7 @@
 $(PDUMP) : $(SRC_DIR)/pdump$(O) $(SRC_DIR)/packdump$(O) $(LIBPARROT)
        $(LINK) ${ld_out}$(PDUMP) \
        $(SRC_DIR)/pdump$(O) \
+       $(RPATH_BLIB) \
        $(SRC_DIR)/null_config$(O) \
        $(SRC_DIR)/packdump$(O) $(LINKFLAGS) $(ALL_PARROT_LIBS)
 
@@ -791,6 +791,7 @@
 $(PINFO) : $(SRC_DIR)/pbc_info$(O) $(LIBPARROT)
        $(LINK) ${ld_out}$(PINFO) \
        $(SRC_DIR)/pbc_info$(O) \
+       $(RPATH_BLIB) \
        $(SRC_DIR)/null_config$(O) \
        $(LINKFLAGS) $(ALL_PARROT_LIBS)
 
@@ -802,6 +803,7 @@
 $(PBCMERGE) : $(SRC_DIR)/pbc_merge$(O) $(LIBPARROT)
        $(LINK) ${ld_out}$(PBCMERGE) \
        $(SRC_DIR)/pbc_merge$(O) \
+       $(RPATH_BLIB) \
        $(SRC_DIR)/null_config$(O) \
        $(LINKFLAGS) $(ALL_PARROT_LIBS)
 
@@ -1546,7 +1548,7 @@
 exec : $(SRC_DIR)/exec_start$(O) $(SRC_DIR)/parrot_config$(O) $(LIBPARROT)
        $(LINK) ${ld_out}$(EXEC)$(EXE) $(LINKFLAGS) $(EXEC)$(O) 
$(SRC_DIR)/exec_start$(O) $(SRC_DIR)/parrot_config$(O) $(ALL_PARROT_LIBS)
 
-exec_so : $(SRC_DIR)/exec_start$(O) blib/lib/libparrot$(SHARE_EXT)
+exec_so : $(SRC_DIR)/exec_start$(O) $(LIBPARROT_SHARED)
        $(LINK) ${ld_out}$(EXEC)$(SHARE_EXT) $(LINKFLAGS) $(EXEC)$(O) 
$(SRC_DIR)/exec_start$(O) $(SRC_DIR)/parrot_config$(O) -lparrot $(C_LIBS)
 
 ###### OS depend targets ##########
=== config/init/data.pl
==================================================================
--- config/init/data.pl (revision 9306)
+++ config/init/data.pl (local)
@@ -115,9 +115,15 @@
     ld_out        => '-o ',               # ld output file.  Keep the trailing 
space.
     ld_debug      => '',                  # include debug info in executable
 
-    # should we have a dependancy upon arc to generate .a's?
-    blib_lib_libparrot_a => 'blib/lib/libparrot$(A)',
+    blib_lib      => 'blib/lib',          # Library build directory
 
+    libparrot_a  => 'libparrot$(A)',      # Name of archive libparrot
+    libparrot_so => 'libparrot$(SHARE_EXT)', # Name of shared libparrot
+
+    libparrot_build_shared => '0',        # Should libparrot be build shared?
+
+    rpath_blib    => '',                  # Use rpath to set SO path
+
     perl          => $^X,
     test_prog     => 'parrot',
     rm_f          => '$(PERL) -MExtUtils::Command -e rm_f',
=== config/init/hints/cygwin.pl
==================================================================
--- config/init/hints/cygwin.pl (revision 9306)
+++ config/init/hints/cygwin.pl (local)
@@ -17,6 +17,7 @@
   ld_share_flags => '-shared',
   ld_load_flags => '-shared',
   libs => $libs,
+  libparrot_build_shared => '1',
 );
 
 #We need to define inet_aton on Cygwin.  The contents of the --define switch 
=== config/init/hints/mswin32.pl
==================================================================
--- config/init/hints/mswin32.pl        (revision 9306)
+++ config/init/hints/mswin32.pl        (local)
@@ -49,7 +49,8 @@
                        ld_load_flags  => '-dll -def:libparrot.def',
                        ld_out     => '-out:',
                        ldflags    => '-nologo -nodefaultlib',
-                       blib_lib_libparrot_a => 'blib/lib/libparrot_s$(A)',
+                       libparrot_a  => 'blib/lib/libparrot_s$(A)',
+                       libparrot_so => 'blib/lib/libparrot_s$(SHARE_EXT)',
                        ar_flags   => '',
                        ar_out     => '-out:',
                        slash      => '\\',
@@ -96,7 +97,8 @@
                        ld_load_flags   => '-dll -def:libparrot.def',
                        ld_out     => '-out:',
                        ldflags    => '-nologo -nodefaultlib',
-                       blib_lib_libparrot_a => 'blib/lib/libparrot_s$(A)',
+                       libparrot_a  => 'libparrot_s$(A)',
+                       libparrot_so => 'libparrot_s$(SHARE_EXT)',
                        ar         => 'xilib',
                        ar_flags   => '',
                        ar_out     => '-out:',
@@ -146,7 +148,8 @@
                         slash => '\\',
                         make_and => "\n\t",
 
-                        blib_lib_libparrot_a => 'blib\lib\libparrot.lib',
+                       blib_lib    => 'blib\blib\',
+                        libparrot_a => 'libparrot.lib',
                );
        }
        elsif( $is_mingw ) {
=== config/inter/libparrot.pl
==================================================================
--- config/inter/libparrot.pl   (revision 9306)
+++ config/inter/libparrot.pl   (local)
@@ -0,0 +1,60 @@
+# Copyright: 2005 The Perl Foundation.  All Rights Reserved.
+# $Id: libparrot.pl $
+
+=head1 NAME
+
+config/inter/libparrot.pl - Should lib parrot be compiled as a shared library
+
+=head1 DESCRIPTION
+
+
+=cut
+
+package Configure::Step;
+
+use strict;
+
+use Cwd;
+use vars qw($description @args);
+use Parrot::Configure::Step ':inter';
+
+$description = 'Determine if libparrot should be a shared library...';
+
[EMAIL PROTECTED] = qw(ask verbose libparrot_build_shared);
+
+sub runstep {
+    my ($ask, $verbose, $libparrot_build_shared) = @_;
+
+    $libparrot_build_shared =
+       integrate(Configure::Data->get('libparrot_build_shared'),
+                 $libparrot_build_shared);
+
+    if ($ask)
+    {
+       $libparrot_build_shared=
+           prompt("\nShould libparrot be built as a shared library?",
+                  $libparrot_build_shared ? 'y' : 'n');
+
+       $libparrot_build_shared = lc($libparrot_build_shared) eq 'y';
+    }
+
+    Configure::Data->set(libparrot_build_shared => $libparrot_build_shared);
+
+    $Configure::Step::result = $libparrot_build_shared ? 'yes' : 'no';
+
+    Configure::Data->set(libparrot =>
+                        $libparrot_build_shared
+                        ? '$(LIBPARROT_SHARED)'
+                        : '$(LIBPARROT_STATIC)');
+
+    if ($libparrot_build_shared)
+    {
+       Configure::Data->set(rpath_blib =>
+                            Configure::Data->get('rpath') . 
+                            getcwd () .
+                            Configure::Data->get('slash') . 
+                            Configure::Data->get('blib_lib'));
+    }
+}
+
+1;
=== languages/perl6/perl6
==================================================================
--- languages/perl6/perl6       (revision 9306)
+++ languages/perl6/perl6       (local)
@@ -54,7 +54,7 @@
 $PARROT = "$PARROT_ROOT${slash}parrot$exe";
 $CD = "cd $PARROT_ROOT; ";
 $PBC2C = "$CD $PERL pbc2c.pl";
-$LIBPA = "$PARROT_ROOT${slash}" .$PConfig{blib_lib_libparrot_a};
+$LIBPA = "$PARROT_ROOT${slash}" .$PConfig{blib_lib} . $slash . $PConfig 
{libparrot_a};
 $LIBPA =~ s/\$\(A\)/$LIB/;
 #
 # imported meth's for Test::More
=== lib/Parrot/Configure/RunSteps.pm
==================================================================
--- lib/Parrot/Configure/RunSteps.pm    (revision 9306)
+++ lib/Parrot/Configure/RunSteps.pm    (local)
@@ -34,6 +34,7 @@
     auto/gcc.pl
     init/optimize.pl
     inter/shlibs.pl
+    inter/libparrot.pl
     inter/charset.pl
     inter/encoding.pl
     inter/types.pl
=== lib/Parrot/Test.pm
==================================================================
--- lib/Parrot/Test.pm  (revision 9306)
+++ lib/Parrot/Test.pm  (local)
@@ -512,16 +512,20 @@
             print SOURCE $source;
             close SOURCE;
 
-            (my $libparrot_root = $PConfig{blib_lib_libparrot_a}) =~ 
s/\$\(A\)//;
-            my $libparrot_dynamic = $libparrot_root.$PConfig{share_ext};
+           my $libparrot_a  = $PConfig{libparrot_a};
+           my $libparrot_so = $PConfig{libparrot_so};
 
             my $libparrot;
 
-            # use shared library version if available
-            if( -e $libparrot_dynamic ) {
-                $libparrot = '-Lblib/lib -lparrot';
+            # Use shared library version if available
+            if($PConfig{libparrot_build_shared}) {
+                $libparrot =
+             "-L$PConfig{blib_lib} -lparrot $PConfig{rpath}$PConfig{blib_lib}";
             } else {
-                $libparrot = $libparrot_root.$PConfig{a};
+               # The static library name needs some mangling as it is
+               # designed for insertion into a Makefile
+                $libparrot = $PConfig{blib_lib} . $PConfig{slash} . 
$libparrot_a;
+                $libparrot =~ s/\$\(A\)$/$PConfig{a}/;
             }
 
             my $iculibs = "";

Reply via email to