On Sun, 2012-09-09 at 03:35 -0400, Tom Lane wrote:
> >> Another problem is that Makefile.shlib isn't designed to build more
> >> than one shared library per directory,
> 
> > That's the main problem, but fixing it would be very useful in other
> > places as well.  I had it on my radar to do something about that.
> 
> This would be a good thing.  Got any ideas how to do it?

Here is a very rough patch.  It obviously will need a lot of
fine-tuning, but it's the idea.

diff --git a/src/Makefile.shlib b/src/Makefile.shlib
index 4da2f10..790fbf4 100644
--- a/src/Makefile.shlib
+++ b/src/Makefile.shlib
@@ -77,6 +77,11 @@
 COMPILER = $(CC) $(CFLAGS)
 LINK.static = $(AR) $(AROPT)
 
+# "legacy" interface
+ifeq ($(words $(NAMES)),1)
+NAMES = $(NAME)
+$(NAME)_OBJS = $(OBJS)
+endif
 
 
 ifdef SO_MAJOR_VERSION
@@ -89,10 +94,20 @@ shlib_bare	= lib$(NAME)$(DLSUFFIX)
 soname		= $(shlib_major)
 else
 # Naming convention for dynamically loadable modules
-shlib		= $(NAME)$(DLSUFFIX)
+shlib_pattern = %$(DLSUFFIX)
 endif
 stlib		= lib$(NAME).a
 
+define shlib_template
+_fullname = $$(patsubst %,$$(shlib_pattern),$(1))
+shlibs := $(shlibs) $$(_fullname)
+$$(_fullname)_OBJS = $$($(1)_OBJS)
+ALL_OBJS += $$($(1)_OBJS)
+endef
+
+$(foreach name,$(NAMES),$(eval $(call shlib_template,$(name))))
+
+
 ifndef soname
 # additional flags for backend modules
 SHLIB_LINK += $(BE_DLLLIBS)
@@ -309,7 +324,7 @@ endif
 
 all-static-lib: $(stlib)
 
-all-shared-lib: $(shlib)
+all-shared-lib: $(shlibs)
 
 ifndef haslibarule
 $(stlib): $(OBJS) | $(SHLIB_PREREQS)
@@ -321,9 +336,10 @@ endif #haslibarule
 ifeq (,$(filter cygwin win32,$(PORTNAME)))
 ifneq ($(PORTNAME), aix)
 
+.SECONDEXPANSION:
 # Normal case
-$(shlib): $(OBJS) | $(SHLIB_PREREQS)
-	$(LINK.shared) -o $@ $(OBJS) $(LDFLAGS) $(LDFLAGS_SL) $(SHLIB_LINK)
+$(shlibs): %: $$(%_OBJS) | $(SHLIB_PREREQS)
+	$(LINK.shared) -o $@ $^ $(LDFLAGS) $(LDFLAGS_SL) $(SHLIB_LINK)
 ifdef shlib_major
 # If we're using major and minor versions, then make a symlink to major-version-only.
 ifneq ($(shlib), $(shlib_major))
@@ -495,7 +511,7 @@ endif # no soname
 
 .PHONY: clean-lib
 clean-lib:
-	rm -f $(shlib) $(shlib_bare) $(shlib_major) $(stlib) $(exports_file)
+	rm -f $(shlibs) $(shlib_bare) $(shlib_major) $(stlib) $(exports_file)
 
 ifneq (,$(SHLIB_EXPORTS))
 maintainer-clean-lib:
diff --git a/src/pl/plpgsql/src/Makefile b/src/pl/plpgsql/src/Makefile
index e3fef84..182cd8e 100644
--- a/src/pl/plpgsql/src/Makefile
+++ b/src/pl/plpgsql/src/Makefile
@@ -11,13 +11,14 @@ top_builddir = ../../../..
 include $(top_builddir)/src/Makefile.global
 
 # Shared library parameters
-NAME= plpgsql
+NAMES= plpgsql foobar
 
 override CPPFLAGS := -I. -I$(srcdir) $(CPPFLAGS)
 SHLIB_LINK = $(filter -lintl, $(LIBS))
 rpath =
 
-OBJS = pl_gram.o pl_handler.o pl_comp.o pl_exec.o pl_funcs.o pl_scanner.o
+plpgsql_OBJS = pl_gram.o pl_handler.o pl_comp.o pl_exec.o pl_funcs.o pl_scanner.o
+foobar_OBJS = foo.o bar.o
 
 DATA = plpgsql.control plpgsql--1.0.sql plpgsql--unpackaged--1.0.sql
 
@@ -74,7 +75,7 @@ distprep: pl_gram.h pl_gram.c plerrcodes.h
 # pl_gram.c, pl_gram.h and plerrcodes.h are in the distribution tarball,
 # so they are not cleaned here.
 clean distclean: clean-lib
-	rm -f $(OBJS)
+	rm -f $(ALL_OBJS)
 
 maintainer-clean: clean
 	rm -f pl_gram.c pl_gram.h plerrcodes.h
-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to