Le vendredi 08 novembre 2013 à 09:06 -0700, Eric Blake a écrit :
> On 11/08/2013 08:31 AM, Benjamin Cama wrote:
> > My goal is to avoid building any library at all when I am only using
> > gnulib for some utils like gitlog-to-changelog or git-version-gen
> > (furthermore when I don't even check for a compiler at all; my project
> > is shell scripting only).
> 
> GNU Autoconf is another such project (all use of gnulib is limited to
> non-code modules); right now it just manually copies files because
> gnulib-tool doesn't quite do the right thing (see the 'make
> gnulib-update' rule encoded into autoconf's cfg.mk).

Thanks for the hint. I looked at the needed files, and appart from
config.guess, config.sub and install-sh (in the havelib-tests module),
which are not really part of gnulib anyway, all the other ones are
included in modules not depending on any compiled code. Maybe Autoconf
would need a separate new module for the aforementioned files.

> > I thought that this was the purpose of this
> > test, but i was mistaken. Is there a way to do what I want? I don't
> > think so. Do you think this would be a worthwhile possibility?
> 
> Absolutely - patches are welcome to make gnulib-tool useful in a
> non-code setting.

What about the following one? My criterion for not building the library
is “no conditional am code and no include nor link directive”. You still
need to pass "--avoid dummy" not to get the library.

I would also advocate a more radical approach not to have a dummy module
at all, but I am not sure it's not needed in all use cases. Furthermore,
its criterion for including the dummy package is even less strict than
mine (no lib_SOURCES augmentation only); should I rather stick to the
same definition? If anyone could explain me the use of a dummy library,
I could have a better idea of what to do.

Regards,
-- 
Benjamin Cama <benjamin.c...@telecom-bretagne.eu>
>From 8ccf6c0c2fa4a56c684a037b2a4bc95bdac06d29 Mon Sep 17 00:00:00 2001
From: Benjamin Cama <benjamin.c...@telecom-bretagne.eu>
Date: Fri, 8 Nov 2013 18:51:41 +0100
Subject: [PATCH] Don't build a library if no code is compiled

You still need to pass "--avoid dummy" not to pull the dummy package.
---
 gnulib-tool |  118 +++++++++++++++++++++++++++++++----------------------------
 1 files changed, 62 insertions(+), 56 deletions(-)

diff --git a/gnulib-tool b/gnulib-tool
index 669931c..fcc41f3 100755
--- a/gnulib-tool
+++ b/gnulib-tool
@@ -3317,6 +3317,10 @@ func_emit_lib_Makefile_am ()
           echo "## end   gnulib module $module"
           echo
         fi
+        # Check if we really need the library, as there might be no compiled code included
+        if ( cat "$tmp"/amsnippet1 ; func_get_include_directive "$module" ; func_get_link_directive "$module" ) | grep '[^	 ]' > /dev/null; then
+          library_needed=yes
+        fi
         rm -f "$tmp"/amsnippet1 "$tmp"/amsnippet2
         # Test whether there are some source files in subdirectories.
         for f in `func_get_filelist "$module"`; do
@@ -3379,67 +3383,69 @@ func_emit_lib_Makefile_am ()
       fi
     fi
   done
-  if test -n "$witness_c_macro"; then
-    cppflags_part1=" -D$witness_c_macro=1"
-  else
-    cppflags_part1=
-  fi
-  if $for_test; then
-    cppflags_part2=" -DGNULIB_STRICT_CHECKING=1"
-  else
-    cppflags_part2=
-  fi
-  if test -z "$makefile_name"; then
+  if test -n "$library_needed"; then
+    if test -n "$witness_c_macro"; then
+      cppflags_part1=" -D$witness_c_macro=1"
+    else
+      cppflags_part1=
+    fi
+    if $for_test; then
+      cppflags_part2=" -DGNULIB_STRICT_CHECKING=1"
+    else
+      cppflags_part2=
+    fi
+    if test -z "$makefile_name"; then
+      echo
+      echo "AM_CPPFLAGS =$cppflags_part1$cppflags_part2"
+      echo "AM_CFLAGS ="
+    else
+      if test -n "$cppflags_part1$cppflags_part2"; then
+        echo
+        echo "AM_CPPFLAGS +=$cppflags_part1$cppflags_part2"
+      fi
+    fi
     echo
