[Top][All Lists]

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

[bug-libunistring] Improve parallel build.

From: Ralf Wildenhues
Subject: [bug-libunistring] Improve parallel build.
Date: Sat, 2 May 2009 08:30:14 +0200
User-agent: Mutt/1.5.18 (2008-05-17)

Hi Bruno, all,

in conjunction with the previous patch to exported.sh.in, this one
allows to take full advantage of parallel make, i.e., also while
building the intermediate objects that are used to generate config.h.

The missing dependency of config.h upon exported.sh is a bug that should
be fixed even if you decide to otherwise drop this patch.

Timings on a two-way system:
[sec]           before  after the patch
serial          86      84
parallel        63      53

Improvements are of course more pronounced on bigger systems.

Another nice side effect of this patch is that it is more visible what
is going on.  (This will be even more visible when used in combination
with Automake-1.10c's silent-rules option.)

The patch has the slight drawback that, in case config.h is out of date,
  make -n

will cause the object files to still be deleted.  This is due to the
fact that GNU make will execute rules containing the string '$(MAKE)'
even when in dry-run mode; there are two possibilities to avoid this
(not using '$(MAKE)' would prevent the desirable parallelism from
working correctly):

- parse $MAKEFLAGS inside the rule, which is a bit tricky,
- split the rule into several shell commands, and let the one with
  the recursive make invocation only do the recursion, but no other
  file changes.  This would require more duplication of code.

(I can write a patch if you like).

Note that, due to the fact that libgettextpo does not use the Automake
subdir-objects option, and due to the fact that it shares objects with
other products in the gettext tree, the patch for gettext needs to be a
bit different from this one (it can't exploit the .c.$(OBJEXT) inference
rule).  The srcdirstrip scriptlet comes from Automake.

On another note, if it were not for the gl_LTLIBOBJS then it would be
possible to
- have another, uninstalled library containing all objects with to-be-
  renamed symbols, created with per-target CPPFLAGS like
  -Dgenerate_symbols (which causes all object names to be distinct),
- have config.h #include another header if generate_symbols is not
  defined, and put all the renames in that other header,
and then even full dependency tracking could work, in the sense that an
update to a source file would trigger rebuilding of the helper object,
the helper library, the header, and then the real object and library
only, without rebuilding any other objects.  I don't know how to
reliably solve this with gl_LTLIBOBJS though.


2009-05-02  Ralf Wildenhues  <address@hidden>

        Improve parallel build.
        * lib/Makefile.am (config.h): Depend on exported.sh.
        Build intermediate objects using a parallelizable sub-make

diff --git a/lib/Makefile.am b/lib/Makefile.am
index 199be73..a7672d6 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -192,7 +192,7 @@ endif
 # libunistring_la_LIBADD from the global namespace, by prefixing them with
 # "libunistring_".
 all check install: config.h
-config.h: $(BUILT_SOURCES) libunistring.sym
+config.h: $(BUILT_SOURCES) libunistring.sym exported.sh
        { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
          : "Avoid double inclusion, to avoid a warning about redefinitions."; \
          echo '#ifndef UNISTRING_CONFIG_H'; \
@@ -203,21 +203,22 @@ config.h: $(BUILT_SOURCES) libunistring.sym
          echo '#endif /* UNISTRING_CONFIG_H */'; \
        } > config.h && \
        if test -n "$(HAVE_GLOBAL_SYMBOL_PIPE)"; then \
-         { \
+         srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'`; \
+         objects=` \
            for f in $(libunistring_la_SOURCES) $(libunistring_la_LIBADD); do \
              case $$f in \
                *.res.lo ) ;; \
                *.c | *.$(OBJEXT) | *.lo ) \
-                 sf=`echo "$$f" | sed -e 's,\\.[^.]*$$,,'`.c; \
-                 test -f $$sf || sf=$(srcdir)/$$sf; \
-                 of=`echo "$$f" | sed -e 's,^.*/,,' -e 
's,\\.[^.]*$$,,'`.$(OBJEXT); \
-                 $(COMPILE) -c $$sf || { rm -f config.h; exit 1; }; \
-                 sh ./exported.sh $$of 1>&5; \
-                 rm -f $$of `echo "$$of" | sed -e 's,\\.$(OBJEXT)$$,.lo,'`; \
-                 ;; \
+                 echo "$$f" ;; \
              esac; \
-           done; \
-         } 5>&1 \
+           done \
+             | sed -e "s|$$srcdirstrip/||" -e 's,\\.[^.]*$$,.$(OBJEXT),'`; \
+         ltobjects=`echo "$$objects" | sed -e 's,\\.$(OBJEXT)$$,.lo,'`; \
+         allobjects="$$objects $$ltobjects"; \
+## Force 'make' to rebuild objects that may have been produced with an older 
full config.h.
+         rm -f $$allobjects; \
+         $(MAKE) $(AM_MAKEFLAGS) $$objects || { rm -f config.h; exit 1; }; \
+         sh ./exported.sh $$objects \
            | sed -e 's,.* ,,' | LC_ALL=C sort | LC_ALL=C uniq \
            | { \
                if test -f libunistring.sym; then \
@@ -228,6 +229,7 @@ config.h: $(BUILT_SOURCES) libunistring.sym
                LC_ALL=C join -v 1 - $$symfile; \
              } \
            | sed -e 's,^\(.*\)$$,#define \1 libunistring_\1,' > config.h-t && \
+         rm -f $$allobjects; \
          if test -f config.h; then \
            cat config.h-t >> config.h; \
            rm -f config.h-t; \

reply via email to

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