bug-gnulib
[Top][All Lists]
Advanced

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

Re: conditional dependencies between modules


From: Bruno Haible
Subject: Re: conditional dependencies between modules
Date: Sat, 28 May 2011 17:09:23 +0200
User-agent: KMail/1.9.9

Conditional dependencies appear to work fine so far. So here's a patch that
does 3 changes:
  - Remove the label "experimental".
  - Make the setting persistent in gnulib-cache.m4, and add an option
    --no-conditional-dependencies to revoke its effect.
  - Document the options.


2011-05-28  Bruno Haible  <address@hidden>

        Finish the conditional dependencies mechanism.
        * gnulib-tool: New option --no-conditional-dependencies.
        (func_usage): Document it. Don't mark --conditional-dependencies as
        experimental.
        (cond_dependencies): The possible values can now be true, false, empty.
        (func_modules_transitive_closure, func_emit_autoconf_snippets): Update.
        (func_import): Store setting in gnulib-cache.m4 and read it from there.
        * doc/gnulib-tool.texi (Conditional dependencies): New section.

--- doc/gnulib-tool.texi.orig   Sat May 28 17:02:50 2011
+++ doc/gnulib-tool.texi        Sat May 28 16:58:42 2011
@@ -48,6 +48,7 @@
 * Localization::                Handling Gnulib's own message translations.
 * VCS Issues::                  Integration with Version Control Systems.
 * Unit tests::                  Bundling the unit tests of the Gnulib modules.
+* Conditional dependencies::    Avoiding unnecessary checks and compilations.
 @end menu
 
 
@@ -713,3 +714,54 @@
 in the scope of the same @code{configure.ac}, you cannot use
 @samp{--with-tests}.  You will have to use a separate @code{configure.ac}
 in this case.
+
+
address@hidden Conditional dependencies
address@hidden Avoiding unnecessary checks and compilations
+
address@hidden conditional dependencies
+In some cases, a module is needed by another module only on specific
+platforms.  But when a module is present, its autoconf checks are always
+executed, and its @code{Makefile.am} additions are always enabled.  So
+it can happen that some autoconf checks are executed and some source files
+are compiled, although no other module needs them on this particular
+platform, just @emph{in case} some other module would need them.
+
+The option @samp{--conditional-dependencies} enables an optimization of
+configure checks and @code{Makefile.am} snippets that avoids this.  With
+this option, whether a module is considered ``present'' is no longer decided
+when @code{gnulib-tool} is invoked, but later, when @code{configure} is run.
+This applies to modules that were added as dependencies while
address@hidden was run; modules that were passed on the command line
+explicitly are always ``present''.
+
+For example, the @code{timegm} module needs, on platforms
+where the system's @code{timegm} function is missing or buggy, a replacement
+that is based on a function @code{mktime_internal}.  The module
address@hidden that provides this function provides it on all
+platforms.  So, by default, the file @file{mktime-internal.c} will be
+compiled on all platforms --- even on glibc and BSD systems which have a
+working @code{timegm} function.  When the option
address@hidden is given, on the other hand, and if
address@hidden was not explicitly required on the command line,
+the file @file{mktime-internal.c} will only be compiled on the platforms
+where the @code{timegm} needs them.
+
+Conditional dependencies are specified in the module description by putting
+the condition on the same line as the dependent module, enclosed in brackets.
+The condition is a boolean shell expression that can assume that the
address@hidden snippet from the module description has already been
+executed.  In the example above, the dependency from @code{timegm} to
address@hidden is written like this:
+
address@hidden
+Depends-on:
+...
+mktime-internal [test $HAVE_TIMEGM = 0 || test $REPLACE_TIMEGM = 1]
+...
address@hidden smallexample
+
+Note: The option @samp{--conditional-dependencies} cannot be used together
+with the option @samp{--with-tests}.  It also cannot be used when a package
+uses @code{gnulib-tool} for several subdirectories, with different values
+of @samp{--source-base}, in the scope of a single @code{configure.ac} file.
--- gnulib-tool.orig    Sat May 28 17:02:50 2011
+++ gnulib-tool Sat May 28 15:20:28 2011
@@ -224,9 +224,10 @@
                             have code that provides equivalent functionality.
                             This option can be repeated.
       --conditional-dependencies
