From 88b595974744cad79fa4bc2492a796c6037eea49 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Sun, 11 Apr 1999 13:02:43 +0000 Subject: [PATCH] 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. --- ChangeLog | 21 ++++++++++++ Makefile.am | 2 +- Makefile.in | 6 ++-- TODO | 7 ++++ automake.in | 75 +++++++++++++++++++++++++++++++----------- compile | 82 ++++++++++++++++++++++++++++++++++++++++++++++ lib/am/Makefile.am | 2 +- lib/compile | 82 ++++++++++++++++++++++++++++++++++++++++++++++ m4/Makefile.am | 4 +-- m4/Makefile.in | 4 +-- m4/minuso.m4 | 15 +++++++++ 11 files changed, 271 insertions(+), 29 deletions(-) create mode 100755 compile create mode 100755 lib/compile create mode 100644 m4/minuso.m4 diff --git a/ChangeLog b/ChangeLog index 37ad6fc6b..5cfa983ec 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,26 @@ 1999-04-11 Tom Tromey + 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. diff --git a/Makefile.am b/Makefile.am index a74b7d889..0a7a901e2 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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/Makefile.in b/Makefile.in index f48afe586..fb3077ce7 100644 --- a/Makefile.in +++ b/Makefile.in @@ -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 55ddd1302..febdb9aa5 100644 --- 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 diff --git a/automake.in b/automake.in index d48370bbf..83661c157 100755 --- a/automake.in +++ b/automake.in @@ -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 index 000000000..7da75ce41 --- /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 . +# +# 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 diff --git a/lib/am/Makefile.am b/lib/am/Makefile.am index a74b7d889..0a7a901e2 100644 --- a/lib/am/Makefile.am +++ b/lib/am/Makefile.am @@ -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 index 000000000..7da75ce41 --- /dev/null +++ b/lib/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 . +# +# 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 diff --git a/m4/Makefile.am b/m4/Makefile.am index a30310dce..050c75a93 100644 --- a/m4/Makefile.am +++ b/m4/Makefile.am @@ -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) diff --git a/m4/Makefile.in b/m4/Makefile.in index 437ba4f93..ec3355020 100644 --- a/m4/Makefile.in +++ b/m4/Makefile.in @@ -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 index 000000000..a28db55c9 --- /dev/null +++ b/m4/minuso.m4 @@ -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 +]) -- 2.47.2