From: Martin Mares Date: Tue, 17 Jul 2007 17:00:58 +0000 (+0200) Subject: Use pkg-config to handle library dependencies. X-Git-Tag: holmes-import~506^2~53 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=580fd9c443c2a4faba5a703d49f366de5d3968c9;p=libucw.git Use pkg-config to handle library dependencies. The original system of library dependencies was very confusing and brittle, so I have decided to use pkg-config instead. Each library now has its .pc file, which is processed by genconf, so conditionals and variable substitutions can be used. You need to specify three Makefile rules: (1) libsomething.a to build the static version (2) libsomething.so to build the shared version (3) libsomething.pc for the pkg-config metadata; this target should depend on .pc files of all libraries required by this library. @DEPS@ in the .pc file will be substituted by the names of such libraries, so you can just say "Requires: @DEPS@" to handle dependencies on other Sherlock libraries. To link with a library, just add a depedency on its .pc file. The default rules are smart enough to run pkg-config and construct the appropriate linker flags. If you want to link with an external library, the LIBS variable still works. If you want an internal library to depend on an external library, just mention it in the linker flags in the .pc file. --- diff --git a/build/lib-deps b/build/lib-deps new file mode 100755 index 00000000..1019bc2c --- /dev/null +++ b/build/lib-deps @@ -0,0 +1,22 @@ +#!/bin/bash +# +# A tool which builds a list of dependent libraries from the list +# of pkg-config files. +# +# (c) 2007 Martin Mares , placed under GNU LGPL +# + +set -e + +shift +SEEN= +while [ -n "$1" ] ; do + case "$1" in + *.pc) if [ -n "$SEEN" ] ; then echo -n ", " ; fi + echo -n "`basename $1 .pc`" + SEEN=1 + ;; + *) ;; + esac + shift +done diff --git a/build/lib-flags b/build/lib-flags new file mode 100755 index 00000000..6c2f8b9b --- /dev/null +++ b/build/lib-flags @@ -0,0 +1,24 @@ +#!/bin/bash +# +# A preprocessor for linker arguments, which replaces references to .pc +# files by results of the proper calls to pkg-config. +# +# (c) 2007 Martin Mares , placed under GNU LGPL +# + +set -e + +PC= +while [ -n "$1" ] ; do + case "$1" in + *.pc) PC="$PC `basename $1 .pc`" + ;; + *) echo -n " $1" + ;; + esac + shift +done +if [ -n "$PC" ] ; then + echo -n " " + PKG_CONFIG_PATH="$PKG_CONFIG_PATH:obj/pkg-config" pkg-config --libs $PC +fi diff --git a/charset/Makefile b/charset/Makefile index 4f3f45b4..c592f5f5 100644 --- a/charset/Makefile +++ b/charset/Makefile @@ -1,4 +1,4 @@ -# Makefile for the Sherlock Charset Library (c) 1997--2002 Martin Mares +# Makefile for the Sherlock Charset Library (c) 1997--2007 Martin Mares DIRS+=charset @@ -7,6 +7,7 @@ LIBCHARSET_INCLUDES=charconv.h unicat.h fb-charconv.h stk-charconv.h mp-charconv $(o)/charset/libcharset.a: $(addsuffix .o,$(addprefix $(o)/charset/,$(LIBCHARSET_MODS))) $(o)/charset/libcharset.so: $(addsuffix .oo,$(addprefix $(o)/charset/,$(LIBCHARSET_MODS))) +$(o)/charset/libcharset.pc: $(LIBUCW) INCLUDES+=$(o)/charset/.include-stamp $(o)/charset/.include-stamp: $(addprefix $(s)/charset/,$(LIBCHARSET_INCLUDES)) diff --git a/charset/libcharset.pc b/charset/libcharset.pc new file mode 100644 index 00000000..ed8a32de --- /dev/null +++ b/charset/libcharset.pc @@ -0,0 +1,7 @@ +# pkg-config metadata for libcharset + +Name: libcharset +Description: Character set conversion library +Version: @SHERLOCK_VERSION@ +Libs: -Lobj/charset -lcharset +Requires: @DEPS@ diff --git a/images/Makefile b/images/Makefile index 31155edf..30392a75 100644 --- a/images/Makefile +++ b/images/Makefile @@ -6,6 +6,7 @@ PROGS+=$(o)/images/image-tool $(o)/images/color-tool CONFIGS+=images LIBIMAGES_MODS=math config context image scale color io-main LIBIMAGES_INCLUDES=images.h error.h color.h math.h +export LIBIMAGES_LIBS= ifdef CONFIG_SHERLOCK LIBIMAGES_MODS+=object @@ -28,8 +29,6 @@ LIBIMAGES_MODS+=sig-dump sig-init sig-seg sig-txt LIBIMAGES_INCLUDES+=signature.h endif -LIBIMAGES_LIBS=-lm -lpthread - ifdef CONFIG_IMAGES_LIBJPEG LIBIMAGES_MODS+=io-libjpeg LIBIMAGES_LIBS+=-ljpeg @@ -60,27 +59,19 @@ endif $(o)/images/libimages.a: $(addsuffix .o,$(addprefix $(o)/images/,$(LIBIMAGES_MODS))) $(o)/images/libimages.so: $(addsuffix .oo,$(addprefix $(o)/images/,$(LIBIMAGES_MODS))) +$(o)/images/libimages.pc: $(LIBUCW) -$(o)/images/image-tool: $(o)/images/image-tool.o $(LIBIMAGES) $(LIBIMAGES_DEPS) -$(o)/images/image-tool: LIBS+=$(LIBIMAGES_LIBS) - -$(o)/images/color-tool: $(o)/images/color-tool.o $(LIBIMAGES) $(LIBIMAGES_DEPS) -$(o)/images/color-tool: LIBS+=$(LIBIMAGES_LIBS) - -$(o)/images/image-dup-test: $(o)/images/image-dup-test.o $(LIBIMAGES) $(LIBIMAGES_DEPS) -$(o)/images/image-dup-test: LIBS+=$(LIBIMAGES_LIBS) - -$(o)/images/image-sim-test: $(o)/images/image-sim-test.o $(LIBIMAGES) $(LIBIMAGES_DEPS) -$(o)/images/image-sim-test: LIBS+=$(LIBIMAGES_LIBS) +$(o)/images/image-tool: $(o)/images/image-tool.o $(LIBIMAGES) +$(o)/images/color-tool: $(o)/images/color-tool.o $(LIBIMAGES) +$(o)/images/image-dup-test: $(o)/images/image-dup-test.o $(LIBIMAGES) +$(o)/images/image-sim-test: $(o)/images/image-sim-test.o $(LIBIMAGES) TESTS+=$(o)/images/image-test.test -$(o)/images/image-test: $(o)/images/image-test.o $(LIBIMAGES) $(LIBIMAGES_DEPS) -$(o)/images/image-test: LIBS+=$(LIBIMAGES_LIBS) +$(o)/images/image-test: $(o)/images/image-test.o $(LIBIMAGES) $(o)/images/image-test.test: $(o)/images/image-test TESTS+=$(o)/images/color.test -$(o)/images/color-t: $(LIBIMAGES) $(LIBIMAGES_DEPS) -$(o)/images/color-t: LIBS+=$(LIBIMAGES_LIBS) $(LIBIMAGES_DEPS) +$(o)/images/color-t: $(LIBIMAGES) $(o)/images/color.test: $(o)/images/color-t INCLUDES+=$(o)/images/.include-stamp diff --git a/images/libimages.pc b/images/libimages.pc new file mode 100644 index 00000000..61ccfeda --- /dev/null +++ b/images/libimages.pc @@ -0,0 +1,7 @@ +# pkg-config metadata for libimages + +Name: libimages +Description: Sherlock image library +Version: @SHERLOCK_VERSION@ +Libs: -Lobj/images -limages -lm -lpthread @LIBIMAGES_LIBS@ +Requires: @DEPS@ diff --git a/lib/Makefile b/lib/Makefile index 98260600..6394d623 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -62,7 +62,6 @@ LIBUCW_INCLUDES= \ ifdef CONFIG_UCW_THREADS # Some modules require threading -LIBS+=-lpthread LIBUCW_MODS+=threads-conf workqueue LIBUCW_INCLUDES+=workqueue.h semaphore.h endif @@ -75,7 +74,7 @@ ifdef CONFIG_OWN_GETOPT include $(s)/lib/getopt/Makefile endif -LIBUCW=$(o)/lib/libucw.$(LS) +LIBUCW=$(o)/lib/libucw.pc LIBUCW_MOD_PATHS=$(addprefix $(o)/lib/,$(LIBUCW_MODS)) $(o)/lib/libucw.a: $(addsuffix .o,$(LIBUCW_MOD_PATHS)) diff --git a/lib/libucw.pc b/lib/libucw.pc new file mode 100644 index 00000000..5045addc --- /dev/null +++ b/lib/libucw.pc @@ -0,0 +1,10 @@ +# pkg-config metadata for libucw + +#ifdef CONFIG_UCW_THREADS +threads=-lpthread +#endif + +Name: libucw +Description: A library of utility functions and data structures +Version: @SHERLOCK_VERSION@ +Libs: -Lobj/lib -lucw ${threads}