Make “make” default to “make -j 8”

前端 未结 8 1075
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-28 20:00

Is there a way that I can make

$ make

default to:

$ make -j 8

?

相关标签:
8条回答
  • 2020-12-28 20:09

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

    0 讨论(0)
  • 2020-12-28 20:10

    Add

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

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

    If that doesn't work, add

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

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

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

    0 讨论(0)
  • 2020-12-28 20:14

    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).

    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.

    0 讨论(0)
  • 2020-12-28 20:19

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

         SUBDIRS = foo bar baz
         .PHONY: subdirs $(SUBDIRS)
         subdirs: $(SUBDIRS)
         $(SUBDIRS):
                 $(MAKE) -j 8 -C $@
    
         foo: baz
    
    0 讨论(0)
  • 2020-12-28 20:21

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

    However, I would recommend against doing that!

    By all means, use an alias to save typing - but call it something other than 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.

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

    0 讨论(0)
  • 2020-12-28 20:24

    You could move /usr/bin/make to /usr/bin/make_orig and make /usr/bin/make this script:

    #!/bin/sh
    
    /usr/bin/make_orig -j 8 $@
    

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

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

    0 讨论(0)
提交回复
热议问题