user784756
user784756

Reputation: 2373

GNU Build Multiple Files at Once

I need to use GNU build system to compile many files at once. So far, I've only seen examples on how to compile one file at once. This is my favorite reference:

http://www.scs.stanford.edu/~reddy/links/gnu/tutorial.pdf

It says:

‘Makefile.am’

bin_PROGRAMS = hello

hello_SOURCES = hello.c

‘configure.ac’

AC_INIT([Hello Program],[1.0],

[Author Of The Program <[email protected]>],

[hello])

AC_CONFIG_AUX_DIR(config)

AM_INIT_AUTOMAKE([dist-bzip2])

AC_PROG_CC

AC_PROG_INSTALL

AC_CONFIG_FILES([Makefile])

AC_OUTPUT

But what do I do if I want to make hello.c and hello2.c at the same time?

Upvotes: 2

Views: 686

Answers (3)

themel
themel

Reputation: 8895

If you want to build multiple targets by default in GNU make, you generate a "phony" target, a virtual target that depends on both of your results, e.g:

.PHONY: both
both: hello hello2
hello: hello.o
hello2: hello2.o
hello2.o: hello2.c

This will build both hello and hello2 if you run make or make both.

Reference

For automake, you just need to define both programs:

bin_PROGRAMS = hello hello2

hello_SOURCES = hello.c
hello2_SOURCES = hello2.c

Upvotes: 1

Didier Trosset
Didier Trosset

Reputation: 37477

Even if using automake, it only generates the Makefile for you. You end up using the plain make command.

Add command line option -j when running make. It will instruct it to run as many build commands as it can in parallel. You can also specify the maximum number of concurrent builds yourself with -j 4. (Usual good value is nbrProcessors+1)

Upvotes: 0

Cougar
Cougar

Reputation: 651

Use make -j num to compile num files at the same time. You can omit num and let make compile as much files at the same time as possible. Usually it does not make things faster any more if you compile more files at the same time than you have CPUs/cores in your system. Make sure that all dependencies are listed before using this.

Upvotes: 0

Related Questions