[LEDE-DEV] [PATCH v2] Consider using { cmd1; cmd2; } >> file instead of individual redirects

Jan-Tarek Butt tarek at ring0.de
Sun Oct 2 02:46:26 PDT 2016


---
 scripts/config/lxdialog/check-lxdialog.sh |  16 ++--
 scripts/diffconfig.sh                     |  18 +++--
 scripts/ext-toolchain.sh                  | 118 +++++++++++++++++-------------
 3 files changed, 86 insertions(+), 66 deletions(-)

diff --git a/scripts/config/lxdialog/check-lxdialog.sh b/scripts/config/lxdialog/check-lxdialog.sh
index 5075ebf..d224a5d 100644
--- a/scripts/config/lxdialog/check-lxdialog.sh
+++ b/scripts/config/lxdialog/check-lxdialog.sh
@@ -50,13 +50,15 @@ check() {
 main() {}
 EOF
 	if [ $? != 0 ]; then
-	    echo " *** Unable to find the ncurses libraries or the"       1>&2
-	    echo " *** required header files."                            1>&2
-	    echo " *** 'make menuconfig' requires the ncurses libraries." 1>&2
-	    echo " *** "                                                  1>&2
-	    echo " *** Install ncurses (ncurses-devel) and try again."    1>&2
-	    echo " *** "                                                  1>&2
-	    exit 1
+		cat 1>&2 <<-EOF
+			 *** Unable to find the ncurses libraries or the
+			 *** required header files.
+			 *** 'make menuconfig' requires the ncurses libraries.
+			 ***
+			 *** Install ncurses (ncurses-devel) and try again.
+			 ***
+		EOF
+		exit 1
 	fi
 }
 
diff --git a/scripts/diffconfig.sh b/scripts/diffconfig.sh
index bdaf1a1..5eccbfa 100755
--- a/scripts/diffconfig.sh
+++ b/scripts/diffconfig.sh
@@ -1,12 +1,14 @@
 #!/bin/sh
-grep \^CONFIG_TARGET_ .config | head -n3 > tmp/.diffconfig.head
-grep \^CONFIG_TARGET_DEVICE_ .config >> tmp/.diffconfig.head
-grep '^CONFIG_ALL=y' .config >> tmp/.diffconfig.head
-grep '^CONFIG_ALL_KMODS=y' .config >> tmp/.diffconfig.head
-grep '^CONFIG_ALL_NONSHARED=y' .config >> tmp/.diffconfig.head
-grep '^CONFIG_DEVEL=y' .config >> tmp/.diffconfig.head
-grep '^CONFIG_TOOLCHAINOPTS=y' .config >> tmp/.diffconfig.head
-grep '^CONFIG_BUSYBOX_CUSTOM=y' .config >> tmp/.diffconfig.head
+{
+	grep \^CONFIG_TARGET_ .config | head -n3
+	grep \^CONFIG_TARGET_DEVICE_ .config
+	grep '^CONFIG_ALL=y' .config
+	grep '^CONFIG_ALL_KMODS=y' .config
+	grep '^CONFIG_ALL_NONSHARED=y' .config
+	grep '^CONFIG_DEVEL=y' .config
+	grep '^CONFIG_TOOLCHAINOPTS=y' .config
+	grep '^CONFIG_BUSYBOX_CUSTOM=y' .config
+} > tmp/.diffconfig.head
 ./scripts/config/conf --defconfig=tmp/.diffconfig.head -w tmp/.diffconfig.stage1 Config.in >/dev/null
 ./scripts/kconfig.pl '>+' tmp/.diffconfig.stage1 .config >> tmp/.diffconfig.head
 ./scripts/config/conf --defconfig=tmp/.diffconfig.head -w tmp/.diffconfig.stage2 Config.in >/dev/null
