]> mj.ucw.cz Git - libucw.git/commitdiff
Use pkg-config to handle library dependencies.
authorMartin Mares <mj@ucw.cz>
Tue, 17 Jul 2007 17:00:58 +0000 (19:00 +0200)
committerMartin Mares <mj@ucw.cz>
Tue, 17 Jul 2007 17:00:58 +0000 (19:00 +0200)
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.

build/lib-deps [new file with mode: 0755]
build/lib-flags [new file with mode: 0755]
charset/Makefile
charset/libcharset.pc [new file with mode: 0644]
images/Makefile
images/libimages.pc [new file with mode: 0644]
lib/Makefile
lib/libucw.pc [new file with mode: 0644]

diff --git a/build/lib-deps b/build/lib-deps
new file mode 100755 (executable)
index 0000000..1019bc2
--- /dev/null
@@ -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 <mj@ucw.cz>, 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 (executable)
index 0000000..6c2f8b9
--- /dev/null
@@ -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 <mj@ucw.cz>, 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
index 4f3f45b45ed6bb4f73e009b0eb060504fec07295..c592f5f5b5215abcb95b9f30170ed91652924b72 100644 (file)
@@ -1,4 +1,4 @@
-# Makefile for the Sherlock Charset Library (c) 1997--2002 Martin Mares <mj@ucw.cz>
+# Makefile for the Sherlock Charset Library (c) 1997--2007 Martin Mares <mj@ucw.cz>
 
 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 (file)
index 0000000..ed8a32d
--- /dev/null
@@ -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@
index 31155edf62378aafce299e5f65bd52a730dd15ee..30392a75a4df5bcbc2414dc68a6cacdf7be566a4 100644 (file)
@@ -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 (file)
index 0000000..61ccfed
--- /dev/null
@@ -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@
index 9826060020193acfe6b2c30e5b57fe735c6e0311..6394d623b4d2406fae4d8b6657212ae45a5ef88a 100644 (file)
@@ -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 (file)
index 0000000..5045add
--- /dev/null
@@ -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}