Re: background jobs in makefile

Henrik Carlqvist <[email protected]> Wed, 18 Aug 2010 21:36:30 +0200
Newsgroups gmane.comp.gnu.utils
Organization SunSITE.dk - Supporting Open source
Message-ID <[email protected]>
James <[email protected]> wrote:
> all:
>         for f in xx yy; do\
>                 (make $$f &);\
>         done;\
>         wait
>         @echo [ $@:done ]
> 
> xx yy:
>         sleep 2
>         @echo [ $@:done ]
> 
> 
> How do I put backgroud jobs in makefile?
> "wait" does not seem to work here.

The right way to do it:

Makefile:
-8<-------------------------
all: xx yy

xx yy:
	sleep 2
	@echo [ $@:done ]
-8<-------------------------

Then, at the command prompt type:

make -j 5

The number after -j is the maximum number of simultaneous jobs that make
will spawn. It is also possible (but sometimes dangerous) to not give any
number att all:

make -j

Then make does not limit the number of simultaneous jobs spawned.

regards Henrik
-- 
The address in the header is only to prevent spam. My real address is:
hc123(at)poolhem.se Examples of addresses which go to spammers:
root@localhost postmaster@localhost