Subject: Techniques for dealing with readline/editline and getopt
To: None <tech-pkg@netbsd.org>
From: Johnny C. Lam <lamj@stat.cmu.edu>
List: tech-pkg
Date: 05/10/2001 15:37:08
I've recently had a problem with developing new packages for
the new 7.1.1 release of PostgreSQL. It can use either libreadline or
libedit, and optionally can use getopt_long() if it's available. Take
readline for example. Since -I${LOCALBASE}/include must be passed to
the compiler to pick up some required headers, if readline is
installed, then the PostgreSQL configure script will _always_ use the
readline headers from ${LOCALBASE}/include/readline/readline.h instead
of the ones from /usr/include/readline/readline.h. It's not right to
force -I/usr/include at the start of the header search list since
private headers may have a name clash with system headers.
The solution I devised for this was the following Makefile
fragment. It links the right headers into a known location, which is
then prepended to the header search list. Does any one have any
thoughts about this? Perhaps a better way to solve this problem?
I've been thinking about doing something like this on a larger scale
to deal with pkg/10860.
Thanks,
-- Johnny C. Lam <lamj@stat.cmu.edu>
Department of Statistics, Carnegie Mellon University
http://www.stat.cmu.edu/~lamj/
.if exists(/usr/include/readline.h)
READLINE_H= /usr/include/readline.h
HISTORY_H= /usr/include/history.h
.elif exists(/usr/include/readline/readline.h)
READLINE_H= /usr/include/readline/readline.h
HISTORY_H= /usr/include/readline/history.h
.else
READLINE_H= ${LOCALBASE}/readline/readline.h
HISTORY_H= ${LOCALBASE}/readline/history.h
DEPENDS+= readline>=4.0:../../devel/readline
.endif
WRKINCDIR= ${WRKDIR}/include
CFLAGS+= -I${WRKINCDIR}
CPPFLAGS+= -I${WRKINCDIR}
CONFIGURE_ENV+= CPPFLAGS="${CPPFLAGS}"
# This target links the readline and history headers into
# ${WRKINCDIR}/include, which is searched first by the C preprocessor.
#
link-readline-headers:
${MKDIR} -p ${WRKINCDIR}/readline
${RM} -f ${WRKINCDIR}/readline/readline.h
${RM} -f ${WRKINCDIR}/readline/history.h
${LN} -sf ${READLINE_H} ${WRKINCDIR}/readline
${LN} -sf ${HISTORY_H} ${WRKINCDIR}/readline
pre-configure: link-readline-headers