imitate "make -j" from within the Makefile

Camille Goudeseune

The shell command make -j runs a Makefile's commands in parallel, which is useful on modern multicore CPUs. Can such parallelism be invoked from within a Makefile?

From the manual for Gnu make, my best guess is using the main Makefile as only a wrapper, which passes -j to a sub-make that does the real work. But maybe there's some environment variable or dot file or internal variable or other ungooglable snoopy-swearing way to do this.

It's ok to limit the number of jobs, e.g,. -j $$(nproc).

Probably Linux, but not necessarily.

(Adding something like alias make='make -j' to ~/.bashrc is too dangerous; the decision about whether to parallelize should be per Makefile, not per user.)

harrymc

You can append to MAKEFLAGS from within the makefile itself, for example:

MAKEFLAGS += --jobs=$(CPUS)

Where CPUS is defined in the makefile.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Git commit from within a Makefile

From Dev

Can't access files from within makefile

From Dev

Hard linking within makefile

From Dev

Hard linking within makefile

From Dev

"make -j 4: command not found" when invoking make from a script

From Dev

Makefile: how to detect changes within the makefile itself?

From Dev

How to imitate Python 3's raise ... from in Python 2?

From Dev

Does Bash imitate Locale-Specific Translation from C?

From Dev

GNU Make - Set MAKEFILE variable from shell command output within a rule/target

From Dev

Makefile: Run other makefile from makefile

From Dev

Using PETSc on makefile within my user-defined makefile

From Dev

Makefile variable referencing within a nested loop

From Dev

Where to add the -lm flag within a makefile?

From Dev

saving PID of spawned process within a Makefile

From Dev

Import multiple libraries in makefile within Javac command

From Dev

Using "$**" to direct file input within a Makefile

From Dev

Put command result in variable within makefile target

From Dev

C++ Linking to .so file within makefile

From Dev

Modifying the "priorities" between include directories within a Makefile

From Dev

Adding comment within a function in kernel makefile

From Dev

How to imitate Break feature(Alt-B) from teraterm in mobaxterm.

From Dev

Removing dependencies from a Makefile

From Dev

Overwrite variable from makefile

From Dev

Control output from makefile

From Dev

From Makefile to Cmake

From Dev

Imitate ActionBar menu with ImageButton

From Dev

Imitate multiple inheritance

From Dev

Imitate unix shell pipe

From Dev

Imitate Matlab Matrix behavior