[Q] Immediately exiting (with return code zero) from Makefile? - Questions

This is a discussion on [Q] Immediately exiting (with return code zero) from Makefile? - Questions ; Hi, How can I write Makefile so that, if some condition is satisfied, it aborts processing immediately --- with a return code ZERO? ----- The situation is like this: my team is developing a software that has several modules. So, ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: [Q] Immediately exiting (with return code zero) from Makefile?

  1. [Q] Immediately exiting (with return code zero) from Makefile?

    Hi,

    How can I write Makefile so that, if some condition is satisfied,
    it aborts processing immediately --- with a return code ZERO?

    -----
    The situation is like this: my team is developing a software that has
    several modules. So, a Makefile at the root directory compiles each
    module by calling its own Makefile:

    all: (blah blah...)
    @for i in $(SRC_DIRS); do \
    if [ -e $$i/Makefile ]; then \
    cd $$i; make all; \
    cd ..; \
    fi \
    done;

    For some reasons, not everybody sees every module. So, if I don't
    have a copy of module M, then the root Makefile won't call M/Makefile.
    (Instead, the author of module M supplies a compiled library file.)

    However, I have a read-only copy of module M1, whose compilation
    depends on another module M2, which I don't have.

    The net effect is that the root Makefile will invoke M1/Makefile,
    and fails. I'd like to change M1/Makefile so that it quits immediately
    if M2/Makefile does not exist, with return code zero, so that the root
    Makefile continues processing (thinking that everything is OK).

    Simply erasing M1/Makefile (or writing a dummy Makefile) is not an option,
    because the code is shared via CVS. (So, that would make the author of M1
    rather unhappy.)

    Thanks in advance,
    - Yongjik

  2. Re: [Q] Immediately exiting (with return code zero) from Makefile?


    Yongjik> For some reasons, not everybody sees every module. So, if I
    Yongjik> don't have a copy of module M, then the root Makefile won't
    Yongjik> call M/Makefile. (Instead, the author of module M supplies a
    Yongjik> compiled library file.)

    Yongjik> However, I have a read-only copy of module M1, whose
    Yongjik> compilation depends on another module M2, which I don't have.

    Yongjik> The net effect is that the root Makefile will invoke
    Yongjik> M1/Makefile, and fails. I'd like to change M1/Makefile so that
    Yongjik> it quits immediately if M2/Makefile does not exist, with return
    Yongjik> code zero, so that the root Makefile continues processing
    Yongjik> (thinking that everything is OK).

    Yongjik> Simply erasing M1/Makefile (or writing a dummy Makefile) is
    Yongjik> not an option, because the code is shared via CVS. (So, that
    Yongjik> would make the author of M1 rather unhappy.)

    You could write the top rule of M1/Makefile like this:

    all:
    if test -e ../M2/Makefile ; then $(MAKE) m1.a ; fi

    The long answer is to stop using recursive make :-)

    --
    Nothing can be explained to a stone.
    Or to a stoned person, either.

  3. Re: Immediately exiting (with return code zero) from Makefile?

    On 10:49 28 Jan 2004, Ian Zimmerman wrote:
    | You could write the top rule of M1/Makefile like this:
    |
    | all:
    | if test -e ../M2/Makefile ; then $(MAKE) m1.a ; fi

    You might find that fails and you need to rephrase like this:

    all:
    test ! -e ../M2/Makefile || $(MAKE) m1.a

    i.e. success if no M2/makefile or success if $(MAKE) succeeds.
    --
    Cameron Simpson DoD#743
    http://www.cskk.ezoshosting.com/cs/

    Men are not hanged for stealing horses, but that horses may not be stolen.
    - Lord Halifax, Works

+ Reply to Thread