]> git.ipfire.org Git - thirdparty/automake.git/commitdiff
First cut at allowing objects in subdirectories:
authorTom Tromey <tromey@redhat.com>
Sun, 11 Apr 1999 13:02:43 +0000 (13:02 +0000)
committerTom Tromey <tromey@redhat.com>
Sun, 11 Apr 1999 13:02:43 +0000 (13:02 +0000)
* m4/Makefile.am (m4data_DATA): Added minuso.m4.
* Makefile.am (dist_script_DATA): Added compile.
* m4/minuso.m4: New file.
* automake.in (initialize_global_constants): Added compile to
common_files.
(seen_cc_c_o): New global.
(scan_one_configure_file): Set it when AM_PROG_CC_C_O seen.
(handle_options): Recognize `subdir-objects' option.
(lang_c_rewrite): Added directory argument.
(lang_yacc_rewrite): Likewise.
(lang_yaccxx_rewrite): Likewise.
(lang_lex_rewrite): Likewise.
(lang_lexxx_rewrite): Likewise.
(handle_single_transform_list): Pass directory to _rewrite
function.  Generate dependencies for dirstamp files for each .o;
it is just the rules we want to create once.
(lang_c_rewrite): Handle `subdir-objects' option.
(lang_c_rewrite): Require `compile' program.
* compile: New file.

ChangeLog
Makefile.am
Makefile.in
TODO
automake.in
compile [new file with mode: 0755]
lib/am/Makefile.am
lib/compile [new file with mode: 0755]
m4/Makefile.am
m4/Makefile.in
m4/minuso.m4 [new file with mode: 0644]

index 37ad6fc6b903d850072c1c85108b781d0b14feca..5cfa983eceb95ee4f6aea4cd5cef367e5459dc7b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,26 @@
 1999-04-11  Tom Tromey  <tromey@cygnus.com>
 
+       First cut at allowing objects in subdirectories:
+       * m4/Makefile.am (m4data_DATA): Added minuso.m4.
+       * Makefile.am (dist_script_DATA): Added compile.
+       * m4/minuso.m4: New file.
+       * automake.in (initialize_global_constants): Added compile to
+       common_files.
+       (seen_cc_c_o): New global.
+       (scan_one_configure_file): Set it when AM_PROG_CC_C_O seen.
+       (handle_options): Recognize `subdir-objects' option.
+       (lang_c_rewrite): Added directory argument.
+       (lang_yacc_rewrite): Likewise.
+       (lang_yaccxx_rewrite): Likewise.
+       (lang_lex_rewrite): Likewise.
+       (lang_lexxx_rewrite): Likewise.
+       (handle_single_transform_list): Pass directory to _rewrite
+       function.  Generate dependencies for dirstamp files for each .o;
+       it is just the rules we want to create once.
+       (lang_c_rewrite): Handle `subdir-objects' option.
+       (lang_c_rewrite): Require `compile' program.
+       * compile: New file.
+
        * automake.in (initialize_per_input): Initialize %directory_map.
        (handle_single_transform_list): Only create .dirstamp rules once
        per directory.
index a74b7d88993acffa400df98a73d68e7874478ce3..0a7a901e2eec370abba6bdc584c1242c00bf35fb 100644 (file)
@@ -26,7 +26,7 @@ $(amfiles)
 ## what we want.  So we make them executable by hand.
 scriptdir = $(pkgdatadir)
 dist_script_DATA = config.guess config.sub install-sh mdate-sh missing \
-mkinstalldirs elisp-comp ylwrap acinstall
+mkinstalldirs elisp-comp ylwrap acinstall compile
 
 install-data-hook:
        @$(POST_INSTALL)
index f48afe5868b75c04ddea570bbed9aaed020613d3..fb3077ce749e7dc57c5b09c9ae53a97ec6150b04 100644 (file)
@@ -88,7 +88,7 @@ $(amfiles)
 
 scriptdir = $(pkgdatadir)
 dist_script_DATA = config.guess config.sub install-sh mdate-sh missing \
-mkinstalldirs elisp-comp ylwrap acinstall
+mkinstalldirs elisp-comp ylwrap acinstall compile
 
 
 ETAGS_ARGS = $(amfiles)
