当 make 不需要做任何事情时,我该如何关闭它?

发布于 2024-08-21 09:50:24 字数 420 浏览 8 评论 0原文

如何阻止 make 说 make: Nothing to be do for 'all'.make: 'file' is up to date?我希望我的构建在不执行任何操作时保持沉默 - 还有其他地方调用 echo 来跟踪构建进度,因此此消息只是让事情变得混乱。我目前正在这样沉默:

all: dependency1 dependency2
    @:

有件事告诉我一定有更好的方法。有什么想法吗?

编辑:

但是,当命令 echo 确实需要构建某些东西时,我希望保持命令 echo 工作。我所希望的一个很好的例子是 --no-print-directory ,但我找不到任何其他标志来关闭选定的消息。

How I stop make from saying make: Nothing to be done for 'all'. or make: 'file' is up to date? I'd like my build to be silent when it's not doing anything - there are other places where echo is called to track build progress, so this message is just cluttering things up. I am currently silencing it like this:

all: dependency1 dependency2
    @:

Something tells me there must be a better way. Any ideas?

Edit:

I would like to keep command echo working when it does need to build something, however. A good example of what I'm hoping for is along the lines of --no-print-directory, but I can't find any other flags to shut up selected messages.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

浮生未歇 2024-08-28 09:50:24

也许make -s

Maybe make -s?

单身狗的梦 2024-08-28 09:50:24

因此,在网上阅读了几天之后,看起来没有比我正在做的更好的方法了。有些人建议的内容大致如下:

all: dependency1 dependency2 | silent

silent:
    @:

也就是说,仅依靠 silent 目标就足以让事情平静下来。由于我没有提出任何其他可行的解决方案,因此我将采用我所拥有的解决方案。

So after a couple days of reading around the web, it looks like there isn't any better way than what I'm doing. Some people recommended something along the lines of:

all: dependency1 dependency2 | silent

silent:
    @:

That is, just depending on the silent target would be enough to quiet things down. Since I didn't come up with any other workable solutions, I'm going with what I have.

风向决定发型 2024-08-28 09:50:24

你可以尝试...

$ make -q || make

这样做的好处是,当没有什么可做的时候,什么也不会打印,但是当确实需要继续时, make 会产生正常的输出...

You might try...

$ make -q || make

The advantage of doing it this way is that nothing is printed when there is nothing to do but make produces the normal output when it does need to proceed...

内心旳酸楚 2024-08-28 09:50:24

引用(凭记忆)旧的 make(1) 手册页的 BUGS 部分:有些事情你不能让 make 闭嘴。同时,-s 或 --silent 选项可能会有所帮助。

To quote (from memory) from the old make(1) man page, BUGS section: There are some things you can't get make to shut up about. Meanwhile, the -s or --silent option may help.

烧了回忆取暖 2024-08-28 09:50:24

您可以通过设置 MAKEFLAGS 在 makefile 本身中设置 -s 命令行参数。除非明确打印,否则不会打印任何内容,因此我使用以下 makefile 来回显调用的命令。

MAKEFLAGS += -s

PROJECT = progname
CC = g++
SDIR = src
ODIR = obj
BDIR = bin
IDIR = include
OBJS = $(patsubst $(SDIR)/%.cc,$(ODIR)/%.o,$(wildcard $(SDIR)/*.cc))

.PHONY: all debug clean

all: $(BDIR)/$(PROJECT)

debug: CFLAGS += -g -Wall -Wextra
debug: all

$(BDIR)/$(PROJECT): $(OBJS)
    @mkdir -p $(BDIR)
    @echo LINKING 
lt;
    @$(CC) -o $@ $(OBJS) -I$(IDIR)

$(ODIR)/%.o: $(SDIR)/%.cc
    @mkdir -p $(ODIR)
    @echo "COMPILING 
lt;"
    @$(CC) -o $@ -c 
lt; $(CFLAGS)

clean:
    @echo "CLEAN"
    @rm -rf $(BDIR) $(ODIR)

删除 MAKEFLAGS 变量将打印所有调用的命令。 Makefile 编译任何 C++ 项目,其中源文件(扩展名为 .cc)放入 src 目录,头文件放入 include 目录。

You can set the -s commandline argument to make in the makefile itself, by setting MAKEFLAGS. Nothing is printed unless you explicitely print it, so I use the following makefile to echo invoked commands.

MAKEFLAGS += -s

PROJECT = progname
CC = g++
SDIR = src
ODIR = obj
BDIR = bin
IDIR = include
OBJS = $(patsubst $(SDIR)/%.cc,$(ODIR)/%.o,$(wildcard $(SDIR)/*.cc))

.PHONY: all debug clean

all: $(BDIR)/$(PROJECT)

debug: CFLAGS += -g -Wall -Wextra
debug: all

$(BDIR)/$(PROJECT): $(OBJS)
    @mkdir -p $(BDIR)
    @echo LINKING 
lt;
    @$(CC) -o $@ $(OBJS) -I$(IDIR)

$(ODIR)/%.o: $(SDIR)/%.cc
    @mkdir -p $(ODIR)
    @echo "COMPILING 
lt;"
    @$(CC) -o $@ -c 
lt; $(CFLAGS)

clean:
    @echo "CLEAN"
    @rm -rf $(BDIR) $(ODIR)

Removing the MAKEFLAGS variable will print all invoked commands. The Makefile compiles any c++ project where source files (with .cc extension) are put into the src directory and header files are put into the include directory.

梦途 2024-08-28 09:50:24

使 2>&1 | egrep -v '无事可做|最新'

make 2>&1 | egrep -v 'Nothing to be done|up to date'

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文