-                            Support conditional dependencies (experimental,
-                            may save configure time and object code, not
-                            compatible with --with-tests).
+                            Support conditional dependencies (may save 
configure
+                            time and object code).
+      --no-conditional-dependencies
+                            Don't use conditional dependencies.
       --libtool             Use libtool rules.
       --no-libtool          Don't use libtool rules.
 
@@ -916,8 +917,8 @@
 # - excl_unportable_tests  true if --without-unportable-tests was given, blank
 #                          otherwise
 # - avoidlist       list of modules to avoid, from --avoid
-# - cond_dependencies  true if --conditional-dependencies was given, blank
-#                      otherwise
+# - cond_dependencies  true if --conditional-dependencies was given, false if
+#                      --no-conditional-dependencies was given, blank otherwise
 # - lgpl            yes or a number if --lgpl was given, blank otherwise
 # - makefile_name   from --makefile-name
 # - libtool         true if --libtool was given, false if --no-libtool was
@@ -1163,6 +1164,9 @@
       --conditional-dependencies | --conditional-dependencie | 
--conditional-dependenci | --conditional-dependenc | --conditional-dependen | 
--conditional-depende | --conditional-depend | --conditional-depen | 
--conditional-depe | --conditional-dep | --conditional-de | --conditional-d | 
--conditional- | --conditional | --conditiona | --condition | --conditio | 
--conditi | --condit | --condi | --cond | --con)
         cond_dependencies=true
         shift ;;
+      --no-conditional-dependencies | --no-conditional-dependencie | 
--no-conditional-dependenci | --no-conditional-dependenc | 
--no-conditional-dependen | --no-conditional-depende | --no-conditional-depend 
| --no-conditional-depen | --no-conditional-depe | --no-conditional-dep | 
--no-conditional-de | --no-conditional-d | --no-conditional- | --no-conditional 
| --no-conditiona | --no-condition | --no-conditio | --no-conditi | --no-condit 
| --no-condi | --no-cond | --no-con | --no-co)
+        cond_dependencies=false
+        shift ;;
       --lgpl )
         lgpl=yes
         shift ;;
@@ -1308,7 +1312,7 @@
   if test -z "$pobase" && test -n "$po_domain"; then
     func_warning "--po-domain has no effect without a --po-base option"
   fi
-  if test -n "$cond_dependencies" && test -n "$inctests"; then
+  if test "$cond_dependencies" = true && test -n "$inctests"; then
     echo "gnulib-tool: option --conditional-dependencies is not supported with 
--with-tests" 1>&2
     func_exit 1
   fi
@@ -2605,7 +2609,7 @@
   inmodules="$modules"
   outmodules=
   fmtc_inc_all_tests="$inc_all_direct_tests"
-  if test -n "$cond_dependencies"; then
+  if test "$cond_dependencies" = true; then
     for module in $inmodules; do
       func_verify_module
       if test -n "$module"; then
@@ -2623,7 +2627,7 @@
       if test -n "$module"; then
         if func_acceptable $module; then
           func_append outmodules " $module"
-          if test -n "$cond_dependencies"; then
+          if test "$cond_dependencies" = true; then
             if func_get_automake_snippet_conditional $module | grep '^if ' > 
/dev/null; then
               # A module whose Makefile.am snippet contains a reference to an
               # automake conditional. If we were to use it conditionally, we
@@ -2692,7 +2696,7 @@
             done
             if $inc; then
               func_append inmodules " $dep"
-              if test -n "$cond_dependencies"; then
+              if test "$cond_dependencies" = true; then
                 escaped_dep=`echo "$dep" | sed -e "$sed_escape_dependency"`
                 sed_extract_condition1='/^ *'"$escaped_dep"' *$/{
                   s/^.*$/true/p
@@ -3057,14 +3061,14 @@
         if grep '[^     ]' "$tmp"/amsnippet1 "$tmp"/amsnippet2 > /dev/null ; 
then
           echo "## begin gnulib module $module"
           echo
-          if test -n "$cond_dependencies"; then
+          if test "$cond_dependencies" = true; then
             if func_cond_module_p "$module"; then
               func_module_conditional_name "$module"
               echo "if $conditional"
             fi
           fi
           cat "$tmp"/amsnippet1
