Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

See output of shell script in Makefile

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)
like image 222
eric.frederich Avatar asked Oct 25 '25 01:10

eric.frederich


1 Answers

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.

like image 87
Eldar Abusalimov Avatar answered Oct 28 '25 03:10

Eldar Abusalimov