views:

312

answers:

5

Is there a way that I can make

$ make

default to:

$ make -j 8

?

Thanks!

+7  A: 

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

aaa
wait .. how does this not recursively call makei.e.make ->make -j 8 ->make -j 8 -j 8 ->make -j 8 -j 8 -j 8
anon
The alias changes the make command to default 'make -j 8' It does not call the make command.
Gazler
This can also be placed in the .bashrc file so you don't have to enter it into each shell, .bashrc is in your home directory (in Debian at least).
Grundlefleck
+5  A: 

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

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

Gazler
A: 

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

Hope this helps, Best regards, Tom.

tommieb75
+2  A: 

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

Matthew Slattery
+5  A: 

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.

Eric Postpischil