aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2025-04-29 04:02:22 +0000
committerLaurent Bercot <ska@appnovation.com>2025-04-29 04:02:22 +0000
commit8ccf1783ae3f41b9675e4ad47b844e837a65a2fd (patch)
tree193e45018340285ced3881cad13c268229a0c49f
parente92e5cbc9c42a7f926eb4b25fdf6e52ec9d2fa4c (diff)
downloadskalibs-8ccf1783ae3f41b9675e4ad47b844e837a65a2fd.tar.gz
Add pkg-config support
Signed-off-by: Laurent Bercot <ska@appnovation.com>
-rw-r--r--.gitignore3
-rw-r--r--Makefile30
-rwxr-xr-xconfigure29
-rwxr-xr-xtools/gen-dotpc.sh80
4 files changed, 134 insertions, 8 deletions
diff --git a/.gitignore b/.gitignore
index d71b7fc..9ea26d4 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,6 +1,7 @@
*.o
-/*.a.xyzzy
*.lo
+/*.pc
+/*.a.xyzzy
/*.so.xyzzy
/config.mak
/src/include/skalibs/config.h
diff --git a/Makefile b/Makefile
index 9321086..3752e2d 100644
--- a/Makefile
+++ b/Makefile
@@ -49,11 +49,16 @@ src/include/$(package)/ip46.h
ALL_INCLUDES := $(sort $(BUILT_INCLUDES) $(wildcard src/include/$(package)/*.h))
ALL_SYSDEPS := $(wildcard $(sysdeps)/*)
ALL_DATA := $(wildcard src/etc/*)
+PC_TARGETS :=
+ifdef DO_PKGCONFIG
+PC_TARGETS += libskarnet.pc
+endif
+
-all: config.mak $(ALL_LIBS) $(ALL_INCLUDES) $(ALL_SYSDEPS) $(ALL_DATA)
+all: config.mak $(ALL_LIBS) $(ALL_INCLUDES) $(ALL_SYSDEPS) $(ALL_DATA) $(PC_TARGETS)
clean:
- @exec rm -f $(ALL_LIBS) $(ALL_BINS) $(ALL_SOBJS) $(ALL_DOBJS) $(BUILT_INCLUDES)
+ @exec rm -f $(ALL_LIBS) $(ALL_BINS) $(ALL_SOBJS) $(ALL_DOBJS) $(BUILT_INCLUDES) $(PC_TARGETS)
distclean: clean
@exec rm -rf config.mak src/include/$(package)/config.h sysdeps.cfg
@@ -74,12 +79,13 @@ ifneq ($(strip $(SHARED_LIBS)),)
exec $(STRIP) -R .note -R .comment $(SHARED_LIBS)
endif
-install: install-sysconf install-sysdeps install-dynlib install-lib install-include
+install: install-sysconf install-sysdeps install-dynlib install-lib install-include install-pkgconfig
install-sysconf: $(ALL_DATA:src/etc/%=$(DESTDIR)$(sysconfdir)/%)
install-sysdeps: $(ALL_SYSDEPS:$(sysdeps)/%=$(DESTDIR)$(sysdepdir)/%)
install-dynlib: $(SHARED_LIBS:lib%.so.xyzzy=$(DESTDIR)$(dynlibdir)/lib%.so)
install-lib: $(STATIC_LIBS:lib%.a.xyzzy=$(DESTDIR)$(libdir)/lib%.a)
install-include: $(ALL_INCLUDES:src/include/$(package)/%.h=$(DESTDIR)$(includedir)/$(package)/%.h)
+install-pkgconfig: $(PC_TARGETS:%=$(DESTDIR)$(pkgconfdir)/%)
ifneq ($(exthome),)
@@ -114,6 +120,9 @@ $(DESTDIR)$(libdir)/lib%.a: lib%.a.xyzzy
$(DESTDIR)$(includedir)/$(package)/%.h: src/include/$(package)/%.h
exec $(INSTALL) -D -m 644 $< $@
+$(DESTDIR)$(pkgconfdir)/lib%.pc: lib%.pc
+ exec $(INSTALL) -D -m 644 $< $@
+
%.o: %.c
exec $(CC) $(CPPFLAGS_ALL) $(CFLAGS_ALL) -c -o $@ $<
@@ -127,6 +136,21 @@ libskarnet.a.xyzzy: $(ALL_SOBJS)
libskarnet.so.xyzzy: $(ALL_DOBJS)
exec $(CC) -o $@ $(CFLAGS_ALL) $(CFLAGS_SHARED) $(LDFLAGS_ALL) $(LDFLAGS_SHARED) -Wl,-soname,libskarnet.so.$(version_M) -Wl,-rpath=$(dynlibdir) $^ $(SOCKET_LIB) $(SPAWN_LIB) $(SYSCLOCK_LIB) $(TAINNOW_LIB) $(TIMER_LIB) $(UTIL_LIB)
+libskarnet.pc:
+ exec env \
+ library="skarnet" \
+ includedir="$(includedir)" \
+ dynlibdir="$(dynlibdir)" \
+ libdir="$(libdir)" \
+ extra_includedirs="$(extra_includedirs)" \
+ extra_libdirs="$(extra_libdirs)" \
+ extra_libs="$(strip $(SOCKET_LIB) $(SPAWN_LIB) $(SYSCLOCK_LIB) $(TAINNOW_LIB) $(TIMER_LIB) $(UTIL_LIB))" \
+ description="The skarnet.org C programming library (skalibs)" \
+ url="https://skarnet.org/software/skalibs/" \
+ ldlibs="$(LDLIBS)" \
+ ./tools/gen-dotpc.sh > $@.tmp
+ exec mv -f $@.tmp $@
+
.PHONY: it all clean distclean tgz strip install install-data install-sysdeps install-dynlib install-lib install-include
.DELETE_ON_ERROR:
diff --git a/configure b/configure
index c063946..5bc0b41 100755
--- a/configure
+++ b/configure
@@ -23,6 +23,7 @@ Fine tuning of the installation directories:
--libdir=DIR static library files [PREFIX/lib]
--includedir=DIR include files for the C compiler [PREFIX/include]
--sysconfdir=DIR global configuration files [PREFIX/etc]
+ --pkgconfdir=DIR pkg-config .pc files [PREFIX/lib/pkgconfig]
--sysdepdir=DIR sysdeps directory [PREFIX/lib/$package/sysdeps]
If no --prefix option is given, by default libdir will be /usr/lib,
@@ -38,8 +39,9 @@ Optional features:
--disable-static do not build static libraries [enabled]
--disable-all-pic do not build static libraries as PIC [enabled]
--enable-slashpackage[=ROOT] assume /package installation at ROOT [disabled]
+ --enable-pkgconfig Build and install .pc files for pkg-config [disabled]
-$package options:
+$package tuning options:
--disable-ipv6 do not build IPv6 support [enabled]
--enable-iopause-select prefer select() over poll() for iopause implementation [disabled]
--enable-tai-clock build for a TAI-10 system clock instead of a UTC one [disabled]
@@ -394,6 +396,7 @@ dynlibdir='$prefix/lib'
libdir='$prefix/lib'
includedir='$prefix/include'
sysconfdir='$prefix/etc'
+pkgconfdir='$prefix/lib/pkgconfig'
sysdepdir='$prefix/lib/$package/sysdeps'
sysdeplist=
shared=true
@@ -406,12 +409,15 @@ taiclock=false
ddefaultpath=/usr/bin:/bin
defaultpath=$ddefaultpath
dpathorig=true
+pcw=false
sproot=
home=
exthome=
addincpath=''
addlibspath=''
addlibdpath=''
+depincpath=''
+deplibpath=''
vpaths=''
vpathd=''
build=
@@ -425,9 +431,10 @@ for arg ; do
--libdir=*) libdir=${arg#*=} ;;
--includedir=*) includedir=${arg#*=} ;;
--sysconfdir=*) sysconfdir=${arg#*=} ;;
+ --pkgconfdir=*) pkgconfdir=${arg#*=} ;;
--sysdepdir=*) sysdepdir=${arg#*=} ;;
- --with-include=*) var=${arg#*=} ; stripdir var ; addincpath="$addincpath -I$var" ;;
- --with-lib=*) var=${arg#*=} ; stripdir var ; addlibspath="$addlibspath -L$var" ; vpaths="$vpaths $var" ;;
+ --with-include=*) var=${arg#*=} ; stripdir var ; addincpath="$addincpath -I$var" ; depincpath="${depincpath}${depincpath:+ }-I$var" ;;
+ --with-lib=*) var=${arg#*=} ; stripdir var ; addlibspath="$addlibspath -L$var" ; deplibpath="${deplibpath}${deplibpath:+ }-L$var" ; vpaths="$vpaths $var" ;;
--with-dynlib=*) var=${arg#*=} ; stripdir var ; addlibdpath="$addlibdpath -L$var" ; vpathd="$vpathd $var" ;;
--enable-shared|--enable-shared=yes) shared=true ;;
--disable-shared|--enable-shared=no) shared=false ;;
@@ -435,6 +442,8 @@ for arg ; do
--disable-static|--enable-static=no) static=false ;;
--enable-all-pic|--enable-all-pic=yes) allpic=true ;;
--disable-all-pic|--enable-all-pic=no) allpic=false ;;
+ --enable-pkgconfig|--enable-pkgconfig=yes) pcw=true ;;
+ --disable-pkgconfig|--enable-pkgconfig=no) pcw=false ;;
--enable-slashpackage=*) sproot=${arg#*=} ; slashpackage=true ; ;;
--enable-slashpackage) sproot= ; slashpackage=true ;;
--disable-slashpackage) sproot= ; slashpackage=false ;;
@@ -467,6 +476,9 @@ if test -z "$prefix" ; then
if test "$includedir" = '$prefix/include' ; then
includedir=/usr/include
fi
+ if test "$pkgconfdir" = '$prefix/lib/pkgconfig' ; then
+ pkgconfdir=/usr/lib/pkgconfig
+ fi
if test "$sysdepdir" = '$prefix/lib/$package/sysdeps' ; then
sysdepdir=/usr/lib/$package/sysdeps
fi
@@ -474,7 +486,7 @@ fi
# Expand installation directories
stripdir prefix
-for i in exec_prefix dynlibdir libdir includedir sysconfdir sysdepdir sysdepspre sproot ; do
+for i in exec_prefix dynlibdir libdir includedir sysconfdir pkgconfdir sysdepdir sysdepspre sproot ; do
eval tmp=\${$i}
eval $i=$tmp
stripdir $i
@@ -490,6 +502,7 @@ if $slashpackage ; then
dynlibdir=${home}/library.so
libdir=${home}/library
includedir=${home}/include
+ pkgconfdir=${home}/pkgconfig
if $dpathorig ; then
if echo $defaultpath | tr : '\n' | grep -q '^/command$' ; then : ; else
defaultpath="/command:$defaultpath"
@@ -721,11 +734,14 @@ sysdepdir := $sysdepdir
dynlibdir := $dynlibdir
libdir := $libdir
includedir := $includedir
+pkgconfdir := $pkgconfdir
sysdeps := $sysdeps
version := $version
sproot := $sproot
home := $home
exthome := ${exthome}
+extra_includedirs :=$depincpath
+extra_libdirs :=$deplibpath
ipv6 := ${ipv6}
SPAWN_LIB := ${spawn_lib}
SOCKET_LIB := ${socket_lib}
@@ -760,6 +776,11 @@ if $shared ; then
else
echo "SHARED_LIBS :="
fi
+if $pcw ; then
+ echo "DO_PKGCONFIG := 1"
+else
+ echo "DO_PKGCONFIG :="
+fi
if $allpic ; then
echo "STATIC_LIBS_ARE_PIC := 1"
else
diff --git a/tools/gen-dotpc.sh b/tools/gen-dotpc.sh
new file mode 100755
index 0000000..a9e344a
--- /dev/null
+++ b/tools/gen-dotpc.sh
@@ -0,0 +1,80 @@
+#!/bin/sh -e
+
+isunique () {
+ x=$1
+ set -- $2
+ while test "$#" -gt 0 ; do
+ if test "$x" = "$1" ; then
+ return 1
+ fi
+ shift
+ done
+ return 0
+}
+
+uniqit () {
+ res=
+ while test "$#" -gt 0 ; do
+ if isunique "$1" "$res" ; then
+ res="${res}${res:+ }${1}"
+ fi
+ shift
+ done
+ printf %s\\n "$res"
+}
+
+filterout () {
+ res=
+ filter="$1"
+ shift
+ while test "$#" -gt 0 ; do
+ if isunique "$1" "$filter" ; then
+ res="${res}${res:+ }${1}"
+ fi
+ shift
+ done
+ printf %s\\n "$res"
+}
+
+. package/info
+
+ilist=
+dlist=
+slist=
+
+if test "${includedir}" != /usr/include ; then
+ ilist="-I${includedir}"
+fi
+if test -n "${extra_includedirs}" ; then
+ ilist="${ilist}${ilist:+ }${extra_includedirs}"
+fi
+ilist=`uniqit ${ilist}`
+
+if test "${dynlibdir}" != /usr/lib && test "${dynlibdir}" != /lib ; then
+ dlist="-L${dynlibdir}"
+fi
+
+if test "${libdir}" != /usr/lib && test "${libdir}" != /lib ; then
+ slist="-L${libdir}"
+fi
+if test -n "${extra_libdirs}" ; then
+ slist="${slist}${slist:+ }${extra_libdirs}"
+fi
+slist="$(filterout "${dlist}" $(uniqit ${slist}))"
+
+echo "prefix=${prefix}"
+echo "includedir=${includedir}"
+echo "libdir=${libdir}"
+echo "dynlibdir=${dynlibdir}"
+echo
+echo "Name: lib${library}"
+echo "Version: ${version}"
+echo "Description: ${description:-The ${library} library.}"
+echo "URL: ${url:-https://skarnet.org/software/${package}/}"
+if test -n "$ilist" ; then
+ echo "Cflags: ${ilist}"
+fi
+echo "Libs: ${dlist}${dlist:+ }-l${library}${ldlibs:+ }${ldlibs}"
+if test -n "${extra_libs}" ; then
+ echo "Libs.private: ${slist}${slist:+ }${extra_libs}"
+fi