-          if test -n "$cond_dependencies"; then
+          if test "$cond_dependencies" = true; then
             if func_cond_module_p "$module"; then
               echo "endif"
             fi
@@ -3678,7 +3682,7 @@
   toplevel="$3"
   disable_libtool="$4"
   disable_gettext="$5"
-  if test -n "$cond_dependencies"; then
+  if test "$cond_dependencies" = true; then
     # Emit the autoconf code for the unconditional modules.
     for module in $1; do
       eval $verifier
@@ -3814,8 +3818,8 @@
 #                         otherwise
 # - inc_all_tests   true if --with-all-tests was given, blank otherwise
 # - avoidlist       list of modules to avoid, from --avoid
-# - cond_dependencies  true if conditional dependencies shall be supported,
-#                      blank otherwise
+# - cond_dependencies  true if --conditional-dependencies was given, false if
+#                      --no-conditional-dependencies was given, blank otherwise
 # - lgpl            yes or a number if library's license shall be LGPL,
 #                   blank otherwise
 # - makefile_name   from --makefile-name
@@ -3856,6 +3860,7 @@
   cached_libname=
   cached_lgpl=
   cached_makefile_name=
+  cached_cond_dependencies=
   cached_libtool=
   cached_macro_prefix=
   cached_po_domain=
@@ -3931,6 +3936,9 @@
       /gl_MAKEFILE_NAME(/ {
         s,^.*gl_MAKEFILE_NAME([[ 
]*\([^]"$`\\)]*\).*$,cached_makefile_name="\1",p
       }
+      /gl_CONDITIONAL_DEPENDENCIES/ {
+        s,^.*$,cached_cond_dependencies=true,p
+      }
       /gl_LIBTOOL/ {
         s,^.*$,cached_libtool=true,p
       }
@@ -4106,6 +4114,10 @@
     if test -z "$makefile_name"; then
       makefile_name="$cached_makefile_name"
     fi
+    # Use conditional dependencies if specified either way.
+    if test -z "$cond_dependencies"; then
+      cond_dependencies="$cached_cond_dependencies"
+    fi
     # Use libtool if specified either way, or if guessed.
     if test -z "$libtool"; then
       if test -n "$cached_m4base"; then
@@ -4129,6 +4141,11 @@
     if test -z "$vc_files"; then
       vc_files="$cached_vc_files"
     fi
+    # Ensure constraints.
+    if test "$cond_dependencies" = true && test -n "$inctests"; then
+      echo "gnulib-tool: option --conditional-dependencies is not supported 
with --with-tests" 1>&2
+      func_exit 1
+    fi
   fi
   # --without-*-tests options are not supported here.
   excl_cxx_tests=
@@ -4577,6 +4594,11 @@
   if test -n "$makefile_name"; then
     func_append actioncmd " --makefile-name=$makefile_name"
   fi
+  if test "$cond_dependencies" = true; then
+    func_append actioncmd " --conditional-dependencies"
+  else
+    func_append actioncmd " --no-conditional-dependencies"
+  fi
   if test "$libtool" = true; then
     func_append actioncmd " --libtool"
   else
@@ -4871,6 +4893,9 @@
       fi
     fi
     echo "gl_MAKEFILE_NAME([$makefile_name])"
+    if test "$cond_dependencies" = true; then
+      echo "gl_CONDITIONAL_DEPENDENCIES"
+    fi
     if test "$libtool" = true; then
       echo "gl_LIBTOOL"
     fi
@@ -5268,8 +5293,8 @@
 # - excl_unportable_tests  true if tests that fail on some platforms should be
 #                          excluded, blank otherwise
 # - avoidlist       list of modules to avoid
-# - cond_dependencies  true if conditional dependencies shall be supported,
-#                      blank otherwise
+# - cond_dependencies  true if --conditional-dependencies was given, false if
+#                      --no-conditional-dependencies was given, blank otherwise
 # - libtool         true if --libtool was given, false if --no-libtool was
 #                   given, blank otherwise
 # - symbolic        true if files should be symlinked, copied otherwise

-- 
In memoriam Thomas Ford 
<http://en.wikipedia.org/wiki/Thomas_Ford_(Catholic_martyr)>



reply via email to

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