Do a better job of escaping components of ldlibpth for the shell
authorEric Brine <ikegami@adaelis.com>
Tue, 13 Nov 2012 00:40:49 +0000 (19:40 -0500)
committerFather Chrysostomos <sprout@cpan.org>
Tue, 13 Nov 2012 08:01:40 +0000 (00:01 -0800)
It's not unusual, for example, for the search path to include "(" and ")" in cygwin.

Makefile.SH

index 7a8399b..97057fd 100755 (executable)
@@ -1,5 +1,14 @@
 #!/bin/sh
 
+# quote() - Creates a shell literal
+# Usage:  echo "...$( quote "..." )..."
+quote() {
+       case "$1" in
+       '') echo "''" ;;
+       *)  echo "$1" | sed 's/\([^a-zA-Z0-9.:_\-\/]\)/\\\1/g' ;;
+       esac
+}
+
 case $PERL_CONFIG_SH in
 '')
        if test -f config.sh
@@ -39,10 +48,8 @@ true)
        # Prefix all runs of 'miniperl' and 'perl' with
        # $ldlibpth so that ./perl finds *this* shared libperl.
        case "$LD_LIBRARY_PATH" in
-       '')
-               ldlibpth="LD_LIBRARY_PATH=`pwd`";;
-       *)
-               ldlibpth="LD_LIBRARY_PATH=`pwd`:${LD_LIBRARY_PATH}";;
+       '')  ldlibpth="LD_LIBRARY_PATH=$( quote "`pwd`" )" ;;
+       *)   ldlibpth="LD_LIBRARY_PATH=$( quote "`pwd`" ):$( quote "$LD_LIBRARY_PATH" )" ;;
        esac
 
        pldlflags="$cccdlflags"
@@ -121,19 +128,19 @@ true)
                ldlibpth=''
                ;;
            *)
-               eval "ldlibpth=\"$ldlibpthname=`pwd`:\$$ldlibpthname\""
+               eval "ldlibpthval=\"\$$ldlibpthname\""
+
+               case "$ldlibpthval" in
+               '')  ldlibpth="$ldlibpthname=$( quote "`pwd`" )" ;;
+               *)   ldlibpth="$ldlibpthname=$( quote "`pwd`" ):$( quote "$ldlibpthval" )" ;;
+               esac
+
                ;;
            esac
-           # Strip off any trailing :'s
-           ldlibpth=`echo $ldlibpth | sed 's/:*$//'`
+
            ;;
         esac
 
-       case "$ldlibpth" in
-       # Protect any spaces
-       *" "*) ldlibpth=`echo $ldlibpth|sed 's/ /\\\\ /g'` ;;
-       esac
-
        case "$osname" in
        linux)
            # If there is a pre-existing $libperl from a previous