Thread: Proposed patch to remove .so pattern rules from platform Makefiles

Proposed patch to remove .so pattern rules from platform Makefiles

From
Tom Lane
Date:
I've wanted for a long time to get rid of the pattern rules in the
port-specific Makefiles that generate shared libraries from single
object files.  These patterns duplicate (or, more often, fail to
completely duplicate) the knowledge in Makefile.shlib.  So from
a maintenance point of view centralizing that knowledge is a good
thing.

The stumbling block has been partly that the regression-test makefile
depended on the pattern rules (easily fixed by using Makefile.shlib)
and partly that pgxs.mk (and its predecessor contrib-global.mk) depended
on the pattern rules to handle Makefiles that wanted to build multiple
.so files.  Since Makefile.shlib is designed to handle only one shlib
per build, there wasn't any obvious way to fix that.

The attached proposed patch gets around this by invoking Makefile.shlib
in a way that produces a pattern rule "lib%.so : %.o".  This is
moderately ugly but it gets the job done without changing Makefile.shlib
itself.  Possibly it could be done more cleanly if we were willing
to introduce pattern rules inside Makefile.shlib.

I am not sure if the patch works on non-Unix platforms --- could someone
test on Win32 and Cygwin, in particular?  AIX is weird enough to need
testing too.

Any other comments?

            regards, tom lane

*** src/makefiles/Makefile.aix.orig    Wed Oct  9 12:21:54 2002
--- src/makefiles/Makefile.aix    Sun Jul 24 16:19:25 2005
***************
*** 23,33 ****

  MKLDEXPORT=$(top_srcdir)/src/backend/port/aix/mkldexport.sh

- %$(EXPSUFF): %.o
-     $(MKLDEXPORT) $*.o > $*$(EXPSUFF)
-
- %$(DLSUFFIX): %.o %$(EXPSUFF)
-     @echo Making shared library $@ from $*.o, $*$(EXPSUFF) and postgres.imp
-     $(CC) $(LDFLAGS) $(LDFLAGS_SL) -o $@ $*.o -Wl,-bI:$(top_builddir)/src/backend/$(POSTGRES_IMP)
-Wl,-bE:$*$(EXPSUFF)$(LIBS) 
-
  sqlmansect = 7
--- 23,26 ----
*** src/makefiles/Makefile.beos.orig    Thu Dec 16 22:49:58 2004
--- src/makefiles/Makefile.beos    Sun Jul 24 16:19:25 2005
***************
*** 8,19 ****
  DLSUFFIX = .so
  CFLAGS_SL = -fpic -DPIC

- %.so: %.o
- ifdef PGXS
-     ln -fs $(DESTDIR)$(bindir)/postgres _APP_
- else
-     ln -fs $(top_builddir)/src/backend/postgres _APP_
- endif
-     $(CC) -nostart -Xlinker -soname=$@ -o $@ _APP_ $<
-
  sqlmansect = 7
--- 8,11 ----
*** src/makefiles/Makefile.bsdi.orig    Tue Dec 21 13:42:04 2004
--- src/makefiles/Makefile.bsdi    Sun Jul 24 16:19:26 2005
***************
*** 20,26 ****
  CFLAGS_SL =
  endif

- %.so: %.o
-     $(CC) -shared -o $@ $<
-
  sqlmansect = 7
--- 20,23 ----
*** src/makefiles/Makefile.cygwin.orig    Thu Dec 16 22:52:48 2004
--- src/makefiles/Makefile.cygwin    Sun Jul 24 16:19:26 2005
***************
*** 16,26 ****
  DLSUFFIX = .dll
  CFLAGS_SL =

- %.dll: %.o
-     $(DLLTOOL) --export-all --output-def $*.def $<
-     $(DLLWRAP) -o $@ --def $*.def $< $(DLLINIT) $(SHLIB_LINK)
-     rm -f $*.def
-
  ifneq (,$(findstring backend,$(subdir)))
  ifeq (,$(findstring conversion_procs,$(subdir)))
  override CPPFLAGS+= -DBUILDING_DLL
