Current-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Building on Solaris, sh problem: empty for loop



On Fri, 28 Nov 2008, Alan Barrett wrote:
        % ~/cvs/src-5/obj.i386/tooldir/bin/nbmake-i386 install                 #
        install
        
/usr/homes/feyrer/cvs/src-5/obj.i386/destdir//usr/tests/modules/k_helper/k_helper.kmod
===> for d in ; do
        /usr/homes/feyrer/cvs/src-5/obj.i386/tooldir/bin/i386--netbsdelf-install
        -U -M /usr/homes/feyrer/cvs/src-5/obj.i386/destdir/METALOG -D
        /usr/homes/feyrer/cvs/src-5/obj.i386/destdir -h sha1 -N
        /usr/homes/feyrer/cvs/src-5/etc -d $d;  done
===> /usr/xpg4/bin/sh: syntax error at line 1 : `;' unexpected

I can't find the Makefile that includes this code.  Anyway...

It's src/share/mk/bsd.kmodule.mk, lines 72+ (for rev. 1.15), the code is:

        ${_MKTARGET_INSTALL}
===>    for d in ${_INST_DIRS}; do \
                ${INSTALL_DIR} $$d; \
        done
        ${INSTALL_DIR} ${KMODULEDIR}



The error is that the shell can't handle an empty list for the "for" loop.

In some shells, this works:

        var="" # empty
        for foo in $var ; do ... ; done

while this doesn't work:

        for foo in ; do ... ; done

Inside a Makefile, where there are both make variables and shell variables,
that would translate as follows:

        sometarget: somedependency
                for d in ${MAKEVAR} ; do ... ; done # fails if MAKEVAR is empty

        sometarget: somedependency
                shellvar=${MAKEVAR:Q} ; \
                for d in $$shellvar ; do ... ; done # this should work

Gotcha, the patch below indeed worked - Thanks!
Any objections to commit?


 - Hubert

Index: bsd.kmodule.mk
===================================================================
RCS file: /cvsroot/src/share/mk/bsd.kmodule.mk,v
retrieving revision 1.15
diff -u -r1.15 bsd.kmodule.mk
--- bsd.kmodule.mk      12 Nov 2008 12:35:54 -0000      1.15
+++ bsd.kmodule.mk      28 Nov 2008 13:12:42 -0000
@@ -69,7 +69,9 @@
 .endif
 .endif
        ${_MKTARGET_INSTALL}
-       for d in ${_INST_DIRS}; do \
+       # The following variable works around a bug in Solaris' sh:
+       dirs=${_INST_DIRS:Q}; \
+       for d in $$dirs; do \
                ${INSTALL_DIR} $$d; \
        done
        ${INSTALL_DIR} ${KMODULEDIR}


Home | Main Index | Thread Index | Old Index