@@ -457,11 +457,11 @@ distcheck: dist
        echo "$$dashes"
 dist: distdir
        -chmod -R a+r $(distdir)
-       tar ch$(AMTARFLAGS)f - $(distdir) | GZIP=$(GZIP_ENV) gzip -c > $(distdir).tar.gz
+       $(TAR) ch$(AMTARFLAGS)f - $(distdir) | GZIP=$(GZIP_ENV) gzip -c > $(distdir).tar.gz
        -rm -rf $(distdir)
 dist-all: distdir
        -chmod -R a+r $(distdir)
-       tar ch$(AMTARFLAGS)f - $(distdir) | GZIP=$(GZIP_ENV) gzip -c > $(distdir).tar.gz
+       $(TAR) ch$(AMTARFLAGS)f - $(distdir) | GZIP=$(GZIP_ENV) gzip -c > $(distdir).tar.gz
        -rm -rf $(distdir)
 distdir: $(DISTFILES)
        @if sed 15q $(srcdir)/NEWS | fgrep -e "$(VERSION)" > /dev/null; then :; else \
diff --git a/TODO b/TODO
index 55ddd1302fbc630e29f544c8edf36f2ce15f5f06..febdb9aa51c36d2867dee97ccc85c6bbbf3e5d63 100644 (file)
--- a/TODO
+++ b/TODO
@@ -1,3 +1,10 @@
+* Test subdir-objects option with yacc, lex, ansi2knr
+  Test `compile' program
+  Our locking scheme won't prevent a parallel make from losing
+  if there are two `bar.o' files and the timing is just right
+  This only happens with parallel make and no-`-c -o' compiler,
+  so it probably isn't very important
+
 * Run automake before libtool.  It will report an error but
   still won't put the file into the disty.  This is wrong.
   From Mark H Wilkinson <mhw@kremvax.demon.co.uk>
index d48370bbf2bd842cf3e2070cb7b33d0a72c057e6..83661c1579271a95d3d98f016abf88868003d245 100755 (executable)
@@ -224,6 +224,9 @@ $seen_objext = 0;
 # TRUE if we've seen AC_ENABLE_MULTILIB.
 $seen_multilib = 0;
 
+# TRUE if we've seen AM_PROG_CC_C_O
+$seen_cc_c_o = 0;
+
 # Hash table of discovered configure substitutions.  Keys are names,
 # values are `FILE:LINE' strings which are used by error message
 # generation.
@@ -726,7 +729,8 @@ sub handle_options
                   || $_ eq 'dist-shar' || $_ eq 'dist-zip'
                   || $_ eq 'dist-tarZ' || $_ eq 'dist-bzip2'
                   || $_ eq 'dejagnu' || $_ eq 'no-texinfo.tex'
-                  || $_ eq 'readme-alpha' || $_ eq 'check-news')
+                  || $_ eq 'readme-alpha' || $_ eq 'check-news'
+                  || $_ eq 'subdir-objects')
            {
                # Explicitly recognize these.
            }
@@ -1098,8 +1102,7 @@ sub handle_single_transform_list
                # Found the language, so see what it says.
                local ($subr) = 'lang_' . $lang . '_rewrite';
                # Note: computed subr call.
-               # FIXME: should pass directory to this function.
-               local ($r) = & $subr ($base, $extension);
+               local ($r) = & $subr ($directory, $base, $extension);
                # Skip this entry if we were asked not to process it.
                next if $r == $LANG_IGNORE;
 
