bug-make
[Top][All Lists]
Advanced

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

GNU make problem and its fix


From: xingxue
Subject: GNU make problem and its fix
Date: Thu, 19 Dec 2002 16:56:58 -0500

Hi Paul,

I noticed a problem in GNU make version 3.80.  The problem
exists in earlier versions as well.

The problem can be reproduced with the following test cases
and steps.  You may need to repeat a couple times to be able to
reproduce it depending on the load of the machine.

/home/xxue/gnumake> cat makefile
all: libmy.a

libmy.a:
        make -f makefile.1
        make -f makefile.2
/home/xxue/gnumake> cat makefile.1
all: libmy.a

libmy.a:  a.o b.o
        /usr/bin/ar rv libmy.a a.o b.o
        rm a.o b.o
/home/xxue/gnumake> cat makefile.2
all: libmy.a

libmy.a:  c.o d.o
        /usr/bin/ar rv libmy.a c.o d.o
        rm c.o d.o
/home/xxue/gnumake> make
make -f makefile.1
make[1]: Entering directory `/home/xxue/gnumake'
cc    -c -o a.o a.c
cc    -c -o b.o b.c
/usr/bin/ar rv libmy.a a.o b.o
a - a.o
a - b.o
rm a.o b.o
make[1]: Leaving directory `/home/xxue/gnumake'
make -f makefile.2
make[1]: Entering directory `/home/xxue/gnumake'
make[1]: Nothing to be done for `all'.
make[1]: Leaving directory `/home/xxue/gnumake'
/home/xxue/gnumake>

Please notice that commands "ar" and "rm" for rule "libmy.a:  c.o d.o"
of makefile.2 were not executed.

With the "-d" option specified for makefile.1 and makefile.2,
the output has the following:
....
   Prerequisite `c.o' is newer than target `libmy.a'.
   Prerequisite `d.o' is newer than target `libmy.a'.
  No need to remake target `libmy.a'.
....

Seems the problem is that sometimes the time stamp of libmy.a resulted
from the previous makefile.1 is exactly the same as the time stamps of
c.o and d.o.  Therefore, the GNU make thinks "No need to remake target
libmy.a."  As a result, these actions were not taken.

Looking into file remake.c of GNU make version 3.80, whether to remake
the target is based on the comparison of timestamps.  The debug info is
based on the fact that initially those .o files did not exist and their
time stamps were set to NONEXISTENT_MTIME.  After they were built, they
have real time stamps and are marked as 'changed'.  This flag is used for
the debug info, but not for deciding whether to remake the target.

I have a tentative fix for this problem and it seems to work:

/home/xxue/gnumake> diff remake.c ../make-3.80/remake.c
598d597
<       deps_changed |= d->changed;
652,656d650
<   else if (!must_make && file->cmds != 0 && deps_changed)
<     {
<       must_make = 1;
<       DBF (DB_VERBOSE, _("Making `%s' due to prerequisites changed.\n"));
<     }
/home/xxue/make-3.80>

Thanks,
Xing Xue
XLF Compiler Development / IBM Software Solutions Toronto Lab.
Tie Line: 969-3972  Phone: 905-413-3972 Email: address@hidden




reply via email to

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