automake-patches
[Top][All Lists]
Advanced

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

Re: Partial linking with _RELOCATABLES - Proposed patch (CVS)


From: Marc Alff
Subject: Re: Partial linking with _RELOCATABLES - Proposed patch (CVS)
Date: Fri, 24 Mar 2006 16:06:51 -0700
User-agent: Thunderbird 1.5 (X11/20051201)


Hi All,
Hi Alexandre

Marc Alff wrote:

Hi Alexandre,

Alexandre Duret-Lutz wrote:
 MA> This is a proposed patch to use partial linking with Automake-1.9.6

Thanks for the proposal, I plan to look at it on saturday. 1.9.6 is a problem since this branch is two-year old.
Not a problem, I will look at the CVS code base and see how the change can be made there.


Here it is (see the attached file)

This proposed patch is based on the content of :
export CVSROOT=":pserver:address@hidden:/cvs/automake"
as of today (2006-03-24)

After applying the match, make sure to :
chmod +x automake/tests/reloc*.test

It took me a while to make it, since :
- CVS automake required CVS autoconf
- CVS autoconf required help2man (I used help2man 1.36)
- help2man required perl gettext (I used perl gettext 1.0.5)
- I required coffee to sort this out.
but I now have a dusted off setup.

The code change for the _RELOCATABLES enhancement in automake itself
is identical for 1.9.6 and CVS-20060324, so there were no surprises.

Test results :
=======================================================
All 582 tests behaved as expected (3 expected failures)
(9 tests were not run)
=======================================================

Thanks for looking at it, and to let me know what you think ...
Marc Alff.


diff -Naur automake/ChangeLog automake-reloc/ChangeLog
--- automake/ChangeLog  2006-03-23 17:43:23.000000000 +0000
+++ automake-reloc/ChangeLog    2006-03-24 20:17:40.000000000 +0000
@@ -1,3 +1,12 @@
+2006-03-24  Marc Alff  <address@hidden>
+
+       * lib/am/reloc.am : New file
+       * lib/am/relocs.am : New file
+       * lib/am/Makefile.am : Adjust.
+       * lib/tests/reloc[1..5].test : New files.
+       * lib/tests/Makefile.am : Adjust.
+       * automake.in (handle_relocatables): implement the new _RELOCATABLES 
primary.
+
 2006-03-23  Stepan Kasal  <address@hidden>
 
        * automake.in (libtool_new_api): Fix a typo in the comment.
diff -Naur automake/automake.in automake-reloc/automake.in
--- automake/automake.in        2006-03-23 17:43:23.000000000 +0000
+++ automake-reloc/automake.in  2006-03-24 20:17:40.000000000 +0000
@@ -1514,6 +1514,32 @@
 }
 
 
+# &append_objext ($MACRO)
+# -----------------------
+# Macro is an Automake magic macro which primary is RELOCATABLES, e.g.
+# noinst_RELOCATABLES.  Make sure these programs have .$(OBJEXT) appended,
+# as well as .o or .obj removed.
+sub append_objext ($)
+{
+  my ($macro) = @_;
+
+  prog_error "append_objext ($macro)"
+    unless $macro =~ /_RELOCATABLES$/;
+
+  transform_variable_recursively
+    ($macro, $macro, 'am__OBJEXT', 0, INTERNAL,
+     sub {
+       my ($subvar, $val, $cond, $full_cond) = @_;
+       # remove .o and .obj
+       $val =~ s/\.o(bj)?$//g;
+       # Append .$(OBJEXT) unless the user did it already, or it's a
+       # @address@hidden
+       $val .= '.$(OBJEXT)' unless $val =~ 
/(?:\.\$\(OBJEXT\)$|address@hidden@]$)/;
+       return $val;
+     });
+}
+
+
 # Check to make sure a source defined in LIBOBJS is not explicitly
 # mentioned.  This is a separate function (as opposed to being inlined
 # in handle_source_transform) because it isn't always appropriate to
@@ -2469,6 +2495,113 @@
 }
 
 
