开发者

Make failure in subdirectory make not stopping build

开发者 https://www.devze.com 2022-12-23 10:09 出处:网络
I have a setup where make is going through a bunch of subdirectories and making inside those directories.I would like it to stop the build on a failure immediately.The code snippet below illustrates t

I have a setup where make is going through a bunch of subdirectories and making inside those directories. I would like it to stop the build on a failure immediately. The code snippet below illustrates this. Can someone point me in the right direction on how the makefile should be set up or some documentation about building from a top level down through subdirectories?

SUBDIRS = \
test1 \
test2 

all clean check :
    @for dir in $(SUBDIRS); do \
        if [ -d $$dir ]; then (cd $$dir; $(MA开发者_JAVA技巧KE) $@) fi \
    done


I am in the (apparent) minority that disagrees with "Recursive Make Considered Harmful". I've written recursive Make systems for large, messy code bases, and they work quite nicely.

Here's how to do it:

all: $(SUBDIRS)

$(SUBDIRS): force
    @ $(MAKE) -s -C $@

.PHONY: force
force :;

(I've added the -s to make things quieter.)

EDIT: To pass a target down to the submakes (I should have done this before):

.PHONY: all check clean
all check clean: $(SUBDIRS)

all: TARGET=all
check: TARGET=check
clean: TARGET=clean
# No, you can't do TARGET=$@, or at least I don't know how to.

# recursive call to make
$(SUBDIRS): force
    @ $(MAKE) -s -C $@ $(TARGET)

.PHONY: force
    force :;


I would urge you to abandon the recursive make approach. It could cause endless amounts of difficulties later as your Makefiles grow. See the paper Recursive Make Considered Harmful for a very good explanation of why invoking make recursively is a bad idea.

An immediate benefit you'll realize from switching to non-recursive make is that this problem you are experiencing right now will simply evaporate. You will not have this problem with a non-recursive Makefile.

Also, feel free to check out this boilerplate non-recursive Makefile that I've created. It requires GNU Make 3.81, but is really easy to use. At the very least, it can act as a good example of a non-recursive Makefile, if you want to create your own.

0

精彩评论

暂无评论...
验证码 换一张
取 消