+++ /dev/null
-sets correct linker ABI flags on MIPS64
-http://git.savannah.gnu.org/cgit/libtool.git/commit/?id=5f7f7d9615bf650cf99d581a33b3e18357f79951
-
-Signed-off-by: Vicente Olivert Riera <Vincent.Riera@imgtec.com>
-
-diff -ru libtool-2.4.2.orig/libltdl/m4/libtool.m4 libtool-2.4.2/libltdl/m4/libtool.m4
---- libtool-2.4.2.orig/libltdl/m4/libtool.m4   2013-11-11 11:44:30.419396295 +0000
-+++ libtool-2.4.2/libltdl/m4/libtool.m4        2013-11-11 11:44:07.055032308 +0000
-@@ -1312,6 +1312,38 @@
-   rm -rf conftest*
-   ;;
- 
-+mips64*-*linux*)
-+  # Find out what ABI is being produced by ac_compile, and set linker
-+  # options accordingly.
-+  echo '[#]line '$LINENO' "configure"' > conftest.$ac_ext
-+  if AC_TRY_EVAL(ac_compile); then
-+    emul=elf
-+    case `/usr/bin/file conftest.$ac_objext` in
-+      *32-bit*)
-+      emul="${emul}32"
-+      ;;
-+      *64-bit*)
-+      emul="${emul}64"
-+      ;;
-+    esac
-+    case `/usr/bin/file conftest.$ac_objext` in
-+      *MSB*)
-+      emul="${emul}btsmip"
-+      ;;
-+      *LSB*)
-+      emul="${emul}ltsmip"
-+      ;;
-+    esac
-+    case `/usr/bin/file conftest.$ac_objext` in
-+      *N32*)
-+      emul="${emul}n32"
-+      ;;
-+    esac
-+    LD="${LD-ld} -m $emul"
-+    fi
-+  rm -rf conftest*
-+  ;;
-+
- x86_64-*kfreebsd*-gnu|x86_64-*linux*|ppc*-*linux*|powerpc*-*linux*| \
- s390*-*linux*|s390*-*tpf*|sparc*-*linux*)
-   # Find out which ABI we are using.
 
--- /dev/null
+sets correct linker ABI flags on MIPS64
+http://git.savannah.gnu.org/cgit/libtool.git/commit/?id=5f7f7d9615bf650cf99d581a33b3e18357f79951
+
+Signed-off-by: Vicente Olivert Riera <Vincent.Riera@imgtec.com>
+
+diff -ru libtool-2.4.2.orig/libltdl/m4/libtool.m4 libtool-2.4.2/libltdl/m4/libtool.m4
+--- libtool-2.4.2.orig/libltdl/m4/libtool.m4   2013-11-11 11:44:30.419396295 +0000
++++ libtool-2.4.2/libltdl/m4/libtool.m4        2013-11-11 11:44:07.055032308 +0000
+@@ -1312,6 +1312,38 @@
+   rm -rf conftest*
+   ;;
+ 
++mips64*-*linux*)
++  # Find out what ABI is being produced by ac_compile, and set linker
++  # options accordingly.
++  echo '[#]line '$LINENO' "configure"' > conftest.$ac_ext
++  if AC_TRY_EVAL(ac_compile); then
++    emul=elf
++    case `/usr/bin/file conftest.$ac_objext` in
++      *32-bit*)
++      emul="${emul}32"
++      ;;
++      *64-bit*)
++      emul="${emul}64"
++      ;;
++    esac
++    case `/usr/bin/file conftest.$ac_objext` in
++      *MSB*)
++      emul="${emul}btsmip"
++      ;;
++      *LSB*)
++      emul="${emul}ltsmip"
++      ;;
++    esac
++    case `/usr/bin/file conftest.$ac_objext` in
++      *N32*)
++      emul="${emul}n32"
++      ;;
++    esac
++    LD="${LD-ld} -m $emul"
++    fi
++  rm -rf conftest*
++  ;;
++
+ x86_64-*kfreebsd*-gnu|x86_64-*linux*|ppc*-*linux*|powerpc*-*linux*| \
+ s390*-*linux*|s390*-*tpf*|sparc*-*linux*)
+   # Find out which ABI we are using.
 
 
 HOST_LIBTOOL_LIBTOOL_PATCH = NO
 
+# libtool-mips64-n64-linking.post-install-patch is an upstream patch that
+# fixes MIPS64 n64 link failures. However, because the patch touches an m4
+# file, applying it triggers a run of autoconf, automake, etc. This sometimes
+# leads to build failures due to incompatible system autotools. We cannot
+# simply set HOST_LIBTOOL_AUTORECONF = YES because that would create a
+# circular dependency on host-libtool. Therefore, just apply the patch
+# directly on the installed file.
+define HOST_LIBTOOL_FIXUP_LIBTOOL_M4
+       patch $(HOST_DIR)/usr/share/aclocal/libtool.m4 < \
+               package/libtool/libtool-mips64-n64-linking.post-install-patch
+endef
+HOST_LIBTOOL_POST_INSTALL_HOOKS += HOST_LIBTOOL_FIXUP_LIBTOOL_M4
+
 $(eval $(autotools-package))
 $(eval $(host-autotools-package))