[committed,pushed] PR-107607 m2: Remove bdepend on realpath, cut and echo

Message ID 87sfhgbuy0.fsf@debian
State Repeat Merge
Headers
Series [committed,pushed] PR-107607 m2: Remove bdepend on realpath, cut and echo |

Checks

Context Check Description
snail/gcc-patch-check warning Git am fail log

Commit Message

Gaius Mulley Dec. 15, 2022, 2:30 p.m. UTC
  It can be replaced by a subshell'd cd just fine.
(cd gcc/m2; autoconf-2.69)

gcc/m2/ChangeLog:
    
            * configure.ac: Stop probing for realpath.
            * tools-src/calcpath: Break dependency on realpath, cut
            and echo.
            * configure: Rebuilt
---
 gcc/m2/configure.ac       |  5 -----
 gcc/m2/tools-src/calcpath | 34 ++++++++++++++++++----------------
 2 files changed, 18 insertions(+), 21 deletions(-)
  

Patch

diff --git a/gcc/m2/configure.ac b/gcc/m2/configure.ac
index 756e01c4321..5583af7f64c 100644
--- a/gcc/m2/configure.ac
+++ b/gcc/m2/configure.ac
@@ -24,11 +24,6 @@  AC_CANONICAL_BUILD
 AC_CANONICAL_HOST
 AC_CANONICAL_TARGET
 
-AC_CHECK_PROGS(regex_realpath, realpath)
-if test x$regex_realpath = "x" ; then
-    AC_MSG_ERROR([realpath is required to build GNU Modula-2 (hint install coreutils).])
-fi
-
 AC_CHECK_FUNCS([stpcpy])
 
 AC_CHECK_HEADERS(sys/types.h)
diff --git a/gcc/m2/tools-src/calcpath b/gcc/m2/tools-src/calcpath
index e0817704f64..05324513aa1 100755
--- a/gcc/m2/tools-src/calcpath
+++ b/gcc/m2/tools-src/calcpath
@@ -23,27 +23,29 @@ 
 
 
 Usage () {
-   echo "Usage: calcpath pathcomponent1 pathcomponent2 subdir"
-   echo -n "  if pathcomponent1 is relative then pathcomponent1/pathcomponet2/subdir is"
-   echo " returned"
-   echo "  otherwise pathcomponet2/subdir is returned"
-   echo "  the path is checked for legality in subdir."
+   cat<<EOF
+Usage: $0 pathcomponent1 pathcomponent2 subdir
+  if pathcomponent2 is relative then pathcomponent1/pathcompinent2/subdir is returned
+  otherwise pathcomponent2/subdir is returned
+  the path is checked for legality in subdir.
+EOF
 }
 
+die () {
+   printf "calcpath: error: %s\n" "$1" >&2
+   exit 1
+}
 
 if [ $# -eq 3 ]; then
-   if [ "$(echo $2 | cut -b 1)" = "." ] ; then
-       # relative path
-       the_path=$1/$2/$3
+   case "$2" in
+      /*) the_path="$2/$3" ;;
+      *) the_path="$1/$2/$3" ;;
+   esac
+   cd "$3" || die "could not access $3"
+   if ( cd "$the_path" ); then
+      printf '%s\n' "${the_path}"
    else
-       the_path=$2/$3
-   fi
-   cd $3
-   if realpath ${the_path} > /dev/null ; then
-       echo ${the_path}
-   else
-       echo "calcpath: error ${the_path} is not a valid path in subdirectory $3" 1>&2
-       exit 1
+      die "${the_path} is not a valid path in subdirectory $3"
    fi
 else
    Usage