add pkg-config files for readline, editline, ncurses

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

add pkg-config files for readline, editline, ncurses

Stephen Gregoratto
mrsh[1], a cross-platform shell, can use readline in interactive mode.
It's configure script detects the presence of readline using
pkg-config(1). Thus, this patch adds a pkg-config file for our readline.
I just copied over the generate_pkgconfig.sh script/make rules found in
other libraries and edited to fit.

I also added pkg-config files for libedit and libcurses, since libedit
requires linking with libcurses. I started getting build errors before I
realised that there are a couple editline libraries floating around,
each differing slightly with each other:

  NetBSD editline
  - Provides <readline/*.h>, <histedit.h>.
  - Uses ncurses.

  OpenBSD editline
  - Provides <histedit.h>.
  - Uses ncurses.

  Jess Thrys√łe editline[2]
  - Cross platform autotool port of NetBSD editline.
  - Provides <editline/*.h> and <histedit.h>
  - Uses ncurses.

  Joachim Nilsson editline[3]
  - Updated version of Rich Salz/Simmule Turner editline.
  - Call compatible with GNU Readline.
  - Provides <editline.h>.
  - Doesn't require ncurses.

A very confusing mess.

Some Linux systems (e.g. Arch) generate pkg-config files for the
different "types" of ncurses:

  /usr/lib/pkgconfig/ncurses++.pc -> ncurses++w.pc
  /usr/lib/pkgconfig/ncurses++w.pc
  /usr/lib/pkgconfig/ncurses.pc -> ncursesw.pc
  /usr/lib/pkgconfig/ncursesw.pc
  /usr/lib/pkgconfig/tic.pc -> ncursesw.pc
  /usr/lib/pkgconfig/tinfo.pc -> ncursesw.pc

Not sure if this is something I should do here.

[1] https://git.sr.ht/~emersion/mrsh
[2] https://thrysoee.dk/editline/
[3] https://github.com/troglobit/editline

Index: lib/libedit/Makefile
===================================================================
RCS file: /cvs/src/lib/libedit/Makefile,v
retrieving revision 1.32
diff -u -p -r1.32 Makefile
--- lib/libedit/Makefile 15 Jan 2019 01:54:00 -0000 1.32
+++ lib/libedit/Makefile 25 Jul 2019 14:00:00 -0000
@@ -19,6 +19,9 @@ LIBEDITDIR?=${.CURDIR}
 INCS= histedit.h
 INCSDIR=/usr/include
 
+PC_FILES=libedit.pc
+CLEANFILES+=${PC_FILES}
+
 CLEANFILES+=common.h.tmp emacs.h.tmp fcns.h.tmp func.h.tmp
 CLEANFILES+=help.h.tmp vi.h.tmp tc1.o tc1
 
@@ -78,6 +81,14 @@ includes:
  /dev/null 2>&1 || \
  ${INSTALL} ${INSTALL_COPY} -o ${BINOWN} -g ${BINGRP} -m 444 histedit.h \
  ${DESTDIR}/usr/include
+
+all: ${PC_FILES}
+${PC_FILES}: histedit.h
+ /bin/sh ${.CURDIR}/generate_pkgconfig.sh -c ${.CURDIR} -o ${.OBJDIR}
+
+beforeinstall:
+ ${INSTALL} ${INSTALL_COPY} -o root -g ${SHAREGRP} \
+    -m ${SHAREMODE} ${.OBJDIR}/${PC_FILES} ${DESTDIR}/usr/lib/pkgconfig/
 
 .include <bsd.lib.mk>
 .include <bsd.subdir.mk>
Index: lib/libedit/generate_pkgconfig.sh
===================================================================
RCS file: lib/libedit/generate_pkgconfig.sh
diff -N lib/libedit/generate_pkgconfig.sh
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ lib/libedit/generate_pkgconfig.sh 25 Jul 2019 14:00:00 -0000
@@ -0,0 +1,71 @@
+#!/bin/sh
+#
+# $OpenBSD$
+#
+# Copyright (c) 2010,2011 Jasper Lievisse Adriaanse <[hidden email]>
+#
+# Permission to use, copy, modify, and distribute this software for any
+# purpose with or without fee is hereby granted, provided that the above
+# copyright notice and this permission notice appear in all copies.
+#
+# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+#
+# Generate pkg-config file for libedit.
+
+usage() {
+ echo "usage: ${0##*/} -c current_directory -o obj_directory"
+ exit 1
+}
+
+curdir=
+objdir=
+while getopts "c:o:" flag; do
+ case "$flag" in
+ c)
+ curdir=$OPTARG
+ ;;
+ o)
+ objdir=$OPTARG
+ ;;
+ *)
+ usage
+ ;;
+ esac
+done
+
+[ -n "${curdir}" ] || usage
+if [ ! -d "${curdir}" ]; then
+ echo "${0##*/}: ${curdir}: not found"
+ exit 1
+fi
+[ -n "${objdir}" ] || usage
+if [ ! -w "${objdir}" ]; then
+ echo "${0##*/}: ${objdir}: not found or not writable"
+ exit 1
+fi
+
+version_major_re="s/^#define[[:blank:]]LIBEDIT_MAJOR[[:blank:]]([0-9]+).*/\1/p"
+version_minor_re="s/^#define[[:blank:]]LIBEDIT_MINOR[[:blank:]]([0-9]+).*/\1/p"
+version_file=${curdir}/histedit.h
+lib_version=$(sed -nE ${version_major_re} ${version_file}).$(sed -nE ${version_minor_re} ${version_file})
+
+pc_file="${objdir}/libedit.pc"
+cat > ${pc_file} << __EOF__
+prefix=/usr
+exec_prefix=\${prefix}
+libdir=\${exec_prefix}/lib
+includedir=\${prefix}/include
+
+Name: editline
+Description: line editor, history and tokenization library
+Version: ${lib_version}
+Requires: ncurses
+Libs: -L\${libdir} -ledit
+Cflags: -I\${includedir}
+__EOF__
Index: lib/libcurses/Makefile
===================================================================
RCS file: /cvs/src/lib/libcurses/Makefile,v
retrieving revision 1.74
diff -u -p -r1.74 Makefile
--- lib/libcurses/Makefile 13 Feb 2019 15:10:40 -0000 1.74
+++ lib/libcurses/Makefile 25 Jul 2019 14:00:00 -0000
@@ -99,6 +99,9 @@ CLEANFILES+= ${GENERATED}
 
 BUILDFIRST = ${GENERATED}
 