--- 16,21 ----
*** src/makefiles/Makefile.darwin.orig    Thu Dec 16 22:49:59 2004
--- src/makefiles/Makefile.darwin    Sun Jul 24 16:19:27 2005
***************
*** 10,18 ****
  BE_DLLLIBS= -bundle_loader $(top_builddir)/src/backend/postgres
  endif

- # Rule for building shared libs (currently used only for regression test
- # shlib ... should go away, since this is not really enough knowledge)
- %.so: %.o
-     $(CC) -bundle -o $@ $< $(BE_DLLLIBS)
-
  sqlmansect = 7
--- 10,13 ----
*** src/makefiles/Makefile.dgux.orig    Wed Aug 29 15:14:40 2001
--- src/makefiles/Makefile.dgux    Sun Jul 24 16:19:27 2005
***************
*** 2,8 ****
  DLSUFFIX = .so
  CFLAGS_SL = -fpic

- %.so: %.o
-     $(CC) -shared -o $@ $<
-
  sqlmansect = 5
--- 2,5 ----
*** src/makefiles/Makefile.freebsd.orig    Tue Dec 21 13:42:10 2004
--- src/makefiles/Makefile.freebsd    Sun Jul 24 16:19:28 2005
***************
*** 13,30 ****
  CFLAGS_SL = -fpic -DPIC
  endif

-
- %.so: %.o
- ifdef ELF_SYSTEM
-     $(LD) -x -shared -o $@ $<
- else
-     $(LD) $(LDREL) $(LDOUT) $<.obj -x $<
-     @echo building shared object $@
-     @rm -f $@.pic
-     @${AR} cq $@.pic `lorder $<.obj | tsort`
-     ${RANLIB} $@.pic
-     @rm -f $@
-     $(LD) -x -Bshareable -Bforcearchive -o $@ $@.pic
- endif
-
  sqlmansect = 7
--- 13,16 ----
*** src/makefiles/Makefile.hpux.orig    Tue Dec 21 13:42:14 2004
--- src/makefiles/Makefile.hpux    Sun Jul 24 16:10:28 2005
***************
*** 49,69 ****
     CFLAGS_SL = +z
  endif

- # Rule for building shared libs (currently used only for regression test
- # shlib ... should go away, since this is not really enough knowledge)
- %$(DLSUFFIX): %.o
- ifeq ($(GCC), yes)
-   ifeq ($(with_gnu_ld), yes)
-     $(CC) $(LDFLAGS) -shared -o $@ $< `$(CC) $(LDFLAGS) -print-libgcc-file-name`
-   else
-     $(LD) -b -o $@ $< `$(CC) $(LDFLAGS) -print-libgcc-file-name`
-   endif
- else
-   ifeq ($(with_gnu_ld), yes)
-     $(CC) $(LDFLAGS) -shared -o $@ $<
-   else
-     $(LD) -b -o $@ $<
-   endif
- endif
-
  sqlmansect = 5
--- 49,52 ----
*** src/makefiles/Makefile.irix.orig    Tue Dec 21 13:42:17 2004
--- src/makefiles/Makefile.irix    Sun Jul 24 16:19:28 2005
***************
*** 6,14 ****
  # PIC is default
  CFLAGS_SL =

- %.so: %.o
-     $(LD) -G -Bdynamic -shared -o $@ $<
-
  override CPPFLAGS += -U_NO_XOPEN4

  ifneq ($(GCC), yes)
--- 6,11 ----
*** src/makefiles/Makefile.linux.orig    Tue Dec 21 13:42:20 2004
--- src/makefiles/Makefile.linux    Sun Jul 24 16:19:29 2005
***************
*** 10,16 ****
  CFLAGS_SL = -fpic
  endif

