Skip to contentSkip to conversation

Fix for POSIX compliance

PATCH New Yann E. MORIN 2 participants 7 messages Sep 20, 2010 – Sep 30, 2010 Kbuild

lore
Share & tools
lore
#0 lore raw

cover Fix for POSIX compliance

Hello All!

This series adds fixes for POSIX 1003.1-2008 compliance in some shell scripts, with respect to string comparison. POSIX says that string comparison in test(1) is done using a sing '='; using two is a bashism. See:
http://www.opengroup.org/onlinepubs/9699919799/utilities/test.html
man 1 test
man 1 bash

[PATCH 1/4] toolchain: fix helpers for POSIX compliance
[PATCH 2/4] skeleton: fix atstk1005, ststk100x and atngw100 for POSIX [...] [PATCH 3/4] scripts: fix for POSIX compliance
[PATCH 4/4] package/tcl: fix for POSIX compliance

Totally untested (I lack the proper Atmel hardware, at least), but should be harmless.

Note: I have done no other compliance checking at all, only string comparison.

Regards,
Yann E. MORIN.

#1 lore raw

PATCH 1/4 toolchain: fix helpers for POSIX compliance

Using two '=' for string comparison is a bashism. Revert to using one, as stated in POSIX 1003.1-2008.

---
 toolchain/helpers.mk |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)
toolchain/helpers.mk +4 -4
index 5c87d2b..05d43e7 100644
@@ -170,11 +170,11 @@ check_glibc = \
 #
 check_uclibc_feature = \
 	IS_IN_LIBC=`grep -q "\#define $(1) 1" $(3) && echo y` ; \
-	if [ x$($(2)) != x"y" -a x$${IS_IN_LIBC} == x"y" ] ; then \
+	if [ x$($(2)) != x"y" -a x$${IS_IN_LIBC} = x"y" ] ; then \
 		echo "$(4) available in C library, please enable $(2)" ; \
 		exit 1 ; \
 	fi ; \
-	if [ x$($(2)) == x"y" -a x$${IS_IN_LIBC} != x"y" ] ; then \
+	if [ x$($(2)) = x"y" -a x$${IS_IN_LIBC} != x"y" ] ; then \
 		echo "$(4) not available in C library, please disable $(2)" ; \
 		exit 1 ; \
 	fi
@@ -214,11 +214,11 @@ check_arm_abi = \
 	else \
 		EXT_TOOLCHAIN_ABI="oabi" ; \
 	fi ; \
-	if [ x$(BR2_ARM_OABI) == x"y" -a $${EXT_TOOLCHAIN_ABI} == "eabi" ] ; then \
+	if [ x$(BR2_ARM_OABI) = x"y" -a $${EXT_TOOLCHAIN_ABI} = "eabi" ] ; then \
 		echo "Incorrect ABI setting" ; \
 		exit 1 ; \
 	fi ; \
-	if [ x$(BR2_ARM_EABI) == x"y" -a $${EXT_TOOLCHAIN_ABI} == "oabi" ] ; then \
+	if [ x$(BR2_ARM_EABI) = x"y" -a $${EXT_TOOLCHAIN_ABI} = "oabi" ] ; then \
 		echo "Incorrect ABI setting" ; \
 		exit 1 ; \
 	fi ; \
Signature · 1 line
1.7.1
#2 lore raw

PATCH 2/4 skeleton: fix atstk1005, ststk100x and atngw100 for POSIX compliance

In reply to Yann E. MORIN

Using two '=' for string comparison is a bashism. Revert to using one, as stated in POSIX 1003.1-2008.

---
 .../atngw100/target_skeleton/etc/init.d/S99gpio    |    6 +++---
 .../atstk1005/target_skeleton/etc/init.d/S99gpio   |    6 +++---
 .../atstk100x/target_skeleton/etc/init.d/S99gpio   |    6 +++---
 3 files changed, 9 insertions(+), 9 deletions(-)
target/device/Atmel/atngw100/target_skeleton/etc/init.d/S99gpio +3 -3
index ea07784..3a17740 100755
@@ -8,9 +8,9 @@ fi
 
 BOARD=`cat /etc/release | cut -d ' ' -f1`
 
