0

我有这个 Makefile:

CC          =   @gcc
RM          =   @rm

TARGET      =   test
PLUGINS_DIR =   plugins
PLUGINS_C   =   $(wildcard $(PLUGINS_DIR)/*.c)
PLUGINS_O   =   $(patsubst %.c,%.o, $(PLUGINS_C))
PLUGINS_SO  =   $(patsubst %.c,%.so, $(PLUGINS_C))

.PHONY: plugins

new: clean all

all: $(TARGET) $(PLUGINS_SO)

$(TARGET): $(TARGET).o
    $(CC) -o $@ $^ -g -Wall -std=gnu99 -ldl -Wl,--export-dynamic

$(PLUGINS_DIR)/%.so: $(PLUGINS_DIR)/%.o
    $(CC) $^ -o $@ -shared

$(PLUGINS_DIR)/%.o: $(PLUGINS_DIR)/%.c
    $(CC) -c $< -o $@ -pedantic -g -Wall -std=c99 -fpic -I.

clean:
    $(RM) -rf $(TARGET) *.o *.a $(PLUGINS_O) $(PLUGINS_SO)

clean仍在输出一条消息!( rm plugins/tt.o plugins/kk.o) 如果我删除@前面的,rm那么除了第一条消息之外,我还会收到另一条消息:rm -rf test *.o *.a plugins/kk.o plugins/tt.o plugins/kk.so plugins/tt.so

我怎样才能make完全保持沉默?(请不要make开关,只需在 Makefile 中编写代码)

编辑:使用 make 4.0

4

1 回答 1

3

I think you've got this wrong; I'll bet it's not your clean rule that's printing this.

Those object files are considered "intermediate targets", and as such make is deleting them for you automatically. When it does, it prints that information so you know where they went. The only way to stop that from happening is to define the .SILENT: special target (or give the -s flag but you said you didn't want to do that).

Or, you can ensure make doesn't consider those files to be intermediate (and thus not deleting them) by listing them as prerequisites, maybe:

all: $(TARGET) $(PLUGINS_SO) $(PLUGINS_O)
于 2013-11-12T20:26:00.977 回答