- %.so: %.o
-     $(CC) -shared -o $@ $<
-
  sqlmansect = 7
--- 10,13 ----
*** src/makefiles/Makefile.netbsd.orig    Tue Dec 21 13:42:24 2004
--- src/makefiles/Makefile.netbsd    Sun Jul 24 16:19:31 2005
***************
*** 15,32 ****
  CFLAGS_SL = -fpic -DPIC
  endif

-
- %.so: %.o
- ifdef ELF_SYSTEM
-     $(LD) -x -Bshareable -o $@ $<
- else
-     $(LD) $(LDREL) $(LDOUT) $<.obj -x $<
-     @echo building shared object $@
-     @rm -f $@.pic
-     @${AR} cq $@.pic `lorder $<.obj | tsort`
-     ${RANLIB} $@.pic
-     @rm -f $@
-     $(LD) -x -Bshareable -Bforcearchive -o $@ $@.pic
- endif
-
  sqlmansect = 7
--- 15,18 ----
*** src/makefiles/Makefile.openbsd.orig    Tue Dec 21 13:42:29 2004
--- src/makefiles/Makefile.openbsd    Sun Jul 24 16:19:31 2005
***************
*** 13,30 ****
  CFLAGS_SL = -fpic -DPIC
  endif

-
- %.so: %.o
- ifdef ELF_SYSTEM
-     $(CC) -shared -o $@ $<
- else
-     $(LD) $(LDREL) $(LDOUT) $<.obj -x $<
-     @echo building shared object $@
-     @rm -f $@.pic
-     @${AR} cq $@.pic `lorder $<.obj | tsort`
-     ${RANLIB} $@.pic
-     @rm -f $@
-     $(LD) -x -Bshareable -Bforcearchive -o $@ $@.pic
- endif
-
  sqlmansect = 7
--- 13,16 ----
*** src/makefiles/Makefile.osf.orig    Thu Jan  6 15:55:45 2005
--- src/makefiles/Makefile.osf    Sun Jul 24 16:19:31 2005
***************
*** 3,9 ****
  CFLAGS_SL =
  rpath = -rpath $(rpathdir)

- %.so: %.o
-     $(LD) -shared -expect_unresolved '*' -o $@ $<
-
  sqlmansect = 5
--- 3,6 ----
*** src/makefiles/Makefile.qnx4.orig    Wed Sep  4 18:54:18 2002
--- src/makefiles/Makefile.qnx4    Sun Jul 24 16:19:32 2005
***************
*** 10,16 ****
  DLSUFFIX = .so
  CFLAGS_SL =

- %$(DLSUFFIX): %.o
-     @echo 'cannot make shared object $@ from $<'
-
  sqlmansect = 7
--- 10,13 ----
*** src/makefiles/Makefile.sco.orig    Tue Dec 21 13:42:35 2004
--- src/makefiles/Makefile.sco    Sun Jul 24 16:19:32 2005
***************
*** 8,13 ****
  CFLAGS_SL = -K PIC
  endif

- %.so: %.o
-     $(LD) -G -Bdynamic -o $@ $<
  sqlmansect = 7
--- 8,11 ----
*** src/makefiles/Makefile.solaris.orig    Tue Dec 21 13:47:42 2004
--- src/makefiles/Makefile.solaris    Sun Jul 24 16:19:33 2005
***************
*** 16,22 ****
  CFLAGS_SL = -KPIC
  endif

- %.so: %.o
-     $(LD) -G -Bdynamic -o $@ $<
-
  sqlmansect = 5sql
--- 16,19 ----
*** src/makefiles/Makefile.sunos4.orig    Wed Sep  4 18:54:18 2002
--- src/makefiles/Makefile.sunos4    Sun Jul 24 16:19:33 2005
***************
*** 7,13 ****
  CFLAGS_SL = -PIC
  endif

- %.so: %.o
-     $(LD) -assert pure-text -Bdynamic -o $@ $<
-
  sqlmansect = 7
