GNU Autoconf, Automake, and Libtool

 

9.3.1 `sic_repl.c'

In `sic_repl.c' (13) there is a loop for reading strings typed by the user , evaluating them and printing the results. GNU readline is ideally suited to this, but it is not always available -- or sometimes people simply may not wish to use it.

With the help of GNU Autotools, it is very easy to cater for building with and without GNU readline. `sic_repl.c' uses this function to read lines of input from the user:

 

static char * getline (FILE *in, const char *prompt) { static char *buf = NULL; /* Always allocated and freed from inside this function. */ XFREE (buf); buf = (char *) readline ((char *) prompt); #ifdef HAVE_ADD_HISTORY if (buf && *buf) add_history (buf); #endif return buf; }

To make this work, I must write an Autoconf macro which adds an option to `configure' , so that when the package is installed, it will use the readline library if `--with-readline' is used:

 

AC_DEFUN(SIC_WITH_READLINE, [AC_ARG_WITH(readline, [ --with-readline compile with the system readline library], [if test x"${withval-no}" != xno; then sic_save_LIBS=$LIBS AC_CHECK_LIB(readline, readline) if test x"${ac_cv_lib_readline_readline}" = xno; then AC_MSG_ERROR(libreadline not found) fi LIBS=$sic_save_LIBS fi]) AM_CONDITIONAL(WITH_READLINE, test x"${with_readline-no}" != xno) ])

Having put this macro in the file `config/readline.m4' , I must also call the new macro ( SIC_WITH_READLINE ) from `configure.in' .

This document was generated by Gary V. Vaughan on May, 24 2001 using texi2html

Категории