From: Tom Tromey Date: Thu, 29 May 1997 06:06:01 +0000 (+0000) Subject: ansi2knr fix from Gord X-Git-Tag: Release-1-2~19 X-Git-Url: https://sourceware.org/git/?a=commitdiff_plain;h=61f8c2c4d783407e341c909b7a8cfc2a32998119;p=automake.git ansi2knr fix from Gord --- diff --git a/ChangeLog b/ChangeLog index ec987b15..429edbca 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +Sat Feb 22 16:05:24 1997 Gordon Matzigkeit + + * Makefile.am (pkgdata_DATA): Under this new scheme, we no longer + need compile-kr.am. Delete it. + + * automake.in (handle_yacc_lex_cxx, get_object_extension): Use + _.c, _.o, _.lo instead of ._c, ._o, .l_o for de-ansification. + + * ansi2knr.c (main): Parse our arguments a little differently so + that we don't create null output files when we can't read the + input file. + Wed May 28 23:40:33 1997 Tom Tromey * depend.am (.deps/.P): Depend on $(BUILT_SOURCES) again. From diff --git a/Makefile.am b/Makefile.am index 604755a7..d77a79a7 100644 --- a/Makefile.am +++ b/Makefile.am @@ -8,14 +8,14 @@ SUBDIRS = tests m4 bin_SCRIPTS = automake aclocal info_TEXINFOS = automake.texi -pkgdata_DATA = clean-kr.am clean.am clean-hdr.am compile-kr.am \ -comp-vars.am compile.am data.am dejagnu.am depend.am depend2.am \ -dist-vars.am footer.am header.am header-vars.am kr-extra.am libs.am \ -library.am libtool.am ltlib.am ltlibrary.am mans-vars.am program.am \ -progs.am remake-hdr.am remake.am scripts.am subdirs.am tags.am \ -tags-clean.am texi-vers.am texinfos.am libs-clean.am ltlib-clean.am \ -progs-clean.am data-clean.am COPYING INSTALL texinfo.tex ansi2knr.c \ -ansi2knr.1 lisp.am lisp-clean.am +pkgdata_DATA = clean-kr.am clean.am clean-hdr.am comp-vars.am \ +compile.am data.am dejagnu.am depend.am depend2.am dist-vars.am \ +footer.am header.am header-vars.am kr-extra.am libs.am library.am \ +libtool.am ltlib.am ltlibrary.am mans-vars.am program.am progs.am \ +remake-hdr.am remake.am scripts.am subdirs.am tags.am tags-clean.am \ +texi-vers.am texinfos.am libs-clean.am ltlib-clean.am progs-clean.am \ +data-clean.am COPYING INSTALL texinfo.tex ansi2knr.c ansi2knr.1 \ +lisp.am lisp-clean.am ## These must all be executable when installed. pkgdata_SCRIPTS = config.guess config.sub install-sh mdate-sh missing \ diff --git a/Makefile.in b/Makefile.in index 5d08900b..cdbf0d9e 100644 --- a/Makefile.in +++ b/Makefile.in @@ -67,14 +67,14 @@ SUBDIRS = tests m4 bin_SCRIPTS = automake aclocal info_TEXINFOS = automake.texi -pkgdata_DATA = clean-kr.am clean.am clean-hdr.am compile-kr.am \ -comp-vars.am compile.am data.am dejagnu.am depend.am depend2.am \ -dist-vars.am footer.am header.am header-vars.am kr-extra.am libs.am \ -library.am libtool.am ltlib.am ltlibrary.am mans-vars.am program.am \ -progs.am remake-hdr.am remake.am scripts.am subdirs.am tags.am \ -tags-clean.am texi-vers.am texinfos.am libs-clean.am ltlib-clean.am \ -progs-clean.am data-clean.am COPYING INSTALL texinfo.tex ansi2knr.c \ -ansi2knr.1 lisp.am lisp-clean.am +pkgdata_DATA = clean-kr.am clean.am clean-hdr.am comp-vars.am \ +compile.am data.am dejagnu.am depend.am depend2.am dist-vars.am \ +footer.am header.am header-vars.am kr-extra.am libs.am library.am \ +libtool.am ltlib.am ltlibrary.am mans-vars.am program.am progs.am \ +remake-hdr.am remake.am scripts.am subdirs.am tags.am tags-clean.am \ +texi-vers.am texinfos.am libs-clean.am ltlib-clean.am progs-clean.am \ +data-clean.am COPYING INSTALL texinfo.tex ansi2knr.c ansi2knr.1 \ +lisp.am lisp-clean.am pkgdata_SCRIPTS = config.guess config.sub install-sh mdate-sh missing \ mkinstalldirs elisp-comp ylwrap acinstall diff --git a/ansi2knr.c b/ansi2knr.c index 64a4578a..c6ee8330 100644 --- a/ansi2knr.c +++ b/ansi2knr.c @@ -195,26 +195,30 @@ main(argc, argv) exit(1); } } - switch ( argc ) + if (argc < 2 || argc > 3) { - default: printf("Usage: ansi2knr input_file [output_file]\n"); - exit(0); - case 2: - out = stdout; - break; - case 3: - out = fopen(argv[2], "w"); - if ( out == NULL ) - { fprintf(stderr, "Cannot open output file %s\n", argv[2]); exit(1); } - } in = fopen(argv[1], "r"); if ( in == NULL ) - { fprintf(stderr, "Cannot open input file %s\n", argv[1]); + { + fprintf(stderr, "Cannot open input file %s\n", argv[1]); exit(1); } + if (argc == 3) + { + out = fopen(argv[2], "w"); + if ( out == NULL ) + { + fprintf(stderr, "Cannot open output file %s\n", argv[2]); + exit(1); + } + } + else + { + out = stdout; + } fprintf(out, "#line 1 \"%s\"\n", argv[1]); buf = malloc(bufsize); line = buf; diff --git a/automake.in b/automake.in index 7192ecd8..565248c9 100755 --- a/automake.in +++ b/automake.in @@ -679,8 +679,8 @@ sub get_object_extension $dir_holds_sources = 1; # Maybe require libtool library object files. - local ($l, $extension) = ('', 'o'); - $l = 'l' if ($out =~ /^lib.*\.la$/); + local ($extension) = '.o'; + $extension = '.lo' if ($out =~ /\.la$/); if (! $included_generic_compile) { @@ -736,7 +736,7 @@ sub get_object_extension # Check for automatic de-ANSI-fication. if (defined $options{'ansi2knr'}) { - $extension = '$o'; + $extension = '$U' . $extension; if (! $included_knr_compile) { if (! $am_c_prototypes) @@ -748,9 +748,6 @@ sub get_object_extension $am_c_prototypes = 1; } - push (@suffixes, '._c', '._o'); - push (@suffixes, '.l_o') if $seen_libtool; - # Only require ansi2knr files if they should appear in # this directory. if ($options{'ansi2knr'} eq 'ansi2knr') @@ -778,8 +775,6 @@ sub get_object_extension . " && \$(MAKE) ansi2knr\n\n"); } - &define_variable ('o', "\@U\@o"); - # Make sure ansi2knr can be found: if no path specified, # specify "./". if ($options{'ansi2knr'} eq 'ansi2knr') @@ -796,7 +791,6 @@ sub get_object_extension &define_variable ("ANSI2KNR", $options{'ansi2knr'}); } - $output_rules .= &file_contents ('compile-kr'); $output_rules .= &file_contents ('clean-kr'); push (@clean, 'kr'); @@ -806,7 +800,7 @@ sub get_object_extension } } - return '.' . $l . $extension; + return $extension; } # Handle yacc and lex. @@ -920,22 +914,21 @@ sub handle_yacc_lex_cxx # # Handle some ansi2knr cleanup. # - if (defined $options{'ansi2knr'} && keys %de_ansi_objects) + if (defined $options{'ansi2knr'} && keys %de_ansi_files) { - # Make all ._o files depend on ansi2knr. Use a sneaky little - # hack to make it print nicely. - &pretty_print_rule ('', '', ((sort keys %de_ansi_objects), - ':', '$(ANSI2KNR)')); - # The ._c files also depend on ansi2knr. We need both because - # some makes don't apply transitivity through implicit rules. - local (%de_ansi_sources, $x); - foreach $x (keys %de_ansi_objects) - { - $x =~ s/o$/c/; - $de_ansi_sources{$x} = 1; - } - &pretty_print_rule ('', '', ((sort keys %de_ansi_sources), - ':', '$(ANSI2KNR)')); + # Make all _.c files depend on their corresponding .c files. + local ($base, @objects); + foreach $base (sort (keys %de_ansi_files)) + { + $output_rules .= $base . "_.c: $base.c\n\t" + . '$(ANSI2KNR) $< ' . $base . "_.c\n"; + push (@objects, $base . '_.o'); + push (@objects, $base . '_.lo') if $seen_libtool; + } + + # Make all _.o (and _.lo) files depend on ansi2knr. + # Use a sneaky little hack to make it print nicely. + &pretty_print_rule ('', '', @objects, ':', '$(ANSI2KNR)'); } # @@ -1135,18 +1128,22 @@ sub handle_single_transform_list { # .s is assembly. Just rewrite it. FIXME: not finished. } - elsif (s/\.[cly]$/._o/) - { - # .c is C. .l is lex. .y is yacc. - - # Note: first we rewrite (eg) foo.c to foo._o and push - # the file onto the list of objects that require - # ansi2knr. Then we rewrite ._o to $obj; $obj can be - # simply `.o' if deansification is not really - # required. - $de_ansi_objects{$_} = 1; - s/\._o$/$obj/; - $seen_c_source = -1 unless $seen_c_source; + elsif (defined ($options{'ansi2knr'}) && s/_\.[cly]$/_.c/) + { + # FIXME include line number in error. + &am_error ("C source file \`$_' would be deleted by ansi2knr rules"); + } + elsif (s/\.[cly]$//) + { + # .c is C. .l is lex. .y is yacc. + + # Note: first we rewrite (eg) foo.c to foo and push + # the file onto the list of deansified files. Then we add + # $obj, which can either be `_.o', or simply `.o' if + # deansification is not required. + $de_ansi_files{$_} = 1; + $_ .= $obj; + $seen_c_source = 1; } else { @@ -5364,9 +5361,9 @@ sub initialize_per_input # This is a list of all targets to run during "make dist". @dist_targets = (); - # Keys in this hash are the names of ._o files which must depend - # on ansi2knr. Ugh. - %de_ansi_objects = (); + # Keys in this hash are the basenames of files which must depend + # on ansi2knr. + %de_ansi_files = (); } diff --git a/clean-kr.am b/clean-kr.am index b5859e26..bf8c78c1 100644 --- a/clean-kr.am +++ b/clean-kr.am @@ -16,7 +16,7 @@ ## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA ## 02111-1307, USA. mostlyclean-kr: - rm -f *._o *.l_o *._c _*.c _*.o + rm -f *_.c clean-kr: diff --git a/compile-kr.am b/compile-kr.am deleted file mode 100644 index 630ea751..00000000 --- a/compile-kr.am +++ /dev/null @@ -1,45 +0,0 @@ -## 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. -.c._c: - $(ANSI2KNR) $< > $*.tmp && mv $*.tmp $@ - -._c._o: - @echo "$(COMPILE) -c $<" - @rm -f _$*.c - @ln $< _$*.c && $(COMPILE) -c _$*.c && mv _$*.o $@ && rm _$*.c - -._c.l_o: - @echo "$(LIBTOOL) --mode=compile $(COMPILE) -c $<" - @rm -f _$*.c - @ln $< _$*.c && $(LIBTOOL) --mode=compile $(COMPILE) -c _$*.c && mv _$*.lo $@ && rm _$*.c - -## This rule exists because some versions of make won't apply -## transitivity through implicit rules. -.c._o: - $(ANSI2KNR) $< > $*.tmp && mv $*.tmp $*._c - @echo "$(COMPILE) -c $*._c" - @rm -f _$*.c - @ln $*._c _$*.c && $(COMPILE) -c _$*.c && mv _$*.o $@ && rm _$*.c - -## This rule exists because some versions of make won't apply -## transitivity through implicit rules. -.c.l_o: - $(ANSI2KNR) $< > $*.tmp && mv $*.tmp $*._c - @echo "$(LIBTOOL) --mode=compile $(COMPILE) -c $*._c" - @rm -f _$*.c - @ln $*._c _$*.c && $(LIBTOOL) --mode=compile $(COMPILE) -c _$*.c && mv _$*.lo $@ && rm _$*.c diff --git a/lib/am/Makefile.am b/lib/am/Makefile.am index 604755a7..d77a79a7 100644 --- a/lib/am/Makefile.am +++ b/lib/am/Makefile.am @@ -8,14 +8,14 @@ SUBDIRS = tests m4 bin_SCRIPTS = automake aclocal info_TEXINFOS = automake.texi -pkgdata_DATA = clean-kr.am clean.am clean-hdr.am compile-kr.am \ -comp-vars.am compile.am data.am dejagnu.am depend.am depend2.am \ -dist-vars.am footer.am header.am header-vars.am kr-extra.am libs.am \ -library.am libtool.am ltlib.am ltlibrary.am mans-vars.am program.am \ -progs.am remake-hdr.am remake.am scripts.am subdirs.am tags.am \ -tags-clean.am texi-vers.am texinfos.am libs-clean.am ltlib-clean.am \ -progs-clean.am data-clean.am COPYING INSTALL texinfo.tex ansi2knr.c \ -ansi2knr.1 lisp.am lisp-clean.am +pkgdata_DATA = clean-kr.am clean.am clean-hdr.am comp-vars.am \ +compile.am data.am dejagnu.am depend.am depend2.am dist-vars.am \ +footer.am header.am header-vars.am kr-extra.am libs.am library.am \ +libtool.am ltlib.am ltlibrary.am mans-vars.am program.am progs.am \ +remake-hdr.am remake.am scripts.am subdirs.am tags.am tags-clean.am \ +texi-vers.am texinfos.am libs-clean.am ltlib-clean.am progs-clean.am \ +data-clean.am COPYING INSTALL texinfo.tex ansi2knr.c ansi2knr.1 \ +lisp.am lisp-clean.am ## These must all be executable when installed. pkgdata_SCRIPTS = config.guess config.sub install-sh mdate-sh missing \ diff --git a/lib/ansi2knr.c b/lib/ansi2knr.c index 64a4578a..c6ee8330 100644 --- a/lib/ansi2knr.c +++ b/lib/ansi2knr.c @@ -195,26 +195,30 @@ main(argc, argv) exit(1); } } - switch ( argc ) + if (argc < 2 || argc > 3) { - default: printf("Usage: ansi2knr input_file [output_file]\n"); - exit(0); - case 2: - out = stdout; - break; - case 3: - out = fopen(argv[2], "w"); - if ( out == NULL ) - { fprintf(stderr, "Cannot open output file %s\n", argv[2]); exit(1); } - } in = fopen(argv[1], "r"); if ( in == NULL ) - { fprintf(stderr, "Cannot open input file %s\n", argv[1]); + { + fprintf(stderr, "Cannot open input file %s\n", argv[1]); exit(1); } + if (argc == 3) + { + out = fopen(argv[2], "w"); + if ( out == NULL ) + { + fprintf(stderr, "Cannot open output file %s\n", argv[2]); + exit(1); + } + } + else + { + out = stdout; + } fprintf(out, "#line 1 \"%s\"\n", argv[1]); buf = malloc(bufsize); line = buf;