Question

Consider the following example, how to print some text when the make reaches those #Print lines

lib: $(LIBOBJ)
if [ -n "$(SHARED_LIBS)" ]; then \
    #Print some stuff here
    $(MAKE) -f $(TOP)/Makefile.shared -e \
        LIBNAME=$(LIBNAME) \
        LIBEXTRAS='$(LIBOBJ)' \
        LIBDEPS='-L$(TOP) -lcrypto' \
        link_o.$(SHLIB_TARGET); \
else \
    #Print some stuff here
    $(AR) $(LIB) $(LIBOBJ); \
fi
@touch lib
Was it helpful?

Solution

Simply use the echo or print command. Don't forget to finish the line with a semi-colon and a backslash in your case.

echo "Print something";

lib: $(LIBOBJ)
if [ -n "$(SHARED_LIBS)" ]; then \
    echo "Print some stuff here"; \
    $(MAKE) -f $(TOP)/Makefile.shared -e \
        LIBNAME=$(LIBNAME) \
        LIBEXTRAS='$(LIBOBJ)' \
        LIBDEPS='-L$(TOP) -lcrypto' \
        link_o.$(SHLIB_TARGET); \
else \
    echo "Print some stuff here"; \
    $(AR) $(LIB) $(LIBOBJ); \
fi
@touch lib

OTHER TIPS

I think @sehe's (edited) answer should work.

Another useful technique for debugging makefile recipes is to define SHELL='bash -x' which tells the shell to print out each command as it executes it, so you can see which branch of the condition is taken.

You can do that either in the makefile, or just when running make:

make SHELL='bash -x' lib
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top