bash 使“make”默认为“make -j 8”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2151605/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 21:36:02  来源:igfitidea点击:

Make "make" default to "make -j 8"

makefilealiasbash

提问by anon

Is there a way that I can make

有没有办法让我

$ make

default to:

默认为:

$ make -j 8

?

?

采纳答案by Anycorn

alias make="make -j 8", assuming bash shell

alias make="make -j 8", 假设 bash shell

回答by Eric Postpischil

Set the environment variable MAKEFLAGS to -j 8. If you are using csh or tcsh, you can do this with setenv MAKEFLAGS '-j 8'. If you are using bash, you can do this with export MAKEFLAGS='-j 8'. You might wish to put this command in your shell's start-up file, such as .cshrc or .bashrc (in your home directory).

将环境变量 MAKEFLAGS 设置为-j 8. 如果您使用的是 csh 或 tcsh,则可以使用setenv MAKEFLAGS '-j 8'. 如果您使用的是 bash,则可以使用export MAKEFLAGS='-j 8'. 您可能希望将此命令放在 shell 的启动文件中,例如 .cshrc 或 .bashrc(在您的主目录中)。

Caution: Setting a default like this will apply to all invocations of make, including when you "make" a project other than your own or run a script that invokes make. If the project was not well designed, it might have problems when it is built with multiple jobs executing in parallel.

注意:设置这样的默认值将适用于所有 make 调用,包括当您“制作”一个不同于您自己的项目或运行调用 make 的脚本时。如果项目设计得不好,则在构建多个作业并行执行时可能会出现问题。

回答by Matthew Slattery

The answers suggesting alias make='make -j 8'are fine responses to your question.

建议的答案alias make='make -j 8'很好地回答了您的问题。

However, I would recommend against doing that!

但是,我建议不要这样做!

By all means, use an alias to save typing - but call it something other than make.

无论如何,使用别名来节省输入——但将它命名为make.

It might be OK for whatever project you're currently working on; but it's quite possible to write makefiles with missing dependencies which do not quite work properly with -j, and if you encounter such a thing, you'll be left wondering why the build fails in a mysterious way for you but works fine for other people.

对于您目前正在从事的任何项目,这都可能没问题;但是很可能会编写缺少依赖项的 makefile,这些依赖项不能很好地与-j.

(That said, if you doalias make, you can get bash to ignore the alias by typing \make.)

(也就是说,如果您执行alias make,则可以通过键入 bash 来忽略别名\make。)

回答by Gazler

If you are using the command line you can do:

如果您使用命令行,您可以执行以下操作:

alias make='make -j 8'

This will be temporary, to make it permanent you need to add it to .bashrc

这将是暂时的,要使其永久化,您需要将其添加到 .bashrc

Read here: http://www.linfo.org/make_alias_permanent.html

在这里阅读:http: //www.linfo.org/make_alias_permanent.html

回答by Geremia

Add

添加

MAKEOPTS='-j8'
MAKEFLAGS='-j8'

to /etc/make.conf(create it if it doesn't already exist).

to /etc/make.conf(如果它不存在则创建它)。

If that doesn't work, add

如果这不起作用,请添加

export MAKEOPTS='-j8'
export MAKEFLAGS='-j8'

to your system-wide profile (e.g., /etc/profile).

到您的系统范围的配置文件(例如,/etc/profile)。

For me, MAKEOPTS alone didn't work. Possibly MAKEFLAGS is all that's needed.

对我来说,仅靠 MAKEOPTS 是行不通的。可能只需要 MAKEFLAGS 即可。

回答by Tom Saleeba

If you're using GNU make:

如果您使用 GNU make:

$ make --version
GNU Make 4.2.1
Built for x86_64-alpine-linux-musl

...then I found that GNUMAKEFLAGSseems to work:

...然后我发现这GNUMAKEFLAGS似乎有效:

export GNUMAKEFLAGS=-j8
make

Disclaimer, I'm a n00b with the C toolchain so sorry if this isn't portable. It's working on Alpine Linux 3.8 (in Docker) though.

免责声明,我是使用 C 工具链的 n00b,如果它不可移植,我很抱歉。不过,它正在 Alpine Linux 3.8(在 Docker 中)上运行。

回答by t0mm13b

Why not create an outer makefile, that calls another makefile like this, this is replicated from the manual here.

为什么不创建一个外部 makefile,它会像这样调用另一个 makefile,这是从此处的手册中复制的。

     SUBDIRS = foo bar baz
     .PHONY: subdirs $(SUBDIRS)
     subdirs: $(SUBDIRS)
     $(SUBDIRS):
             $(MAKE) -j 8 -C $@

     foo: baz

回答by Geremia

You could move /usr/bin/maketo /usr/bin/make_origand make /usr/bin/makethis script:

你可以移动/usr/bin/make/usr/bin/make_orig并制作/usr/bin/make这个脚本:

#!/bin/sh

/usr/bin/make_orig -j 8 $@

Be sure to run chmod +x /usr/bin/make.

一定要运行chmod +x /usr/bin/make

Try this method if the simpler method in my other answerdoesn't work. This method isn't as safe and is a bit of a kludge.

如果我的其他答案中更简单的方法不起作用,请尝试此方法。这种方法并不安全,而且有点麻烦。