+PC_FILES=ncurses.pc
+CLEANFILES+=${PC_FILES}
+
 includes:
  @cmp -s ${DESTDIR}/usr/include/ncurses.h ${.CURDIR}/curses.h || \
   ${INSTALL} ${INSTALL_COPY} -m 444 -o $(BINOWN) -g $(BINGRP) \
@@ -153,6 +156,14 @@ unctrl.c: ${.CURDIR}/base/MKunctrl.awk
  echo | ${AWK} -f ${.CURDIR}/base/MKunctrl.awk bigstrings=1 > ${.TARGET}
 
 .include <bsd.own.mk>
+
+all: ${PC_FILES}
+${PC_FILES}: curses.h
+ /bin/sh ${.CURDIR}/generate_pkgconfig.sh -c ${.CURDIR} -o ${.OBJDIR}
+
+beforeinstall:
+ ${INSTALL} ${INSTALL_COPY} -o root -g ${SHAREGRP} \
+    -m ${SHAREMODE} ${.OBJDIR}/${PC_FILES} ${DESTDIR}/usr/lib/pkgconfig/
 
 # Link libtermlib, libtermcap to libcurses so we don't break people's Makefiles
 afterinstall:
Index: lib/libcurses/generate_pkgconfig.sh
===================================================================
RCS file: lib/libcurses/generate_pkgconfig.sh
diff -N lib/libcurses/generate_pkgconfig.sh
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ lib/libcurses/generate_pkgconfig.sh 25 Jul 2019 14:00:00 -0000
@@ -0,0 +1,69 @@
+#!/bin/sh
+#
+# $OpenBSD$
+#
+# Copyright (c) 2010,2011 Jasper Lievisse Adriaanse <[hidden email]>
+#
+# Permission to use, copy, modify, and distribute this software for any
+# purpose with or without fee is hereby granted, provided that the above
+# copyright notice and this permission notice appear in all copies.
+#
+# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+#
+# Generate pkg-config file for ncurses.
+
+usage() {
+ echo "usage: ${0##*/} -c current_directory -o obj_directory"
+ exit 1
+}
+
+curdir=
+objdir=
+while getopts "c:o:" flag; do
+ case "$flag" in
+ c)
+ curdir=$OPTARG
+ ;;
+ o)
+ objdir=$OPTARG
+ ;;
+ *)
+ usage
+ ;;
+ esac
+done
+
+[ -n "${curdir}" ] || usage
+if [ ! -d "${curdir}" ]; then
+ echo "${0##*/}: ${curdir}: not found"
+ exit 1
+fi
+[ -n "${objdir}" ] || usage
+if [ ! -w "${objdir}" ]; then
+ echo "${0##*/}: ${objdir}: not found or not writable"
+ exit 1
+fi
+
+version_re="s/^#define[[:blank:]]+NCURSES_VERSION[[:blank:]]+\"(.*)\".*/\1/p"
+version_file=${curdir}/curses.h
+lib_version=$(sed -nE ${version_re} ${version_file})
+
+pc_file="${objdir}/ncurses.pc"
+cat > ${pc_file} << __EOF__
+prefix=/usr
+exec_prefix=\${prefix}
+libdir=\${exec_prefix}/lib
+includedir=\${prefix}/include
+
+Name: ncurses
+Description: ncurses library
+Version: ${lib_version}
+Libs: -L\${libdir} -lcurses
+Cflags: -I\${includedir}
+__EOF__
Index: gnu/lib/libreadline/Makefile
===================================================================
RCS file: /cvs/src/gnu/lib/libreadline/Makefile,v
retrieving revision 1.9
diff -u -p -r1.9 Makefile
--- gnu/lib/libreadline/Makefile 15 Jan 2019 01:54:00 -0000 1.9
+++ gnu/lib/libreadline/Makefile 25 Jul 2019 14:00:00 -0000
@@ -13,6 +13,9 @@ CPPFLAGS+=-DHAVE_CONFIG_H -I${.CURDIR}
 LDADD+= -L${BSDOBJDIR}/lib/libcurses -lcurses
 DPADD+= ${LIBCURSES}
 
