Wrapping GNU makefile with another makefile

柔情痞子 提交于 2019-12-11 07:36:34

问题


This is following question.

I have Makefile.real (Makefile from prev question):

all: a b

a:
        echo a
        exit 1


b:
        echo b start
        sleep 1
        echo b end

Now I want to create Makefile that is simple wrap of Makefile.real:

  • It calls make with Makefile.real with the same args as it was called
  • It should print error message id Makefile.real fails This is my goal - print error message in the end of parallel make (see question)

Therefore following commands should terminate with error message:

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

I suspect Makefile should be something close to:

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

The problem is that target '%' will be called twice for a and b for (2).

Any ideas?


回答1:


This is the solution I ended with

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)


来源:https://stackoverflow.com/questions/10999800/wrapping-gnu-makefile-with-another-makefile

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!