Source-Changes-HG archive

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

[src/trunk]: src build.sh: improve help versus usage



details:   https://anonhg.NetBSD.org/src/rev/b4dade607c14
branches:  trunk
changeset: 368948:b4dade607c14
user:      lukem <lukem%NetBSD.org@localhost>
date:      Sun Aug 14 08:51:41 2022 +0000

description:
build.sh: improve help versus usage

Rework help / usage semantics:
- send help to stdout, exit 0.
- send usage to stderr, exit 1.

diffstat:

 build.sh |  37 +++++++++++++++++++++++++++----------
 1 files changed, 27 insertions(+), 10 deletions(-)

diffs (124 lines):

diff -r 2198928d7d5b -r b4dade607c14 build.sh
--- a/build.sh  Sun Aug 14 08:49:00 2022 +0000
+++ b/build.sh  Sun Aug 14 08:51:41 2022 +0000
@@ -1,7 +1,7 @@
 #! /usr/bin/env sh
-#      $NetBSD: build.sh,v 1.361 2021/12/31 15:43:35 christos Exp $
+#      $NetBSD: build.sh,v 1.362 2022/08/14 08:51:41 lukem Exp $
 #
-# Copyright (c) 2001-2011 The NetBSD Foundation, Inc.
+# Copyright (c) 2001-2022 The NetBSD Foundation, Inc.
 # All rights reserved.
 #
 # This code is derived from software contributed to The NetBSD Foundation
@@ -360,6 +360,7 @@
 # Find a program in the PATH, and print the result.  If not found,
 # print a default.  If $2 is defined (even if it is an empty string),
 # then that is the default; otherwise, $1 is used as the default.
+#
 find_in_PATH()
 {
        local prog="$1"
@@ -379,6 +380,7 @@
 
 # Try to find a working POSIX shell, and set HOST_SH to refer to it.
 # Assumes that uname_s, uname_m, and PWD have been set.
+#
 set_HOST_SH()
 {
        # Even if ${HOST_SH} is already defined, we still do the
@@ -948,6 +950,7 @@
        eval "$1='$2'; export $1"
        makeenv="${makeenv} $1"
 }
+
 safe_setmakeenv()
 {
        case "$1" in
@@ -966,6 +969,7 @@
        eval "unset $1"
        makeenv="${makeenv} $1"
 }
+
 safe_unsetmakeenv()
 {
        case "$1" in
@@ -980,6 +984,7 @@
 
 # Given a variable name in $1, modify the variable in place as follows:
 # For each space-separated word in the variable, call resolvepath.
+#
 resolvepaths()
 {
        local var="$1"
@@ -997,6 +1002,7 @@
 # Given a variable name in $1, modify the variable in place as follows:
 # Convert possibly-relative path to absolute path by prepending
 # ${TOP} if necessary.  Also delete trailing "/", if any.
+#
 resolvepath()
 {
        local var="$1"
@@ -1015,12 +1021,10 @@
        eval ${var}=\"\${val}\"
 }
 
-usage()
+# Display help to stdout.
+#
+help()
 {
-       if [ -n "$*" ]; then
-               echo ""
-               echo "${progname}: $*"
-       fi
        cat <<_usage_
 
 Usage: ${progname} [-EhnoPRrUuxy] [-a arch] [-B buildid] [-C cdextras]
@@ -1130,6 +1134,17 @@
     -Z var         Unset ("zap") variable \`var'.
 
 _usage_
+}
+
+# Display optional error message, help to stderr, and exit 1.
+#
+usage()
+{
+       if [ -n "$*" ]; then
+               echo ""
+               echo "${progname}: $*"
+       fi
+       help 1>&2
        exit 1
 }
 
@@ -1349,7 +1364,8 @@
                        ;;
 
                -'?'|-h)
-                       usage
+                       help
+                       exit 0
                        ;;
 
                esac
@@ -1365,7 +1381,8 @@
                case "${op}" in
 
                help)
-                       usage
+                       help
+                       exit 0
                        ;;
 
                list-arch)
@@ -1974,7 +1991,7 @@
        eval cat <<EOF ${makewrapout}
 #! ${HOST_SH}
 # Set proper variables to allow easy "make" building of a NetBSD subtree.
-# Generated from:  \$NetBSD: build.sh,v 1.361 2021/12/31 15:43:35 christos Exp $
+# Generated from:  \$NetBSD: build.sh,v 1.362 2022/08/14 08:51:41 lukem Exp $
 # with these arguments: ${_args}
 #
 



Home | Main Index | Thread Index | Old Index