automake-patches
[Top][All Lists]
Advanced

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

FYI: check LIBOBJS duplicates on a per-target/library basis


From: Alexandre Duret-Lutz
Subject: FYI: check LIBOBJS duplicates on a per-target/library basis
Date: 17 Sep 2002 22:51:54 +0200
User-agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/20.7

I Assar,

The FSF has received your assignment.  I was about to install
your patch when I realized it was just a workaround to a bug
elsewhere in Automake.

The callers of &check_libobjs_sources (handle_programs,
handle_libraries, handle_ltlibraries) all have some code to make
this call conditionnal: if @LIBOBJS@ isn't used, it shouldn't be
called.  The trouble is that each of these function maintains
the "I must call &check_libobjs_sources"-flag global to all
targets processed.

I'm installing the following patch, that redefines $seen_libobjs
for each target.  Since the change is larger I've also extended
your test case to test _PROGRAMS and _LTLIBRARIES.


BTW, the patch is shown in `diff -b' mode, hence the weird
indentations.  (I've entirely reindented these three functions.)

2002-09-17  Assar Westerlund  <address@hidden>
            Alexandre Duret-Lutz  <address@hidden>

        * automake.in (handle_programs, handle_libraries,
        handle_ltlibraries): Maintain $seen_libobjs on a
        per-program/per-library basis, instead of globally to each
        of these functions.
        * tests/libobj12.test, tests/libobj12b.test: New files.
        * tests/Makefile.am (TESTS): Add libobj12.test and libobj12b.test.

Index: automake.in
===================================================================
RCS file: /cvs/automake/automake/automake.in,v
retrieving revision 1.1352
diff -u -b -r1.1352 automake.in
--- automake.in 17 Sep 2002 18:07:23 -0000      1.1352
+++ automake.in 17 Sep 2002 20:49:11 -0000
@@ -3095,9 +3095,12 @@
                                    'noinst', 'check');
     return if ! @proglist;
 
-    my $seen_libobjs = 0;
+  my $seen_global_libobjs =
+    variable_defined ('LDADD') && &handle_lib_objects ('', 'LDADD');
+
     foreach my $one_file (@proglist)
     {
+      my $seen_libobjs = 0;
        my $obj = &get_object_extension ($one_file);
 
        # Canonicalize names and check for misspellings.
@@ -3110,10 +3113,7 @@
        my $xt = '';
        if (variable_defined ($xname . "_LDADD"))
        {
-           if (&handle_lib_objects ($xname, $xname . '_LDADD'))
-           {
-               $seen_libobjs = 1;
-           }
+         $seen_libobjs = &handle_lib_objects ($xname, $xname . '_LDADD');
            $xt = '_LDADD';
        }
        else
@@ -3125,16 +3125,13 @@
            # generate _DEPENDENCIES when appropriate.
            if (variable_defined ('LDADD'))
            {
-               if (&handle_lib_objects ($xname, 'LDADD'))
-               {
-                   $seen_libobjs = 1;
-               }
+             $seen_libobjs = $seen_global_libobjs;
            }
            elsif (! variable_defined ($xname . '_DEPENDENCIES'))
            {
                &define_variable ($xname . '_DEPENDENCIES', '');
            }
-           $xt = '_SOURCES'
+         $xt = '_SOURCES';
        }
 
        reject_var ($xname . '_LIBADD',
@@ -3172,19 +3169,9 @@
                                          'XLINK'    => $xlink,
                                          'DIRSTAMP' => $dirstamp,
                                          'EXEEXT'   => $extension));
-    }
 
-    if (variable_defined ('LDADD') && &handle_lib_objects ('', 'LDADD'))
-    {
-       $seen_libobjs = 1;
-    }
-
-    if ($seen_libobjs)
+      if ($seen_libobjs || $seen_global_libobjs)
     {
-       foreach my $one_file (@proglist)
-       {
-           my $xname = &canonicalize ($one_file);
-
            if (variable_defined ($xname . '_LDADD'))
            {
                &check_libobjs_sources ($xname, $xname . '_LDADD');
@@ -3214,9 +3201,9 @@
                                 'library used', 'RANLIB')
       if (@prefix);
 
-    my $seen_libobjs = 0;
     foreach my $onelib (@liblist)
     {
+      my $seen_libobjs = 0;
        # Check that the library fits the standard naming convention.
        if (basename ($onelib) !~ /^lib.*\.a/)
          {
@@ -3267,13 +3254,9 @@
                                         ('LIBRARY'  => $onelib,
                                          'XLIBRARY' => $xlib,
                                          'DIRSTAMP' => $dirstamp));
-    }
 
     if ($seen_libobjs)
     {
-       foreach my $onelib (@liblist)
-       {
-           my $xlib = &canonicalize ($onelib);
            if (variable_defined ($xlib . '_LIBADD'))
            {
                &check_libobjs_sources ($xlib, $xlib . '_LIBADD');
@@ -3318,9 +3301,9 @@
          }
       }
 
-    my $seen_libobjs = 0;
     foreach my $onelib (@liblist)
     {
+      my $seen_libobjs = 0;
        my $obj = &get_object_extension ($onelib);
 
        # Canonicalize names and check for misspellings.
@@ -3337,11 +3320,12 @@
        # Check that the library fits the standard naming convention.
        my $libname_rx = "^lib.*\.la";
        if ((variable_defined ($xlib . '_LDFLAGS')
-            && grep (/-module/, &variable_value_as_list_recursive (
-                                       $xlib . '_LDFLAGS', 'all')))
+          && grep (/-module/,
+                   &variable_value_as_list_recursive ($xlib . '_LDFLAGS',
+                                                      'all')))
            || (variable_defined ('LDFLAGS')
-               && grep (/-module/, &variable_value_as_list_recursive (
-                                       'LDFLAGS', 'all'))))
+             && grep (/-module/,
+                      &variable_value_as_list_recursive ('LDFLAGS', 'all'))))
        {
                # Relax name checking for libtool modules.
                $libname_rx = "\.la";
@@ -3414,13 +3398,8 @@
                                          'RPATH'      => $rpath,
                                          'XLINK'      => $xlink,
                                          'DIRSTAMP'   => $dirstamp));
-    }
-
     if ($seen_libobjs)
     {
-       foreach my $onelib (@liblist)
-       {
-           my $xlib = &canonicalize ($onelib);
            if (variable_defined ($xlib . '_LIBADD'))
            {
                &check_libobjs_sources ($xlib, $xlib . '_LIBADD');
Index: tests/Makefile.am
===================================================================
RCS file: /cvs/automake/automake/tests/Makefile.am,v
retrieving revision 1.438
diff -u -b -r1.438 Makefile.am
--- tests/Makefile.am   14 Sep 2002 15:58:41 -0000      1.438
+++ tests/Makefile.am   17 Sep 2002 20:49:20 -0000
@@ -218,6 +218,8 @@
 libobj8.test \
 libobj10.test \
 libobj11.test \
+libobj12.test \
+libobj12b.test \
 library.test \
 library2.test \
 libtool.test \
Index: tests/libobj12.test
===================================================================
RCS file: tests/libobj12.test
diff -N tests/libobj12.test
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ tests/libobj12.test 17 Sep 2002 20:49:22 -0000
@@ -0,0 +1,74 @@
+#! /bin/sh
+# Copyright (C) 2002  Free Software Foundation, Inc.
+#
+# This file is part of GNU Automake.
+#
+# GNU Automake is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# GNU Automake is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with autoconf; see the file COPYING.  If not, write to
+# the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+# Boston, MA 02111-1307, USA.
+
+
+# Test if a file can be mentioned in LIBOBJS and explicitly.
+# (See libobj12b.test for the LTLIBRARIES check.)
+
+. $srcdir/defs || exit 1
+set -e
+
+cat >> configure.in << 'END'
+AC_PROG_CC
+AC_PROG_RANLIB
+AC_LIBOBJ([foo])
+AC_LIBOBJ([bar])
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+noinst_LIBRARIES = libfoo.a libbar.a
+noinst_PROGRAMS = p1 p2
+
+libfoo_a_SOURCES =
+libfoo_a_LIBADD = @LIBOBJS@
+
+libbar_a_SOURCES = foo.c
+
+p1_SOURCES =
+p1_LDADD = @LIBOBJS@
+
+p2_SOURCES = bar.c
+END
+
+: > foo.c
+: > bar.c
+
+$ACLOCAL
+$AUTOMAKE
+
+# This however should be diagnosed, since foo.c and bar.c are in 
@address@hidden
+echo 'libfoo_a_SOURCES += foo.c' >> Makefile.am
+echo 'p1_SOURCES += bar.c' >> Makefile.am
+$AUTOMAKE 2>stderr && exit 1
+cat stderr
+$FGREP foo.c stderr
+$FGREP bar.c stderr
+
+# Global `LDADD' can also come into play.
+cat > Makefile.am << 'END'
+noinst_PROGRAMS = a b
+LDADD = @LIBOBJS@
+END
+$AUTOMAKE
+echo 'a_SOURCES = foo.c' >> Makefile.am
+$AUTOMAKE 2>stderr && exit 1
+cat stderr
+$FGREP foo.c stderr
Index: tests/libobj12b.test
===================================================================
RCS file: tests/libobj12b.test
diff -N tests/libobj12b.test
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ tests/libobj12b.test        17 Sep 2002 20:49:22 -0000
@@ -0,0 +1,54 @@
+#! /bin/sh
+# Copyright (C) 2002  Free Software Foundation, Inc.
+#
+# This file is part of GNU Automake.
+#
+# GNU Automake is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# GNU Automake is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with autoconf; see the file COPYING.  If not, write to
+# the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+# Boston, MA 02111-1307, USA.
+
+
+# Test if a file can be mentioned in LTLIBOBJS and explicitly.
+# (Like libobj12.test, but for Libtool libraries.)
+
+required='libtoolize'
+. $srcdir/defs || exit 1
+set -e
+
+cat >> configure.in << 'END'
+AC_PROG_CC
+AC_PROG_LIBTOOL
+AC_LIBOBJ([foo])
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+noinst_LTLIBRARIES = libfoo.la libbar.la
+
+libfoo_la_SOURCES =
+libfoo_la_LIBADD = @LTLIBOBJS@
+
+libbar_la_SOURCES = foo.c
+END
+
+: > foo.c
+
+$ACLOCAL
+$AUTOMAKE --add-missing
+
+# This however should be diagnosed, since foo.c is in @address@hidden
+echo 'libfoo_la_SOURCES += foo.c' >> Makefile.am
+$AUTOMAKE 2>stderr && exit 1
+cat stderr
+$FGREP foo.c stderr
-- 
Alexandre Duret-Lutz





reply via email to

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