bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] bootstrap: take advantage of POSIX shell features


From: Stefano Lattarini
Subject: [PATCH] bootstrap: take advantage of POSIX shell features
Date: Sun, 13 May 2012 10:18:23 +0200

The 'bootstrap' script offered by Gnulib script already uses POSIX
shell features (like $((...)) arithmetic expansions) that are not
supported by legacy Bourne shells like Solaris 10 /bin/sh.  This
means that bootstrap must already be run using a proper POSIX shell,
which will thus provide more features, like ${var#pattern} parameter
expansion or inversion of a command exit status with '!'.  We can
thus use these features to improve the clarity and the performances
of the bootstrap script.

* bootstrap: Prefer xpg4 parameter expansions over use of sed/expr
plus command substitutions, to save some forks.  Since we are at it,
prefer the POSIX $(...) form of command substitution, rather than
the legacy form `...` (since the former is visually clearer and
interacts better with quoting), and prefer "if ! CMD; then ACTION"
over the idiom "if CMD; then :; else ACTION" (which was required by
legacy Bourne shells not supporting '!').
---
 ChangeLog           |   21 +++++++++++++++++++++
 build-aux/bootstrap |   40 +++++++++++++++++++---------------------
 2 files changed, 40 insertions(+), 21 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 268fbe5..cf73593 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,24 @@
+2012-05-13  Stefano Lattarini  <address@hidden>
+
+       bootstrap: take advantage of POSIX shell features
+
+       The 'bootstrap' script offered by Gnulib script already uses POSIX
+       shell features (like $((...)) arithmetic expansions) that are not
+       supported by legacy Bourne shells like Solaris 10 /bin/sh.  This
+       means that bootstrap must already be run using a proper POSIX shell,
+       which will thus provide more features, like ${var#pattern} parameter
+       expansion or inversion of a command exit status with '!'.  We can
+       thus use these features to improve the clarity and the performances
+       of the bootstrap script.
+
+       * bootstrap: Prefer xpg4 parameter expansions over use of sed/expr
+       plus command substitutions, to save some forks.  Since we are at it,
+       prefer the POSIX $(...) form of command substitution, rather than
+       the legacy form `...` (since the former is visually clearer and
+       interacts better with quoting), and prefer "if ! CMD; then ACTION"
+       over the idiom "if CMD; then :; else ACTION" (which was required by
+       legacy Bourne shells not supporting '!').
+
 2012-05-08  Jim Meyering  <address@hidden>
 
        init.sh: don't let bash aliases interfere with tests
diff --git a/build-aux/bootstrap b/build-aux/bootstrap
index c496d29..d9b985e 100755
--- a/build-aux/bootstrap
+++ b/build-aux/bootstrap
@@ -1,6 +1,6 @@
 #! /bin/sh
 # Print a version string.
-scriptversion=2012-04-26.13; # UTC
+scriptversion=2012-05-13.09; # UTC
 
 # Bootstrap this package from checked-out sources.
 
@@ -130,7 +130,7 @@ extract_package_name='
      p
   }
 '
-package=`sed -n "$extract_package_name" configure.ac` || exit
+package=$(sed -n "$extract_package_name" configure.ac) || exit
 gnulib_name=lib$package
 
 build_aux=build-aux
@@ -256,7 +256,7 @@ do
     usage
     exit;;
   --gnulib-srcdir=*)
-    GNULIB_SRCDIR=`expr "X$option" : 'X--gnulib-srcdir=\(.*\)'`;;
+    GNULIB_SRCDIR=${option#--gnulib-srcdir=};;
   --skip-po)
     SKIP_PO=t;;
   --force)
@@ -323,7 +323,7 @@ insert_vc_ignore() {
     # A .gitignore entry that does not start with '/' applies
     # recursively to subdirectories, so prepend '/' to every
     # .gitignore entry.
-    pattern=`echo "$pattern" | sed s,^,/,`;;
+    pattern=$(echo "$pattern" | sed s,^,/,);;
   esac
   insert_sorted_if_absent "$vc_ignore_file" "$pattern"
 }
@@ -427,7 +427,7 @@ check_versions() {
       $use_git || continue
     fi
     # Honor $APP variables ($TAR, $AUTOCONF, etc.)
-    appvar=`echo $app | LC_ALL=C tr '[a-z]-' '[A-Z]_'`
+    appvar=$(echo $app | LC_ALL=C tr '[a-z]-' '[A-Z]_')
     test "$appvar" = TAR && appvar=AMTAR
     case $appvar in
         GZIP) ;; # Do not use $GZIP:  it contains gzip options.
@@ -442,7 +442,7 @@ check_versions() {
     # "GNU automake-ng") when asked their version.
     case $app in
       automake-ng|aclocal-ng)
