Improve the checking of sed by adding some common GNU sed installation
authorBernhard Reutner-Fischer <rep.dot.nop@gmail.com>
Fri, 9 Mar 2007 08:33:34 +0000 (08:33 -0000)
committerBernhard Reutner-Fischer <rep.dot.nop@gmail.com>
Fri, 9 Mar 2007 08:33:34 +0000 (08:33 -0000)
names (gsed/gnused), checking for a basic OS X sed feature in command
line option handling, checking the actual result of the sed run against
the expected result, and placing common code for the check under
toolchain/dependencies/.  (Heikki Lindholm)

package/sed/sedcheck.sh
toolchain/dependencies/check-host-sed.sh [new file with mode: 0755]
toolchain/dependencies/dependencies.sh

index 535ad6023faa9ceaeb70b8da05c856d656d48c3e..3fe44e85e96c06da04ae398061bd21eb4638c0dc 100755 (executable)
@@ -2,24 +2,10 @@
 
 # Make sure the host sed supports '-i' (in-place).
 # If it doesn't, we'll build and use our own.
+SED=$(toolchain/dependencies/check-host-sed.sh)
 
-if test -x /usr/bin/sed ; then
-       SED="/usr/bin/sed"
-else
-       if test -x /bin/sed ; then
-               SED="/bin/sed"
-       else
-               SED="sed"
-       fi
-fi
-
-echo "HELLO" > .sedtest
-$SED -i -e "s/HELLO/GOODBYE/" .sedtest >/dev/null 2>&1
-
-if test $? != 0 ; then
+if [ -z "$SED" ] ; then
        echo build-sed-host-binary
 else
        echo use-sed-host-binary
 fi
-
-rm -f .sedtest
diff --git a/toolchain/dependencies/check-host-sed.sh b/toolchain/dependencies/check-host-sed.sh
new file mode 100755 (executable)
index 0000000..ba99a42
--- /dev/null
@@ -0,0 +1,38 @@
+SEDLIST="/usr/bin/sed /bin/sed sed gnused gsed"
+
+DIFF=$(which diff)
+if ! test -x "$DIFF" ; then
+       /bin/echo -e "\n\ntesting for sed needs 'diff' on your build machine\n";
+       exit 1;
+fi;
+
+for SED in $SEDLIST
+do
+       if ! test -x $SED ; then
+               SED=$(which $SED)
+               if ! test -x "$SED" > /dev/null ; then
+                       SED=""
+                       continue
+               fi
+       fi
+
+       echo "HELLO" > .sedtest
+       echo "GOODBYE" > .sedtest-correct
+       $SED -i -e "s/HELLO/GOODBYE/" .sedtest >/dev/null 2>&1
+
+       if test $? != 0 ; then
+               SED=""
+       elif test -e ".sedtest-e" ; then
+               rm -f ".sedtest-e"
+               SED=""
+       elif ! $DIFF ".sedtest" ".sedtest-correct" > /dev/null ; then
+               echo "diff failed"
+               SED=""
+       fi
+
+       rm -f .sedtest .sedtest-correct
+       if [ ! -z "$SED" ] ; then
+               break
+       fi
+done
+echo $SED
index 084e835cbc34a4649cf03c187872bddd2cf91d72..40bfd9a2ae002f9d31e8f5a11ff32b2a7abd777c 100755 (executable)
@@ -86,30 +86,6 @@ fi;
 
 
 
-#############################################################
-#
-# check build system 'sed'
-#
-#############################################################
-if test -x /usr/bin/sed ; then
-       SED="/usr/bin/sed"
-else
-       if test -x /bin/sed ; then
-               SED="/bin/sed"
-       else
-               SED="sed"
-       fi
-fi
-echo "HELLO" > .sedtest
-$SED -i -e "s/HELLO/GOODBYE/" .sedtest >/dev/null 2>&1
-if test $? != 0 ; then
-       echo "sed works:                                No, using buildroot version instead"
-else
-       echo "sed works:                                        Ok"
-fi
-rm -f .sedtest
-XSED=$HOST_SED_DIR/bin/sed
-
 #############################################################
 #
 # check build system 'which'
@@ -123,6 +99,25 @@ fi;
 echo "which installed:                         Ok"
 
 
+
+#############################################################
+#
+# check build system 'sed'
+#
+#############################################################
+SED=$(toolchain/dependencies/check-host-sed.sh)
+
+if [ -z "$SED" ] ; then
+       XSED=$HOST_SED_DIR/bin/sed
+       echo "sed works:                                        No, using buildroot version instead"
+else
+       XSED=$SED
+       echo "sed works:                                        Ok ($SED)"
+fi
+
+
+
+
 #############################################################
 #
 # check build system 'make'