--- 7,10 ----
*** src/makefiles/Makefile.svr4.orig    Wed Aug 29 15:14:40 2001
--- src/makefiles/Makefile.svr4    Sun Jul 24 16:19:34 2005
***************
*** 8,14 ****
  DLSUFFIX = .so
  CFLAGS_SL =

- %.so: %.o
-     $(LD) -G -Bdynamic -o $@ $<
-
  sqlmansect = 5
--- 8,11 ----
*** src/makefiles/Makefile.ultrix4.orig    Wed Aug 29 15:14:40 2001
--- src/makefiles/Makefile.ultrix4    Sun Jul 24 16:19:34 2005
***************
*** 6,12 ****
  # "-G 0" works for both DEC cc and GNU cc.
  CFLAGS_SL = -G 0

- %.so: %.c
-     $(CC) -c -G 0 $(CPPFLAGS) $(CFLAGS) -o $@ $<
-
  sqlmansect = 7
--- 6,9 ----
*** src/makefiles/Makefile.univel.orig    Wed Aug 29 15:14:40 2001
--- src/makefiles/Makefile.univel    Sun Jul 24 16:19:35 2005
***************
*** 3,9 ****
  DLSUFFIX = .so
  CFLAGS_SL = -K PIC

- %.so: %.o
-     $(LD) -G -Bdynamic -o $@ $<
-
  sqlmansect = 5
--- 3,6 ----
*** src/makefiles/Makefile.unixware.orig    Tue Dec 21 13:42:39 2004
--- src/makefiles/Makefile.unixware    Sun Jul 24 16:19:35 2005
***************
*** 13,18 ****
--- 13,21 ----
  endif
  endif

+ # Unixware needs threads for everything that uses libpq
+ CFLAGS += $(PTHREAD_CFLAGS)
+
  DLSUFFIX = .so
  ifeq ($(GCC), yes)
  CFLAGS_SL = -fpic
***************
*** 25,34 ****
  SO_FLAGS = -G
  endif

- %.so: %.o
-     $(CC) $(SO_FLAGS) -o $@ $<
-
  sqlmansect = 5sql
-
- # Unixware needs threads for everything that uses libpq
- CFLAGS += $(PTHREAD_CFLAGS)
--- 28,31 ----
*** src/makefiles/Makefile.win32.orig    Thu Dec 16 22:52:49 2004
--- src/makefiles/Makefile.win32    Sun Jul 24 16:19:36 2005
***************
*** 16,26 ****
  DLSUFFIX = .dll
  CFLAGS_SL =

- %.dll: %.o
-     $(DLLTOOL) --export-all --output-def $*.def $<
-     $(DLLWRAP) -o $@ --def $*.def $< $(DLLINIT) $(SHLIB_LINK)
-     rm -f $*.def
-
  ifneq (,$(findstring backend,$(subdir)))
  ifeq (,$(findstring conversion_procs,$(subdir)))
  override CPPFLAGS+= -DBUILDING_DLL
--- 16,21 ----
*** src/makefiles/pgxs.mk.orig    Tue May 17 14:26:22 2005
--- src/makefiles/pgxs.mk    Sun Jul 24 17:33:00 2005
***************
*** 14,23 ****
  #   PGXS := $(shell pg_config --pgxs)
  #   include $(PGXS)
  #
! # The following variables can be set:
  #
! #   MODULES -- list of shared objects to be build from source file with
  #     same stem (do not include suffix in this list)
  #   DATA -- random files to install into $PREFIX/share/contrib
  #   DATA_built -- random files to install into $PREFIX/share/contrib,
  #     which need to be built first
--- 14,29 ----
  #   PGXS := $(shell pg_config --pgxs)
  #   include $(PGXS)
  #
! # Set at most one of these three variables to describe code to be built:
  #
! #   MODULES -- list of shared objects to be built from source files with
  #     same stem (do not include suffix in this list)
