Hi,

the exit status of a shell pipeline is the exit status of the last
command in the pipeline. Since mkdep(1) pipes the output of ${CC} into
sed(1), the following check of '$?' checks the exit status of sed(1)
and not the of of cc(1).

This is nasty if some modification broke the compilation of a particular
source file. It cannot be compiled, but mkdep(1) exits with zero and
'make depend' completes without error. Since the source couldn't be
compiled, the resulting depend file will not list this source. Without
having any dependencies, make(1) will not try to rebuild the derived
targets. Unless I do a 'make clean', I won't even notice that my
build is broken.

Below is a possible patch to fix this.

Gerhard


--- usr.bin/mkdep/mkdep.gcc.sh  2008/08/28 09:39:44     1.15
+++ usr.bin/mkdep/mkdep.gcc.sh  2012/06/25 10:47:29
@@ -89,14 +89,9 @@ TMP=`mktemp /tmp/mkdep.XXXXXXXXXX` || exit 1
 trap 'rm -f $TMP ; trap 2 ; kill -2 $$' 1 2 3 13 15

 if [ "x$file" = x ]; then
-       ${CC:-cc} -M "$@"
+       ${CC:-cc} -M "$@" > $TMP
 else
-       ${CC:-cc} -M "$@" && cat "$file"
-fi |
-if [ x$pflag = x ]; then
-       sed -e 's; \./; ;g' > $TMP
-else
-       sed -e 's;\.o[ ]*:; :;' -e 's; \./; ;g' > $TMP
+       ${CC:-cc} -M "$@" && cat "$file" > $TMP
 fi

 if [ $? != 0 ]; then
@@ -105,15 +100,24 @@ if [ $? != 0 ]; then
        exit 1
 fi

+postproc() {
+       in=$1
+       if [ x$pflag = x ]; then
+               sed -e 's; \./; ;g' $in
+       else
+               sed -e 's;\.o[ ]*:; :;' -e 's; \./; ;g' $in
+       fi
+}
+
 if [ $append = 1 ]; then
-       cat $TMP >> $D
+       postproc $TMP >> $D
        if [ $? != 0 ]; then
                echo 'mkdep: append failed.'
                rm -f $TMP
                exit 1
        fi
 else
-       mv -f $TMP $D
+       postproc $TMP > $D
        if [ $? != 0 ]; then
                echo 'mkdep: rename failed.'
                rm -f $TMP


Gerhard
--
genua
Gesellschaft fuer Netzwerk- und Unix-Administration mbH
Domagkstrasse 7, 85551 Kirchheim bei Muenchen
tel +49 89 991950-0, fax -999, www.genua.de
Geschaeftsfuehrer: Dr. Magnus Harlander, Dr. Michaela Harlander,
Bernhard Schneck. Amtsgericht Muenchen HRB 98238

Reply via email to