@@ -87,6 +87,7 @@ shlib_bare= lib$(NAME)$(DLSUFFIX)
8787# Testing the soname variable is a reliable way to determine whether a
8888# linkable library is being built.
8989soname= $(shlib_major)
90+ pkgconfigdir = $(libdir)/pkgconfig
9091else
9192# Naming convention for dynamically loadable modules
9293shlib= $(NAME)$(DLSUFFIX)
@@ -305,6 +306,7 @@ all-lib: all-shared-lib
305306ifdef soname
306307# no static library when building a dynamically loadable module
307308all-lib: all-static-lib
309+ all-lib: lib$(NAME).pc
308310endif
309311
310312all-static-lib: $(stlib)
@@ -388,6 +390,23 @@ $(stlib): $(shlib) $(DLL_DEFFILE) | $(SHLIB_PREREQS)
388390endif # PORTNAME == cygwin || PORTNAME == win32
389391
390392
393+ %.pc: $(MAKEFILE_LIST)
394+ echo 'Name: lib$(NAME)' >$@
395+ echo 'Description: PostgreSQL lib$(NAME) library' >>$@
396+ echo 'Url: http://www.postgresql.org/' >>$@
397+ echo 'Version: $(VERSION)' >>$@
398+ echo 'Requires: ' >>$@
399+ echo 'Requires.private: $(PKG_CONFIG_REQUIRES_PRIVATE)' >>$@
400+ echo 'Cflags: -I$(includedir)' >>$@
401+ echo 'Libs: -L$(libdir) -l$(NAME)' >>$@
402+ # Record -L flags that the user might have passed in to the PostgreSQL
403+ # build to locate third-party libraries (e.g., ldap, ssl). Filter out
404+ # those that point inside the build or source tree. Use sort to
405+ # remove duplicates. Also record the -l flags necessary for static
406+ # linking, but not those already covered by Requires.private.
407+ echo 'Libs.private: $(sort $(filter-out -L.% -L$(top_srcdir)/%,$(filter -L%,$(LDFLAGS) $(SHLIB_LINK)))) $(filter-out $(PKG_CONFIG_REQUIRES_PRIVATE:lib%=-l%),$(filter -l%,$(SHLIB_LINK)))' >>$@
408+
409+
391410# We need several not-quite-identical variants of .DEF files to build
392411# DLLs for Windows. These are made from the single source file
393412# exports.txt. Since we can't assume that Windows boxes will have
@@ -430,8 +449,12 @@ endif # SHLIB_EXPORTS
430449install-lib: install-lib-shared
431450ifdef soname
432451install-lib: install-lib-static
452+ install-lib: install-lib-pc
433453endif
434454
455+ install-lib-pc: lib$(NAME).pc installdirs-lib
456+ $(INSTALL_DATA) $< '$(DESTDIR)$(pkgconfigdir)/lib$(NAME).pc'
457+
435458install-lib-static: $(stlib) installdirs-lib
436459$(INSTALL_STLIB) $< '$(DESTDIR)$(libdir)/$(stlib)'
437460ifeq ($(PORTNAME), darwin)
@@ -467,7 +490,7 @@ endif
467490
468491installdirs-lib:
469492ifdef soname
470- $(MKDIR_P) '$(DESTDIR)$(libdir)'
493+ $(MKDIR_P) '$(DESTDIR)$(libdir)' '$(DESTDIR)$(pkgconfigdir)'
471494else
472495$(MKDIR_P) '$(DESTDIR)$(pkglibdir)'
473496endif
@@ -483,7 +506,8 @@ ifdef soname
483506rm -f '$(DESTDIR)$(libdir)/$(stlib)'
484507rm -f '$(DESTDIR)$(libdir)/$(shlib_bare)' \
485508 '$(DESTDIR)$(libdir)/$(shlib_major)' \
486- '$(DESTDIR)$(libdir)/$(shlib)'
509+ '$(DESTDIR)$(libdir)/$(shlib)' \
510+ '$(DESTDIR)$(pkgconfigdir)/lib$(NAME).pc'
487511else # no soname
488512rm -f '$(DESTDIR)$(pkglibdir)/$(shlib)'
489513endif # no soname
@@ -495,7 +519,7 @@ endif # no soname
495519
496520.PHONY: clean-lib
497521clean-lib:
498- rm -f $(shlib) $(shlib_bare) $(shlib_major) $(stlib) $(exports_file)
522+ rm -f $(shlib) $(shlib_bare) $(shlib_major) $(stlib) $(exports_file) lib$(NAME).pc
499523
500524ifneq (,$(SHLIB_EXPORTS))
501525maintainer-clean-lib: