mkdep ignores the return value of cc, so errors in cc do not propagate back up to the caller. The if [ $? != 0 ] test applies to the sed, which will probably never fail. The fix is probably to change the script so it writes to a temporary $TMP file and then runs the sed against that.