From: Stuart Henderson Subject: pkg-config files for curses? To: tech Date: Tue, 18 Feb 2025 23:48:31 +0000 I ran into some problems with curses when trying to build Python 3.13.x. Their build system really would like to have pkg-config files. We have a workaround for 3.12.x but it doesn't work as-is for 3.13 and their build system is byzantine. I have an alternative workaround which I think would be acceptable for ports (include local copies of pc files in the port and point pkg-config at them during configure/build) but I was wondering what anyone's thoughts are about including them in base. It would simplify things in ports, and we are providing pc files for a number of other libraries so there's some prior art. Python just wants pc files for ncurses and panel but if we do install, I think it would be safer to use the same set as curses upstream: ncurses, panel, menu, form. The diff below uses a modified version of our usual generate_pkgconfig.sh script. I'm using a "don't really do anything" value for Cflags like we do for libssl etc (this is different from upstream who set -D_BSD_SOURCE -D_XOPEN_SOURCE=700 in theirs; that seems a step too far and broke at least one port in earlier tests). It's currently running through a ports bulk build. Index: lib/libcurses/Makefile =================================================================== RCS file: /cvs/src/lib/libcurses/Makefile,v diff -u -p -r1.76 Makefile --- lib/libcurses/Makefile 8 Feb 2024 20:28:54 -0000 1.76 +++ lib/libcurses/Makefile 18 Feb 2025 23:29:54 -0000 @@ -73,11 +73,12 @@ MAN= curs_add_wch.3 curs_add_wchstr.3 cu GENERATED= codes.c comp_captab.c comp_userdefs.c expanded.c fallback.c \ init_keytry.h keys.list lib_gen.c lib_keyname.c make_hash make_keys \ names.c unctrl.c +PC_FILES= ncurses.pc CAPLIST = ${.CURDIR}/Caps USE_BIG_STRINGS = 1 -CLEANFILES+= ${GENERATED} make_hash.d make_keys.d +CLEANFILES+= ${GENERATED} ${PC_FILES} make_hash.d make_keys.d BUILDFIRST = ${GENERATED} @@ -143,10 +144,19 @@ codes.c: ${.CURDIR}/tinfo/MKcodes.awk unctrl.c: ${.CURDIR}/base/MKunctrl.awk echo | ${AWK} -f ${.CURDIR}/base/MKunctrl.awk bigstrings=1 > ${.TARGET} +all: ${PC_FILES} + +${PC_FILES}: ${.CURDIR}/../libcurses/curses.h ${.CURDIR}/../libcurses/ncurses_cfg.h + /bin/sh ${.CURDIR}/generate_pkgconfig.sh -c ${.CURDIR} -o ${.OBJDIR} + .include # Link libtermlib, libtermcap to libcurses so we don't break people's Makefiles afterinstall: +.for p in ${PC_FILES} + ${INSTALL} ${INSTALL_COPY} -o root -g ${SHAREGRP} \ + -m ${SHAREMODE} ${.OBJDIR}/$p ${DESTDIR}/usr/lib/pkgconfig/ +.endfor -cd ${DESTDIR}${LIBDIR}; \ for i in ${_LIBS}; do \ ln -f $$i `echo $$i | sed 's/curses/termlib/'`; \ 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 18 Feb 2025 23:29:54 -0000 @@ -0,0 +1,81 @@ +#!/bin/ksh +# +# $OpenBSD: generate_pkgconfig.sh,v 1.11 2022/02/04 16:42:15 tb Exp $ +# +# Copyright (c) 2010,2011 Jasper Lievisse Adriaanse +# +# 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 files 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_STRING[[:blank:]]+\"(.*)\".*/\1/p" +version_file=${curdir}/ncurses_cfg.h +lib_version=$(sed -nE ${version_re} ${version_file}) + +version_re="s/^#define[[:blank:]]+NCURSES_VERSION_MAJOR[[:blank:]]+(.*)([[:blank:]].*)?/\1/p" +version_file=${curdir}/curses.h +abi_version=$(sed -nE ${version_re} ${version_file}) + +# Put -I${includedir} into Cflags so configure script tests like +# test -n "`pkg-config --cflags ncurses`" +# don't assume that ncurses isn't available. + +pc_file="${objdir}/ncurses.pc" +cat > ${pc_file} << __EOF__ +prefix=/usr +exec_prefix=\${prefix} +libdir=\${exec_prefix}/lib +includedir=\${prefix}/include +abi_version=${abi_version} +major_version=${abi_version} +version=${lib_version} + +Name: ncurses +Description: ncurses library +Version: ${lib_version} +Requires.private: +Libs: -L\${libdir} -lncurses +Cflags: -I\${includedir} +__EOF__ Index: lib/libform/Makefile =================================================================== RCS file: /cvs/src/lib/libform/Makefile,v diff -u -p -r1.17 Makefile --- lib/libform/Makefile 17 Oct 2023 09:52:10 -0000 1.17 +++ lib/libform/Makefile 18 Feb 2025 23:29:54 -0000 @@ -18,6 +18,8 @@ MAN= form.3 form_cursor.3 form_data.3 fo form_hook.3 form_new.3 form_new_page.3 form_opts.3 form_page.3 \ form_post.3 form_requestname.3 form_userptr.3 form_variables.3 \ form_win.3 +PC_FILES= form.pc +CLEANFILES+= ${PC_FILES} includes: @cd ${.CURDIR}; for i in ${HDRS}; do \ @@ -25,9 +27,18 @@ includes: ${INSTALL} ${INSTALL_COPY} -m 444 -o $(BINOWN) -g $(BINGRP) $$i \ ${DESTDIR}/usr/include; done +all: ${PC_FILES} + +${PC_FILES}: ${.CURDIR}/../libcurses/curses.h ${.CURDIR}/../libcurses/ncurses_cfg.h + /bin/sh ${.CURDIR}/generate_pkgconfig.sh -c ${.CURDIR} -o ${.OBJDIR} + .include afterinstall: +.for p in ${PC_FILES} + ${INSTALL} ${INSTALL_COPY} -o root -g ${SHAREGRP} \ + -m ${SHAREMODE} ${.OBJDIR}/$p ${DESTDIR}/usr/lib/pkgconfig/ +.endfor -cd ${DESTDIR}${LIBDIR}; \ for i in ${_LIBS}; do \ ln -f $$i `echo $$i | sed 's/form/formw/'`; \ Index: lib/libform/generate_pkgconfig.sh =================================================================== RCS file: lib/libform/generate_pkgconfig.sh diff -N lib/libform/generate_pkgconfig.sh --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lib/libform/generate_pkgconfig.sh 18 Feb 2025 23:29:54 -0000 @@ -0,0 +1,82 @@ +#!/bin/ksh +# +# $OpenBSD: generate_pkgconfig.sh,v 1.11 2022/02/04 16:42:15 tb Exp $ +# +# Copyright (c) 2010,2011 Jasper Lievisse Adriaanse +# +# 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 files for libform. + +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_STRING[[:blank:]]+\"(.*)\".*/\1/p" +version_file=${curdir}/../libcurses/ncurses_cfg.h +lib_version=$(sed -nE ${version_re} ${version_file}) + +version_re="s/^#define[[:blank:]]+NCURSES_VERSION_MAJOR[[:blank:]]+(.*)([[:blank:]].*)?/\1/p" +version_file=${curdir}/../libcurses/curses.h +abi_version=$(sed -nE ${version_re} ${version_file}) + +# Put -I${includedir} into Cflags so configure script tests like +# test -n "`pkg-config --cflags form`" +# don't assume that libform isn't available. + +pc_file="${objdir}/form.pc" +cat > ${pc_file} << __EOF__ +prefix=/usr +exec_prefix=\${prefix} +libdir=\${exec_prefix}/lib +includedir=\${prefix}/include +abi_version=${abi_version} +major_version=${abi_version} +version=${lib_version} + +Name: form +Description: ncurses add-on library +Version: ${lib_version} +Requires.private: ncurses +Libs: -L\${libdir} -lform +Libs.private: +Cflags: -I\${includedir} +__EOF__ Index: lib/libmenu/Makefile =================================================================== RCS file: /cvs/src/lib/libmenu/Makefile,v diff -u -p -r1.20 Makefile --- lib/libmenu/Makefile 17 Oct 2023 09:52:10 -0000 1.20 +++ lib/libmenu/Makefile 18 Feb 2025 23:29:54 -0000 @@ -13,6 +13,8 @@ MAN= menu.3 menu_attributes.3 menu_curso menu_pattern.3 menu_post.3 menu_requestname.3 menu_spacing.3 \ menu_userptr.3 menu_win.3 mitem_current.3 mitem_name.3 mitem_new.3 \ mitem_opts.3 mitem_userptr.3 mitem_value.3 mitem_visible.3 +PC_FILES= menu.pc +CLEANFILES+= ${PC_FILES} includes: @cd ${.CURDIR}; for i in ${HDRS}; do \ @@ -20,9 +22,18 @@ includes: ${INSTALL} ${INSTALL_COPY} -m 444 -o $(BINOWN) -g $(BINGRP) $$i \ ${DESTDIR}/usr/include; done +all: ${PC_FILES} + +${PC_FILES}: ${.CURDIR}/../libcurses/curses.h ${.CURDIR}/../libcurses/ncurses_cfg.h + /bin/sh ${.CURDIR}/generate_pkgconfig.sh -c ${.CURDIR} -o ${.OBJDIR} + .include afterinstall: +.for p in ${PC_FILES} + ${INSTALL} ${INSTALL_COPY} -o root -g ${SHAREGRP} \ + -m ${SHAREMODE} ${.OBJDIR}/$p ${DESTDIR}/usr/lib/pkgconfig/ +.endfor -cd ${DESTDIR}${LIBDIR}; \ for i in ${_LIBS}; do \ ln -f $$i `echo $$i | sed 's/menu/menuw/'`; \ Index: lib/libmenu/generate_pkgconfig.sh =================================================================== RCS file: lib/libmenu/generate_pkgconfig.sh diff -N lib/libmenu/generate_pkgconfig.sh --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lib/libmenu/generate_pkgconfig.sh 18 Feb 2025 23:29:54 -0000 @@ -0,0 +1,82 @@ +#!/bin/ksh +# +# $OpenBSD: generate_pkgconfig.sh,v 1.11 2022/02/04 16:42:15 tb Exp $ +# +# Copyright (c) 2010,2011 Jasper Lievisse Adriaanse +# +# 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 files for libmenu. + +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_STRING[[:blank:]]+\"(.*)\".*/\1/p" +version_file=${curdir}/../libcurses/ncurses_cfg.h +lib_version=$(sed -nE ${version_re} ${version_file}) + +version_re="s/^#define[[:blank:]]+NCURSES_VERSION_MAJOR[[:blank:]]+(.*)([[:blank:]].*)?/\1/p" +version_file=${curdir}/../libcurses/curses.h +abi_version=$(sed -nE ${version_re} ${version_file}) + +# Put -I${includedir} into Cflags so configure script tests like +# test -n "`pkg-config --cflags menu`" +# don't assume that libmenu isn't available. + +pc_file="${objdir}/menu.pc" +cat > ${pc_file} << __EOF__ +prefix=/usr +exec_prefix=\${prefix} +libdir=\${exec_prefix}/lib +includedir=\${prefix}/include +abi_version=${abi_version} +major_version=${abi_version} +version=${lib_version} + +Name: menu +Description: ncurses add-on library +Version: ${lib_version} +Requires.private: ncurses +Libs: -L\${libdir} -lmenu +Libs.private: +Cflags: -I\${includedir} +__EOF__ Index: lib/libpanel/Makefile =================================================================== RCS file: /cvs/src/lib/libpanel/Makefile,v diff -u -p -r1.13 Makefile --- lib/libpanel/Makefile 17 Oct 2023 09:52:10 -0000 1.13 +++ lib/libpanel/Makefile 18 Feb 2025 23:29:54 -0000 @@ -7,6 +7,8 @@ SRCS= p_above.c p_below.c p_bottom.c p_d HDRS= panel.h CFLAGS+=-I${.CURDIR}/../libcurses -D_XOPEN_SOURCE_EXTENDED -DNDEBUG MAN= panel.3 +PC_FILES= panel.pc +CLEANFILES+= ${PC_FILES} includes: @cd ${.CURDIR}; for i in ${HDRS}; do \ @@ -14,9 +16,18 @@ includes: ${INSTALL} ${INSTALL_COPY} -m 444 -o $(BINOWN) -g $(BINGRP) $$i \ ${DESTDIR}/usr/include; done +all: ${PC_FILES} + +${PC_FILES}: ${.CURDIR}/../libcurses/curses.h ${.CURDIR}/../libcurses/ncurses_cfg.h + /bin/sh ${.CURDIR}/generate_pkgconfig.sh -c ${.CURDIR} -o ${.OBJDIR} + .include afterinstall: +.for p in ${PC_FILES} + ${INSTALL} ${INSTALL_COPY} -o root -g ${SHAREGRP} \ + -m ${SHAREMODE} ${.OBJDIR}/$p ${DESTDIR}/usr/lib/pkgconfig/ +.endfor -cd ${DESTDIR}${LIBDIR}; \ for i in ${_LIBS}; do \ ln -f $$i `echo $$i | sed 's/panel/panelw/'`; \ Index: lib/libpanel/generate_pkgconfig.sh =================================================================== RCS file: lib/libpanel/generate_pkgconfig.sh diff -N lib/libpanel/generate_pkgconfig.sh --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lib/libpanel/generate_pkgconfig.sh 18 Feb 2025 23:29:54 -0000 @@ -0,0 +1,82 @@ +#!/bin/ksh +# +# $OpenBSD: generate_pkgconfig.sh,v 1.11 2022/02/04 16:42:15 tb Exp $ +# +# Copyright (c) 2010,2011 Jasper Lievisse Adriaanse +# +# 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 files for libpanel. + +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_STRING[[:blank:]]+\"(.*)\".*/\1/p" +version_file=${curdir}/../libcurses/ncurses_cfg.h +lib_version=$(sed -nE ${version_re} ${version_file}) + +version_re="s/^#define[[:blank:]]+NCURSES_VERSION_MAJOR[[:blank:]]+(.*)([[:blank:]].*)?/\1/p" +version_file=${curdir}/../libcurses/curses.h +abi_version=$(sed -nE ${version_re} ${version_file}) + +# Put -I${includedir} into Cflags so configure script tests like +# test -n "`pkg-config --cflags panel`" +# don't assume that libpanel isn't available. + +pc_file="${objdir}/panel.pc" +cat > ${pc_file} << __EOF__ +prefix=/usr +exec_prefix=\${prefix} +libdir=\${exec_prefix}/lib +includedir=\${prefix}/include +abi_version=${abi_version} +major_version=${abi_version} +version=${lib_version} + +Name: panel +Description: ncurses add-on library +Version: ${lib_version} +Requires.private: ncurses +Libs: -L\${libdir} -lpanel +Libs.private: +Cflags: -I\${includedir} +__EOF__ Index: distrib/sets/lists/base/mi =================================================================== RCS file: /cvs/src/distrib/sets/lists/base/mi,v diff -u -p -r1.1155 mi --- distrib/sets/lists/base/mi 5 Feb 2025 14:12:26 -0000 1.1155 +++ distrib/sets/lists/base/mi 18 Feb 2025 23:29:54 -0000 @@ -790,11 +790,15 @@ ./usr/lib/locate/src.db ./usr/lib/pkgconfig ./usr/lib/pkgconfig/expat.pc +./usr/lib/pkgconfig/form.pc ./usr/lib/pkgconfig/fuse.pc ./usr/lib/pkgconfig/libcrypto.pc ./usr/lib/pkgconfig/libelf.pc ./usr/lib/pkgconfig/libssl.pc +./usr/lib/pkgconfig/menu.pc +./usr/lib/pkgconfig/ncurses.pc ./usr/lib/pkgconfig/openssl.pc +./usr/lib/pkgconfig/panel.pc ./usr/lib/pkgconfig/sndio.pc ./usr/lib/pkgconfig/zlib.pc ./usr/lib/rcrt0.o