diff --git a/scripts/ext-toolchain.sh b/scripts/ext-toolchain.sh
index 2817b90..18a75c4 100755
--- a/scripts/ext-toolchain.sh
+++ b/scripts/ext-toolchain.sh
@@ -201,17 +201,19 @@ wrap_bin_cc() {
 	local out="$1"
 	local bin="$2"
 
-	echo    '#!/bin/sh'                                                > "$out"
-	echo    'for arg in "$@"; do'                                     >> "$out"
-	echo    ' case "$arg" in -l*|-L*|-shared|-static)'                >> "$out"
-	echo -n '  exec "'"$bin"'" '"$CFLAGS"' ${STAGING_DIR:+'           >> "$out"
-	echo -n '-idirafter "$STAGING_DIR/usr/include" '                  >> "$out"
-	echo -n '-L "$STAGING_DIR/usr/lib" '                              >> "$out"
-	echo    '-Wl,-rpath-link,"$STAGING_DIR/usr/lib"} "$@" ;;'         >> "$out"
-	echo    ' esac'                                                   >> "$out"
-	echo    'done'                                                    >> "$out"
-	echo -n 'exec "'"$bin"'" '"$CFLAGS"' ${STAGING_DIR:+'             >> "$out"
-	echo    '-idirafter "$STAGING_DIR/usr/include"} "$@"'             >> "$out"
+	{
+		echo    '#!/bin/sh'
+		echo    'for arg in "$@"; do'
+		echo    ' case "$arg" in -l*|-L*|-shared|-static)'
+		echo -n '  exec "'"$bin"'" '"$CFLAGS"' ${STAGING_DIR:+'
+		echo -n '-idirafter "$STAGING_DIR/usr/include" '
+		echo -n '-L "$STAGING_DIR/usr/lib" '
+		echo    '-Wl,-rpath-link,"$STAGING_DIR/usr/lib"} "$@" ;;'
+		echo    ' esac'
+		echo    'done'
+		echo -n 'exec "'"$bin"'" '"$CFLAGS"' ${STAGING_DIR:+'
+		echo    '-idirafter "$STAGING_DIR/usr/include"} "$@"'
+	} > "$out"
 
 	chmod +x "$out"
 }
@@ -220,10 +222,12 @@ wrap_bin_ld() {
 	local out="$1"
 	local bin="$2"
 
-	echo    '#!/bin/sh'                                                > "$out"
-	echo -n 'exec "'"$bin"'" ${STAGING_DIR:+'                         >> "$out"
-	echo -n '-L "$STAGING_DIR/usr/lib" '                              >> "$out"
-	echo    '-rpath-link "$STAGING_DIR/usr/lib"} "$@"'                >> "$out"
+	{
+		echo    '#!/bin/sh'
+		echo -n 'exec "'"$bin"'" ${STAGING_DIR:+'
+		echo -n '-L "$STAGING_DIR/usr/lib" '
+		echo    '-rpath-link "$STAGING_DIR/usr/lib"} "$@"'
+	} > "$out"
 
 	chmod +x "$out"
 }
@@ -349,12 +353,13 @@ print_config() {
 	else
 		echo "# CONFIG_BUILD_NLS is not set" >> "$config"
 	fi
-
-	echo "CONFIG_DEVEL=y" >> "$config"
-	echo "CONFIG_EXTERNAL_TOOLCHAIN=y" >> "$config"
-	echo "CONFIG_TOOLCHAIN_ROOT=\"$TOOLCHAIN\"" >> "$config"
-	echo "CONFIG_TOOLCHAIN_PREFIX=\"$prefix\"" >> "$config"
-	echo "CONFIG_TARGET_NAME=\"$target\"" >> "$config"
+	{
+		echo "CONFIG_DEVEL=y"
+		echo "CONFIG_EXTERNAL_TOOLCHAIN=y"
+		echo "CONFIG_TOOLCHAIN_ROOT=\"$TOOLCHAIN\""
+		echo "CONFIG_TOOLCHAIN_PREFIX=\"$prefix\""
+		echo "CONFIG_TARGET_NAME=\"$target\""
+	} >> "$config"
 
 	if [ "$LIBC_TYPE" != glibc ]; then
 		echo "CONFIG_TOOLCHAIN_LIBC=\"$LIBC_TYPE\"" >> "$config"
@@ -538,36 +543,47 @@ while [ -n "$1" ]; do
 
 		-h|--help)
 			me="$(basename "$0")"
