Subject: toolchain/30726: bsd.subdir.mk infinite loop when one of SUBDIR does not exist.
To: None <toolchain-manager@netbsd.org, gnats-admin@netbsd.org,>
From: None <eau@phear.org>
List: netbsd-bugs
Date: 07/11/2005 18:10:00
>Number:         30726
>Category:       toolchain
>Synopsis:       bsd.subdir.mk infinite loop when one of SUBDIR does not exist.
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    toolchain-manager
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Jul 11 18:10:00 +0000 2005
>Originator:     Eric AUGE
>Release:        2.0.2_STABLE
>Organization:
>Environment:
NetBSD stardust.intra.nexthink.com 2.0.2_STABLE NetBSD 2.0.2_STABLE (GLOP) #7: Thu May 12 14:54:11 CEST 2005  root@glop.nexthink.com:/usr/src/sys/arch/i386/compile/GLOP i386

>Description:
Using that Makefile :

--- Makefile ---
SUBDIR= prout tsoin

.include <bsd.subdir.mk>
--- Makefile EOF ---

SUBDIR infinitely loop when the SUBDIR included dir doesn't exist.

eau@stardust:~/tmp$make 2>&1 | more
all ===> prout
cd: can't cd to /home/eau/tmp/prout
all ===> prout/prout
cd: can't cd to /home/eau/tmp/prout
all ===> prout/prout/prout
cd: can't cd to /home/eau/tmp/prout
all ===> prout/prout/prout/prout
cd: can't cd to /home/eau/tmp/prout
all ===> prout/prout/prout/prout/prout
cd: can't cd to /home/eau/tmp/prout
all ===> prout/prout/prout/prout/prout/prout
cd: can't cd to /home/eau/tmp/prout
all ===> prout/prout/prout/prout/prout/prout/prout
cd: can't cd to /home/eau/tmp/prout
all ===> prout/prout/prout/prout/prout/prout/prout/prout
cd: can't cd to /home/eau/tmp/prout

>How-To-Repeat:
just try that Makefile:

--- Makefile ---
SUBDIR= prout tsoin

.include "bsd.subdir.mk"
--- Makefile EOF ---

without creating the subdir and type 'make'.

>Fix:

I'm not sure the fix is good enough :/

--- /usr/share/mk/bsd.subdir.mk.orig 2005-07-11 19:50:24.000000000 +0200
+++ /usr/share/mk/bsd.subdir.mk       2005-07-11 20:01:06.000000000 +0200
@@ -21,7 +21,9 @@
        *)                                                              \
                echo "$$targ ===> ${_THISDIR_}$$dir";                   \
                cd "${.CURDIR}/$$dir";                                  \
+               if [ -d $$dir ]; then                                   \
                ${MAKE} "_THISDIR_=${_THISDIR_}$$dir/" $$targ;          \
+               fi                                                      \
                ;;                                                      \
        esac