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
有帮助吗?

解决方案

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

其他提示

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
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top