+ #   MODULE_big -- a single shared object to build from multiple source
+ #     files (list object files in OBJS)
+ #   PROGRAM -- an executable program to build (list object files in OBJS)
+ #
+ # The following can also be set:
+ #
  #   DATA -- random files to install into $PREFIX/share/contrib
  #   DATA_built -- random files to install into $PREFIX/share/contrib,
  #     which need to be built first
***************
*** 26,43 ****
  #   SCRIPTS_built -- script files (not binaries) to install into $PREFIX/bin,
  #     which need to be built first
  #   REGRESS -- list of regression test cases (without suffix)
- #
- # or at most one of these two:
- #
- #   PROGRAM -- a binary program to build (list objects files in OBJS)
- #   MODULE_big -- a shared object to build (list object files in OBJS)
- #
- # The following can also be set:
- #
  #   EXTRA_CLEAN -- extra files to remove in 'make clean'
  #   PG_CPPFLAGS -- will be added to CPPFLAGS
  #   PG_LIBS -- will be added to PROGRAM link line
! #   SHLIB_LINK -- will be added to MODULE_big link line
  #
  # Better look at some of the existing uses for examples...

--- 32,41 ----
  #   SCRIPTS_built -- script files (not binaries) to install into $PREFIX/bin,
  #     which need to be built first
  #   REGRESS -- list of regression test cases (without suffix)
  #   EXTRA_CLEAN -- extra files to remove in 'make clean'
  #   PG_CPPFLAGS -- will be added to CPPFLAGS
  #   PG_LIBS -- will be added to PROGRAM link line
! #   SHLIB_LINK -- will be added to MODULES or MODULE_big link line
  #
  # Better look at some of the existing uses for examples...

***************
*** 61,88 ****

  override CPPFLAGS := -I$(srcdir) $(CPPFLAGS)

- ifdef MODULES
- override CFLAGS += $(CFLAGS_SL)
- SHLIB_LINK += $(BE_DLLLIBS)
- endif
-
  ifdef PG_CPPFLAGS
  override CPPFLAGS := $(PG_CPPFLAGS) $(CPPFLAGS)
  endif

  all: $(PROGRAM) $(DATA_built) $(SCRIPTS_built) $(addsuffix $(DLSUFFIX), $(MODULES))

  ifdef MODULE_big
  # shared library parameters
  NAME = $(MODULE_big)
  SO_MAJOR_VERSION= 0
  SO_MINOR_VERSION= 0

  SHLIB_LINK += $(BE_DLLLIBS)

  include $(top_srcdir)/src/Makefile.shlib

  all: all-lib
  endif # MODULE_big


--- 59,113 ----

  override CPPFLAGS := -I$(srcdir) $(CPPFLAGS)

  ifdef PG_CPPFLAGS
  override CPPFLAGS := $(PG_CPPFLAGS) $(CPPFLAGS)
  endif

  all: $(PROGRAM) $(DATA_built) $(SCRIPTS_built) $(addsuffix $(DLSUFFIX), $(MODULES))

+ ifdef MODULES
+
+ # set up shared library parameters to produce a pattern rule lib%.so : %.o
+ NAME = %
+ SO_MAJOR_VERSION= 0
+ SO_MINOR_VERSION= 0
+ OBJS := %.o
+
+ SHLIB_LINK += $(BE_DLLLIBS)
+
+ include $(top_srcdir)/src/Makefile.shlib
+
+ # Now adjust $(OBJS) so that evaluation of the pattern rule works correctly
+ OBJS = $<
+
+ # This rule converts libNAME.so to NAME.so and gets rid of extra symlinks
+ %$(DLSUFFIX): $(shlib)
+     rm -f $@
+     ln $< $@
+ ifneq ($(shlib), $(shlib_major))
+     rm -f $(shlib_major)
+ endif
+ ifneq ($(shlib), $(shlib_bare))
+     rm -f $(shlib_bare)
+ endif
+
+ endif # MODULES
+
+
  ifdef MODULE_big
