Fast compilation flags

Hi all,

I recently searched for a way to speedup make — if you change some header-file it may causes a complete recompilation of the whole source code and it is annoying to wait, if you just changed small stuff or try around etc…

I didn’t found something here regarding this issue, so I want to share what I did:

make can operate parallel if you call it via: make --jobs=XX where X is how many parallel tasks will run. Depending on your CPU cores you can try 2-8 or even more - it will speedup a lot!

In some cases it can result in problems due to the parallel execution of tasks, but for me it run fine - even on building Rack sources.

I added this small peace to my makefile:

ifdef ARCH_MAC
	CPUS ?= $(shell sysctl -n hw.ncpu || echo 1)
    MAKEFLAGS += --jobs=$(CPUS)
else
	MAKEFLAGS += --jobs=2
endif

It retrieves the number of CPU cores and automatically set’s a useful number of parallel jobs. Quick and dirty just for Mac, you may change it for your needs or just play around with that.

Cheers, Patrick

1 Like

This is in the Rack manual. https://vcvrack.com/manual/Building#building-rack I usually just add

alias m='make -j$(nproc)'

to my .bashrc or whatever shell I’m using along with my other alphabet aliases.

Oh sorry, just searched the form and github, missed that part of the Rack doc… :wink: Shell aliases are ok, but not tracked in the project sources, so adding it to the make file seems more clean to me. Otherwise an alias is global, so you can use it quick on all makes :slight_smile:

It’s certainly doesn’t belong in your project’s Makefile. There are many good reasons for users to have control over the number of Make jobs they use and your override kills that. It belongs in your local environment, such as .bashrc.

1 Like

Ok, when I am thinking about that fact you’re right, it really does not belong to the makefile… thanks