0

Solved I need to spawn background processes in MakeFile and also consider their exit codes. Scenario:

  • several processes are spawned in background.
  • MakeFile continue evaluation (and do not want to check spawned processes PIDs in some loop an so forth)
  • Some process exits with non zero exit code
  • make utility exits with non zero exit code

Naturally, I am consider to use command & to spawn a process in background.

Problem: If command is specified like command & then make process does not track it's exit code.

Sample 1

do:
        @false & \
        echo "all is normal"


%make -f exit_status_test.mk
all is normal

Sample 2

do:
        @false && \
        echo "all is normal"


%make -f exit_status_test.mk
*** Error code 1

Stop in /usr/home/scher/tmp/lock_testing.

Sample 1 shows that make utility does not consider exit code of the background process.

P.S. Please do not advice to store spawned processes PIDs and to check them in a loop with some sleep delay and so forth. A need to continue evaluation of MakeFile and exit with non zero code automatically.

Solution

do:
        @(echo "background command" ; (echo "[HANDLER] Prev command exits with $$?")) & \
        echo "doing something"

So we can create a sequence of commands to handle exit status of background process.

scherka
  • 81
  • 1
  • 10

1 Answers1

0

This seems like an ill-conceived attempt to create a Makefile that can run multiple jobs in parallel, when in fact make can generally do this for you.

All you need to do is give each job a separate command in make:

target: job1 job2

job1:
    some_command

job2:
    some_other_command

If you use something like this in your Makefile and then run make -j2 target, then both some_command and some_other_command will be run in parallel.

See if you can find a way to get make to run your work in parallel like this.

Michael Slade
  • 13,802
  • 2
  • 39
  • 44
  • I assume is not appropriate for MakeFile I am working with since it is bsd.port.mk from The FreeBSD Ports Collection. All manuals state to be as accurate as possible with -j options, and to write you make file compatible with this option. – scherka May 16 '12 at 22:14