+
  # shared library parameters
  NAME = $(MODULE_big)
  SO_MAJOR_VERSION= 0
  SO_MINOR_VERSION= 0
+ # OBJS must have been set by caller

  SHLIB_LINK += $(BE_DLLLIBS)

  include $(top_srcdir)/src/Makefile.shlib

  all: all-lib
+
  endif # MODULE_big


*** src/test/regress/GNUmakefile.orig    Sun Jul 17 14:28:45 2005
--- src/test/regress/GNUmakefile    Sun Jul 24 17:27:58 2005
***************
*** 1,13 ****
  #-------------------------------------------------------------------------
  #
  # GNUmakefile--
! #    Makefile for regress (the regression tests)
  #
! # Copyright (c) 1994, Regents of the University of California
  #
! #
! # IDENTIFICATION
! #    $PostgreSQL: pgsql/src/test/regress/GNUmakefile,v 1.50 2005/07/17 18:28:45 tgl Exp $
  #
  #-------------------------------------------------------------------------

--- 1,12 ----
  #-------------------------------------------------------------------------
  #
  # GNUmakefile--
! #    Makefile for src/test/regress (the regression tests)
  #
! # Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
! # Portions Copyright (c) 1994, Regents of the University of California
  #
! # $PostgreSQL: pgsql/src/test/regress/GNUmakefile,v 1.50 2005/07/17 18:28:45 tgl Exp $
  #
  #-------------------------------------------------------------------------

***************
*** 17,27 ****

  contribdir := $(top_builddir)/contrib

- override CPPFLAGS := -I$(libpq_srcdir) $(CPPFLAGS)
- override CFLAGS += $(CFLAGS_SL)
-
- SHLIB_LINK = $(BE_DLLLIBS)
-
  # port number for temp-installation test postmaster
  TEMP_PORT = 5$(DEF_PGPORT)

--- 16,21 ----
***************
*** 59,71 ****

  # Build dynamically-loaded object file for CREATE FUNCTION ... LANGUAGE 'C'.

! DLOBJS := regress$(DLSUFFIX)
! # This is for some platforms
! ifdef EXPSUFF
! DLOBJS += regress$(EXPSUFF)
! endif

! all: $(DLOBJS)


  # Build test input and expected files
--- 53,71 ----

  # Build dynamically-loaded object file for CREATE FUNCTION ... LANGUAGE 'C'.

! NAME = regress
! SO_MAJOR_VERSION= 0
! SO_MINOR_VERSION= 0
! OBJS = regress.o
! SHLIB_LINK = $(BE_DLLLIBS)
!
! include $(top_srcdir)/src/Makefile.shlib
!
! all: $(NAME)$(DLSUFFIX)

! $(NAME)$(DLSUFFIX): $(shlib)
!     rm -f $(NAME)$(DLSUFFIX)
!     $(LN_S) $(shlib) $(NAME)$(DLSUFFIX)


  # Build test input and expected files
***************
*** 163,172 ****
  ## Clean up
  ##

! clean distclean maintainer-clean:
  # things built by `all' target
      $(MAKE) -C $(contribdir)/spi clean
!     rm -f $(output_files) $(input_files) $(DLOBJS) regress.o pg_regress
  # things created by various check targets
      rm -rf testtablespace
      rm -rf results tmp_check log
--- 163,173 ----
  ## Clean up
  ##

! clean distclean maintainer-clean: clean-lib
  # things built by `all' target
+     rm -f $(NAME)$(DLSUFFIX) $(OBJS)
      $(MAKE) -C $(contribdir)/spi clean
!     rm -f $(output_files) $(input_files) pg_regress
  # things created by various check targets
      rm -rf testtablespace
      rm -rf results tmp_check log

Re: Proposed patch to remove .so pattern rules from platform Makefiles

