< Previous by Date Date Index Next by Date >
  Thread Index  

[reSIProcate] [RFC] pkgconfig support


Hi,

I've got a patch here for you to comment on. Now that we can choose
between ares and c-ares, the application developers will have to
link against the correct version, too. To ease this step, I've
implemented support for generating a pkgconfig file during install.

Some comments:

build/Makefile.pkg

* For every library you can specify an additional variable naming the
  pkgconfig name. It is called *_PKGNAME. 

build/Makefile.post

* if it's a library we're installing PKGCONFIG_FILE points to the
  pkgconfig location. After all libs and headers are installed, the file
  is written by simple echo calls. I've preferred this procedure over a
  template libfoo.pc.in, because it produced the non-intrusivest patch

* We sort and make the dependent libraries unique by calling '$(sort ) 

* For every dependent library 'pkg' in this unique list we do the following:
  
  We add all $($(pkg)_PKGNAME) to the Requires: field. Libraries with
  a not set (thus empty) PKGNAME will therefore not end up here

  If the *_PKGNAME was empty, we add -l*_LIBNAME if *_LIBNAME is not
  empty to avoid nasty things like -lbar -l -lfoo happening

To be done:
* Add Name: Version: and Description: to generated .pc files
* Understand and use Libs.private:

I await your comments!

Thanks,
Gregor
Index: build/Makefile.post
===================================================================
--- build/Makefile.post	(Revision 8343)
+++ build/Makefile.post	(Arbeitskopie)
@@ -309,14 +309,25 @@
 else
 ifdef TARGET_LIBRARY
 INSTALL_LIBDIR := $(DESTDIR)$(INSTALL_PREFIX)/lib
+INSTALL_PKGDIR := $(INSTALL_LIBDIR)/pkgconfig
 INSTALL_INCDIR := $(DESTDIR)$(INSTALL_PREFIX)/include/$(subst lib,,$(TARGET_LIBRARY))
+PKGCONFIG_FILE := $(INSTALL_PKGDIR)/$(TARGET_LIBRARY).pc
 
+pkg_dep_libs = $(if $(1),,$(if $(2),-l$(2)))
+
 install: all
 	$(INSTALL) -d $(DESTDIR)$(INSTALL_PREFIX)
 	$(INSTALL) -d $(DESTDIR)$(INSTALL_PREFIX)/lib
 	$(INSTALL) $(OBJ)/$(TARGET_LIBRARY).$(LIBSUFFIX) $(INSTALL_LIBDIR)/$(TARGET_LIBRARY).$(LIBSUFFIX)
 	$(INSTALL) -d $(INSTALL_INCDIR)
 	$(INSTALL) -m 644 *.h* $(INSTALL_INCDIR)
+	$(INSTALL) -d $(INSTALL_PKGDIR)
+	@echo 'prefix=$(INSTALL_PREFIX)' > $(PKGCONFIG_FILE)
+	@echo 'libdir=$(INSTALL_PREFIX)/lib' >> $(PKGCONFIG_FILE)
+	@echo >> $(PKGCONFIG_FILE)
+	@echo 'Requires: $(foreach pkg,$(sort $(PACKAGES)),$($(pkg)_PKGNAME))' >> $(PKGCONFIG_FILE)
+	@echo 'Libs: -L$${libdir} -l$(subst lib,,$(TARGET_LIBRARY)) $(foreach pkg,$(sort $(PACKAGES)),$(call pkg_dep_libs,$($(pkg)_PKGNAME),$($(pkg)_LIBNAME)))' >> $(PKGCONFIG_FILE)
+	@echo 'Cflags: -I$${prefix}/include' >> $(PKGCONFIG_FILE)
 ifdef CODE_SUBDIRS
 	@ for subdir in $(CODE_SUBDIRS) ;  do ( $(INSTALL) -d $(INSTALL_INCDIR)/$$subdir ; $(INSTALL) -m 644 $$subdir/*.h* $(INSTALL_INCDIR)/$$subdir) ; done 
 endif
Index: build/Makefile.pkg
===================================================================
--- build/Makefile.pkg	(Revision 8343)
+++ build/Makefile.pkg	(Arbeitskopie)
@@ -42,6 +42,7 @@
   OPENSSL_INCLUDEDIRS := 
   OPENSSL_LIBDIRS :=
   OPENSSL_DEFINES += USE_SSL
+  OPENSSL_PKGNAME := libssl
 
   ifeq ($(OSTYPE),MinGW)
       MINGW_OPENSSL_DIR    := /c/openssl
@@ -102,6 +103,7 @@
    ARES_LIBDIRS := $(CARES_LIBDIRS)
    ARES_LIBNAME := cares
    ARES_DEFINES :=
+   ARES_PKGNAME := libcares
 endif
 
 S2C_INCLUDEDIRS := $(ROOT)/p2p/s2c/s2c
@@ -191,12 +193,14 @@
 
 ifeq ($(USE_CURL),yes)
 CURL_LIBNAME := curl
+CURL_PKGNAME := libcurl
 CURL_DEFINES := USE_CURL
 endif
 
 RUTIL_INCLUDEDIRS := $(ROOT)
 RUTIL_LIBDIRS := $(ROOT)/rutil/obj.$(TARGET_NAME) 
 RUTIL_LIBNAME := rutil
+RUTIL_PKGNAME := librutil
 RUTIL_DEPENDS := $(ROOT)/rutil/obj.$(TARGET_NAME)/librutil.$(LIBSUFFIX)
 $(RUTIL_DEPENDS): 
 	$(MAKE) -C $(ROOT)/rutil
@@ -204,12 +208,14 @@
 RESIP_INCLUDEDIRS := $(ROOT)
 RESIP_LIBDIRS := $(ROOT)/resip/stack/obj.$(TARGET_NAME) 
 RESIP_LIBNAME := resip
+RESIP_PKGNAME := libresip
 RESIP_DEPENDS := $(ROOT)/resip/stack/obj.$(TARGET_NAME)/libresip.$(LIBSUFFIX)
 $(RESIP_DEPENDS): 
 	$(MAKE) -C $(ROOT)/resip/stack
 
 DUM_LIBDIRS := $(ROOT)/resip/dum/obj.$(TARGET_NAME) 
 DUM_LIBNAME := dum
+DUM_PKGNAME := libdum
 DUM_DEPENDS := $(ROOT)/resip/dum/obj.$(TARGET_NAME)/libdum.$(LIBSUFFIX)
 $(DUM_DEPENDS): 
 	$(MAKE) -C $(ROOT)/resip/dum