@@ -1164,26 +1167,37 @@ sub handle_single_transform_list
                # sure the subdir exists at build time.
                if ($object =~ /\//)
                {
+                   # FIXME: check that $DIRECTORY is somewhere in the
+                   # project
+
+                   # We don't allow `..' in object file names for
+                   # *any* source, not just Java.  For Java it just
+                   # doesn't make sense, but in general it is
+                   # a problem because we can't pick a good name for
+                   # the .deps entry.
                    if ($object =~ /(\/|^)\.\.\//)
                    {
                        &am_error ("\`$full' contains \`..' component but should not");
                    }
 
+                   push (@dep_list, $directory . '/.dirstamp');
+
+                   # If we're generating dependencies, we also want
+                   # to make sure that the appropriate subdir of the
+                   # .deps directory is created.
+                   if ($use_dependencies)
+                   {
+                       push (@dep_list, '.deps/' . $directory . '/.dirstamp');
+                   }
+
                    if (! defined $directory_map{$directory})
                    {
                        $directory_map{$directory} = 1;
-
-                       push (@dep_list, $directory . '/.dirstamp');
                        $output_rules .= ($directory . "/.dirstamp:\n"
                                          . "\t\@\$(mkinstalldirs) $directory\n"
                                          . "\t\@: > $directory/.dirstamp\n");
-
-                       # If we're generating dependencies, we also
-                       # want to make sure that the appropriate
-                       # subdir of the .deps directory is created.
                        if ($use_dependencies)
                        {
-                           push (@dep_list, '.deps/' . $directory . '/.dirstamp');
                            $output_rules .= ('.deps/' . $directory
                                              . "/.dirstamp:\n"
                                              . "\t\@\$(mkinstalldirs) .deps/$directory\n"
@@ -4277,6 +4291,9 @@ sub scan_one_configure_file
            $configure_vars{'OBJEXT'} = $filename . ':' . $.;
        }
 
+       # Check for `-c -o' code.
+       $seen_cc_c_o = 1 if /AM_PROG_CC_C_O/;
+
        # Check for NLS support.
        if (/AM_GNU_GETTEXT/)
        {
@@ -4573,7 +4590,7 @@ sub check_gnits_standards
 # Functions to handle files of each language.
 
 # Each `lang_X_rewrite' function follows a simple formula:
-# * Args are the base name and extension of the file.
+# * Args are the directory, base name and extension of the file.
 # * Return value is 1 if file is to be dealt with, 0 otherwise.
 # Much of the actual processing is handled in handle_single_transform_list.
 # These functions exist so that auxiliary information can be recorded
@@ -4584,7 +4601,7 @@ sub check_gnits_standards
 # Rewrite a single C source file.
 sub lang_c_rewrite
 {
-    local ($base, $ext) = @_;
+    local ($directory, $base, $ext) = @_;
 
     if (defined $options{'ansi2knr'} && $base =~ /_$/)
     {
@@ -4592,8 +4609,26 @@ sub lang_c_rewrite
        &am_error ("C source file \`$base.c' would be deleted by ansi2knr rules");
     }
 
+    local ($r) = $LANG_PROCESS;
+    if (defined $options{'subdir-objects'})
+    {
+       $r = $LANG_SUBDIR;
+       $base = $directory . '/' . $base;
+
+       if (! $seen_cc_c_o)
+       {
+           # Only give error once.
+           $seen_cc_c_o = 1;
+           # FIXME: line number.
+           &am_error ("C objects in subdir but \`AM_PROG_CC_C_O' not in \`configure.in'");
+       }
+
+       &require_file ($FOREIGN, 'compile')
+           if $relative_dir eq '.';
+    }
+
     $de_ansi_files{$base} = 1;
-    return $LANG_PROCESS;
+    return $r;
 }
 
 # Rewrite a single C++ source file.
@@ -4612,9 +4647,9 @@ sub lang_header_rewrite
 # Rewrite a single yacc file.
 sub lang_yacc_rewrite
 {
-    local ($base, $ext) = @_;
+    local ($directory, $base, $ext) = @_;
 
-    &lang_c_rewrite ($base, $ext);
+    &lang_c_rewrite ($directory, $base, $ext);
     $yacc_sources{$base . '.' . $ext} = 1;
     $ext =~ tr/y/c/;
     &saw_extension ('c');
@@ -4625,7 +4660,7 @@ sub lang_yacc_rewrite
 # Rewrite a single yacc++ file.
 sub lang_yaccxx_rewrite
 {
-    local ($base, $ext) = @_;
+    local ($directory, $base, $ext) = @_;
 
     $yacc_sources{$base . '.' . $ext} = 1;
     $ext =~ tr/y/c/;
@@ -4637,9 +4672,9 @@ sub lang_yaccxx_rewrite
 # Rewrite a single lex file.
 sub lang_lex_rewrite
 {
-    local ($base, $ext) = @_;
+    local ($directory, $base, $ext) = @_;
 
-    &lang_c_rewrite ($base, $ext);
+    &lang_c_rewrite ($directory, $base, $ext);
     $lex_sources{$base . '.' . $ext} = 1;
     $ext =~ tr/l/c/;
     &saw_extension ('c');
@@ -4650,7 +4685,7 @@ sub lang_lex_rewrite
 # Rewrite a single lex++ file.
 sub lang_lexxx_rewrite
 {
-    local ($base, $ext) = @_;
+    local ($directory, $base, $ext) = @_;
 
     $lex_sources{$base . '.' . $ext} = 1;
     $ext =~ tr/l/c/;
@@ -6474,7 +6509,7 @@ sub initialize_global_constants
         "libversion.in", "mdate-sh", "mkinstalldirs", "install-sh",
         'texinfo.tex', "ansi2knr.c", "ansi2knr.1", 'elisp-comp',
         'ylwrap', 'acinclude.m4', @libtoolize_files,
-        'missing'
+        'missing', 'compile'
         );
 
     # Commonly used files we auto-include, but only sometimes.
diff --git a/compile b/compile
new file mode 100755 (executable)
index 0000000..7da75ce
--- /dev/null
+++ b/compile
@@ -0,0 +1,82 @@
+#! /bin/sh
+
+# Wrapper for compilers which do not understand `-c -o'.
+
+# Copyright (C) 1999 Free Software Foundation, Inc.
+# Written by Tom Tromey <tromey@cygnus.com>.
+#
+# 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.
+
+# Usage:
+# compile PROGRAM [ARGS]...
+# `-o FOO.o' is removed from the args passed to the actual compile.
+
+prog="$1"
+shift
+
+ofile=
+cfile=
+args=
+while test $# -gt 0; do
+   case "$1" in
+    -o)
+       ofile="$2"
+       shift
+       ;;
+    *.c)
+       cfile="$1"
+       args="$args $1"
+       ;;
+    *)
+       args="$args $1"
+       ;;
+   esac
+   shift
+done
+
+test -z "$ofile" && {
+   echo "compile: no \`-o' option seen" 1>&2
+   exit 1
+}
+
+test -z "$cfile" && {
+   echo "compile: no \`.c' file seen" 1>&2
+   exit 1
+}
+
+# Name of file we expect compiler to create.
+cofile="`echo $cfile | sed -e 's|^.*/||' -e 's/\.c$/.o/'`"
+
+# Create the lock directory.
+lockdir="`echo $ofile | sed -e 's|/|_|g'`"
+while true; do
+   if mkdir $lockdir > /dev/null 2>&1; then
+      break
+   fi
+   sleep 1
+done
+# FIXME: race condition here if user kills between mkdir and trap.
+trap "rmdir $lockdir; exit 1" 1 2 15
+
+# Run the compile.
+"$prog" $args
+status=$?
+
+if test -f "$cofile"; then
+   mv "$cofile" "$ofile"
+fi
+
+rmdir $lockdir
+exit $status
index a74b7d88993acffa400df98a73d68e7874478ce3..0a7a901e2eec370abba6bdc584c1242c00bf35fb 100644 (file)
@@ -26,7 +26,7 @@ $(amfiles)
 ## what we want.  So we make them executable by hand.
 scriptdir = $(pkgdatadir)
 dist_script_DATA = config.guess config.sub install-sh mdate-sh missing \
-mkinstalldirs elisp-comp ylwrap acinstall
+mkinstalldirs elisp-comp ylwrap acinstall compile
 
 install-data-hook:
        @$(POST_INSTALL)
diff --git a/lib/compile b/lib/compile
new file mode 100755 (executable)
index 0000000..7da75ce
--- /dev/null
@@ -0,0 +1,82 @@
+#! /bin/sh
+
+# Wrapper for compilers which do not understand `-c -o'.
+
+# Copyright (C) 1999 Free Software Foundation, Inc.
+# Written by Tom Tromey <tromey@cygnus.com>.
+#
+# 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.
+
+# Usage:
+# compile PROGRAM [ARGS]...
+# `-o FOO.o' is removed from the args passed to the actual compile.
+
+prog="$1"
+shift
+
+ofile=
+cfile=
+args=
+while test $# -gt 0; do
+   case "$1" in
+    -o)
+       ofile="$2"
+       shift
+       ;;
+    *.c)
+       cfile="$1"
+       args="$args $1"
+       ;;
+    *)
+       args="$args $1"
+       ;;
+   esac
+   shift
+done
+
+test -z "$ofile" && {
+   echo "compile: no \`-o' option seen" 1>&2
+   exit 1
+}
+
+test -z "$cfile" && {
+   echo "compile: no \`.c' file seen" 1>&2
+   exit 1
+}
+
+# Name of file we expect compiler to create.
+cofile="`echo $cfile | sed -e 's|^.*/||' -e 's/\.c$/.o/'`"
+
+# Create the lock directory.
+lockdir="`echo $ofile | sed -e 's|/|_|g'`"
+while true; do
+   if mkdir $lockdir > /dev/null 2>&1; then
+      break
+   fi
+   sleep 1
+done
+# FIXME: race condition here if user kills between mkdir and trap.
+trap "rmdir $lockdir; exit 1" 1 2 15
+
+# Run the compile.
+"$prog" $args
+status=$?
+
+if test -f "$cofile"; then
+   mv "$cofile" "$ofile"
+fi
+
+rmdir $lockdir
+exit $status
index a30310dce05abe6118b6e9c83d67809d5f35d38c..050c75a934dffaf19a669fa13f57b0d53b323c36 100644 (file)
@@ -5,8 +5,8 @@ MAINT_CHARSET = latin1
 
 m4datadir = $(datadir)/aclocal
 m4data_DATA = ccstdc.m4 cond.m4 dmalloc.m4 error.m4 gcj.m4 header.m4 \
-init.m4 lex.m4 lispdir.m4 maintainer.m4 missing.m4 mktime.m4 multi.m4 \
-obstack.m4 protos.m4 ptrdiff.m4 regex.m4 sanity.m4 strtod.m4 \
+init.m4 lex.m4 lispdir.m4 maintainer.m4 minuso.m4 missing.m4 mktime.m4 \
+multi.m4 obstack.m4 protos.m4 ptrdiff.m4 regex.m4 sanity.m4 strtod.m4 \
 termios.m4 winsz.m4
 
 EXTRA_DIST = $(m4data_DATA)
index 437ba4f93351599369b2d31517864d23b1482059..ec335502023b398ede8eb6fc74d749e3da0d4187 100644 (file)
@@ -70,8 +70,8 @@ MAINT_CHARSET = latin1
 
 m4datadir = $(datadir)/aclocal
 m4data_DATA = ccstdc.m4 cond.m4 dmalloc.m4 error.m4 gcj.m4 header.m4 \
-init.m4 lex.m4 lispdir.m4 maintainer.m4 missing.m4 mktime.m4 multi.m4 \
-obstack.m4 protos.m4 ptrdiff.m4 regex.m4 sanity.m4 strtod.m4 \
+init.m4 lex.m4 lispdir.m4 maintainer.m4 minuso.m4 missing.m4 mktime.m4 \
+multi.m4 obstack.m4 protos.m4 ptrdiff.m4 regex.m4 sanity.m4 strtod.m4 \
 termios.m4 winsz.m4
 
 
diff --git a/m4/minuso.m4 b/m4/minuso.m4
new file mode 100644 (file)
index 0000000..a28db55
--- /dev/null
@@ -0,0 +1,15 @@
+dnl Like AC_PROG_CC_C_O, but changed for automake.
+
+AC_DEFUN([AM_PROG_CC_C_O],[
+AC_REQUIRE([AC_PROG_CC_C_O])
+dnl FIXME: we rely on the cache variable name because
+dnl there is no other way.
+set dummy $CC; ac_cc="`echo [$]2 |
+changequote(, )dnl
+                      sed -e 's/[^a-zA-Z0-9_]/_/g' -e 's/^[0-9]/_/'`"
+changequote([, ])dnl
+if eval "test \"`echo '$ac_cv_prog_cc_'${ac_cc}_c_o`\" != yes"; then
+   # Losing compiler, so override with the script.
+   CC="\$(top_srcdir)/compile $CC"
+fi
+])