Blame SOURCES/libtool-handle-ppc64le.sh

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