+PC_FILES=readline.pc
+CLEANFILES+=${PC_FILES}
+
 includes:
  ${INSTALL} -d -o ${BINOWN} -g ${BINGRP} -m 755 \
     ${DESTDIR}/usr/include/readline
@@ -23,6 +26,14 @@ includes:
     echo $$j; \
     eval "$$j"; \
  done
+
+all: ${PC_FILES}
+${PC_FILES}: readline.h
+ /bin/sh ${.CURDIR}/generate_pkgconfig.sh -c ${.CURDIR} -o ${.OBJDIR}
+
+beforeinstall:
+ ${INSTALL} ${INSTALL_COPY} -o root -g ${SHAREGRP} \
+    -m ${SHAREMODE} ${.OBJDIR}/${PC_FILES} ${DESTDIR}/usr/lib/pkgconfig/
 
 .include <bsd.lib.mk>
 .include <bsd.subdir.mk>
Index: gnu/lib/libreadline/generate_pkgconfig.sh
===================================================================
RCS file: gnu/lib/libreadline/generate_pkgconfig.sh
diff -N gnu/lib/libreadline/generate_pkgconfig.sh
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ gnu/lib/libreadline/generate_pkgconfig.sh 25 Jul 2019 14:00:00 -0000
@@ -0,0 +1,70 @@
+#!/bin/sh
+#
+# $OpenBSD$
+#
+# Copyright (c) 2010,2011 Jasper Lievisse Adriaanse <[hidden email]>
+#
+# Permission to use, copy, modify, and distribute this software for any
+# purpose with or without fee is hereby granted, provided that the above
+# copyright notice and this permission notice appear in all copies.
+#
+# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+#
+# Generate pkg-config file for readline.
+
+usage() {
+ echo "usage: ${0##*/} -c current_directory -o obj_directory"
+ exit 1
+}
+
+curdir=
+objdir=
+while getopts "c:o:" flag; do
+ case "$flag" in
+ c)
+ curdir=$OPTARG
+ ;;
+ o)
+ objdir=$OPTARG
+ ;;
+ *)
+ usage
+ ;;
+ esac
+done
+
+[ -n "${curdir}" ] || usage
+if [ ! -d "${curdir}" ]; then
+ echo "${0##*/}: ${curdir}: not found"
+ exit 1
+fi
+[ -n "${objdir}" ] || usage
+if [ ! -w "${objdir}" ]; then
+ echo "${0##*/}: ${objdir}: not found or not writable"
+ exit 1
+fi
+
+version_major_re="s/^#define[[:blank:]]+RL_VERSION_MAJOR[[:blank:]]+([0-9]+).*/\1/p"
+version_minor_re="s/^#define[[:blank:]]+RL_VERSION_MINOR[[:blank:]]+([0-9]+).*/\1/p"
+version_file=${curdir}/readline.h
+lib_version=$(sed -nE ${version_major_re} ${version_file}).$(sed -nE ${version_minor_re} ${version_file})
+
+pc_file="${objdir}/readline.pc"
+cat > ${pc_file} << __EOF__
+prefix=/usr
+exec_prefix=\${prefix}
+libdir=\${exec_prefix}/lib
+includedir=\${prefix}/include
+
+Name: Readline
+Description: GNU readline library
+Version: ${lib_version}
+Libs: -L\${libdir} -lreadline
+Cflags: -I\${includedir}
+__EOF__
--
Stephen Gregoratto