From
"Rocco Altier"
Date:
The patch works on AIX with one small tweak to Makefile.shlib
(attached).  This is needed because of the clever trick with using % as
name, and when its evaulated for the mkldexport.

Also, it appears that the changes for regress/GNUmakefile are already
applied.

I am able to build everything and pass the regression tests.  This just
leaves the contrib/pgport issue from letting AIX go green on the
buildfarm.

Thanks for getting this simplification done!

    -rocco


> -----Original Message-----
> From: pgsql-patches-owner@postgresql.org
> [mailto:pgsql-patches-owner@postgresql.org] On Behalf Of Tom Lane
> Sent: Sunday, July 24, 2005 6:00 PM
> To: pgsql-patches@postgresql.org
> Subject: [PATCHES] Proposed patch to remove .so pattern rules
> from platform Makefiles
>
>
> I've wanted for a long time to get rid of the pattern rules in the
> port-specific Makefiles that generate shared libraries from single
> object files.  These patterns duplicate (or, more often, fail to
> completely duplicate) the knowledge in Makefile.shlib.  So from
> a maintenance point of view centralizing that knowledge is a good
> thing.
>
> The stumbling block has been partly that the regression-test makefile
> depended on the pattern rules (easily fixed by using Makefile.shlib)
> and partly that pgxs.mk (and its predecessor
> contrib-global.mk) depended
> on the pattern rules to handle Makefiles that wanted to build multiple
> .so files.  Since Makefile.shlib is designed to handle only one shlib
> per build, there wasn't any obvious way to fix that.
>
> The attached proposed patch gets around this by invoking
> Makefile.shlib
> in a way that produces a pattern rule "lib%.so : %.o".  This is
> moderately ugly but it gets the job done without changing
> Makefile.shlib
> itself.  Possibly it could be done more cleanly if we were willing
> to introduce pattern rules inside Makefile.shlib.
>
> I am not sure if the patch works on non-Unix platforms ---
> could someone
> test on Win32 and Cygwin, in particular?  AIX is weird enough to need
> testing too.
>
> Any other comments?
>
>             regards, tom lane
>
>

Attachment

Re: Proposed patch to remove .so pattern rules from platform Makefiles

From
"Rocco Altier"
Date:
Please disregard this patch.  I have a ton of lib%.exp and similar files
created currently.

I am working on a new patch to deal with the MODULES expansion
correctly.

Thanks,
    -rocco

> -----Original Message-----
> From: pgsql-patches-owner@postgresql.org
> [mailto:pgsql-patches-owner@postgresql.org] On Behalf Of Rocco Altier
> Sent: Monday, July 25, 2005 1:17 PM
> To: Tom Lane; pgsql-patches@postgresql.org
> Subject: Re: [PATCHES] Proposed patch to remove .so pattern
> rules from platform Makefiles
>
>
> The patch works on AIX with one small tweak to Makefile.shlib
> (attached).  This is needed because of the clever trick with
> using % as
> name, and when its evaulated for the mkldexport.
>
> Also, it appears that the changes for regress/GNUmakefile are already
> applied.
>
> I am able to build everything and pass the regression tests.
> This just
> leaves the contrib/pgport issue from letting AIX go green on the
> buildfarm.
>
> Thanks for getting this simplification done!
>
>     -rocco
>
>
> > -----Original Message-----
> > From: pgsql-patches-owner@postgresql.org
> > [mailto:pgsql-patches-owner@postgresql.org] On Behalf Of Tom Lane
> > Sent: Sunday, July 24, 2005 6:00 PM
> > To: pgsql-patches@postgresql.org
> > Subject: [PATCHES] Proposed patch to remove .so pattern rules
> > from platform Makefiles
> >
> >
> > I've wanted for a long time to get rid of the pattern rules in the
> > port-specific Makefiles that generate shared libraries from single
> > object files.  These patterns duplicate (or, more often, fail to
> > completely duplicate) the knowledge in Makefile.shlib.  So from
> > a maintenance point of view centralizing that knowledge is a good
> > thing.
> >
> > The stumbling block has been partly that the
> regression-test makefile
> > depended on the pattern rules (easily fixed by using Makefile.shlib)
> > and partly that pgxs.mk (and its predecessor
> > contrib-global.mk) depended
> > on the pattern rules to handle Makefiles that wanted to
> build multiple
> > .so files.  Since Makefile.shlib is designed to handle only
> one shlib
> > per build, there wasn't any obvious way to fix that.
> >
> > The attached proposed patch gets around this by invoking
> > Makefile.shlib
> > in a way that produces a pattern rule "lib%.so : %.o".  This is
> > moderately ugly but it gets the job done without changing
> > Makefile.shlib
> > itself.  Possibly it could be done more cleanly if we were willing
> > to introduce pattern rules inside Makefile.shlib.
> >
> > I am not sure if the patch works on non-Unix platforms ---
> > could someone
> > test on Win32 and Cygwin, in particular?  AIX is weird
> enough to need
> > testing too.
> >
> > Any other comments?
> >
> >             regards, tom lane
> >
> >
>

