]> git.ipfire.org Git - thirdparty/autoconf.git/commitdiff
(AS_DIRNAME): Use 'dirname' if that works.
authorPaul Eggert <eggert@cs.ucla.edu>
Thu, 18 Oct 2001 23:43:52 +0000 (23:43 +0000)
committerPaul Eggert <eggert@cs.ucla.edu>
Thu, 18 Oct 2001 23:43:52 +0000 (23:43 +0000)
(AS_BASENAME_EXPR): New macro.
(AS_BASENAME_SED): Do not assume GNU sed semantics.
(AS_BASENAME): Use 'basename' if that works; then try 'expr';
and fall back on 'sed' only if the other two fail.  This makes
AS_BASENAME act more like AS_DIRNAME.

lib/m4sugar/m4sh.m4

index 8cf3c9baee5e7ef0e0e7ff9d632912767a35c062..09935c9404bec4db9d3f6b147bdaa62ff0caa642 100644 (file)
@@ -407,19 +407,34 @@ m4_defun([AS_DIRNAME_SED],
          s/.*/./; q']])
 
 m4_defun([AS_DIRNAME],
-[AS_DIRNAME_EXPR([$1]) 2>/dev/null ||
+[(dirname $1) 2>/dev/null ||
+AS_DIRNAME_EXPR([$1]) 2>/dev/null ||
 AS_DIRNAME_SED([$1])])
 
 
 # AS_BASENAME(PATHNAME)
 # --------------------
 # Simulate running `basename(1)' on PATHNAME, not all systems have it.
-# This macro must be usable from inside ` `.
+# Also see the comments for AS_DIRNAME.
+
+m4_defun([AS_BASENAME_EXPR],
+[m4_require([_AS_EXPR_PREPARE])dnl
+$as_expr X/[]$1 : '.*/\([[^/][^/]*]\)/*$' \| \
+        X[]$1 : 'X\(//\)$' \| \
+        X[]$1 : 'X\(/\)$' \| \
+        .     : '\(.\)'])
+
 m4_defun([AS_BASENAME_SED],
-[echo "$1" |sed 's,\(.*[[\\/]]\+\)\?\([[^\\/]]\+\)[[\\/]]*,\2,'])
+[echo X/[]$1 |
+    sed ['/^.*\/\([^/][^/]*\)\/*$/{ s//\1/; q; }
+         /^X\/\(\/\/\)$/{ s//\1/; q; }
+         /^X\/\(\/\).*/{ s//\1/; q; }
+         s/.*/./; q']])
 
 m4_defun([AS_BASENAME],
-[AS_BASENAME_SED([$1])])
+[(basename $1) 2>/dev/null ||
+AS_BASENAME_EXPR([$1]) 2>/dev/null ||
+AS_BASENAME_SED([$1])])
 
 
 # AS_EXECUTABLE_P