Reply | Threaded
Open this post in threaded view
|

Re: add pkg-config files for readline, editline, ncurses

Ingo Schwarze
Hi Stephen,

Stephen Gregoratto wrote on Fri, Jul 26, 2019 at 01:23:21AM +1000:

> mrsh[1], a cross-platform shell, can use readline in interactive mode.
> It's configure script detects the presence of readline using
> pkg-config(1). Thus, this patch adds a pkg-config file for our readline.

It is not obvious to me whether or not that is desirable.  It depends
on which version of readline mrsh requires.  If mrsh builds and is
usable with our base system readline (which is quite old), what you
propose may help.  On the other hand, if it requires a newer readline
or doesn't work well with the base readline, adding a library dependency
on ports readline might be better.

> I just copied over the generate_pkgconfig.sh script/make rules found in
> other libraries and edited to fit.
>
> I also added pkg-config files for libedit and libcurses,

I think that ought to be a completely separate change because a program
either uses base libedit or base readline or ports readline but never
more than one of these.  I know relatively little about pkg-config(1);
the reason i'm speaking up here is that nobody else spoke up so far and
that i occasionally worked on libedit in the past.  Now, as far as i
understand (take this with a grain of salt), the effect of adding a
pkg-config file for libedit would possibly be that additional ports
might pick up our base libedit that now think that no libedit is
available and consequently compile without it.  That might improve
some ports - and/or break others.  So i suspect that adding libedit.pc
to base would probably require a bulk build before commit to make sure
nothing breaks.  Also - even though it seems less likely that anything
in the base system looks at *.pc files - it would probably require a
complete make build & release of base and xenocara.