-if [ "${BOARD}" == "" ]; then
+if [ "${BOARD}" = "" ]; then
 	echo "none";
-elif [ "${BOARD}" == "NGW100" ]; then
+elif [ "${BOARD}" = "NGW100" ]; then
 	echo "'${BOARD}'"
 
 	echo -n "  boot LED: "
@@ -111,7 +111,7 @@ elif [ "${BOARD}" == "NGW100" ]; then
 		echo "failed"
 		exit 1
 	fi
-elif [ "${BOARD}" == "STK1000" ]; then # end NGW100
+elif [ "${BOARD}" = "STK1000" ]; then # end NGW100
 	echo "'${BOARD}'"
 
 	echo -n "  switches: "
target/device/Atmel/atstk1005/target_skeleton/etc/init.d/S99gpio +3 -3
index 967761a..7c07f28 100644
@@ -8,9 +8,9 @@ fi
 
 BOARD=`cat /etc/release | cut -d ' ' -f1`
 
-if [ "${BOARD}" == "" ]; then
+if [ "${BOARD}" = "" ]; then
 	echo "none";
-elif [ "${BOARD}" == "NGW" ]; then
+elif [ "${BOARD}" = "NGW" ]; then
 	echo "'${BOARD}'"
 
 	echo -n "  boot LED: "
@@ -111,7 +111,7 @@ elif [ "${BOARD}" == "NGW" ]; then
 		echo "failed"
 		exit 1
 	fi
-elif [ "${BOARD}" == "STK1000" ]; then # end NGW
+elif [ "${BOARD}" = "STK1000" ]; then # end NGW
 	echo "'${BOARD}'"
 
 	echo -n "  switches: "
target/device/Atmel/atstk100x/target_skeleton/etc/init.d/S99gpio +3 -3
index 967761a..7c07f28 100644
@@ -8,9 +8,9 @@ fi
 
 BOARD=`cat /etc/release | cut -d ' ' -f1`
 
-if [ "${BOARD}" == "" ]; then
+if [ "${BOARD}" = "" ]; then
 	echo "none";
-elif [ "${BOARD}" == "NGW" ]; then
+elif [ "${BOARD}" = "NGW" ]; then
 	echo "'${BOARD}'"
 
 	echo -n "  boot LED: "
@@ -111,7 +111,7 @@ elif [ "${BOARD}" == "NGW" ]; then
 		echo "failed"
 		exit 1
 	fi
-elif [ "${BOARD}" == "STK1000" ]; then # end NGW
+elif [ "${BOARD}" = "STK1000" ]; then # end NGW
 	echo "'${BOARD}'"
 
 	echo -n "  switches: "
Signature · 1 line
1.7.1
#3 lore raw

PATCH 3/4 scripts: fix for POSIX compliance

In reply to Yann E. MORIN

Using two '=' for string comparison is a bashism. Revert to using one, as stated in POSIX 1003.1-2008.

Of the three affected scripts, two are explicitly called vi #!/bin/bash. Those two do not _need_ the fix, but gets it nonetheless, in case we later switch to a POSIX-compliant shell for those scripts.

---
 scripts/get_linux_config.sh |    6 +++---
 scripts/mkpkg               |   14 +++++++-------
 scripts/testheader.inc      |   16 ++++++++--------
 3 files changed, 18 insertions(+), 18 deletions(-)
scripts/get_linux_config.sh +3 -3
index 5cd0e37..6c00036 100755
@@ -23,7 +23,7 @@ LINUX_MINOR_VERSION=${LINUX26_DIR:13}
 
 function DBG_PRINT
 {
-	if [ ${DEBUG} == 1 ] ; then
+	if [ ${DEBUG} = 1 ] ; then
 		echo $1
 	fi
 }
@@ -50,8 +50,8 @@ for i in ${CONFIGS} ; do
 	    echo Copying `basename $i`.config ...
 	    cp $i.config ${LINUX26_CONFIG}
     elif [ ${THIS_MAJOR} -eq ${LINUX_MAJOR_VERSION} ] ; then
