Makefile works in bash but fails in zsh. Can you point out error in syntax of for loop?
Here's the beginning of a GNUMakefile that works well under bash but has failed since I switched to zsh (and oh-my-zsh). It is annoying that I need to start a bash shell to perform it, so do you think you can help point out the syntax problem?
SUBDIRS = generator geometry io management physicslist processing
makeall:
@echo "********************************************************************************"
@echo " Building Project"
@echo "********************************************************************************"
@for dir in $(SUBDIRS); do (echo; echo; echo Building $$dir...; cd $$dir; $(MAKE) "SUBDIRS=$(SUBDIRS)"); done
This results in an infinite loop:
[●]% make
********************************************************************************
Building Project
********************************************************************************
Building generator...
/bin/sh: line 0: cd: generator: No such file or directory
********************************************************************************
Building Project
********************************************************************************
Building generator...
/bin/sh: line 0: cd: generator: No such file or directory
********************************************************************************
Building Project
********************************************************************************
...
...
It seems I fork-bomb myself with make's and /bin/sh's:
...
...
24921 ttys012 0:00.00 make SUBDIRS=generator geometry io management physicslist processing
24925 ttys012 0:00.00 /bin/sh -c for dir in generator geometry io management physicslist processing; do (echo; echo; echo Building $dir...; cd $dir; make "SUBDIRS=generator geometry io man
24926 ttys012 0:00.00 /bin/sh -c for dir in generator geometry io management physicslist processing; do (echo; echo; echo Building $dir...; cd $dir; make "SUBDIRS=generator geometry io man
24927 ttys012 0:00.00 make SUBDIRS=generator geometry io management physicslist processing
24931 ttys012 0:00.00 /bin/sh -c for dir in generator geometry io management physicslist processing; do (echo; echo; echo Building $dir...; cd $dir; make "SUBDIRS=generator geometry io man
24932 ttys012 0:00.00 /bin/sh -c for dir in generator geometry io management physicslist processing; do (echo; echo
...
...
EDIT:
The makefile inside of generator looks like:
name := generator
include ../ProgramConfig/Libraries.gmk
Libraries.gmk looks like
.PHONY: all lib
all: lib
inclu开发者_如何学Gode ../ProgramConfig/BuildDirs.gmk
include $(G4INSTALL)/config/architecture.gmk
include $(G4INSTALL)/config/common.gmk
include ../ProgramConfig/ExtraDeps.gmk
include ../ProgramConfig/GEANT4.gmk
# Add the sub-directory include directories to the compilation list
CPPFLAGS += $(addprefix -I../, $(addsuffix /include, $(SUBDIRS))) -O2
cleanup:
cd $(G4WORKDIR)
rm -rf bin tmp lib
Experiment 1. Try this:
makeall:
@for dir in $(SUBDIRS); do (echo Building $$dir...; cd $$dir; $(MAKE) "SUBDIRS=$(SUBDIRS)" ; cd -); done
And the safer method I had in mind: iterate in Make, not in the shell.
makeall: $(SUBDIRS)
.PHONY: $(SUBDIRS)
$(SUBDIRS):
@echo Building $@
@cd $@; $(MAKE) "SUBDIRS=$(SUBDIRS)"
Note that you can also make that last rule a little cleaner:
$(SUBDIRS):
@echo Building $@
@$(MAKE) -C $@ "SUBDIRS=$(SUBDIRS)"
精彩评论