[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: gmake keeps going when it shouldn't?

From: David Boyce
Subject: Re: gmake keeps going when it shouldn't?
Date: Thu, 13 Aug 2009 11:22:29 -0400

On Thu, Aug 13, 2009 at 4:55 AM, Stephen
O'Loughlin<address@hidden> wrote:
> Say I have a makefile with the following...
> file4.txt: file3.txt
>        xterm -e "sleep 4 ; touch file4.txt"
> file1.txt:
>        xterm -e "sleep 4 ; touch file1.txt"
> file2.txt: file1.txt
>        xterm -e "sleep 4 ; touch file2.txt"
> file3.txt: file2.txt
>        xterm -e "sleep 4 ; touch file3.txt"
> This makefile creates four files file[1-4].txt by launching an xterm,
> waiting for 4 seconds, and then touching the appropriate file.  Now if
> I close one of the xterms during the waiting period, the touch command
> doesn't get executed and the file isn't created, so you'd expect that
> make would stop.  However it doesn't stop and keeps building the
> remaining targets.  So if for example I killed the xterm that was
> supposed to build file2.txt.  I would end up with file1.txt, file3.txt
> and file4.txt, which isn't what I would expect or what I want.
> Any ideas?

Make takes no responsibility for ensuring that the makefile keeps its
promises. In other words, if the makefile says "Here's the recipe for
building file XYZ", make will execute that recipe when XYZ is needed.
But it does NOT check that XYZ was actually created; it checks only
the exit status. So if the command finishes with an exit(0), make is
happy and goes on.

When you exit the xterm the return status will normally be 0, so make
will figure it did what it said it would do. I suspect, without having
tried it, that if you typed "exit 2" to a shell prompt in the xterm
then things would go as you expect.

You might consider rewriting the rules like

file2.txt: file1.txt
        xterm -e "sleep 4 ; touch $@" && test -r $@

or there are probably a number of other workarounds depending on what
your makefile really needs to do, assuming this one is just a test
sample. However, the real problem is that the command you're modeling
here with "xterm -e" is not telling the truth; it sets out to make
file XYZ and reports success without having done so.

David Boyce

reply via email to

[Prev in Thread] Current Thread [Next in Thread]