"Rocco Altier" <RoccoA@Routescape.com> writes:
> Please disregard this patch.  I have a ton of lib%.exp and similar files
> created currently.

Yeah, that was one of the reasons I called it ugly :-(.  I had put in an
"rm" step to get rid of lib%.so, you could probably fix the extraneous
.exp files similarly.

Alternatively we could look at expanding Makefile.shlib to provide %.so
pattern rules directly.  My patch was more intended as proof of concept
than anything we necessarily wanted to apply as-is.

            regards, tom lane

Re: Proposed patch to remove .so pattern rules from platform Makefiles

From
"Rocco Altier"
Date:
> -----Original Message-----
> From: Tom Lane [mailto:tgl@sss.pgh.pa.us]
>
> "Rocco Altier" <RoccoA@Routescape.com> writes:
> > Please disregard this patch.  I have a ton of lib%.exp and
> > similar files created currently.
>
> Yeah, that was one of the reasons I called it ugly :-(.  I
> had put in an
> "rm" step to get rid of lib%.so, you could probably fix the extraneous
> .exp files similarly.
>
If they are part of the rule, they get expanded, but if its part of the
commands to run, they don't, which is where I was getting the lib%.exp
from.

I have gotten them to where they will be expanded for the .exp, so that
there are the multiple files correctly, instead of just the one
lib%.exp.  I will look at doing the same for lib%.so, etc.

> Alternatively we could look at expanding Makefile.shlib to
> provide %.so pattern rules directly.
>
If I am reading the affect on the makefiles correctly, that is basically
what is happening.  We get a bunch of pattern rules...

From gmake -p (in contrib/spi - a multiple MODULES rule):
lib%.a: %.o
#  commands to execute (from `../../src/Makefile.shlib', line 281):
    $(LINK.static) $@ $^
    $(RANLIB) $@


lib%.so: lib%.a
#  commands to execute (from `../../src/Makefile.shlib', line 313):
    $(MKLDEXPORT) $< > $(subst .a,$(EXPSUFF),$<)
    $(COMPILER) $(LDFLAGS_SL) -o $@ $< $(LDFLAGS) $(SHLIB_LINK)
-Wl,-bI:$(top_builddir)/src/backend/$(POSTGRES_IMP) -Wl,-bE:$(subst
.a,$(EXPSUFF),$<)


%.so: lib%.so
#  commands to execute (from `../../src/makefiles/pgxs.mk', line 85):
    rm -f $@
    ln $< $@
    rm -f $(shlib_major)
...
(Substituted rules with autoinc later..)


> My patch was more intended as proof of concept
> than anything we necessarily wanted to apply as-is.
>
I have been trying to iron out some of the wrinkles, but over all its
definitely a good place to start.

Thanks,
    -rocco