From: "Juan Manuel Guerrero" Organization: Darmstadt University of Technology To: djgpp AT delorie DOT com Date: Mon, 6 Dec 1999 11:45:36 +0100 Subject: Support of BISON in AUTOCONF/AUTOMAKE X-mailer: Pegasus Mail for Windows (v2.54DE) Message-ID: <944B391AAA@HRZ1.hrz.tu-darmstadt.de> Reply-To: djgpp AT delorie DOT com If one inspects the sources of AUTOCONF and AUTOMAKE one will notice that there is already build-in support for MSDOS ports of FLEX/LEX. This support is done in the AC_DECL_YYTEXT macro contained in file acspecif.m4 and in function: output_lex_build_rule in file automake.in. AC_DECL_YYTEXT, apart from all other jobs it does, compiles a minimal lex program, checks for the output file name and set the variable @LEX_OUTPUT_ROOT@ to lex.yy or lexyy accordingly. The function output_lex_build_rule in automake.in creates in makefile.in the following line: LEX_OUTPUT_ROOT = @LEX_OUTPUT_ROOT@ and the implicit rule for flex: .l.c: $(SHELL) $(YLWRAP) "$(LEX)" $< $(LEX_OUTPUT_ROOT).c $@ -- $(AM_LFLAGS) $(LFLAGS) or a similar rule without YLWRAP. When config.status is executed @LEX_OUTPUT_ROOT@ is replaced by the appropiate value. All this can be used as a guide line for how to properly implement support for MSDOS ports of BISON/BYACC. It should be clear that changes to autoconf AND automake will be needed. 1) AUTOCONF modifications. The macro AC_PROG_YACC contained in file acspecific.m4 has been modified to provide the following functionality: 1: Check for bison, byacc, yacc or issue a "missing" message. 2: Compile a minimal grammar file and check for the output file name. 3: Set the the new variable to: @YACC_TABEXT@ = .tab for BISON ports that create file names with multiple dots. @YACC_TABEXT@ = _tab for BISON ports that do NOT create file names with multiple dots. The choose of @YACC_TABEXT@ =.tab or_tab instead of @YACC_OUTPUT_ROOT@ = y.tab ory_tab is not arbitrary. Choosing the variable @YACC_TABEXT@ instead of @YACC_OUTPUT_ROOT@ allows to cope with the two types of output file name that bison can create: 1: y.tab.[ch] --> y$(YACC_TABEXT).[ch] 2: foo.tab.[ch] --> foo$(YACC_TABEXT).[ch] There is no need to introduce a second variable to cope with the case that bison is invoked with the file name prefix option (-b). 2) AUTOMAKE modifications. The modifications needed concern the files automake.in and compile.am automake.in creates the implicit rule for the grammar files and compile.am contains the "clean" rule. The function: output_yacc_build_rule in automake.in has been modified the following way: 1: The command line: &define_configure_variable ('YACC_TABEXT'); has been inserted. This command will create in makefile.in the following line: YACC_TABEXT = @YACC_TABEXT@ The appropiate value for @YACC_TABEXT@ will be substituted by config.status. 2: In the string containing the implicit rule for grammar files every occurence of ".tab" has been replaced by "$(YACC_TABEXT)". In compile.am ".tab" has been replaced by "$(YACC_TABEXT)". This are all modifications that are needed to get support for MSDOS ports of BISON/BYACC. From the written above it should be clear that neither the build-in support for FLEX nor the new support for BISON can cope with explicit rules. It is a feature of automake to copy explicit rules from makefile.am to makefile.in without process them in any way. This is important for makefile.ins like the one in gdb-4.18/gdb where a lot of explicit rules for grammar files exist. All this rules must still be manually modified. Of course, every ".tab" string can be replaced by "@YACC_TABEXT@" and config.status will always recognize this and replace "@YACC_TABEXT@" with the appropiate value but there is no real gain here. IMPORTANT: To avoid the posibility of overwritting existing y.tab.[ch] files during the file name test, AC_PROG_YACC will invoke bison with the -b option (file prefix). Unfortunatly the DJGPP port of bison has a bug that will not allow to use this option. It is essential to use a corrected bison version or the macro will not properly work. If the bogus bison is used in a DOS box of WIN 3.XX it will simply crash the box and on WIN9X the output file name will be: actest.tab.c wich implies that YACC_TABEXT = .tab will be used and an unix style makefile will be created. The modified autoconf and automake have been tested on Linux and MSDOS6.XX On both OS binutils 2.8/2.9.1, gdb-4.18, fileutils-3.16, shellutils-1.16 and some other packages that use AUTOMAKE/AUTOCONF have been succesfully configured and compiled. No WIN9X testing at all. The patches are based on AUTOCONF-2.13.TAR.GZ and AUTOMAKE-1.4.TAR.GZ This means the GNU distributions and not the DJGPP ports. The last patch is the small patch needed to correct the bison bug. Although I have done this primarily for my own use I hope it is of some use for someone else or at least it serves as a starting point to implement the needed support for bison's MSDOS port. Suggestions, comments objections, etc are welcome. A last suggestion: In autoconf lines like the following one are used: if ! test -z "$COMSPEC$ComSpec"; then I would suggest: if test "x$OSTYPE" = xMSDOS; then OSTYPE is always set to MSDOS, at least by bash 1.14. and will clearly identify MSDOS code. Regards, Guerrero, Juan Manuel. Patch for AUTOCONF. diff -acrpNC3 aconf213.gnu/acspecif.m4 aconf213.djg/acspecif.m4 *** aconf213.gnu/acspecif.m4 Tue Jan 5 14:27:52 1999 --- aconf213.djg/acspecif.m4 Mon Dec 6 09:07:54 1999 *************** AC_DEFUN(AC_PROG_AWK, *** 484,490 **** [AC_CHECK_PROGS(AWK, mawk gawk nawk awk, )]) AC_DEFUN(AC_PROG_YACC, ! [AC_CHECK_PROGS(YACC, 'bison -y' byacc, yacc)]) AC_DEFUN(AC_PROG_CPP, [AC_MSG_CHECKING(how to run the C preprocessor) --- 484,509 ---- [AC_CHECK_PROGS(AWK, mawk gawk nawk awk, )]) AC_DEFUN(AC_PROG_YACC, ! [missing_dir=ifelse([$1],,`cd $ac_aux_dir && pwd`,$1) ! AC_CHECK_PROGS(YACC, 'bison -y' byacc yacc, "$missing_dir/missing bison") ! AC_CACHE_CHECK(yacc output file tab extension, ac_cv_prog_yacc_tab_extension, ! [# Minimal yacc program. ! cat > actest.y << EOF ! %% ! rule: /* empty */ ! ; ! EOF ! $YACC -b actest actest.y ! if test -f actest.tab.c; then ! ac_cv_prog_yacc_tab_extension=.tab ! elif test -f actest_tab.c; then ! ac_cv_prog_yacc_tab_extension=_tab ! else ! AC_MSG_ERROR(cannot find output from $YACC; giving up) ! fi ! rm -f actest*]) ! YACC_TABEXT=$ac_cv_prog_yacc_tab_extension ! AC_SUBST(YACC_TABEXT)]) AC_DEFUN(AC_PROG_CPP, [AC_MSG_CHECKING(how to run the C preprocessor) Patch for AUTOMAKE. diff -acrpNC3 amake-14.gnu/automake.in amake-14.djg/automake.in *** amake-14.gnu/automake.in Fri Jan 15 07:42:36 1999 --- amake-14.djg/automake.in Mon Dec 6 09:12:42 1999 *************** sub output_yacc_build_rule *** 960,965 **** --- 960,966 ---- local ($suffix); ($suffix = $yacc_suffix) =~ tr/y/c/; push (@suffixes, $yacc_suffix, $suffix); + &define_configure_variable ('YACC_TABEXT'); # Generate rule for c/c++. $output_rules .= "$yacc_suffix$suffix:\n\t"; *************** sub output_yacc_build_rule *** 967,981 **** if ($use_ylwrap) { $output_rules .= ('$(SHELL) $(YLWRAP)' ! . ' "$(YACC)" $< y.tab.c $*' . $suffix ! . ' y.tab.h $*.h -- $(AM_YFLAGS) $(YFLAGS)'); } else { $output_rules .= ('$(YACC) $(AM_YFLAGS) $(YFLAGS) $< && mv y.tab.c $*' . $suffix . "\n" ! . "\tif test -f y.tab.h; then \\\n" ! . "\tif cmp -s y.tab.h \$*.h; then rm -f y.tab.h; else mv y.tab.h \$*.h; fi; \\\n" . "\telse :; fi"); } $output_rules .= "\n"; --- 968,982 ---- if ($use_ylwrap) { $output_rules .= ('$(SHELL) $(YLWRAP)' ! . ' "$(YACC)" $< y$(YACC_TABEXT).c $*' . $suffix ! . ' y$(YACC_TABEXT).h $*.h -- $(AM_YFLAGS) $(YFLAGS)'); } else { $output_rules .= ('$(YACC) $(AM_YFLAGS) $(YFLAGS) $< && mv y.tab.c $*' . $suffix . "\n" ! . "\tif test -f y\$(YACC_TABEXT).h; then \\\n" ! . "\tif cmp -s y\$(YACC_TABEXT).h \$*.h; then rm -f y\$(YACC_TABEXT).h; else mv y\$(YACC_TABEXT).h \$*.h; fi; \\\n" . "\telse :; fi"); } $output_rules .= "\n"; diff -acrpNC3 amake-14.gnu/compile.am amake-14.djg/compile.am *** amake-14.gnu/compile.am Sun Sep 27 03:06:42 1998 --- amake-14.djg/compile.am Mon Dec 6 09:13:16 1999 *************** OBJEXT -rm -f *.$(OBJEXT) *** 38,43 **** clean-compile: distclean-compile: ! -rm -f *.tab.c maintainer-clean-compile: --- 38,43 ---- clean-compile: distclean-compile: ! -rm -f *$(YACC_TABEXT).c maintainer-clean-compile: Patch for BISON. *** files.c~ Wed May 19 04:43:04 1999 --- files.c Mon Nov 29 01:46:02 1999 *************** openfiles (void) *** 195,205 **** --- 195,209 ---- /* Append `.tab'. */ strcpy (name_base, spec_file_prefix); #ifdef VMS strcat (name_base, "_tab"); #else + #ifdef MSDOS + strcat (name_base, "_tab"); + #else strcat (name_base, ".tab"); + #endif #endif #ifdef MSDOS strlwr (name_base); #endif /* MSDOS */ }