From a1a0ed1ca9d5e16fd62608e078d1c4a364f2706e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Cl=C3=A9ment=20Chigot?= <clement.chigot@atos.net>
Date: Tue, 7 May 2019 10:15:32 +0200
Subject: [PATCH] libgo/configure: use copycsect instead of objcopy

Change-Id: I6bdec9d19c73800df8e1756973b1497eec9e7076
---
 libgo/configure    | 100 ++++++++++++++++++++++++++++++++++++++++++++-
 libgo/configure.ac |   9 +++-
 2 files changed, 107 insertions(+), 2 deletions(-)

diff --git a/libgo/configure b/libgo/configure
index 9661cb5a..12fc3243 100755
--- a/libgo/configure
+++ b/libgo/configure
@@ -5138,7 +5138,103 @@ else
   RANLIB="$ac_cv_prog_RANLIB"
 fi
 
-if test -n "$ac_tool_prefix"; then
+case ${target} in
+  *-*-aix*)
+    if test -n "$ac_tool_prefix"; then
+  # Extract the first word of "${ac_tool_prefix}copycsect", so it can be a program name with args.
+set dummy ${ac_tool_prefix}copycsect; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_OBJCOPY+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$OBJCOPY"; then
+  ac_cv_prog_OBJCOPY="$OBJCOPY" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_OBJCOPY="${ac_tool_prefix}copycsect"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+OBJCOPY=$ac_cv_prog_OBJCOPY
+if test -n "$OBJCOPY"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $OBJCOPY" >&5
+$as_echo "$OBJCOPY" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+fi
+if test -z "$ac_cv_prog_OBJCOPY"; then
+  ac_ct_OBJCOPY=$OBJCOPY
+  # Extract the first word of "copycsect", so it can be a program name with args.
+set dummy copycsect; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_ac_ct_OBJCOPY+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$ac_ct_OBJCOPY"; then
+  ac_cv_prog_ac_ct_OBJCOPY="$ac_ct_OBJCOPY" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_ac_ct_OBJCOPY="copycsect"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+ac_ct_OBJCOPY=$ac_cv_prog_ac_ct_OBJCOPY
+if test -n "$ac_ct_OBJCOPY"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_OBJCOPY" >&5
+$as_echo "$ac_ct_OBJCOPY" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+  if test "x$ac_ct_OBJCOPY" = x; then
+    OBJCOPY="missing-objcopy"
+  else
+    case $cross_compiling:$ac_tool_warned in
+yes:)
+{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5
+$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;}
+ac_tool_warned=yes ;;
+esac
+    OBJCOPY=$ac_ct_OBJCOPY
+  fi
+else
+  OBJCOPY="$ac_cv_prog_OBJCOPY"
+fi
+
+    ;;
+  *)
+    if test -n "$ac_tool_prefix"; then
   # Extract the first word of "${ac_tool_prefix}objcopy", so it can be a program name with args.
 set dummy ${ac_tool_prefix}objcopy; ac_word=$2
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
@@ -5230,6 +5326,8 @@ else
   OBJCOPY="$ac_cv_prog_OBJCOPY"
 fi
 
+    ;;
+esac
 
 enable_dlopen=yes
 
diff --git a/libgo/configure.ac b/libgo/configure.ac
index a361a7a4..a6cb2f41 100644
--- a/libgo/configure.ac
+++ b/libgo/configure.ac
@@ -34,7 +34,14 @@ AM_MAINTAINER_MODE
 
 AC_PROG_LD
 AC_PROG_RANLIB
-AC_CHECK_TOOL(OBJCOPY, objcopy, missing-objcopy)
+case ${target} in
+  *-*-aix*)
+    AC_CHECK_TOOL(OBJCOPY, copycsect, missing-objcopy)
+    ;;
+  *)
+    AC_CHECK_TOOL(OBJCOPY, objcopy, missing-objcopy)
+    ;;
+esac
 
 AC_LIBTOOL_DLOPEN
 AM_PROG_LIBTOOL
-- 
2.17.1

