From: Tom Tromey Date: Sun, 11 Aug 1996 18:02:21 +0000 (+0000) Subject: Better C++ support X-Git-Tag: Release-1-1c~6 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=4c809afecb1f24ae7355e94e75fe2195ceb29b22;p=thirdparty%2Fautomake.git Better C++ support --- diff --git a/ChangeLog b/ChangeLog index 7e69ab3f0..b57e862b9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,10 +1,25 @@ Sun Aug 11 00:20:16 1996 Tom Tromey + * compile-vars.am (CC, CFLAGS, COMPILE, LINK): Removed. + * automake.in (handle_yacc_lex_cxx): Require ylwrap in multi-lex/yacc case. (handle_source_transform): Changed return result. (handle_programs): Use linker returned by handle_source_transform. + (seen_prog_cc, seen_prog_cxx): New globals. + (scan_configure): Recognize AC_PROG_CC and AC_PROG_CXX. + (handle_yacc_lex_cxx): Error message if AC_PROG_CXX or + AC_PROG_YACC missing. + (seen_decl_yytext, seen_prog_lex): New globals. + (scan_configure): Set them. + (handle_yacc_lex_cxx): Warn about missing AC_PROG_LEX or + AC_DECL_YYTEXT. + (handle_yacc_lex_cxx): Use $(LEX_OUTPUT_ROOT). + (initialize_per_input): Initialize seen_c_source. + (handle_yacc_lex_cxx): Define CC, CFLAGS, COMPILE, LINK only when + C source seen. + (handle_source_transform): Set seen_c_source. * interlock: Changed usage. diff --git a/TODO b/TODO index 0bdbfa167..f8370b817 100644 --- a/TODO +++ b/TODO @@ -3,13 +3,6 @@ Priorities for release: ** when can aclocal.m4 be auto-generated? -multi-language support. Gord's idea is to have _FORTRAN_PROGRAMS, -_CXX_PROGRAMS, etc, and have the right linker used by each. -* seems to handle multi-language stuff ok ? -* maybe some kind of auto-detection would be better ? with linker - overridable on per-program basis -* what about EXTRA_PROGRAMS stuff? - ** many requests for a way to omit a file from the distribution. Should be done like `!foo' or `~foo' in _SOURCES, etc. Such files should be removed explicitly after the copy step! @@ -154,13 +147,12 @@ Lex, yacc support: y.tab.c:perly.y for yacc and lex source * if AC_PROG_LEX used, ensure (no, *PUT*) LEXLIB in foo_LDADD -* require AC_DECL_YYTEXT for lex -* Actually use $seen_prog_yacc -* Require AC_PROG_LEX or equivalent - -require AC_PROG_CXX if any C++ source files found? -Better support for C++ all around +Multi-language support: +* should have mapping of file extensions to languages +* should automatically handle the linking issue (special-case C++) +* must get compile rules for various languages; FORTRAN probably + most important unimplemented language 'maintainer-clean' should "rm -rf .deps". Ditto distclean Should look for clean-local targets in Makefile.am. diff --git a/automake.in b/automake.in index c43a4b023..27b245d24 100755 --- a/automake.in +++ b/automake.in @@ -139,6 +139,17 @@ $seen_path_xtra = 0; # Whether YACC variable has been seen in configure.in. $seen_prog_yacc = 0; +# Two variables to control lex use. One is for AC_DECL_YYTEXT and the +# other is for AC_PROG_LEX. +$seen_decl_yytext = 0; +$seen_prog_lex = 0; + +# TRUE if we've seen AC_PROG_CC. +$seen_prog_cc = 0; + +# TRUE if we've seen AC_PROG_CXX. +$seen_prog_cxx = 0; + # TRUE if we've seen AC_CANONICAL_(HOST|SYSTEM). The presence of # AC_CHECK_TOOL also sets this. $seen_canonical = 0; @@ -572,10 +583,12 @@ sub get_object_extension # Handle yacc and lex. sub handle_yacc_lex_cxx { + # + # First do yacc and lex. + # + local ($yacc_count) = scalar (keys %yacc_sources); local ($lex_count) = scalar (keys %lex_sources); - local ($cxx_count) = scalar (keys %cxx_extensions); - if ($yacc_count) { push (@suffixes, '.y'); @@ -590,29 +603,64 @@ sub handle_yacc_lex_cxx $output_rules .= '$(YACC) $(YFLAGS) $< && mv y.tab.c $@'; } $output_rules .= "\n"; + + if (! $seen_prog_yacc) + { + # FIXME should include a reference line. FIXME maybe + # directly reference AC_PROG_YACC somehow? + &am_error ("yacc source seen but \`YACC' not defined in \`configure.in'\n"); + } } if ($lex_count) { push (@suffixes, '.l'); - $output_vars .= "LEX = \@LEX\@\n"; + $output_vars .= ("LEX = \@LEX\@\n" + . "LEX_OUTPUT_ROOT = \@LEX_OUTPUT_ROOT\@\n"); $output_rules .= (".l.c:\n\t" . "\n"); if ($lex_count > 1) { - $output_rules .= '$(INTERLOCK) =lexlockdir $(YLWRAP) lex.yy.c $@ $(LEX) $(LFLAGS) $<'; + $output_rules .= '$(INTERLOCK) =lexlockdir $(YLWRAP) $(LEX_OUTPUT_ROOT).c $@ $(LEX) $(LFLAGS) $<'; } else { - $output_rules .= '$(LEX) $(LFLAGS) $< && mv lex.yy.c $@'; + $output_rules .= '$(LEX) $(LFLAGS) $< && mv $(LEX_OUTPUT_ROOT).c $@'; } $output_rules .= "\n"; + + if (! $seen_prog_lex) + { + &am_error ("lex source seen but \`AC_PROG_LEX' not in \`configure.in'\n"); + } + if (! $seen_decl_yytext) + { + &am_error ("lex source seen but \`AC_DECL_YYTEXT' not in \`configure.in'\n"); + } } + + if ($yacc_count > 1 || $lex_count > 1) + { + # If there is more than one distinct yacc (resp lex) source + # file in a given directory, then the `interlock' program is + # required to allow parallel builds to work correctly. FIXME + # for now, no line number. + &require_config_file ($FOREIGN, 'interlock', 'ylwrap'); + $output_vars .= ('INTERLOCK = ' . $config_aux_dir . "/interlock\n" + . 'YLWRAP = ' . $config_aux_dir . "/ylwrap\n"); + } + + # + # Now handle C++. + # + local ($cxx_count) = scalar (keys %cxx_extensions); if ($cxx_count) { $output_vars .= ("CXX = \@CXX\@\n" . "CXXFLAGS = \@CXXFLAGS\@\n" - . "CXXCOMPILE = $(CXX) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CXXFLAGS)\n" - . "CXXLINK = $(CXX) $(LDFLAGS) -o $@\n"); + . 'CXXCOMPILE = $(CXX) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CXXFLAGS)' + . "\n" + . 'CXXLINK = $(CXX) $(LDFLAGS) -o $@' + . "\n"); local ($ext); foreach $ext (keys %cxx_extensions) @@ -620,17 +668,24 @@ sub handle_yacc_lex_cxx $output_rules .= ("$ext.o:\n" . "\t\$(CXXCOMPILE) -c \$<\n"); } + + if (! $seen_prog_cxx) + { + &am_error ("C++ source seen but \`AC_PROG_CXX' not in \`configure.in'\n"); + } } - if ($yacc_count > 1 || $lex_count > 1) + # + # Last, handle some C cleanup. + # + if ($seen_c_source) { - # If there is more than one distinct yacc (resp lex) source - # file in a given directory, then the `interlock' program is - # required to allow parallel builds to work correctly. FIXME - # for now, no line number. - &require_config_file ($FOREIGN, 'interlock', 'ylwrap'); - $output_vars .= ('INTERLOCK = ' . $config_aux_dir . "/interlock\n" - . 'YLWRAP = ' . $config_aux_dir . "/ylwrap\n"); + $output_vars .= ("CC = \@CC\@\n" + . "CFLAGS = \@CFLAGS\@\n" + . 'COMPILE = $(CC) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS)' + . "\n" + . 'LINK = $(CC) $(LDFLAGS) -o $@' + . "\n"); } } @@ -729,15 +784,23 @@ sub handle_source_transform $cxx_extensions{$&} = 1; $linker = 'CXXLINK'; } + else + { + # FORTRAN support. FIXME not finished. + s/\.f90$/$obj/g; + s/\.for$/$obj/g; + + # .y is yacc. .l is lex. .f and .F is fortran. + # .s is assembly. .M is Objective-C++. .m is + # Objective-C. + s/\.[cylfFsmM]$/$obj/g; + + # FIXME of course, this should only happen for C + # source. The multi-language support must really + # be cleaned up more globally. + $seen_c_source = 1; + } - # FORTRAN support. - s/\.f90$/$obj/g; - s/\.for$/$obj/g; - - # .y is yacc. .l is lex. .f and .F is fortran. .s - # is assembly. .M is Objective-C++. .m is - # Objective-C. - s/\.[cylfFsmM]$/$obj/g; push (@result, $_) unless $prefix eq 'EXTRA_'; @@ -2490,6 +2553,10 @@ sub scan_configure $seen_make_set = 1 if /AC_PROG_MAKE_SET/; $seen_arg_prog = 1 if /AC_ARG_PROGRAM/; $seen_ranlib = 1 if /AC_PROG_RANLIB/; + $seen_prog_cc = 1 if /AC_PROG_CC/; + $seen_prog_cxx = 1 if /AC_PROG_CXX/; + $seen_prog_lex = 1 if /AC_PROG_LEX/; + $seen_decl_yytext = 1 if /AC_DECL_YYTEXT/; $seen_maint_mode = 1 if /AM_MAINTAINER_MODE/; $seen_package = 1 if /PACKAGE=/; $seen_version = 1 if /VERSION=/; @@ -2983,6 +3050,9 @@ sub initialize_per_input # C++ source extensions we've seen. %cxx_extensions = (); + + # TRUE if we've seen any non-C++ sources. + $seen_c_source = 0; } diff --git a/compile-vars.am b/compile-vars.am index d732b3096..801b2351c 100644 --- a/compile-vars.am +++ b/compile-vars.am @@ -15,13 +15,8 @@ ## along with this program; if not, write to the Free Software ## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA ## 02111-1307, USA. -CC = @CC@ DEFS = @DEFS@ -I. -I$(srcdir) @CONFIG_INCLUDE_SPEC@ CPPFLAGS = @CPPFLAGS@ -CFLAGS = @CFLAGS@ LDFLAGS = @LDFLAGS@ LIBS = @LIBS@ - -COMPILE = $(CC) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS) -LINK = $(CC) $(LDFLAGS) -o $@ diff --git a/interlock b/interlock index 60f9fbf3e..88e27332e 100755 --- a/interlock +++ b/interlock @@ -33,7 +33,7 @@ done # Race condition here: if interrupted after the loop but before this # trap, the lock can be left around. -trap "rmdir $dirname > /dev/null 2>&1" 1 2 +trap "rmdir $dirname > /dev/null 2>&1" 1 2 3 15 # We have the lock, so run the program. $program ${1+"$@"} diff --git a/tests/ChangeLog b/tests/ChangeLog index 14b67c715..26419d5f6 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,5 +1,13 @@ Sun Aug 11 00:10:42 1996 Tom Tromey + * cxxnoc.test: New file. + + * cxxlink.test: Use AC_PROG_CXX. + + * lex.test: Use AC_PROG_LEX, AC_DECL_YYTEXT. + + * yacc.test: Use AC_PROG_YACC in configure.in. + * cxxlink.test: New file. * yacc.test: Fixed test for new yacc code. diff --git a/tests/Makefile.am b/tests/Makefile.am index 52168ac02..ca0394973 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -12,6 +12,6 @@ insh2.test outdir.test fpinstall.test fpinst2.test texinfo.test dejagnu.test \ yacc.test mkinstall2.test texinfo2.test ansi.test depacl.test depacl2.test \ error.test colon.test vtexi2.test tags.test comment.test libfiles.test \ man.test info.test obsolete.test lex.test scripts.test subdir2.test \ -exsource.test canon4.test dup.test defun.test cxxlink.test +exsource.test canon4.test dup.test defun.test cxxlink.test cxxnoc.test EXTRA_DIST = defs $(TESTS) diff --git a/tests/Makefile.in b/tests/Makefile.in index bd8177444..3a0eb5419 100644 --- a/tests/Makefile.in +++ b/tests/Makefile.in @@ -50,7 +50,7 @@ insh2.test outdir.test fpinstall.test fpinst2.test texinfo.test dejagnu.test \ yacc.test mkinstall2.test texinfo2.test ansi.test depacl.test depacl2.test \ error.test colon.test vtexi2.test tags.test comment.test libfiles.test \ man.test info.test obsolete.test lex.test scripts.test subdir2.test \ -exsource.test canon4.test dup.test defun.test cxxlink.test +exsource.test canon4.test dup.test defun.test cxxlink.test cxxnoc.test EXTRA_DIST = defs $(TESTS) mkinstalldirs = $(top_srcdir)/mkinstalldirs diff --git a/tests/cxxlink.test b/tests/cxxlink.test index c06acb8d1..6de9974e6 100755 --- a/tests/cxxlink.test +++ b/tests/cxxlink.test @@ -4,6 +4,10 @@ . $srcdir/defs || exit 1 +cat >> configure.in << 'END' +AC_PROG_CXX +END + cat > Makefile.am << 'END' bin_PROGRAMS = lavalamp lavalamp_SOURCES = lava.c lamp.cxx diff --git a/tests/cxxnoc.test b/tests/cxxnoc.test new file mode 100755 index 000000000..a4f5b0091 --- /dev/null +++ b/tests/cxxnoc.test @@ -0,0 +1,22 @@ +#! /bin/sh + +# Test to make sure pure C++ sources don't include C-specific code. + +. $srcdir/defs || exit 1 + +cat >> configure.in << 'END' +AC_PROG_CXX +END + +cat > Makefile.am << 'END' +sbin_PROGRAMS = anonymous +anonymous_SOURCES = doe.C jane.C +END + +: > doe.C +: > jane.C + +$AUTOMAKE || exit 1 + +grep CC Makefile.in && exit 1 +exit 0 diff --git a/tests/lex.test b/tests/lex.test index 42505fa44..d6ea7c6e0 100755 --- a/tests/lex.test +++ b/tests/lex.test @@ -4,6 +4,11 @@ . $srcdir/defs || exit 1 +cat >> configure.in << 'END' +AC_PROG_LEX +AC_DECL_YYTEXT +END + cat > Makefile.am << 'END' bin_PROGRAMS = zot zot_SOURCES = joe.l diff --git a/tests/yacc.test b/tests/yacc.test index 3c8e37ce2..366c975e8 100755 --- a/tests/yacc.test +++ b/tests/yacc.test @@ -5,6 +5,10 @@ . $srcdir/defs || exit 1 +cat >> configure.in << 'END' +AC_PROG_YACC +END + cat > Makefile.am <<'END' bin_PROGRAMS = zardoz zardoz_SOURCES = zardoz.y