help-make
[Top][All Lists]
Advanced

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

file unexpectedly removed


From: Perry Hutchison
Subject: file unexpectedly removed
Date: Thu, 12 May 2016 23:50:31 -0700
User-agent: nail 11.25 7/29/05

While looking into something else, I ran into a case where make (3.82)
removes an intermediate target file after building the final target.
I had not expected this, and could not find any mention of such behavior
in the manual -- nor in the list archives -- although it's certainly
possible that I didn't use the right search terms.  Is this in fact
normal, or have I perhaps found a bug?

While small, the case is a bit complicated -- because this came up
while I was attempting to construct a minimal example of a different
(and most likely unrelated) issue.  (I haven't yet gotten that issue
to arise in a simplified case.)

There is a Makefile in the base directory and another Makefile in a
subdirectory which also contains a (small) C program.  These are the
only files involved.  Tabs in the Makefiles are where you expect them
to be :)


$ cat Makefile
all: outfiles

%/bar.c:
#       mkdir -p $(dirname $@)
        $(MAKE) -C subdir

ifeq ($(shell which foo),)
# this section used when build system does not have foo
%/bar: %/bar.c
        @echo using $(CC)
        $(CC) -o $@ $<
else
# this section used when build system has foo
%/bar: %/bar.c
        @echo using foo
        foo $< $@
endif

outfiles: new-subdir/bar

.PHONY: outfiles


$ cat subdir/Makefile
all:
        mkdir -p ../new-subdir
        cp bar.c ../new-subdir
        touch ../new-subdir/bar.c


$ cat subdir/bar.c
#include <stdio.h>
main()
{
        printf("this is bar\n");
}


$ type foo           # there is no "foo" program in $PATH
bash: type: foo: not found


$ make
which: no foo in 
(/home/pch/.local/bin:/home/pch/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin)
make -C subdir
make[1]: Entering directory `/home/pch/cond/subdir'
mkdir -p ../new-subdir
cp bar.c ../new-subdir
touch ../new-subdir/bar.c
make[1]: Leaving directory `/home/pch/cond/subdir'
using cc
cc -o new-subdir/bar new-subdir/bar.c
rm new-subdir/bar.c


The make output is all as expected, until the last line; but that
"rm" sure didn't come from any rule in either of the Makefiles.


Here's the resulting directory structure:

$ ll -R | egrep -v '^total '
.:
-rwxrwxr-x. 1 pch pch  346 May 12 16:33 Makefile
drwxrwxr-x. 2 pch pch   16 May 12 16:38 new-subdir
drwxrwxr-x. 2 pch pch   33 May 12 16:36 subdir

./new-subdir:
-rwxrwxr-x. 1 pch pch 8501 May 12 16:38 bar

./subdir:
-rw-rw-r--. 1 pch pch 80 May 12 16:33 Makefile
-rw-rw-r--. 1 pch pch 56 May 12 15:18 bar.c


This, too, is as expected -- except there's no bar.c in new-subdir
(which is consistent with the "rm new-subdir/bar.c" line at the end
of the make log).

What's going on?



reply via email to

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