Don't use "echo \1"

Zack Weinberg zack@codesourcery.com
Mon Apr 7 01:56:00 GMT 2003


Some shells generate a control-A character from "echo \1", which
breaks libgcc.mk.  Others do not.  There doesn't appear to be any way
to get a literal '\1' that works with both variants, so this patch
changes that part of the script to use a here document instead.

Bootstrapping i686-linux, will apply if successful.  Also I've tested
the script on both shell variants.

zw

        * mklibgcc.in: Use a here document to avoid running afoul of
        shells that generate control-A from "echo \1".

===================================================================
Index: mklibgcc.in
--- mklibgcc.in	5 Feb 2003 00:52:24 -0000	1.55
+++ mklibgcc.in	7 Apr 2003 01:54:02 -0000
@@ -311,13 +311,20 @@ for ml in $MULTILIBS; do
   if [ "$SHLIB_LINK" -a "$SHLIB_MKMAP" ]; then
     mapfile="libgcc/${dir}/libgcc.map"
     tmpmapfile="libgcc/${dir}/tmp-libgcc.map"
-    echo ""
-    echo "${mapfile}: $SHLIB_MKMAP $SHLIB_MAPFILES $libgcc_sh_objs"
-    echo '	{ $(NM_FOR_TARGET)'" $SHLIB_NM_FLAGS $libgcc_sh_objs; echo %%; \\"
-    echo "	  cat $SHLIB_MAPFILES | sed -e "'"/^[ 	]*#/d" -e '\''s/^%\(if\|else\|elif\|endif\|define\)/#\1/'\'" \\"
-    echo "	  | $gcc_compile $flags -E -xassembler-with-cpp -; \\"
-    echo '	} | $(AWK)'" -f $SHLIB_MKMAP $SHLIB_MKMAP_OPTS > ${tmpmapfile}"
-    echo '	mv '"$tmpmapfile"' $@'
+    # This uses a here document instead of echos because some shells
+    # will convert the \1 in the second sed command to a control-A.
+    # The behavior of here documents is more predictable.
+    cat <<EOF
+
+${mapfile}: $SHLIB_MKMAP $SHLIB_MAPFILES $libgcc_sh_objs
+	{ \$(NM_FOR_TARGET) $SHLIB_NM_FLAGS $libgcc_sh_objs; echo %%; \\
+	  cat $SHLIB_MAPFILES \\
+	    | sed -e '/^[   ]*#/d' \\
+	          -e 's/^%\(if\|else\|elif\|endif\|define\)/#\1/' \\
+	    | $gcc_compile $flags -E -xassembler-with-cpp -; \\
+	} | \$(AWK) -f $SHLIB_MKMAP $SHLIB_MKMAP_OPTS > ${tmpmapfile}
+	mv '$tmpmapfile' \$@
+EOF
   fi
   shlib_deps="$shlib_deps $mapfile"
 



More information about the Gcc-patches mailing list