+# handle_relocatables ()
+# -------------------
+# Handle relocatables.
+sub handle_relocatables
+{
+  my @liblist = &am_install_var ('relocs', 'RELOCATABLES',
+                                'noinst', 'check');
+  return if ! @liblist;
+
+  my @prefix = am_primary_prefixes ('RELOCATABLES', 0,
+                                   'noinst', 'check');
+
+  if (@prefix)
+    {
+      my $var = rvar ($prefix[0] . '_RELOCATABLES');
+      $var->requires_variables ('relocatables used', 'LIBTOOL');
+    }
+
+  &define_variable ('LDRFLAGS', '', INTERNAL);
+  &define_variable ('LDR', '$(LIBTOOL) --mode=link $(CC)', INTERNAL);
+
+  foreach my $pair (@liblist)
+    {
+      my ($where, $onelib) = @$pair;
+
+      my $seen_libobjs = 0;
+      # Check that the library fits the standard naming convention.
+      my $bn = basename ($onelib);
+      if ($bn !~ /^.*\.o(bj)?$/)
+       {
+         $bn =~ s/^(?:lib)?(.*?)(?:\.[^.]*)?$/$1.o or $1.obj/;
+         my $suggestion = dirname ($onelib) . "/$bn";
+         $suggestion =~ s|^\./||g;
+         msg ('error-gnu/warn', $where,
+              "`$onelib' is not a standard object name\n"
+              . "did you mean `$suggestion'?")
+       }
+
+      $where->push_context ("while processing relocatable `$onelib'");
+      $where->set (INTERNAL->get);
+
+      my $obj = get_object_extension '.$(OBJEXT)';
+
+      # Canonicalize names and check for misspellings.
+      my $xlib = &check_canonical_spelling ($onelib, '_LIBADD', '_SOURCES',
+                                           '_OBJECTS', '_DEPENDENCIES',
+                                           '_LDR', '_LDRFLAGS');
+
+      if (! var ($xlib . '_LDRFLAGS'))
+       {
+         &define_variable ($xlib . '_LDRFLAGS', '$(LDRFLAGS)', $where);
+       }
+
+      if (! var ($xlib . '_LDR'))
+       {
+         &define_variable ($xlib . '_LDR', '$(LDR)', $where);
+       }
+
+      # Generate support for conditional object inclusion in
+      # libraries.
+      if (var ($xlib . '_LIBADD'))
+       {
+         if (&handle_lib_objects ($xlib, $xlib . '_LIBADD'))
+           {
+             $seen_libobjs = 1;
+           }
+       }
+      else
+       {
+         &define_variable ($xlib . "_LIBADD", '', $where);
+       }
+
+      reject_var ($xlib . '_LDADD',
+                 "use `${xlib}_LIBADD', not `${xlib}_LDADD'");
+
+      # Make sure we at look at this.
+      set_seen ($xlib . '_DEPENDENCIES');
+
+      &handle_source_transform ($xlib, $onelib, $obj, $where,
+                               NONLIBTOOL => 1, LIBTOOL => 0);
+
+      # If the resulting library lies into a subdirectory,
+      # make sure this directory will exist.
+      my $dirstamp = require_build_directory_maybe ($onelib);
+
+      # So far, $onelib was a lazy .o or .obj notation
+      # Change it to the portable .$(OBJEXT) before generating code
+      $onelib =~ s/\.o(bj)?$//g;
+      $onelib .= "\.\$(OBJEXT)";
+
+      $output_rules .= &file_contents ('reloc',
+                                      $where,
+                                      RELOCATABLE  => $onelib,
+                                      XRELOCATABLE => $xlib,
+                                      DIRSTAMP => $dirstamp);
+
+      if ($seen_libobjs)
+       {
+         if (var ($xlib . '_LIBADD'))
+           {
+             &check_libobjs_sources ($xlib, $xlib . '_LIBADD');
+           }
+       }
+    }
+}
+
+
 # handle_libraries ()
 # -------------------
 # Handle libraries.
@@ -6901,6 +7034,10 @@
       # EXEEXT.
       append_exeext { 1 } $one_name
        if $primary eq 'PROGRAMS';
