Blame SOURCES/libtool-handle-ppc64le.sh

3bf4a1
#!/bin/bash
3bf4a1
3bf4a1
# Date: April 2, 2014
3bf4a1
# by Aldy Hernandez
3bf4a1
3bf4a1
# Attempt to fix any "-m elf64ppc" linker checks in configure and
3bf4a1
# libtool.m4 files.
3bf4a1
#
3bf4a1
# This script is meant to run silently as part of rpm's %configure
3bf4a1
# macro.  It either fixes the problem, or we silently ignore it, in
3bf4a1
# which case it is up to the package maintainer to add support for
3bf4a1
# ppc64le.
3bf4a1
3bf4a1
# Our two attempts at fixing the problem.
3bf4a1
PATCH1=/tmp/$$.patch1
3bf4a1
PATCH2=/tmp/$$.patch2
3bf4a1
3bf4a1
cleanup() {
3bf4a1
    rm -f $PATCH1 $PATCH2
3bf4a1
}
3bf4a1
3bf4a1
trap cleanup 0 1 2 3 4 5 6 7 8 9 11 13 14 15
3bf4a1
3bf4a1
# There are two variants in RHEL7 so far.  The first version, handled
3bf4a1
# with $PATCH1, currently handles all but 3 packages.  The $PATCH2
3bf4a1
# version handles the remnant.
3bf4a1
#
3bf4a1
cat > $PATCH1 <
3bf4a1
--- configure.orig	2014-03-18 15:56:15.575070238 -0500
3bf4a1
+++ configure	2014-03-18 16:05:50.877861163 -0500
3bf4a1
@@ -7714,6 +7714,9 @@
3bf4a1
 	  x86_64-*linux*)
3bf4a1
 	    LD="\${LD-ld} -m elf_i386"
3bf4a1
 	    ;;
3bf4a1
+	  ppc64le-*linux*|powerpc64le-*linux*)
3bf4a1
+	    LD="\${LD-ld} -m elf32lppclinux"
3bf4a1
+	    ;;
3bf4a1
 	  ppc64-*linux*|powerpc64-*linux*)
3bf4a1
 	    LD="\${LD-ld} -m elf32ppclinux"
3bf4a1
 	    ;;
3bf4a1
@@ -7733,6 +7736,9 @@
3bf4a1
 	  x86_64-*linux*)
3bf4a1
 	    LD="\${LD-ld} -m elf_x86_64"
3bf4a1
 	    ;;
3bf4a1
+	  ppc*le-*linux*|powerpc*le-*linux*)
3bf4a1
+	    LD="\${LD-ld} -m elf64lppc"
3bf4a1
+	    ;;
3bf4a1
 	  ppc*-*linux*|powerpc*-*linux*)
3bf4a1
 	    LD="\${LD-ld} -m elf64ppc"
3bf4a1
 	    ;;
3bf4a1
EOF
3bf4a1
3bf4a1
cat > $PATCH2 <
3bf4a1
--- configure.orig	2014-03-18 16:35:28.942799967 -0500
3bf4a1
+++ configure	2014-03-18 16:34:35.608519090 -0500
3bf4a1
@@ -3798,6 +3798,9 @@
3bf4a1
         x86_64-*linux*)
3bf4a1
           LD="\${LD-ld} -m elf_i386"
3bf4a1
           ;;
3bf4a1
+        ppc64le-*linux*)
3bf4a1
+          LD="\${LD-ld} -m elf32lppclinux"
3bf4a1
+          ;;
3bf4a1
         ppc64-*linux*)
3bf4a1
           LD="\${LD-ld} -m elf32ppclinux"
3bf4a1
           ;;
3bf4a1
@@ -3814,6 +3817,9 @@
3bf4a1
         x86_64-*linux*)
3bf4a1
           LD="\${LD-ld} -m elf_x86_64"
3bf4a1
           ;;
3bf4a1
+        ppc*le-*linux*|powerpc*le-*linux*)
3bf4a1
+          LD="\${LD-ld} -m elf64lppc"
3bf4a1
+          ;;
3bf4a1
         ppc*-*linux*|powerpc*-*linux*)
3bf4a1
           LD="\${LD-ld} -m elf64ppc"
3bf4a1
           ;;
3bf4a1
EOF
3bf4a1
3bf4a1
3bf4a1
FILES=`find . -name configure -o -name libtool.m4`
3bf4a1
for f in $FILES; do
3bf4a1
    # Filter out candidates that already handle ppc64le.
3bf4a1
    if grep -s -e '-m elf64lppc' $f >/dev/null; then
3bf4a1
	continue
3bf4a1
    fi
3bf4a1
3bf4a1
    # Filter out candidates that don't handle PPC.
3bf4a1
    if ! grep -s -e '-m elf64ppc' $f >/dev/null; then
3bf4a1
	continue
3bf4a1
    fi
3bf4a1
3bf4a1
    echo "Broken -m elf64ppc use in $f should handle elf64lppc."
3bf4a1
    echo "Attempting automatic fix."
3bf4a1
3bf4a1
    # Attempt to fix the offended file.
3bf4a1
    basename=`basename $f`
3bf4a1
    dirname=`dirname $f`
3bf4a1
    for p in $PATCH1 $PATCH2; do
3bf4a1
	# This is an all for nothing affair.  The patch either
3bf4a1
	# applies entirely clean, or we don't even try.
3bf4a1
	#
3bf4a1
	# Tentatively try either patch cleanly, and if we succeed then
3bf4a1
	# do it for real.
3bf4a1
	pushd $dirname 2>&1 > /dev/null
3bf4a1
	if [ $basename = libtool.m4 ]; then
3bf4a1
	    sed s/configure/libtool.m4/ < $p | patch --dry-run --follow-symlinks -l 2>&1 >/dev/null
3bf4a1
	else
3bf4a1
	    patch --dry-run --follow-symlinks -l < $p 2>&1 > /dev/null
3bf4a1
	fi
3bf4a1
	if [ $? != 0 ]; then
3bf4a1
	    echo -n "$p approach did not work for $dirname/$basename: "
3bf4a1
	    pwd
3bf4a1
	    # This approach didn't work, try the next one.
3bf4a1
	    popd 2>&1 > /dev/null
3bf4a1
	    continue
3bf4a1
	fi
3bf4a1
3bf4a1
	# Seriously now...
3bf4a1
	if [ $basename = libtool.m4 ]; then
3bf4a1
	    # Save the timestamp.
3bf4a1
	    cp -p $basename /tmp/tmp.$$
3bf4a1
	    sed s/configure/libtool.m4/ < $p | patch --follow-symlinks -l -s 2>&1 > /dev/null
3bf4a1
	    # Use the old timestamp, to avoid anyone noticing changes
3bf4a1
	    # to libtool.m4.
3bf4a1
	    touch --reference=/tmp/tmp.$$ $basename
3bf4a1
	    rm -f /tmp/tmp.$$
3bf4a1
	else
3bf4a1
	    patch --follow-symlinks -l -s < $p 2>&1 > /dev/null
3bf4a1
	fi
3bf4a1
	echo "Fixed $f for ld -m ppc64le support."
3bf4a1
	popd 2>&1 > /dev/null
3bf4a1
	break
3bf4a1
    done
3bf4a1
done
3bf4a1
3bf4a1
rm -f $PATCH1 $PATCH2