For adding readline.pc, the same caveats apply, only even more so.
I suspect that the risk of breaking ports by adding readline.pc to
base is larger than for editline because probaly more ports use readline
than editline and those that do are probably more likely to use
pkg-config(1) and those that do both are probably more likely to be
unhappy with our base readline, whereas ports looking for editline
probably have a better chance to be happy with our base editline.

As far as i understand, adding editline.pc does not necessarily
require also adding ncurses.pc, nor does it require Requires:
lines.  So far, we don't have a single non-empty Requires: line
in base even though libssl depends on libcrypto.  Again, the effect
of adding ncurses.pc to base might be that some ports suddenly
pick up our base curses, for good or ill.  If there is a benefit
to that, i suspect it might make sense to test that change
independently from libedit.pc.  I don't think we want a bulk build
with three combined changes and lots of fallout, because then we
would be forced to figure out which fallout was caused by which
part of the changes, which sounds like gratuitious additional pain.

> since libedit requires linking with libcurses.  I started getting
> build errors before I realised that there are a couple editline
> libraries floating around, each differing slightly with each other:

*If* we want editline.pc, then i expect we probably just want one,
for our own editline.  Additional ones would only make sense to me
in the context of a port of one of the other editline implementations.
But i don't really see the point of such a port.  If some port does
not work with our editline but does work with a different editline,
we should probably either fix our editline or patch the port to
work with our editline, depending on what exactly to port is doing.

> Some Linux systems (e.g. Arch) generate pkg-config files for the
> different "types" of ncurses:
>
>   /usr/lib/pkgconfig/ncurses++.pc -> ncurses++w.pc
>   /usr/lib/pkgconfig/ncurses++w.pc
>   /usr/lib/pkgconfig/ncurses.pc -> ncursesw.pc
>   /usr/lib/pkgconfig/ncursesw.pc
>   /usr/lib/pkgconfig/tic.pc -> ncursesw.pc
>   /usr/lib/pkgconfig/tinfo.pc -> ncursesw.pc
>
> Not sure if this is something I should do here.

I doubt it.  In any case, the base system should contain one *curses*.pc
at most, i think, because we only have one curses in base.  Any other
*curses*.pc would be a matter of ports - and like for editline, i doubt
that having a port of a different version of curses makes sense.

That said, even though you are changing the base system, i suspect
discussing this kind of patches may be more fruitful on ports@
because that's where all the ports developers are that will be
affected by such changes.

I suggest that you decide which of the three changes you care about
most, then send a patch to ports@ with only that one change,
explaining what exactly it is supposed to improve (and how you
tested that it indeed does), and what exactly you already tested
in addition to that (for example, building which ports that use
pkg-config(1) and the library in question), asking for feedback.
The feedback you get there will then determine how to proceed.  If
people there like the idea in general and the patch is deemed mature
enough, base and xenocara build/release testing and a ports bulk build
will likely be required, and after that, fixing the fallout.  If
it ultimately gets committed and you are still interested, you can
then proceed to the second library in the same way.

I hope this makes sense, i'm somewhat out of my usual league here.

Yours,
  Ingo

Reply | Threaded
Open this post in threaded view
|

Re: add pkg-config files for readline, editline, ncurses

Stuart Henderson
In reply to this post by Stephen Gregoratto
On 2019/07/26 01:23, Stephen Gregoratto wrote:
> mrsh[1], a cross-platform shell, can use readline in interactive mode.
> It's configure script detects the presence of readline using
> pkg-config(1). Thus, this patch adds a pkg-config file for our readline.
> I just copied over the generate_pkgconfig.sh script/make rules found in
> other libraries and edited to fit.

Just patch the configure script.

It's going to be horrible to validate adding these pc files across the
ports tree, and unless there are a bunch of ports needing patches due
to us not having this, the work isn't justifiable.

>               there are a couple editline libraries floating around,
> each differing slightly with each other:

exactly, this gives me the feeling that this is opening a can of worms.

(While on the subject of pkg-config files, the bogus version number in
the libressl ones is a small problem for ports, though I have no idea
what we'd change it to instead ...)