【问题标题】:Wrapping GNU makefile with another makefile用另一个 makefile 包装 GNU makefile
【发布时间】:2012-06-12 15:25:35
【问题描述】:

这是question

我有Makefile.realMakefile 来自上一个question):

all: a b

a:
        echo a
        exit 1


b:
        echo b start
        sleep 1
        echo b end

现在我想创建Makefile,它是Makefile.real 的简单包装:

  • 它调用 makeMakefile.real,参数与调用时相同
  • 它应该打印错误消息 id Makefile.real 失败 这是我的目标 - 在并行制作结束时打印错误消息 (见question

因此,以下命令应终止并显示错误消息:

make -j1 a b (1)
make -j2 a b (2)

我怀疑Makefile 应该接近于:

%:
      $(MAKE) -f Makefile.real $(MAKECMDGOALS); \
      res=$$?; if [ $$res != 0 ]; then echo "Failed!!!"; fi; exit $$res

问题是目标 '%' 将被调用两次 ab 对于 (2)。

有什么想法吗?

【问题讨论】:

  • 你考虑过include Makefile.real吗?
  • @Beta 看不到它如何解决我的问题 - 我试图克服的是,在并行编译的情况下,make 的末尾没有错误消息。问题已编辑

标签: linux compilation makefile gnu-make


【解决方案1】:

这是我结束的解决方案

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)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-19
    • 2013-10-18
    • 2011-01-13
    • 2015-01-11
    • 2011-06-17
    • 1970-01-01
    相关资源
    最近更新 更多