Skip to contentSkip to conversation

pkg-config support

PATCH Applied Stefan Hajnoczi 2 participants 4 messages May 25, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover pkg-config support

Patch 1 adds pkg-config support so that applications are not required to hardcode compiler flags that may change depending on the distro.

Patch 2 moves installation paths to ./configure so they are adjustable from the command-line and do not require modifying the makefile. This is necessary so Fedora x86_64 can set libdir to /usr/lib64.

I have tested this by building Aarushi Mehta's QEMU io_uring support using pkg-config on a Fedora x86_64 host.

Stefan Hajnoczi (2):
pkgconfig: install a liburing.pc file
configure: move directory options to ./configure

 configure      | 55 +++++++++++++++++++++++++++++++++++++++++++++++++-
 Makefile       | 17 ++++++++++------
 .gitignore     |  2 ++
 liburing.pc.in | 12 +++++++++++
 4 files changed, 79 insertions(+), 7 deletions(-)
 create mode 100644 liburing.pc.in
Signature · 1 line
2.21.0
#1 lore raw

PATCH 1/2 pkgconfig: install a liburing.pc file

pkg-config (https://pkgconfig.freedesktop.org/) makes it easier to build applications that have library dependencies. Libraries ship .pc files containing the compiler and linker flags needed to build successfully. This saves applications from hardcoding these details into their build scripts, especially when these details can change between operating systems or distributions.

To build a liburing application:

  gcc $(pkg-config --cflags --libs liburing) -o myapp myapp.c
---
 Makefile       | 13 +++++++++++--
 .gitignore     |  2 ++
 liburing.pc.in | 12 ++++++++++++
 3 files changed, 25 insertions(+), 2 deletions(-)
 create mode 100644 liburing.pc.in
Makefile +11 -2
index d42dd45..6755713 100644
@@ -33,13 +33,22 @@ ifneq ($(MAKECMDGOALS),clean)
 include config-host.mak
 endif
 
-install:
+%.pc: %.pc.in
+	sed -e "s%@prefix@%$(prefix)%g" \
+	    -e "s%@libdir@%$(libdir)%g" \
+	    -e "s%@includedir@%$(includedir)%g" \
+	    -e "s%@NAME@%$(NAME)%g" \
+	    -e "s%@VERSION@%$(VERSION)%g" \
+	    $< >$@
+
+install: $(NAME).pc
 	@$(MAKE) -C src install prefix=$(DESTDIR)$(prefix) includedir=$(DESTDIR)$(includedir) libdir=$(DESTDIR)$(libdir)
+	$(INSTALL) -D -m 644 $(NAME).pc $(DESTDIR)$(libdir)/pkgconfig/$(NAME).pc
 	$(INSTALL) -m 755 -d $(DESTDIR)$(mandir)/man2
 	$(INSTALL) -m 644 man/*.2 $(DESTDIR)$(mandir)/man2
 
 clean:
-	@rm -f config-host.mak config-host.h cscope.out
+	@rm -f config-host.mak config-host.h cscope.out $(NAME).pc
 	@$(MAKE) -C src clean
 	@$(MAKE) -C test clean
 	@$(MAKE) -C examples clean
.gitignore +2 -0
index e292825..08ba0e0 100644
@@ -12,3 +12,5 @@
 config-host.h
 config-host.mak
 config.log
+
+liburing.pc
liburing.pc.in new file +12 -0
new file mode 100644
index 0000000..e621939
@@ -0,0 +1,12 @@
+prefix=@prefix@
+exec_prefix=${prefix}
+libdir=@libdir@
+includedir=@includedir@
+
+Name: @NAME@
+Version: @VERSION@
+Description: io_uring library
+URL: http://git.kernel.dk/cgit/liburing/
+
+Libs: -L${libdir} -luring
+Cflags: -I${includedir}
Signature · 1 line
2.21.0
#2 lore raw

PATCH 2/2 configure: move directory options to ./configure

In reply to Stefan Hajnoczi

libdir is hardcoded to ${prefix}/lib in Makefile. Fedora x86_64 uses /usr/lib64 and this means libaries will be installed in the wrong place.

This patch moves prefix, includedir, libdir, and mandir into ./configure for easier customization. To build and install on Fedora x86_64:

  # ./configure --libdir=/usr/lib64
  # make && make install
---
 configure | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 Makefile  |  4 ----
 2 files changed, 54 insertions(+), 5 deletions(-)
configure +54 -1
index ef71a14..19c2b54 100755
@@ -10,6 +10,10 @@ else
 fi
 
 cc=gcc
+prefix=/usr
+includedir="$prefix/include"
+libdir="$prefix/lib"
+mandir="$prefix/man"
 
 TMPC="${TMPDIR1}/fio-conf-${RANDOM}-$$-${RANDOM}.c"
 TMPC2="${TMPDIR1}/fio-conf-${RANDOM}-$$-${RANDOM}-2.c"
@@ -98,11 +102,60 @@ has() {
   type "$1" >/dev/null 2>&1
 }
 
+output_mak() {
+  echo "$1=$2" >> $config_host_mak
+}
+
 output_sym() {
-  echo "$1=y" >> $config_host_mak
+  output_mak "$1" "y"
   echo "#define $1" >> $config_host_h
 }
 
+print_and_output_mak() {
+  print_config "$1" "$2"
+  output_mak "$1" "$2"
+}
+
+for opt do
+  optarg=$(expr "x$opt" : 'x[^=]*=\(.*\)')
+  case "$opt" in
+  --help|-h) show_help=yes
+  ;;
+  --prefix=*) prefix="$optarg"
+  ;;
+  --includedir=*) includedir="$optarg"
+  ;;
+  --libdir=*) libdir="$optarg"
+  ;;
+  --mandir=*) mandir="$optarg"
+  ;;
+  *)
+    echo "ERROR: unkown option $opt"
+    echo "Try '$0 --help' for more information"
+    exit 1
+  ;;
+  esac
+done
+
+if test "$show_help" = "yes"; then
+cat <<EOF
+
+Usage: configure [options]
+Options: [defaults in brackets after descriptions]
+  --help                   print this message
+  --prefix=PATH            install in PATH [$prefix]
+  --includedir=PATH        install headers in PATH [$includedir]
+  --libdir=PATH            install libraries in PATH [$libdir]
+  --mandir=PATH            install man pages in PATH [$mandir]
+EOF
+exit 0
+fi
+
+print_and_output_mak "prefix" "$prefix"
+print_and_output_mak "includedir" "$includedir"
+print_and_output_mak "libdir" "$libdir"
+print_and_output_mak "mandir" "$mandir"
+
 ##########################################
 # check for __kernel_rwf_t
 __kernel_rwf_t="no"
Makefile +0 -4
index 6755713..ea639d6 100644
@@ -5,10 +5,6 @@ TAG = $(NAME)-$(VERSION)
 RPMBUILD=$(shell `which rpmbuild >&/dev/null` && echo "rpmbuild" || echo "rpm")
 
 INSTALL=install
-prefix ?= /usr
-includedir=$(prefix)/include
-libdir=$(prefix)/lib
-mandir=$(prefix)/man
 
 default: all
 
Signature · 1 line
2.21.0
maintainer Applied
#3 lore raw
In reply to Stefan Hajnoczi
Quoted 9 lines · Stefan Hajnoczi

Patch 1 adds pkg-config support so that applications are not required to hardcode compiler flags that may change depending on the distro.

Patch 2 moves installation paths to ./configure so they are adjustable from the command-line and do not require modifying the makefile. This is necessary so Fedora x86_64 can set libdir to /usr/lib64.

I have tested this by building Aarushi Mehta's QEMU io_uring support using pkg-config on a Fedora x86_64 host.

Applied, thanks.

Signature · 1 line
Jens Axboe