This patch supercedes my earlier built sources patch.
This version provides:
* automated per target built sources detection (using suffix rules)
* hook based per target built source generation.
* NEW patsubst style variable substition
* NEW the ability for users to add to the list of dep files
(USER_DEP_FILES). This is handy for people with suffix rules that
can generate dependency information.
If you are interested in my TAO IDL suffix rules that use these
features I will make them available.
Note that CORBA is only one possible use of these extensions, and
would expect them also to be of use to those using embedded SQL, Qt
etc.
Please try it out. If it doesn't break normal automake usage I'd like
to have this considered for CVS.
NB It was hard to add new files cleanly to Makefile.am as they are all
listed on one line :)
The patch applies cleanly to current cvs with patch -p1
diff -u --unidirectional-new-file automake/.cvsignore automake-anvil/.cvsignore
--- automake/.cvsignore Thu Sep 24 00:54:55 1998
+++ automake-anvil/.cvsignore Wed Jun 21 14:45:49 2000
@@ -1 +1,2 @@
automake.info*
+Makefile.in
Common subdirectories: automake/CVS and automake-anvil/CVS
diff -u --unidirectional-new-file automake/ChangeLog automake-anvil/ChangeLog
--- automake/ChangeLog Mon Jun 19 23:30:34 2000
+++ automake-anvil/ChangeLog Wed Jun 21 16:12:52 2000
@@ -1,3 +1,38 @@
+2000-06-21 Alex Hornby <[EMAIL PROTECTED]>
+
+ * automake.in (handle_source_transform): Added support for per
+ target built source detection using suffix rules. This allows
+ projects with built sources to build with make -j without prior
+ dependency computation.
+ (read_am_file) : Improved suffix rule matching to find rules not
+ split on period. This uses match_suffixes_to_rule to do the actual
+ work.
+ (match_suffixes_to_rule): new function
+ (%reverse_suffix_rules): new global, holds object to source
+ mappings
+ (longest_suffix): new function, finds longest suffix rule matching
+ a source file.
+ (previous_suffix): new function, finds suffix of file that
+ generated this one, if any.
+ (value_to_list): added support for patsubst style variable
+ substitution.
+ (handle_dependencies): added support for USER_DEP_FILES, so that
+ user suffix rules can have their auto generated dependencies
+ considered.
+
+ * depcomp: added extra sed clause to strip of inclusion depth
+ numbers generated by cpp
+
+ * library-hook.am : new file, used to generate a target with per
+ target built sources
+
+ * ltlibrary-hook.am: likewise
+
+ * program-hook.am: likewise
+
+ * Makefile.am: added library-hook.am ltlibrary-hook.am
+ program-hook.am
+
2000-06-19 Paolo Bonzini <[EMAIL PROTECTED]>
* texi-vers.am: define UPDATED-MONTH variable (for an example, see
diff -u --unidirectional-new-file automake/Makefile.am automake-anvil/Makefile.am
--- automake/Makefile.am Mon Nov 22 19:22:02 1999
+++ automake-anvil/Makefile.am Tue Jun 20 10:58:01 2000
@@ -13,9 +13,11 @@
amfiles = clean-hdr.am clean-kr.am clean.am comp-vars.am compile.am \
data-clean.am data.am dejagnu.am depend.am depend2.am dist.am \
dist-vars.am footer.am header-vars.am header.am java-clean.am java.am \
-kr-extra.am library.am libs-clean.am libs.am libtool.am lisp-clean.am \
-lisp.am ltlib-clean.am ltlib.am ltlibrary.am mans-vars.am mans.am \
-multilib.am program.am progs-clean.am progs.am python.am \
+kr-extra.am library.am library-hook.am libs-clean.am libs.am libtool.am \
+lisp-clean.am \
+lisp.am ltlib-clean.am ltlib.am ltlibrary.am ltlibrary-hook.am \
+mans-vars.am mans.am \
+multilib.am program.am program-hook.am progs-clean.am progs.am python.am \
python-clean.am remake-hdr.am remake.am scripts.am subdirs.am \
tags-clean.am tags.am texi-vers.am texinfos.am
diff -u --unidirectional-new-file automake/Makefile.in automake-anvil/Makefile.in
--- automake/Makefile.in Wed Feb 2 04:29:02 2000
+++ automake-anvil/Makefile.in Tue Jun 20 11:00:36 2000
@@ -1,6 +1,6 @@
# Makefile.in generated automatically by automake 1.4a from Makefile.am
-# Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc.
+# Copyright (C) 1994, 1995-9, 2000 Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
@@ -31,8 +31,6 @@
includedir = @includedir@
oldincludedir = /usr/include
-DESTDIR =
-
pkgdatadir = $(datadir)/@PACKAGE@
pkglibdir = $(libdir)/@PACKAGE@
pkgincludedir = $(includedir)/@PACKAGE@
@@ -80,9 +78,11 @@
amfiles = clean-hdr.am clean-kr.am clean.am comp-vars.am compile.am \
data-clean.am data.am dejagnu.am depend.am depend2.am dist.am \
dist-vars.am footer.am header-vars.am header.am java-clean.am java.am \
-kr-extra.am library.am libs-clean.am libs.am libtool.am lisp-clean.am \
-lisp.am ltlib-clean.am ltlib.am ltlibrary.am mans-vars.am mans.am \
-multilib.am program.am progs-clean.am progs.am python.am \
+kr-extra.am library.am library-hook.am libs-clean.am libs.am libtool.am \
+lisp-clean.am \
+lisp.am ltlib-clean.am ltlib.am ltlibrary.am ltlibrary-hook.am \
+mans-vars.am mans.am \
+multilib.am program.am program-hook.am progs-clean.am progs.am python.am \
python-clean.am remake-hdr.am remake.am scripts.am subdirs.am \
tags-clean.am tags.am texi-vers.am texinfos.am
@@ -135,7 +135,7 @@
$(srcdir)/Makefile.in: Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4)
cd $(top_srcdir) && $(AUTOMAKE) --gnits Makefile
-Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status $(BUILT_SOURCES)
+Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
cd $(top_builddir) \
&& CONFIG_FILES=$@ CONFIG_HEADERS= $(SHELL) ./config.status
@@ -292,7 +292,6 @@
d=$(srcdir); \
for file in `CDPATH=: && cd $$d && eval echo $$base*`; do \
test -f $(distdir)/$$file \
- || ln $$d/$$file $(distdir)/$$file 2> /dev/null \
|| cp -p $$d/$$file $(distdir)/$$file; \
done; \
done
@@ -414,7 +413,7 @@
done | \
$(AWK) ' { files[$$0] = 1; } \
END { for (i in files) print i; }'`; \
- mkid -f$$here/ID $$unique $(LISP)
+ mkid -fID $$unique $(LISP)
TAGS: tags-recursive $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
$(TAGS_FILES) $(LISP)
@@ -503,11 +502,12 @@
@for file in $(DISTFILES); do \
d=$(srcdir); \
if test -d $$d/$$file; then \
- cp -pR $$d/$$file $(distdir); \
+ cp -pR $$d/$$file $(distdir) \
+ || exit 1; \
else \
test -f $(distdir)/$$file \
- || ln $$d/$$file $(distdir)/$$file 2> /dev/null \
- || cp -p $$d/$$file $(distdir)/$$file || :; \
+ || cp -p $$d/$$file $(distdir)/$$file \
+ || exit 1; \
fi; \
done
for subdir in $(SUBDIRS); do \
diff -u --unidirectional-new-file automake/automake.in automake-anvil/automake.in
--- automake/automake.in Fri May 12 01:02:29 2000
+++ automake-anvil/automake.in Wed Jun 21 13:18:35 2000
@@ -1477,6 +1477,22 @@
$linker = $temp if $linker eq '';
&define_pretty_variable ($xpfx . $one_file . "_OBJECTS", '', @result)
unless $prefix =~ /EXTRA_/;
+
+ local ($bs, @builtsources);
+ foreach $bs ( @files )
+ {
+ local ($sf) = longest_suffix($bs);
+ if ( $sf ne '' && previous_suffix($sf) ne $sf )
+ {
+ print "$bs identified as a built source\n" if $verbose;
+ push @builtsources, $bs;
+ }
+ }
+ if ( scalar @builtsources != 0)
+ {
+ &define_pretty_variable ( $one_file . "_BUILTSOURCES", '',
+ @builtsources);
+ }
}
local (@keys) = sort keys %used_pfx;
@@ -1794,13 +1810,20 @@
$xexe = 's/\@EXEEXT\@//g;';
}
+ local $template = '';
+ if ( &variable_defined ($xname . '_BUILTSOURCES' ) ) {
+ $template = 'program-hook';
+ } else {
+ $template = 'program';
+ }
+
$output_rules .=
&file_contents_with_transform
('s/\@PROGRAM\@/' . $one_file . '/go;'
. 's/\@XPROGRAM\@/' . $xname . '/go;'
. 's/\@XLINK\@/' . $xlink . '/go;'
. $xexe,
- 'program');
+ $template);
}
if (&variable_defined ('LDADD') && &handle_lib_objects ('', 'LDADD', 0))
@@ -1905,11 +1928,18 @@
&handle_source_transform ($xlib, $onelib, $obj);
+ local $template = '';
+ if ( &variable_defined ($xlib . '_BUILTSOURCES' ) ) {
+ $template = 'library-hook';
+ } else {
+ $template = 'library';
+ }
+
$output_rules .=
&file_contents_with_transform ('s/\@LIBRARY\@/' . $onelib . '/go;'
. 's/\@XLIBRARY\@/'
. $xlib . '/go;',
- 'library');
+ $template);
}
if ($seen_libobjs)
@@ -2057,7 +2087,13 @@
$rpath = ('s/\@RPATH\@/-rpath \$(' . $instdirs{$onelib}
. 'dir)/go;');
}
-
+
+ local $template = '';
+ if ( &variable_defined ($xlib . '_BUILTSOURCES' ) ) {
+ $template = 'ltlibrary-hook';
+ } else {
+ $template = 'ltlibrary';
+ }
$output_rules .=
&file_contents_with_transform ('s/\@LTLIBRARY\@/'
. $onelib . '/go;'
@@ -2065,7 +2101,7 @@
. $xlib . '/go;'
. $rpath
. 's/\@XLINK\@/' . $xlink . '/go;',
- 'ltlibrary');
+ $template);
}
if ($seen_libobjs)
@@ -3033,6 +3069,11 @@
local ($iter);
local (@deplist) = sort keys %dep_files;
+ # Allow the user to add dependency files if they wish
+ if ( &variable_defined('USER_DEP_FILES') )
+ {
+ push @deplist, &variable_value_as_list ('USER_DEP_FILES', '');
+ }
&define_pretty_variable ('DEP_FILES', '', ("\@AMDEP\@", @deplist));
# Generate each `include' individually. Irix 6 make will
@@ -5316,6 +5357,80 @@
}
}
+# Finds longest initial suffix, then longest trailing for that intial
+sub match_suffixes_to_rule
+{
+ local ($rule) = @_;
+ local @result = ();
+
+ local $s = '';
+ local @sufbylen = ();
+
+ # Gather all know suffixes
+ if ( variable_defined("SUFFIXES") )
+ {
+ @sufbylen = sort { length($b)<=>length($a) }
+ ( @suffixes, &variable_value_as_list ('SUFFIXES', '') );
+ }
+ else
+ {
+ @sufbylen = sort { length($b)<=>length($a) }( @suffixes);
+ }
+
+ # Match longest source suffix
+ foreach $s ( @sufbylen )
+ {
+ if ( $rule =~ m/^$s/ )
+ {
+ $result[0] = $s;
+ last;
+ }
+ }
+ # Match longest target suffix
+ foreach $s ( @sufbylen )
+ {
+ if ( $rule =~ m/${result[0]}${s}$/ )
+ {
+ $result[1] = $s;
+ last;
+ }
+ }
+
+ return @result;
+}
+
+# This function takes a source file name and return the longest suffix that
+# matches
+sub longest_suffix
+{
+ local ($filename) = @_;
+ local ($longest_suffix) = '';
+ local ($suf);
+ foreach $suf ( keys %reverse_suffix_rules )
+ {
+ if ( length($suf) > length($longest_suffix) &&
+ $filename =~ m/${suf}$/ )
+ {
+ $longest_suffix = $suf;
+ }
+ }
+ return $longest_suffix;
+}
+
+# This function gives the suffix this suffix was generated from
+# In the case of normal static source files, it will always return
+# the same as the input
+sub previous_suffix
+{
+ local ($source_ext) = @_;
+ while ( defined $reverse_suffix_rules{$source_ext})
+ {
+ $source_ext = $reverse_suffix_rules{$source_ext};
+ }
+ return $source_ext;
+}
+
+
# This function is used to find a path from a user-specified suffix to
# `o' or to some other suffix we recognize internally, eg `cc'.
sub derive_suffix
@@ -5856,16 +5971,31 @@
{
$varname = $1;
$to = $3;
- ($from = $2) =~ s/(\W)/\\$1/g;
+ ($from = $2) =~ s/(\W)/$1/g;
+ print STDERR "from=$from to=$to\n";
}
# Find the value.
@temp_list = &variable_value_as_list_worker ($1, $cond, $var);
# Now rewrite the value if appropriate.
- if ($from)
+ if ($from =~ '^([^%]*)%([^%]*)')
+ {
+ # patsubst style substitution
+ local ($prefrom, $suffrom, $preto, $sufto);
+ $prefrom = $1;
+ $suffrom = $2;
+ if ( $to =~ '^([^%]*)%([^%]*)')
+ {
+ $preto = $1;
+ $sufto = $2;
+ }
+ grep (s/$prefrom$_$suffrom$/$preto$_$sufto/, @temp_list);
+ }
+ elsif ($from)
{
- grep (s/$from$/$to/, @temp_list);
+ # standard substitution reference style
+ grep (s/$from$/$to/, @temp_list);
}
push (@result, @temp_list);
@@ -6242,14 +6372,16 @@
# Check the rule for being a suffix rule. If so, store in
# a hash.
- local ($source_suffix);
- local ($object_suffix);
-
- if (($source_suffix, $object_suffix) = ($1 =~ $SUFFIX_RULE_PATTERN))
- {
- $suffix_rules{$source_suffix} = $object_suffix;
- print "Sources ending in .$source_suffix become .$object_suffix\n" if
$verbose;
- $source_suffix_pattern = "(" . join ('|', keys %suffix_rules) . ")";
+ local ($source_suffix) = '';
+ local ($object_suffix) = '';
+
+ ($source_suffix, $object_suffix) = match_suffixes_to_rule($1);
+ if ($source_suffix ne '' && $object_suffix ne '')
+ {
+ $suffix_rules{$source_suffix} = $object_suffix;
+ $reverse_suffix_rules{$object_suffix} = $source_suffix;
+ print "Sources ending in $source_suffix become $object_suffix\n" if
+$verbose;
+ $source_suffix_pattern = "(" . join ('|', keys %suffix_rules) . ")";
}
# FIXME: make sure both suffixes are in SUFFIXES? Or set
@@ -6842,6 +6974,9 @@
# corresponding output extension.
%suffix_rules = ();
+ # Reverse mapping of suffix rules. Used for detecting built sources
+ %reverse_suffix_rules = ();
+
# This is a regular expression which matches all the known source
# suffix. A source suffix is one that appears in the first
# position of a suffix rule.
@@ -6974,7 +7109,7 @@
}
}
- close (FC_FILE);
+ close (FC_FILE);
return $result_vars . $result_rules . $comment;
}
diff -u --unidirectional-new-file automake/depcomp automake-anvil/depcomp
--- automake/depcomp Sat Jun 3 00:27:02 2000
+++ automake-anvil/depcomp Wed Jun 21 13:50:49 2000
@@ -249,7 +249,7 @@
done
;;
esac
- "$@" -E |
+ "$@" -E | sed -e 's/ [0-9 ]*$//' |
sed -n '/^# [0-9][0-9]* "\([^"]*\)"/ s::'"$object"'\: \1:p' > "$tmpdepfile"
) &
proc=$!
diff -u --unidirectional-new-file automake/library-hook.am
automake-anvil/library-hook.am
--- automake/library-hook.am Thu Jan 1 01:00:00 1970
+++ automake-anvil/library-hook.am Wed Jun 21 11:01:50 2000
@@ -0,0 +1,26 @@
+## automake - create Makefile.in from Makefile.am
+## Copyright (C) 1994, 1995, 1996, 1999 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., 59 Temple Place - Suite 330, Boston, MA
+## 02111-1307, USA.
+
+@XLIBRARY@-objects-hook: $(@XLIBRARY@_OBJECTS)
+
+@LIBRARY@: $(@XLIBRARY@_DEPENDENCIES) $(@XLIBRARY@_BUILTSOURCES) $(@XLIBRARY@_SOURCES)
+## Build the dependencies
+ $(MAKE) @XLIBRARY@-objects-hook
+ -rm -f @LIBRARY@
+ $(@XLIBRARY@_AR) @LIBRARY@ $(@XLIBRARY@_OBJECTS) $(@XLIBRARY@_LIBADD)
+ $(RANLIB) @LIBRARY@
diff -u --unidirectional-new-file automake/ltlibrary-hook.am
automake-anvil/ltlibrary-hook.am
--- automake/ltlibrary-hook.am Thu Jan 1 01:00:00 1970
+++ automake-anvil/ltlibrary-hook.am Wed Jun 21 11:02:34 2000
@@ -0,0 +1,24 @@
+## automake - create Makefile.in from Makefile.am
+## Copyright (C) 1994, 1995, 1996 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., 59 Temple Place - Suite 330, Boston, MA
+## 02111-1307, USA.
+
+@XLTLIBRARY@-objects-hook: $(@XLTLIBRARY@_OBJECTS)
+
+@LTLIBRARY@: $(@XLTLIBRARY@_DEPENDENCIES) $(@XLTLIBRARY@_BUILTSOURCES)
+$(@XLTLIBRARY@_SOURCES)
+## Build the dependencies
+ $(MAKE) @XLTLIBRARY@-objects-hook
+ $(@XLINK@) @RPATH@ $(@XLTLIBRARY@_LDFLAGS) $(@XLTLIBRARY@_OBJECTS)
+$(@XLTLIBRARY@_LIBADD) $(LIBS)
Common subdirectories: automake/m4 and automake-anvil/m4
diff -u --unidirectional-new-file automake/program-hook.am
automake-anvil/program-hook.am
--- automake/program-hook.am Thu Jan 1 01:00:00 1970
+++ automake-anvil/program-hook.am Wed Jun 21 10:59:18 2000
@@ -0,0 +1,30 @@
+## automake - create Makefile.in from Makefile.am
+## Copyright (C) 1994, 1995, 1996, 1997 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., 59 Temple Place - Suite 330, Boston, MA
+## 02111-1307, USA.
+
+@XPROGRAM@-objects-hook: $(@XPROGRAM@_OBJECTS)
+
+@PROGRAM@@EXEEXT@: $(@XPROGRAM@_DEPENDENCIES) $(@XPROGRAM@_BUILTSOURCES)
+$(@XPROGRAM@_SOURCES)
+## Build the objects
+ $(MAKE) @XPROGRAM@-objects-hook
+## Remove program before linking. Otherwise the link will fail if the
+## program is running somewhere. FIXME: this could be a loss if
+## you're using an incremental linker. Maybe we should think twice?
+## Or maybe not... sadly, incremental linkers are rarer than losing
+## systems.
+ @rm -f @PROGRAM@@EXEEXT@
+ $(@XLINK@) $(@XPROGRAM@_LDFLAGS) $(@XPROGRAM@_OBJECTS) $(@XPROGRAM@_LDADD)
+$(LIBS)
Common subdirectories: automake/tests and automake-anvil/tests