-    echo "AM_CPPFLAGS =$cppflags_part1$cppflags_part2"
-    echo "AM_CFLAGS ="
-  else
-    if test -n "$cppflags_part1$cppflags_part2"; then
+    if LC_ALL=C grep "^[a-zA-Z0-9_]*_${perhapsLT}LIBRARIES *+\{0,1\}= *$libname\\.$libext\$" "$tmp"/allsnippets > /dev/null \
+       || { test -n "$makefile_name" \
+            && test -f "$sourcebase/Makefile.am" \
+            && LC_ALL=C grep "^[a-zA-Z0-9_]*_${perhapsLT}LIBRARIES *+\{0,1\}= *$libname\\.$libext\$" "$sourcebase/Makefile.am" > /dev/null; \
+          }; then
+      # One of the snippets or the user's Makefile.am already specifies an
+      # installation location for the library. Don't confuse automake by saying
+      # it should not be installed.
+      :
+    else
+      # By default, the generated library should not be installed.
+      echo "noinst_${perhapsLT}LIBRARIES += $libname.$libext"
+    fi
+    echo
+    echo "${libname}_${libext}_SOURCES ="
+    # Here we use $(LIBOBJS), not @LIBOBJS@. The value is the same. However,
+    # automake during its analysis looks for $(LIBOBJS), not for @LIBOBJS@.
+    echo "${libname}_${libext}_LIBADD = \$(${macro_prefix}_${perhapsLT}LIBOBJS)"
+    echo "${libname}_${libext}_DEPENDENCIES = \$(${macro_prefix}_${perhapsLT}LIBOBJS)"
+    echo "EXTRA_${libname}_${libext}_SOURCES ="
+    if test "$libtool" = true; then
+      echo "${libname}_${libext}_LDFLAGS = \$(AM_LDFLAGS)"
+      echo "${libname}_${libext}_LDFLAGS += -no-undefined"
+      # Synthesize an ${libname}_${libext}_LDFLAGS augmentation by combining
+      # the link dependencies of all modules.
+      for module in $modules; do
+        func_verify_nontests_module
+        if test -n "$module"; then
+          func_get_link_directive "$module"
+        fi
+      done \
+        | LC_ALL=C sed -e '/^$/d' -e 's/ when linking with libtool.*//' \
+        | LC_ALL=C sort -u \
+        | LC_ALL=C sed -e 's/^/'"${libname}_${libext}"'_LDFLAGS += /'
+    fi
+    if test -n "$pobase"; then
       echo
-      echo "AM_CPPFLAGS +=$cppflags_part1$cppflags_part2"
+      echo "AM_CPPFLAGS += -DDEFAULT_TEXT_DOMAIN=\\\"${po_domain}-gnulib\\\""
     fi
   fi
   echo
-  if LC_ALL=C grep "^[a-zA-Z0-9_]*_${perhapsLT}LIBRARIES *+\{0,1\}= *$libname\\.$libext\$" "$tmp"/allsnippets > /dev/null \
-     || { test -n "$makefile_name" \
-          && test -f "$sourcebase/Makefile.am" \
-          && LC_ALL=C grep "^[a-zA-Z0-9_]*_${perhapsLT}LIBRARIES *+\{0,1\}= *$libname\\.$libext\$" "$sourcebase/Makefile.am" > /dev/null; \
-        }; then
-    # One of the snippets or the user's Makefile.am already specifies an
-    # installation location for the library. Don't confuse automake by saying
-    # it should not be installed.
-    :
-  else
-    # By default, the generated library should not be installed.
-    echo "noinst_${perhapsLT}LIBRARIES += $libname.$libext"
-  fi
-  echo
-  echo "${libname}_${libext}_SOURCES ="
-  # Here we use $(LIBOBJS), not @LIBOBJS@. The value is the same. However,
-  # automake during its analysis looks for $(LIBOBJS), not for @LIBOBJS@.
-  echo "${libname}_${libext}_LIBADD = \$(${macro_prefix}_${perhapsLT}LIBOBJS)"
-  echo "${libname}_${libext}_DEPENDENCIES = \$(${macro_prefix}_${perhapsLT}LIBOBJS)"
-  echo "EXTRA_${libname}_${libext}_SOURCES ="
-  if test "$libtool" = true; then
-    echo "${libname}_${libext}_LDFLAGS = \$(AM_LDFLAGS)"
-    echo "${libname}_${libext}_LDFLAGS += -no-undefined"
-    # Synthesize an ${libname}_${libext}_LDFLAGS augmentation by combining
-    # the link dependencies of all modules.
-    for module in $modules; do
-      func_verify_nontests_module
-      if test -n "$module"; then
-        func_get_link_directive "$module"
-      fi
-    done \
-      | LC_ALL=C sed -e '/^$/d' -e 's/ when linking with libtool.*//' \
-      | LC_ALL=C sort -u \
-      | LC_ALL=C sed -e 's/^/'"${libname}_${libext}"'_LDFLAGS += /'
-  fi
-  echo
-  if test -n "$pobase"; then
-    echo "AM_CPPFLAGS += -DDEFAULT_TEXT_DOMAIN=\\\"${po_domain}-gnulib\\\""
-    echo
-  fi
   cat "$tmp"/allsnippets \
     | sed -e 's|\$(top_srcdir)/build-aux/|$(top_srcdir)/'"$auxdir"'/|g'
   echo
-- 
1.7.2.5

Reply via email to