lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

On Thu, Jun 11, 2020 at 7:02 PM William Ahern <> wrote:
On Thu, Jun 11, 2020 at 02:34:46PM -0300, Luiz Henrique de Figueiredo wrote:
> > In a perfect world, the Makefile would include code to detect whether the readline library exists and automatically use it if found.
> If you can contribute simple portable code that does this, it'd be great.

I had an hour to kill. The following was tested and works correctly with the
native make implementations on AIX, FreeBSD, NetBSD, OpenBSD, and Solaris,
as well as with GNU Make. (But see AIX notes.) Excepting the command
substitution constructs and the macro expansion pattern replacement
construct ($(MACRO:PATT=REPL)), as far as I know everything else is POSIX
compliant. In particular, the use of recursive expansion and dynamically
evaluated macro names is sound as far as I understand. Macro expansion
pattern replacement is so well supported that the POSIX standard notes that
it may be mandated in the future.

BOOL,1 = 1
BOOL,0 = 0
BOOL,  = 0

OR,1,1 = 1
OR,1,0 = 1
OR,0,1 = 1
OR,0,0 = 0

HAVE_READLINE.cmd = printf "\043include <readline/readline.h>\n" | $(CC) $(CFLAGS) -E - 2>/dev/null | grep -q rl_readline_name && echo 1 || echo 0
HAVE_READLINE.gnu = $(shell $(HAVE_READLINE.cmd))
HAVE_READLINE.if.aix,1 = 0

        @printf "HAVE_READLINE=%s\n" "$(HAVE_READLINE)"

I spent an hour and a half this evening and couldn't come up with anything better than the above. The only tweaks I would suggest would be to replace the OR lines with:

OR,1,1= linux-readline
OR,1,0= linux-readline
OR,0,1= linux-readline
OR,0,0= linux-noreadline

and then the line

Linux linux:   linux-noreadline


Linux linux: $(HAVE_READLINE)  # or call it $(LINUX_TARGET)