help-make
[Top][All Lists]
Advanced

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

Nested for-loop fails: unexpected token


From: Alexander Farber
Subject: Nested for-loop fails: unexpected token
Date: Sat, 29 May 2004 22:39:00 +0000
User-agent: Mutt/1.4.1i

Hi,

could anyone please help me with the GNU Makefile listed
at the bottom of this mail? For some reason I get the error:

/bin/sh: -c: line 1: syntax error near unexpected token `cd'

When I remove the inner for-loop, the "gmake all" runs fine.
First I thought, that the shell wouldn't be capable of running
nested for-loops, but this test script does run fine:

    #!/bin/sh

    for dir in a b c; do
            for file in x y z; do
                    echo $dir/$file
            done
    done

What am I doing wrong? Also, does anyone please have an advice, how
could I handle the directory names (in $(SUBDIRS)) containing spaces?

And what to do, when my directory list in $(SUBDIRS) will grow longer?
Will a plain "for in $^; do blah; done" still work or should I use some 
trick with "read" or "xargs"?

Thank you
Alex


CPP      = cpp -undef -nostdinc -+
PERL     = perl
TOPDIR   = $(shell pwd)
GEN2MAKE = $(PERL) $(TOPDIR)/gen2make.pl
INF2MAKE = $(PERL) $(TOPDIR)/inf2make.pl
MMP2MAKE = $(PERL) $(TOPDIR)/mmp2make.pl

all: Makefile.targets

Makefile.subdirs: $(GENBUILD)
        @if [ -r '$<' ]; then \
                $(GEN2MAKE) $< > $@; \
        else \
                echo 'Set GENBUILD variable to the genbuild list file' >&2; \
                exit 1; \
        fi

-include Makefile.subdirs
# XXX how to handle spaces in dir and file names?
Makefile.targets: $(SUBDIRS)  
        rm -f $@; \ 
        for dir in $^; do \
                if cd $$dir; then \
                        echo "Extracting mmp filenames from $$dir/bld.inf"; \
                        MMPFILES=`$(CPP) < bld.inf | $(INF2MAKE) -m`; \
                        for file in "$$MMPFILES"; do \ 
                                echo "Appending TARGET from $$dir/$$file to 
$@"; \  
                                $(CPP) < $$file | \
                                        perl $(MMP2MAKE) -t >> $(TOPDIR)/$@; \
                                echo ": $$dir" >> $(TOPDIR)/$@; \
                        done \
                        cd $(TOPDIR); \ 
                else \
                        echo "Can not change to the directory $$dir" >&2; \
                fi; \
        done

$(SUBDIRS):
        @#echo $(INF2MAKE) -g > $@/Makefile

.PHONY: all





reply via email to

[Prev in Thread] Current Thread [Next in Thread]