+      # Another blatant hack: we rewrite each _RELOCATABLES primary to include
+      # OBJEXT.
+      append_objext ($one_name)
+       if $primary eq 'RELOCATABLES';
       # "EXTRA" shouldn't be used when generating clean targets,
       # all, or install targets.  We used to warn if EXTRA_FOO was
       # defined uselessly, but this was annoying.
@@ -7432,6 +7569,7 @@
 
   handle_configure ($makefile_am, $makefile_in, $makefile, @inputs);
   handle_gettext;
+  handle_relocatables;
   handle_libraries;
   handle_ltlibraries;
   handle_programs;
diff -Naur automake/lib/am/Makefile.am automake-reloc/lib/am/Makefile.am
--- automake/lib/am/Makefile.am 2005-05-14 20:28:51.000000000 +0000
+++ automake-reloc/lib/am/Makefile.am   2006-03-24 20:17:40.000000000 +0000
@@ -54,6 +54,8 @@
 program.am \
 progs.am \
 python.am \
+reloc.am \
+relocs.am \
 remake-hdr.am \
 scripts.am \
 subdirs.am \
diff -Naur automake/lib/am/reloc.am automake-reloc/lib/am/reloc.am
--- automake/lib/am/reloc.am    1970-01-01 00:00:00.000000000 +0000
+++ automake-reloc/lib/am/reloc.am      2006-03-24 20:17:40.000000000 +0000
@@ -0,0 +1,22 @@
+## automake - create Makefile.in from Makefile.am
+## Copyright (C) 2006 Free Software Foundation, Inc.
+
+## This program 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.
+
+## This program 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 this program; if not, write to the Free Software
+## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+## 02110-1301, USA.
+
+%RELOCATABLE%: $(%XRELOCATABLE%_OBJECTS) $(%XRELOCATABLE%_DEPENDENCIES) 
%DIRSTAMP%
+       -rm -f %RELOCATABLE%
+       $(%XRELOCATABLE%_LDR) $(%XRELOCATABLE%_LDRFLAGS) -o %RELOCATABLE% 
$(%XRELOCATABLE%_OBJECTS) $(%XRELOCATABLE%_LIBADD)
+
diff -Naur automake/lib/am/relocs.am automake-reloc/lib/am/relocs.am
--- automake/lib/am/relocs.am   1970-01-01 00:00:00.000000000 +0000
+++ automake-reloc/lib/am/relocs.am     2006-03-24 20:17:40.000000000 +0000
@@ -0,0 +1,26 @@
+## automake - create Makefile.in from Makefile.am
+## Copyright (C) 2006 Free Software Foundation, Inc.
+
+## This program 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.
+
+## This program 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 this program; if not, write to the Free Software
+## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+## 02110-1301, USA.
+
+## ---------- ##
+## Cleaning.  ##
+## ---------- ##
+
+.PHONY clean-am: clean-%DIR%RELOCATABLES
+clean-%DIR%RELOCATABLES:
+       -test -z "$(%DIR%_RELOCATABLES)" || rm -f $(%DIR%_RELOCATABLES)
+
diff -Naur automake/tests/Makefile.am automake-reloc/tests/Makefile.am
--- automake/tests/Makefile.am  2006-03-23 17:43:23.000000000 +0000
+++ automake-reloc/tests/Makefile.am    2006-03-24 20:17:40.000000000 +0000
@@ -448,6 +448,11 @@
 python12.test \
 recurs.test \
 recurs2.test \
+reloc1.test \
+reloc2.test \
+reloc3.test \
+reloc4.test \
+reloc5.test \
 remake.test \
 remake2.test \
 remake3.test \
