help-make
[Top][All Lists]
Advanced

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

Re: parallel make issue with archive members


From: John Doe
Subject: Re: parallel make issue with archive members
Date: Thu, 8 Mar 2007 09:12:08 -0600

Sure here is a makefile:
DEST = /tmp/dest

VPATH = $(DEST)

ARCHIVE = libfoo.a

.PHONY: all
all: libfoo.a

.cc.o :
    $(CXX) $(CXX_FLAGS) $(INCLUDES) -c -o $(DEST)/$@ $<

$(ARCHIVE) : $(CXX_OBJS)
    cd $(DEST); \
    $(AR) $(ARFLAGS) $(ARCHIVE) $?;
Here is a simple example:

1. Copy this Makefile
<Makefile begin>
DEST = /tmp/dest

VPATH = $(DEST)

ARCHIVE = libfoo.a

.PHONY: all
all: libfoo.a

.cc.o :
    $(CXX) $(CXX_FLAGS) $(INCLUDES) -c -o $(DEST)/$@ $<

$(ARCHIVE) : $(CXX_OBJS)
    cd $(DEST); \
    $(AR) $(ARFLAGS) $(ARCHIVE) $?;
<Makefile end>

2. Create a directory and put some empty files in it along with the Makefile:
mkdir makeprob
cd makeprob
touch foo1.cc
touch foo2.cc
touch foo3.cc
touch foo4.cc

3. Create destination dir
mkdir /tmp/dest

4. Do a make -j2 and it works fine:
> make -j2
g++   -c -o /tmp/dest/foo1.o foo1.cc
g++   -c -o /tmp/dest/foo2.o foo2.cc
g++   -c -o /tmp/dest/foo3.o foo3.cc
g++   -c -o /tmp/dest/foo4.o foo4.cc
cd /tmp/dest; \
        ar rv libfoo.a foo1.o foo2.o foo3.o foo4.o;
ar: creating libfoo.a
a - foo1.o
a - foo2.o
a - foo3.o
a - foo4.o

5. touch all the .cc files and do another make -j2 and it does not work without doing a second make:
> touch *cc
> make -j2
g++   -c -o /tmp/dest/foo1.o foo1.cc
g++   -c -o /tmp/dest/foo2.o foo2.cc
g++   -c -o /tmp/dest/foo3.o foo3.cc
g++   -c -o /tmp/dest/foo4.o foo4.cc
cd /tmp/dest; \
        ar rv libfoo.a ;
> make -j2
cd /tmp/dest; \
        ar rv libfoo.a /tmp/dest/foo1.o /tmp/dest/foo2.o /tmp/dest/foo3.o /tmp/dest/foo4.o;
r - /tmp/dest/foo1.o
r - /tmp/dest/foo2.o
r - /tmp/dest/foo3.o
r - /tmp/dest/foo4.o


6. Do the same procedure with single threaded make and it works fine:
> touch *.cc
> make
g++   -c -o /tmp/dest/foo1.o foo1.cc
g++   -c -o /tmp/dest/foo2.o foo2.cc
g++   -c -o /tmp/dest/foo3.o foo3.cc
g++   -c -o /tmp/dest/foo4.o foo4.cc
cd /tmp/dest; \
        ar rv libfoo.a foo1.o foo2.o foo3.o foo4.o;
r - foo1.o
r - foo2.o
r - foo3.o
r - foo4.o

It is my suspicion this has something to do with vpath and parallel make.  Please let me know if you are able to reproduce this.  This was not an issue before I started using VPATH and a destination directory outside of the source area.  My temporary fix is to change the $? in the archive rule to $(CXX_OBJS).  This is make 3.81 and I am able to reproduce it on both a 32 bit and a 64 bit gentoo system.

Thanks,
Juan

On 3/8/07, Paul Smith < address@hidden> wrote:
On Thu, 2007-03-08 at 01:03 -0600, John Doe wrote:
> I am using make 3.81 and I am using the following make rule to put
> object files into an archive:
>
> $(ARCHIVE) : $(CXX_OBJS)
>     echo $?; \
>     cd $(DEST); \
>     $(AR) $(ARFLAGS) $(ARCHIVE) $?
>
> where archive is a ".a" file and CXX_OBJS are my ".o" files.
>
> If I am doing make, the echo and the the ar command will get the
> complete list of .o files which have changed and update the archive.
>
>
> If I do a parallel make (-j2) the list of files is empty.
>
> What am I doing wrong to getting the list of changed files to update
> the archives in parallel mode?

Offhand I can't think of any reason why this might be happening.  Can
you create a small test case to show the problem?

--
-------------------------------------------------------------------------------
Paul D. Smith <address@hidden>          Find some GNU make tips at:
http://www.gnu.org                      http://make.paulandlesley.org
"Please remain calm...I may be mad, but I am a professional." --Mad Scientist


reply via email to

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