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, Hubert Feyrer wrote:
> When crosscompiling from Solaris 10 to NetBSD for the netbsd-5 branch (I 
> haven't checked -current), running a "nbmake-i386 install" in  
> src/tests/modules/k_helper gives:
>
>       % ~/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...

> 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

--apb (Alan Barrett)


Home | Main Index | Thread Index | Old Index