diff -Naur automake/tests/reloc1.test automake-reloc/tests/reloc1.test
--- automake/tests/reloc1.test  1970-01-01 00:00:00.000000000 +0000
+++ automake-reloc/tests/reloc1.test    2006-03-24 20:17:40.000000000 +0000
@@ -0,0 +1,41 @@
+#! /bin/sh
+# Copyright (C) 2006  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 Automake; see the file COPYING.  If not, write to
+# the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+# Boston, MA 02110-1301, USA.
+
+# test of _RELOCATABLES functionality : verify that AC_PROG_LIBTOOL is required
+
+. ./defs || exit 1
+
+set -e
+
+cat >>configure.in <<'EOF'
+AC_PROG_CC
+AC_OUTPUT
+EOF
+
+
+cat > Makefile.am << 'EOF'
+noinst_RELOCATABLES = all.o
+EOF
+
+$ACLOCAL
+$AUTOCONF
+AUTOMAKE_fails
+grep "relocatables used but .LIBTOOL. is undefined" stderr
+grep AC_PROG_LIBTOOL stderr
diff -Naur automake/tests/reloc2.test automake-reloc/tests/reloc2.test
--- automake/tests/reloc2.test  1970-01-01 00:00:00.000000000 +0000
+++ automake-reloc/tests/reloc2.test    2006-03-24 20:17:40.000000000 +0000
@@ -0,0 +1,48 @@
+#! /bin/sh
+# Copyright (C) 2006  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 Automake; see the file COPYING.  If not, write to
+# the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+# Boston, MA 02110-1301, USA.
+
+# test of _RELOCATABLES functionality : verify object extention
+
+required='libtool'
+
+. ./defs || exit 1
+
+set -e
+
+cat >>configure.in <<'EOF'
+AC_PROG_CC
+AC_PROG_LIBTOOL
+AC_OUTPUT
+EOF
+
+
+cat > Makefile.am << 'EOF'
+noinst_RELOCATABLES = all.bug
+all_bug_SOURCES = a.c b.c
+EOF
+
+: > ltmain.sh
+
+$ACLOCAL
+$AUTOCONF
+AUTOMAKE_fails --add-missing
+grep ".all\.bug. is not a standard object name" stderr
+grep "did you mean .all\.o or all\.obj." stderr
+
diff -Naur automake/tests/reloc3.test automake-reloc/tests/reloc3.test
--- automake/tests/reloc3.test  1970-01-01 00:00:00.000000000 +0000
+++ automake-reloc/tests/reloc3.test    2006-03-24 20:17:40.000000000 +0000
@@ -0,0 +1,86 @@
+#! /bin/sh
+# Copyright (C) 2006  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 Automake; see the file COPYING.  If not, write to
+# the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+# Boston, MA 02110-1301, USA.
+
+# test of _RELOCATABLES functionality : verify generated makefile
+
+required='libtool'
+
+. ./defs || exit 1
+
+set -e
+
+cat >>configure.in <<'EOF'
+AC_PROG_CC
+AC_PROG_LIBTOOL
+AC_OUTPUT
+EOF
+
+cat > Makefile.am << 'EOF'
+noinst_RELOCATABLES = all1.o all2.obj all3.o all4.obj
+all1_o_SOURCES = a1.c b1.c
+all2_obj_SOURCES = a2.c b2.c
+all3_o_SOURCES = a3.c b3.c
+all3_o_LIBADD = all3.stuff all3-more.stuff
+all4_obj_SOURCES = a4.c b4.c
+all4_obj_LDR = my-own-ldr
+all4_obj_LDRFLAGS = my-own-ldr-flags
+EOF
+
+: > ltmain.sh
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing
+
+## Verify defaults
+
+grep "^LDRFLAGS =$" Makefile.in
+grep "^LDR = \$(LIBTOOL) --mode=link \$(CC)$" Makefile.in
+
+## Verify _SOURCES is detected and used
+
+grep "^all1_o_SOURCES = a1\.c b1\.c" Makefile.in
+grep "^all2_obj_SOURCES = a2\.c b2\.c" Makefile.in
+
+## Verify that dependent objects properly uses $(OBJEXT)
+
+grep "^am_all1_o_OBJECTS = a1.\$(OBJEXT) b1.\$(OBJEXT)" Makefile.in
+grep "^all1_o_OBJECTS = \$(am_all1_o_OBJECTS)" Makefile.in
+
+grep "^am_all2_obj_OBJECTS = a2.\$(OBJEXT) b2.\$(OBJEXT)" Makefile.in
+grep "^all2_obj_OBJECTS = \$(am_all2_obj_OBJECTS)" Makefile.in
+
+## Verify that target objects properly uses $(OBJEXT)
+
+grep "^all1\.\$(OBJEXT): \$(all1_o_OBJECTS) \$(all1_o_DEPENDENCIES)" 
Makefile.in
+grep "^all2\.\$(OBJEXT): \$(all2_obj_OBJECTS) \$(all2_obj_DEPENDENCIES)" 
Makefile.in
+
+## Verify _LDADD is detected and used
+
+grep "^all3_o_DEPENDENCIES = all3\.stuff all3-more\.stuff" Makefile.in
+
+## Verify _LDRFLAGS is detected and used
+
+grep "^all4_obj_LDRFLAGS = my-own-ldr-flags$" Makefile.in
+
+## Verify _LDR is detected and used
+
+grep "^all4_obj_LDR = my-own-ldr$" Makefile.in
+
diff -Naur automake/tests/reloc4.test automake-reloc/tests/reloc4.test
--- automake/tests/reloc4.test  1970-01-01 00:00:00.000000000 +0000
+++ automake-reloc/tests/reloc4.test    2006-03-24 20:17:40.000000000 +0000
@@ -0,0 +1,62 @@
+#! /bin/sh
+# Copyright (C) 2006  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 Automake; see the file COPYING.  If not, write to
+# the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+# Boston, MA 02110-1301, USA.
+
+# test of _RELOCATABLES functionality 
+
+required='libtool'
+
+. ./defs || exit 1
+
+set -e
+
+cat >>configure.in <<'EOF'
+AC_PROG_CXX
+AC_PROG_LIBTOOL
+AC_OUTPUT
+EOF
+
+
+cat > Makefile.am << 'EOF'
+noinst_RELOCATABLES = all.o
+all_o_SOURCES = a.cpp b.cpp
+EOF
+
+libtoolize
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+$AUTOMAKE
+
+cat >a.cpp <<EOF
+void foo(){}
+EOF
+
+cat >b.cpp <<EOF
+void bar(){}
+EOF
+
+./configure --prefix `pwd`
+$MAKE
+test -f all.o || test -f all.obj
+
+$MAKE distcheck
+test -f reloc4-1.0.tar.gz
+
diff -Naur automake/tests/reloc5.test automake-reloc/tests/reloc5.test
--- automake/tests/reloc5.test  1970-01-01 00:00:00.000000000 +0000
+++ automake-reloc/tests/reloc5.test    2006-03-24 20:17:40.000000000 +0000
@@ -0,0 +1,100 @@
+#! /bin/sh
+# Copyright (C) 2006  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 Automake; see the file COPYING.  If not, write to
+# the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+# Boston, MA 02110-1301, USA.
+
+# test of _RELOCATABLES functionality 
+
+required='libtool'
+
+. ./defs || exit 1
+
+set -e
+
+cat >>configure.in <<'EOF'
+AC_PROG_CXX
+AC_PROG_LIBTOOL
+AC_OUTPUT
+EOF
+
+
+cat > Makefile.am << 'EOF'
+noinst_RELOCATABLES = all.o
+all_o_SOURCES = a.cpp b.cpp
+
+noinst_PROGRAMS = proof
+proof_SOURCES = proof.cpp
+proof_LDADD = all.$(OBJEXT)
+
+verify:
+       proof$(EXEEXT)
+EOF
+
+libtoolize
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+$AUTOMAKE
+
+cat >a.cpp <<EOF
+extern int magic ;
+class A {
+   public: A() {
+      magic += 10 ;
+   }
+};
+static A a ;
+EOF
+
+cat >b.cpp <<EOF
+extern int magic ;
+class B {
+   public: B() {
+      magic += 20 ;
+   }
+};
+static B b ;
+EOF
+
+cat >proof.cpp <<EOF
+extern int magic ;
+int magic = 0 ;
+
+int main(int, char*[])
+{
+   if (magic == 0)
+   {
+      return -1 ;
+   }
+
+   if (magic != 30)
+   {
+      return -2 ;
+   }
+
+   // believe it or not, the expected result is 30
+   return 0 ;
+}
+EOF
+
+./configure --prefix `pwd`
+$MAKE
+proof
+
+$MAKE distcheck

reply via email to

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