-			echo -e "\nUsage:\n"                                            >&2
-			echo -e "  $me --toolchain {directory} --print-libc"            >&2
-			echo -e "    Print the libc implementation and exit.\n"         >&2
-			echo -e "  $me --toolchain {directory} --print-target"          >&2
-			echo -e "    Print the GNU target name and exit.\n"             >&2
-			echo -e "  $me --toolchain {directory} --print-bin {program}"   >&2
-			echo -e "    Print executables belonging to given program,"     >&2
-			echo -e "    omit program argument to get a list of names.\n"   >&2
-			echo -e "  $me --toolchain {directory} --print-libs {library}"  >&2
-			echo -e "    Print shared objects belonging to given library,"  >&2
-			echo -e "    omit library argument to get a list of names.\n"   >&2
-			echo -e "  $me --toolchain {directory} --test {feature}"        >&2
-			echo -e "    Test given feature, exit code indicates success."  >&2
-			echo -e "    Possible features are 'c', 'c++', 'softfloat',"    >&2
-			echo -e "    'lfs', 'rpc', 'ipv6', 'wchar', 'locale' and "      >&2
-			echo -e "    'threads'.\n"                                      >&2
-			echo -e "  $me --toolchain {directory} --wrap {directory}"      >&2
-			echo -e "    Create wrapper scripts for C and C++ compiler, "   >&2
-			echo -e "    linker, assembler and other key executables in "   >&2
-			echo -e "    the directory given with --wrap.\n"                >&2
-			echo -e "  $me --toolchain {directory} --config {target}"       >&2
-			echo -e "    Analyze the given toolchain and print a suitable"  >&2
-			echo -e "    .config for the given target. Omit target "        >&2
-			echo -e "    argument to get a list of names.\n"                >&2
-			echo -e "  $me --help"                                          >&2
-			echo -e "    Display this help text and exit.\n\n"              >&2
-			echo -e "  Most commands also take a --cflags parameter which " >&2
-			echo -e "  is used to specify C flags to be passed to the "     >&2
-			echo -e "  cross compiler when performing tests."               >&2
-			echo -e "  This paremter may be repeated multiple times."       >&2
+			cat >&2 <<-EOF
+				Usage:
+
+				  $me --toolchain {directory} --print-libc
+				    Print the libc implementation and exit.
+
+				  $me --toolchain {directory} --print-target
+				    Print the GNU target name and exit.
+
+				  $me --toolchain {directory} --print-bin {program}
+				    Print executables belonging to given program,
+				    omit program argument to get a list of names.
+
+				  $me --toolchain {directory} --print-libs {library}
+				    Print shared objects belonging to given library,
+				    omit library argument to get a list of names.
+
+				  $me --toolchain {directory} --test {feature}
+				    Test given feature, exit code indicates success.
+				    Possible features are 'c', 'c++', 'softfloat',
+				    'lfs', 'rpc', 'ipv6', 'wchar', 'locale' and
+				    'threads'.
+
+				  $me --toolchain {directory} --wrap {directory}
+				    Create wrapper scripts for C and C++ compiler,
+				    linker, assembler and other key executables in
+				    the directory given with --wrap.
+
+				  $me --toolchain {directory} --config {target}
+				    Analyze the given toolchain and print a suitable
+				    .config for the given target. Omit target
+				    argument to get a list of names.
+
+				  $me --help
+				    Display this help text and exit.
+
+				    Most commands also take a --cflags parameter which
+				  is used to specify C flags to be passed to the
+				  cross compiler when performing tests.
+				  This paremter may be repeated multiple times.
+			EOF
 			exit 1
 		;;
 
-- 
2.10.0




More information about the Lede-dev mailing list