[DVDnav-discuss] parallel make problem

Dan Nicholson dbn.lists at gmail.com
Sat Aug 30 17:30:48 CEST 2008


On Sat, Aug 30, 2008 at 7:05 AM, Dominik 'Rathann' Mierzejewski
<dominik at greysector.net> wrote:
> I'm experiencing a problem with make -j2:
>
> I've added the following patch to make it easily reproducible:
> Index: Makefile
> ===================================================================
> --- Makefile    (revision 1122)
> +++ Makefile    (working copy)
> @@ -76,6 +76,7 @@
>  # General targets
>
>  $(.OBJDIR):
> +       sleep 2
>        mkdir $(.OBJDIR)
>
>  ${DVDREAD_LIB}: version.h $(.OBJDIR) $(DVDREAD_OBJS) $(BUILDDEPS)
>
>
> $ make clean && make -j2
> rm -rf  *~ obj version.h
> sh "/home/rathann/cvs/dvdnav/libdvdread"/version.sh "/home/rathann/cvs/dvdnav/libdvdread" "4.1.3"
> sleep 2
> cd obj && gcc -fPIC -DPIC -MD -O3  -g -Wall -funsigned-char -I/home/rathann/cvs/dvdnav/libdvdread -I"/home/rathann/cvs/dvdnav/libdvdread"/src -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE -DHAVE_CONFIG_H -DHAVE_DLFCN_H -I"/home/rathann/cvs/dvdnav/libdvdread"/src -c -o dvd_input.so /home/rathann/cvs/dvdnav/libdvdread/src/dvd_input.c
> /bin/sh: line 0: cd: obj: No such file or directory
> make: *** [dvd_input.so] Error 1
> make: *** Waiting for unfinished jobs....
> mkdir obj
>
> Now, I tried this:
> Index: Makefile
> ===================================================================
> --- Makefile    (revision 1122)
> +++ Makefile    (working copy)
> @@ -85,10 +85,10 @@
>  ${DVDREAD_SHLIB}: version.h $(.OBJDIR) $(DVDREAD_SHOBJS) $(BUILDDEPS)
>        cd $(.OBJDIR) && $(CC) $(SHLDFLAGS) $(LDFLAGS) -ldl -Wl,-soname=$(DVDREAD_SHLIB).$(SHLIB_MAJOR) -o $@ $(DVDREAD_SHOBJS)
>
> -.c.so: $(BUILDDEPS)
> +.c.so: $(.OBJDIR) $(BUILDDEPS)
>        cd $(.OBJDIR) && $(CC) -fPIC -DPIC -MD $(CFLAGS) -c -o $@ $<
>
> -.c.o:  $(BUILDDEPS)
> +.c.o:  $(.OBJDIR) $(BUILDDEPS)
>        cd $(.OBJDIR) && $(CC) -MD $(CFLAGS) -c -o $@ $<
>
>
> but it didn't help.
> The only thing I could find to fix this is:
> Index: Makefile
> ===================================================================
> --- Makefile    (revision 1122)
> +++ Makefile    (working copy)
> @@ -168,3 +168,5 @@
>  # include dependency files if they exist
>  $(addprefix ${.OBJDIR}/, ${DEPS}): ;
>  -include $(addprefix ${.OBJDIR}/, ${DEPS})
> +
> +.NOTPARALLEL: $(.OBJDIR)
>
> But I'd rather have a proper fix instead of workarounds.
> Ideas?

You really don't want to have a target dependent on a directory
because make will always think the target is out of date. That
prevents doing the right thing:

$(OBJS) $(DVDREAD_OBJS) $(SHOBJS) $(DVDREAD_SHOBJS): $(.OBJDIR)

I think the only way to handle this race free without polluting make's
timestamp handling is to make the targets explicitly handle the mkdir
on their own and get rid of the target for it (watch out for gmail
wrapping):

diff --git a/Makefile b/Makefile
index cb1340e..ee2df97 100644
--- a/Makefile
+++ b/Makefile
@@ -75,20 +75,19 @@ $(SRCS) $(DVDREAD_SRCS): version.h

 # General targets

-$(.OBJDIR):
-       mkdir $(.OBJDIR)
-
-${DVDREAD_LIB}: version.h $(.OBJDIR) $(DVDREAD_OBJS) $(BUILDDEPS)
+${DVDREAD_LIB}: version.h $(DVDREAD_OBJS) $(BUILDDEPS)
        cd $(.OBJDIR) && $(AR) rc $@ $(DVDREAD_OBJS)
        cd $(.OBJDIR) && $(RANLIB) $@

-${DVDREAD_SHLIB}: version.h $(.OBJDIR) $(DVDREAD_SHOBJS) $(BUILDDEPS)
+${DVDREAD_SHLIB}: version.h $(DVDREAD_SHOBJS) $(BUILDDEPS)
        cd $(.OBJDIR) && $(CC) $(SHLDFLAGS) $(LDFLAGS) -ldl -Wl,-soname=$(DVDREA

 .c.so: $(BUILDDEPS)
+       @[ -d $(.OBJDIR) ] || mkdir -p $(.OBJDIR)
        cd $(.OBJDIR) && $(CC) -fPIC -DPIC -MD $(CFLAGS) -c -o $@ $<

 .c.o:  $(BUILDDEPS)
+       @[ -d $(.OBJDIR) ] || mkdir -p $(.OBJDIR)
        cd $(.OBJDIR) && $(CC) -MD $(CFLAGS) -c -o $@ $<


@@ -133,7 +132,8 @@ distclean: clean
        find . -name "*~" | xargs rm -rf
        rm -rf config.mak

-dvdread-config: $(.OBJDIR)
+dvdread-config:
+       @[ -d $(.OBJDIR) ] || mkdir -p $(.OBJDIR)
        @echo '#!/bin/sh' > $(.OBJDIR)/dvdread-config
        @echo 'prefix='$(PREFIX) >> $(.OBJDIR)/dvdread-config
        @echo 'libdir='$(shlibdir) >> $(.OBJDIR)/dvdread-config

--
Dan



More information about the DVDnav-discuss mailing list