Hi Bruno, > Le 3 mai 2020 à 15:10, Bruno Haible <[email protected]> a écrit : > > The 'bistromathic' example uses readline. Due to the variations in which > it can be installed on the system, this causes build failured during > "make check" on several platforms. > > Code like > > # You probably need to customize this for your own environment. > CPPFLAGS = -I/opt/local/include > LDFLAGS = -L/opt/local/lib > > is not flying for examples that are part of "make check".
Of course not. The lines you are quoting are not part of the build system. The examples are compiled and checked. That's the job of the build system, which has a unique Makefile, the top-level one, assembled from the local.mk file. The examples are installed. The whole point of having examples is to have people look at them as part of the installed documentation. To help them, we install Makefiles. These files, as far as the bison package is concerned, is just plain data. That is what you are quoting. The test suite must be as independent as possible of gnulib, because gnulib protects us too well from portability issues in the generated files. It happened in the past, and I won't use again gnulib in the test suite. The case of the examples is somewhat in between. > 1) On FreeBSD 12.0 > ------------------ > > CC examples/c/bistromathic/bistromathic-parse.o > examples/c/bistromathic/parse.c:75:12: fatal error: 'readline/readline.h' > file not found > #include <readline/readline.h> > ^~~~~~~~~~~~~~~~~~~~~ > 1 error generated. > *** Error code 1 > > > On this machine, <readline/readline.h> and libreadline.so are installed in > /usr/local. > But this is apparently not in the compiler's default search path. > > > 2) On NetBSD 9.0 > ---------------- > > CC examples/c/bistromathic/bistromathic-parse.o > CCLD examples/c/bistromathic/bistromathic > ld: cannot find -lreadline > *** Error code 1 > > > On this machine, <readline/readline.h> is installed in /usr/include, but > there is > no libreadline.* anywhere. > > > 3) On Solaris 11.4 > ------------------ > > CC examples/c/bistromathic/bistromathic-parse.o > CCLD examples/c/bistromathic/bistromathic > Undefined first referenced > symbol in file > tgoto /usr/lib/amd64/libreadline.so > tputs /usr/lib/amd64/libreadline.so > tgetent /usr/lib/amd64/libreadline.so > tgetnum /usr/lib/amd64/libreadline.so > tgetstr /usr/lib/amd64/libreadline.so > tgetflag /usr/lib/amd64/libreadline.so > ld: fatal: symbol referencing errors > collect2: error: ld returned 1 exit status > gmake[3]: *** [Makefile:3961: examples/c/bistromathic/bistromathic] Error 1 > > On this machine, <readline/readline.h> and libreadline.so are installed > in /usr. 'ldd /usr/lib/amd64/libreadline.so' shows libc as the only > dependency. But the library also needs the symbols 'tgoto' etc., which > are defined in libcurses.so (and this library is also visible under the > symlinks libncurses.so, libtermcap.so, libtermlib.so). > > > Conclusion > ---------- > An autoconf test is really needed. Ideally it will look for the include file > and > library, based on an option --with-readline-prefix=DIR. You find some code to > this effect > - in gnulib/m4/readline.m4 > - in bash: > > https://git.savannah.gnu.org/gitweb/?p=bash.git;a=blob_plain;f=aclocal.m4;hb=HEAD > - in clisp: > https://gitlab.com/gnu-clisp/clisp/-/blob/master/src/m4/readline.m4 > https://gitlab.com/gnu-clisp/clisp/-/blob/master/src/m4/termcap.m4 Thanks for the pointers! I'm already using gnulib/m4/readline.m4, but I clearly forgot to make this part conditional. I'll install this. Thanks! commit 6c87e7f977692bf851e3c0712e3e4ce18b908da8 Author: Akim Demaille <[email protected]> Date: Sun May 3 16:05:03 2020 +0200 bistromathic: beware of portability of readline Don't try to build bistromathic if we don't have readline. Reported by Bruno Haible. https://lists.gnu.org/r/bug-bison/2020-05/msg00028.html * configure.ac (ENABLE_BISTROMATHIC): New. * examples/c/bistromathic/local.mk: Use it. diff --git a/configure.ac b/configure.ac index c1b0c182..7e673b51 100644 --- a/configure.ac +++ b/configure.ac @@ -331,6 +331,13 @@ AC_MSG_RESULT([$suppfile]) # Whether we cannot run the compiled bison. AM_CONDITIONAL([CROSS_COMPILING], [test "$cross_compiling" = yes]) +# Build bistromathic if we have the lib and both readline/readline.h +# and readline/history.h. +AM_CONDITIONAL([ENABLE_BISTROMATHIC], +[test "$gl_cv_lib_readline" != no && + test "$ac_cv_header_readline_readline_h" = yes && + test "$ac_cv_header_readline_history_h" = yes]) + AM_MISSING_PROG([AUTOM4TE], [autom4te]) # Needed by tests/atlocal.in. AC_SUBST([GCC]) diff --git a/examples/c/bistromathic/local.mk b/examples/c/bistromathic/local.mk index 607fdc52..cad0425b 100644 --- a/examples/c/bistromathic/local.mk +++ b/examples/c/bistromathic/local.mk @@ -19,19 +19,22 @@ bistromathicdir = $(docdir)/%D% ## Bistromathics. ## ## --------------- ## -check_PROGRAMS += %D%/bistromathic -TESTS += %D%/bistromathic.test -EXTRA_DIST += %D%/bistromathic.test -nodist_%C%_bistromathic_SOURCES = %D%/parse.y %D%/parse.h %D%/parse.c: $(dependencies) -# Don't use gnulib's system headers. -%C%_bistromathic_CPPFLAGS = \ - -DBISON_LOCALEDIR='"$(localdir)"' \ - -DLOCALEDIR='"$(localdir)"' \ - -I$(top_srcdir)/%D% -I$(top_builddir)/%D% -%C%_bistromathic_LDADD = -lm -lreadline $(LIBINTL) +if ENABLE_BISTROMATHIC + check_PROGRAMS += %D%/bistromathic + TESTS += %D%/bistromathic.test + nodist_%C%_bistromathic_SOURCES = %D%/parse.y + + # Don't use gnulib's system headers. + %C%_bistromathic_CPPFLAGS = \ + -DBISON_LOCALEDIR='"$(localdir)"' \ + -DLOCALEDIR='"$(localdir)"' \ + -I$(top_srcdir)/%D% -I$(top_builddir)/%D% + %C%_bistromathic_LDADD = -lm $(LIBREADLINE) $(LIBINTL) +endif +EXTRA_DIST += %D%/bistromathic.test dist_bistromathic_DATA = %D%/parse.y %D%/Makefile %D%/README.md CLEANFILES += %D%/parse.[ch] %D%/parse.output CLEANDIRS += %D%/*.dSYM