-	if [ "${LINUX_MINOR_VERSION}X" == "X" ] ; then
-		if [ "${THIS_MINOR}X" == "X" ] ; then
+	if [ "${LINUX_MINOR_VERSION}X" = "X" ] ; then
+		if [ "${THIS_MINOR}X" = "X" ] ; then
 		    echo Copying `basename $i`.config ...
 		    cp $i.config ${LINUX26_CONFIG}
 		else		
scripts/mkpkg +7 -7
index af47f42..4db0fef 100755
@@ -36,7 +36,7 @@ function	process ()
 {
 	make $1 >> ${LOG} 2>&1 || test=${FAIL}
 	grep "\.tar\." ${LOG} > ${DEPENDENCY}
-	if [ ${test} == ${OK} ] ; then
+	if [ ${test} = ${OK} ] ; then
 		mv ${LOG} ${LOG_OK_FILE}
 		printf "%-16s" "OK"
 		if [ "${2}X" != "X" ] ; then
@@ -65,29 +65,29 @@ function build_package ()
 {
 	# echo "BUILD PACKAGE:1=$1 2=$2 3=$3 4=$4 5=$5 6=$6 7=$7"
 	printf "mk	%-32s" "$1"
-	if [ "$2X" == "X" ] ; then		# no parameters
+	if [ "$2X" = "X" ] ; then		# no parameters
 		clean_files	$1
 		dirclean	$1
 		process		$1 "$3"
-	elif [ "$2X" == "?X" ] ; then		# no parameters
+	elif [ "$2X" = "?X" ] ; then		# no parameters
 		clean_files	$1
 		dirclean	$1
 		process		$1 "$3"
-	elif [ "$2X" == "OKX" ] ; then	# Previous build was OK
+	elif [ "$2X" = "OKX" ] ; then	# Previous build was OK
 		clean_files	$1
 		dirclean	$1
 		process		$1 "$3"
-	elif [ "$2X" == "FAILX" ] ; then
+	elif [ "$2X" = "FAILX" ] ; then
 		clean_files	$1
 		dirclean	$1
 		process		$1 "$3"
-	elif [ "$2X" == "BROKENX" ] ; then
+	elif [ "$2X" = "BROKENX" ] ; then
 		printf  "%-16s" "BROKEN"
 		if [ "${3}X" != "X" ] ; then
 			printf	"%s"	"\"$3\"";
 		fi
 		echo
-	elif [ "$2X" == "DISABLEDX" ] ; then
+	elif [ "$2X" = "DISABLEDX" ] ; then
 		printf  "%-16s" "DISABLED"
 		if [ "${3}X" != "X" ] ; then
 			printf	"%s"	"\"$3\"";
scripts/testheader.inc +8 -8
index 232e1e0..44b5585 100644
@@ -31,7 +31,7 @@ function	RESTART()
 function	EXE()
 {
 	printf 	"EXE	"				| tee -a ${LOGFILE}
-	if [ ${active} == 1 ] ; then
+	if [ ${active} = 1 ] ; then
 		$1 $2 $3 "$4"
 		return 0;
 	else
@@ -49,10 +49,10 @@ function	EXE()
 function	AVR()
 {
 	printf 	"AVR	"				| tee -a ${LOGFILE}
-	if [ "${ARCH}X" == "avr32X" ] ; then
+	if [ "${ARCH}X" = "avr32X" ] ; then
 		echo "mk $2 UNSUPPORTED \"$4\" $5 $6"	| tee -a ${LOGFILE}
 		return 1;
-	elif [ ${active} == 1 ] ; then
+	elif [ ${active} = 1 ] ; then
 		$1 $2 "$3" "$4"
 		return 0;
 	else
@@ -72,22 +72,22 @@ function skip()
 {
 	printf "skip	%-8s" "$1"			| tee -a ${LOGFILE}
 	printf "%-32s" "$2"				| tee -a ${LOGFILE}
-	if [   "$3X" == "OKX" ] ; then
+	if [   "$3X" = "OKX" ] ; then
 		printf "%-16s"	"DISABLED"		| tee -a ${LOGFILE}
 		if [ "${4}X" != "X" ] ; then
 			printf	"%-64s"	"\"$4\""	| tee -a ${LOGFILE}
 		fi
-	elif [ "$3X" == "FAILX" ] ; then
+	elif [ "$3X" = "FAILX" ] ; then
 		printf "%-16s"	"DISABLED"		| tee -a ${LOGFILE}
 		if [ "${4}X" != "X" ] ; then
 			printf	"%-64s"	"\"$4\""	| tee -a ${LOGFILE}
 		fi
-	elif [ "$3X" == "BROKENX" ] ; then
+	elif [ "$3X" = "BROKENX" ] ; then
 		printf "%-16s"	"DISABLED"		| tee -a ${LOGFILE}
 		if [ "${4}X" != "X" ] ; then
 			printf	"%-64s"	"\"$4\""	| tee -a ${LOGFILE}
 		fi
-	elif [ "$3X" == "DISABLEDX" ] ; then
+	elif [ "$3X" = "DISABLEDX" ] ; then
 		printf "%-16s"	"DISABLED"		| tee -a ${LOGFILE}
 		if [ "${4}X" != "X" ] ; then
 			printf	"%-64s"	"\"$4\""	| tee -a ${LOGFILE}
@@ -104,7 +104,7 @@ function skip()
 function bb()
 {
 	printf 	"%-8s"	"bb"				| tee -a ${LOGFILE}
-	if [ ${busybox} == 1 ] ; then
+	if [ ${busybox} = 1 ] ; then
 		printf "%-8s"	"$1"			| tee -a ${LOGFILE}
 		$1 $2 $3 $4 $5 $6
 		return 0;
Signature · 1 line
1.7.1
#4 lore raw

PATCH 4/4 package/tcl: fix for POSIX compliance

In reply to Yann E. MORIN

Using two '=' for string comparison is a bashism. Revert to using one, as stated in POSIX 1003.1-2008.

---
 package/tcl/tcl.mk |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
package/tcl/tcl.mk +2 -2
index edcc441..cf46811 100644
@@ -15,10 +15,10 @@ TCL_CONF_OPT = \
 
 define TCL_POST_INSTALL_CLEANUP
 	-$(STRIPCMD) $(STRIP_STRIP_UNNEEDED) $(TARGET_DIR)/usr/lib/libtcl8.4.so
-	-if [ "$(BR2_PACKAGE_TCL_DEL_ENCODINGS)" == "y" ]; then \
+	-if [ "$(BR2_PACKAGE_TCL_DEL_ENCODINGS)" = "y" ]; then \
 	rm -Rf $(TARGET_DIR)/usr/lib/tcl8.4/encoding/*; \
 	fi
-	-if [ "$(BR2_PACKAGE_TCL_SHLIB_ONLY)" == "y" ]; then \
+	-if [ "$(BR2_PACKAGE_TCL_SHLIB_ONLY)" = "y" ]; then \
 	rm -f $(TARGET_DIR)/usr/bin/tclsh8.4; \
 	fi
 endef
Signature · 1 line
1.7.1
#5 lore raw

cover Fix for POSIX compliance

In reply to Yann E. MORIN

All,

Quoted 3 lines · On Monday 20 September 2010 23:26:05 Yann E. MORIN wrote:

This series adds fixes for POSIX 1003.1-2008 compliance in some shell scripts, with respect to string comparison. POSIX says that string comparison in test(1) is done using a sing '='; using two is a bashism.

Ping? ;-)

Regards,
Yann E. MORIN.

Signature · 6 lines
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 223 225 172 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'
#6 lore raw

cover Fix for POSIX compliance

In reply to Yann E. MORIN
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Yann" == Yann E MORIN <[email protected]> writes:

Yann> Hello All!
Yann> This series adds fixes for POSIX 1003.1-2008 compliance in some shell Yann> scripts, with respect to string comparison. POSIX says that string Yann> comparison in test(1) is done using a sing '='; using two is a bashism. Yann> See:

 Yann>   http://www.opengroup.org/onlinepubs/9699919799/utilities/test.html
 Yann>   man 1 test
 Yann>   man 1 bash

Committed all 4, thanks!

Signature · 1 line
Bye, Peter Korsgaard