-        app=`echo "$app" | sed 's/-ng$//'`
+        app=${appo%-ng}
         ($app --version | grep '(GNU automake-ng)') >/dev/null 2>&1 || {
           echo "$me: Error: '$app' not found or not from Automake-NG" >&2
           ret=1
@@ -512,10 +512,8 @@ esac
 
 # When we can deduce that gnulib-tool will require patch,
 # and when patch is not already listed as a prerequisite, add it, too.
-if test ! -d "$local_gl_dir" \
-    || find "$local_gl_dir" -name '*.diff' -exec false {} +; then
-  :
-else
+if test -d "$local_gl_dir" \
+    && ! find "$local_gl_dir" -name '*.diff' -exec false {} +; then
   case $buildreq in
     *patch*) ;;
     *) buildreq="patch -
@@ -559,7 +557,7 @@ git_modules_config () {
   test -f .gitmodules && git config --file .gitmodules "$@"
 }
 
-gnulib_path=`git_modules_config submodule.gnulib.path`
+gnulib_path=$(git_modules_config submodule.gnulib.path)
 test -z "$gnulib_path" && gnulib_path=gnulib
 
 # Get gnulib files.
@@ -632,10 +630,10 @@ download_po_files() {
   subdir=$1
   domain=$2
   echo "$me: getting translations into $subdir for $domain..."
-  cmd=`printf "$po_download_command_format" "$domain" "$subdir"`
+  cmd=$(printf "$po_download_command_format" "$domain" "$subdir")
   eval "$cmd" && return
   # Fallback to HTTP.
-  cmd=`printf "$po_download_command_format2" "$subdir" "$domain"`
+  cmd=$(printf "$po_download_command_format2" "$subdir" "$domain")
   eval "$cmd"
 }
 
@@ -658,7 +656,7 @@ update_po_files() {
     && ls "$ref_po_dir"/*.po 2>/dev/null |
       sed 's|.*/||; s|\.po$||' > "$po_dir/LINGUAS" || return
 
-  langs=`cd $ref_po_dir && echo *.po|sed 's/\.po//g'`
+  langs=$(cd $ref_po_dir && echo *.po | sed 's/\.po//g')
   test "$langs" = '*' && langs=x
   for po in $langs; do
     case $po in x) continue;; esac
@@ -695,18 +693,18 @@ symlink_to_dir()
 
     # If the destination directory doesn't exist, create it.
     # This is required at least for "lib/uniwidth/cjk.h".
-    dst_dir=`dirname "$dst"`
+    dst_dir=$(dirname "$dst")
     if ! test -d "$dst_dir"; then
       mkdir -p "$dst_dir"
 
       # If we've just created a directory like lib/uniwidth,
       # tell version control system(s) it's ignorable.
       # FIXME: for now, this does only one level
-      parent=`dirname "$dst_dir"`
+      parent=$(dirname "$dst_dir")
       for dot_ig in x $vc_ignore; do
         test $dot_ig = x && continue
         ig=$parent/$dot_ig
-        insert_vc_ignore $ig `echo "$dst_dir"|sed 's,.*/,,'`
+        insert_vc_ignore $ig "${dst_dir##*/}"
       done
     fi
 
@@ -730,10 +728,10 @@ symlink_to_dir()
       # so that broken tools aren't confused into skipping needed builds.  See
       # <http://lists.gnu.org/archive/html/bug-gnulib/2011-05/msg00326.html>.
       test -h "$dst" &&
-      src_ls=`ls -diL "$src" 2>/dev/null` && set $src_ls && src_i=$1 &&
-      dst_ls=`ls -diL "$dst" 2>/dev/null` && set $dst_ls && dst_i=$1 &&
+      src_ls=$(ls -diL "$src" 2>/dev/null) && set $src_ls && src_i=$1 &&
+      dst_ls=$(ls -diL "$dst" 2>/dev/null) && set $dst_ls && dst_i=$1 &&
       test "$src_i" = "$dst_i" &&
-      both_ls=`ls -dt "$src" "$dst"` &&
+      both_ls=$(ls -dt "$src" "$dst") &&
       test "X$both_ls" = "X$dst$nl$src" || {
         dot_dots=
         case $src in
@@ -868,7 +866,7 @@ AUTOPOINT=true LIBTOOLIZE=true \
 for file in $gnulib_extra_files; do
   case $file in
   */INSTALL) dst=INSTALL;;
-  build-aux/*) dst=$build_aux/`expr "$file" : 'build-aux/\(.*\)'`;;
+  build-aux/*) dst=$build_aux/${file#build-aux/};;
   *) dst=$file;;
   esac
   symlink_to_dir "$GNULIB_SRCDIR" $file $dst || exit
-- 
1.7.9.5




reply via email to

[Prev in Thread] Current Thread [Next in Thread]