See output of shell script in Makefile

时间秒杀一切 提交于 2021-02-07 20:43:27

问题


How can I execute a shell script before building my targets in a Makefile, and see the output as it runs?

I have a script called prepare.sh that generates a bunch of .pyx files. The .pyx files are the starting point of my build process involving make. It goes from .pyx -> .c -> .o -> .so

I don't like having to run prepare.sh separately prior to make. I'd like make to run it for me.

I got it to work but I don't see the output of the command. I'd like to see it. This is what I have now:

PATH := ${PYTHONHOME}/bin:${PATH}

NOTHING:=$(shell ./prepare.sh)

PYXS?=$(wildcard merged/*.pyx)
SOURCES=$(PYXS:.pyx=.c)
OBJECTS=$(SOURCES:.c=.o)
SOBJECTS=$(OBJECTS:.o=.so)

回答1:


Redirect the output of your script to stderr. In this case you also can get rid of dummy NOTHING variable:

$(shell ./prepare.sh >&2)

UPD.

Another option is to execute the script inside a recipe which runs prior to everithing else:

.PHONY : prepare
prepare :
    ./prepare.sh

-include prepare

See also: the original Beta's answer with this hack, GNU Make manual entry explaining how it works.



来源:https://stackoverflow.com/questions/11021245/see-output-of-shell-script-in-makefile

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