Parallel Make Output

六眼飞鱼酱① 提交于 2019-11-30 15:48:22
Eric Melski

If you're using GNU make, you can do it by redefining SHELL such that commands are wrapped by a trivial utility that ensures atomicity of information printed to standard output. Here's a more detailed description, including sample source for the wrapper utility.

I tried to get the CMake people to fix this, but apparently they don't want to. See http://www.cmake.org/Bug/view.php?id=7062.

The specific CMake bug related to interleaved make output using -jN with N>1 is CMake bug 0012991: "Parallel build output mess". It is still open in the "backlog" state waiting to be fixed.

This bug is actually annoying enough that it's a strong reason to switch to Ninja instead of make. Plus the fact that Ninja is faster than make. Ninja also uses an appropriate number of parallel jobs based on the number of CPU cores present. Also cool is how Ninja is, by default, very quiet: all progress happens on a single line in the terminal unless the build process emits messages or a build step fails. If a build step fails, Ninja prints the full command line that invoked it and displays the output. It's really nice since it makes any warning or error messages stand out. Although currently there is no colored terminal output: that would be a nice improvement but for me the advantages of Ninja over make are tremendous.

Sun's (now Oracle's) dmake available on Linux and Solaris takes care of that. See here and there.

Here is a simple working example of using a wrapper for Make. I'm not sure if I'd encourage it's use, but it's an idea.

# Makefile
SHELL = /tmp/test/wrapper

test: test1 test2

test1:
    $(eval export TARGET=$@)
    env

test2:
    $(eval export TARGET=$@)
    env

and this:

#!/usr/bin/env bash
# wrapper
bash $@ | sed -e "s/^/${TARGET} /"
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!