以下是question
我有Makefile.realMakefile来自prevquestion):

all: a b

a:
        echo a
        exit 1


b:
        echo b start
        sleep 1
        echo b end

现在我想创建一个简单的Makefile包装:
它用与被调用的参数相同的参数调用Makefile.real
它应该打印错误消息idmake失败
这是我的目标-在并行制造结束时打印错误消息
(见question
因此,以下命令应终止并显示错误消息:
make -j1 a b (1)
make -j2 a b (2)

我想应该是接近于:
%:
      $(MAKE) -f Makefile.real $(MAKECMDGOALS); \
      res=$$?; if [ $$res != 0 ]; then echo "Failed!!!"; fi; exit $$res

问题是,Makefile.real的目标“%”将被调用两次,而(2)的目标“%”将被调用两次。
有什么想法吗?

最佳答案

这就是我最后的解决方案

ifneq ($(REAL_MAKE),1)
# run_make will be called once (it's .PHONY target),
# even if make is called with several targets
%: run_make
        @:

.PHONY: run_make
run_make:
        $(MAKE) $(MAKECMDGOALS) REAL_MAKE=1; \
        if [ $$? -ne 0 ]; then               \
            echo "*** Error ***" >&2;        \
            exit 1;                          \
        fi

else  # REAL_MAKE defined (actual makefile)

### HERE comes original make we want to wrap ###

endif  # # REAL_MAKE defined (actual makefile)

关于linux - 用另一个makefile包裹GNU makefile,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10999800/

10-14 17:10
查看更多