On Mon, Dec 22, 2014 at 2:05 PM, Michael Paquier
<michael.paqu...@gmail.com> wrote:
> Peter, could it be possible to merge this patch with its MSVC portion
> for simplicity? I think that it would more readable to do all the
> changes at the same time once and for all. Also, that's still a bug,
> so are we still considering a backpatch? I wouldn't mind putting some
> time into a patch to get that fixed..

Attached are two patches, one for MinGW/cygwin, a slightly modified
version from Peter and the second implementing the same thing but for
the MSVC scripts. The method for MSVC is similar to what is done in
Peter's patch: roughly it checks if SO_MAJOR_VERSION is present in the
Makefile of a given library, the path of Makefile is found by looking
at the location of the .rc in the vcproj file (could be better but I
could not come up with a better method). TBH, it would be good to be
completely consistent in the way we build things on Windows, and we
may as well consider a backpatch to fix this long-standing bug. The
MSVC patch removes of course the hack copying libpq.dll from lib/ to
bin/.

I mentioned the fix for MSVC scripts as well here:
http://www.postgresql.org/message-id/cab7npqqiuepzphd3mmk+q7_cqqrkk_v1fvxknymri660z4d...@mail.gmail.com
Regards,
-- 
Michael
From 23c3fd58d65309e2ee6cc5ada9c3dee37110c70d Mon Sep 17 00:00:00 2001
From: Michael Paquier <michael@otacoo.com>
Date: Tue, 23 Dec 2014 05:01:38 -0800
Subject: [PATCH 1/2] Install shared libraries in bin/ and lib/ with
 MinGW/cygwin

Those libraries can be found by scanning for SO_MAJOR_VERSION in their
respective Makefiles.
---
 src/Makefile.shlib            | 11 ++++++++++-
 src/interfaces/libpq/Makefile |  9 ---------
 2 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/src/Makefile.shlib b/src/Makefile.shlib
index 674fe7e..c3af1fe 100644
--- a/src/Makefile.shlib
+++ b/src/Makefile.shlib
@@ -486,6 +486,9 @@ endif
 endif # not win32
 endif # not cygwin
 endif # not aix
+ifneq (,$(findstring $(PORTNAME),win32 cygwin))
+	$(INSTALL_SHLIB) $< '$(DESTDIR)$(bindir)/$(shlib)'
+endif
 else # no soname
 	$(INSTALL_SHLIB) $< '$(DESTDIR)$(pkglibdir)/$(shlib)'
 endif
@@ -494,7 +497,10 @@ endif
 installdirs-lib:
 ifdef soname
 	$(MKDIR_P) '$(DESTDIR)$(libdir)' '$(DESTDIR)$(pkgconfigdir)'
-else
+ifneq (,$(findstring $(PORTNAME),win32 cygwin))
+	$(MKDIR_P) '$(DESTDIR)$(bindir)'
+endif
+else # no soname
 	$(MKDIR_P) '$(DESTDIR)$(pkglibdir)'
 endif
 
@@ -511,6 +517,9 @@ ifdef soname
 	  '$(DESTDIR)$(libdir)/$(shlib_major)' \
 	  '$(DESTDIR)$(libdir)/$(shlib)' \
 	  '$(DESTDIR)$(pkgconfigdir)/lib$(NAME).pc'
+ifneq (,$(findstring $(PORTNAME),win32 cygwin))
+	rm -f '$(DESTDIR)$(bindir)/$(shlib)'
+endif
 else # no soname
 	rm -f '$(DESTDIR)$(pkglibdir)/$(shlib)'
 endif # no soname
diff --git a/src/interfaces/libpq/Makefile b/src/interfaces/libpq/Makefile
index 18d9b85..5f0042e 100644
--- a/src/interfaces/libpq/Makefile
+++ b/src/interfaces/libpq/Makefile
@@ -125,18 +125,12 @@ install: all installdirs install-lib
 	$(INSTALL_DATA) $(srcdir)/libpq-int.h '$(DESTDIR)$(includedir_internal)'
 	$(INSTALL_DATA) $(srcdir)/pqexpbuffer.h '$(DESTDIR)$(includedir_internal)'
 	$(INSTALL_DATA) $(srcdir)/pg_service.conf.sample '$(DESTDIR)$(datadir)/pg_service.conf.sample'
-ifneq (,$(findstring $(PORTNAME), win32 cygwin))
-	$(INSTALL_SHLIB) $(shlib) '$(DESTDIR)$(bindir)/$(shlib)'
-endif
 
 installcheck:
 	$(MAKE) -C test $@
 
 installdirs: installdirs-lib
 	$(MKDIR_P) '$(DESTDIR)$(includedir)' '$(DESTDIR)$(includedir_internal)' '$(DESTDIR)$(datadir)'
-ifneq (,$(findstring $(PORTNAME), win32 cygwin))
-	$(MKDIR_P) '$(DESTDIR)$(bindir)'
-endif
 
 uninstall: uninstall-lib
 	rm -f '$(DESTDIR)$(includedir)/libpq-fe.h'
@@ -144,9 +138,6 @@ uninstall: uninstall-lib
 	rm -f '$(DESTDIR)$(includedir_internal)/libpq-int.h'
 	rm -f '$(DESTDIR)$(includedir_internal)/pqexpbuffer.h'
 	rm -f '$(DESTDIR)$(datadir)/pg_service.conf.sample'
-ifneq (,$(findstring $(PORTNAME), win32 cygwin))
-	rm -f '$(DESTDIR)$(bindir)/$(shlib)'
-endif
 
 clean distclean: clean-lib
 	$(MAKE) -C test $@
-- 
2.2.1

From 13ca64cb5cdae419d6ee1bbf7c7a04f6bd3d2388 Mon Sep 17 00:00:00 2001
From: Michael Paquier <michael@otacoo.com>
Date: Tue, 23 Dec 2014 21:58:50 -0800
Subject: [PATCH 2/2] Install shared libraries in bin/ and lib/ with MSVC

This is the MSVC part of the previous commit, to ensure that install is
completely consistent with the multiple methods supported.
---
 src/tools/msvc/Install.pm | 43 +++++++++++++++++++++++++++++++++++--------
 1 file changed, 35 insertions(+), 8 deletions(-)

diff --git a/src/tools/msvc/Install.pm b/src/tools/msvc/Install.pm
index eba9aa0..616cd9d 100644
--- a/src/tools/msvc/Install.pm
+++ b/src/tools/msvc/Install.pm
@@ -91,7 +91,6 @@ sub Install
 	}
 
 	CopySolutionOutput($conf, $target);
-	lcopy($target . '/lib/libpq.dll', $target . '/bin/libpq.dll');
 	my $sample_files = [];
 	my @top_dir      = ("src");
 	@top_dir = ("src\\bin", "src\\interfaces") if ($insttype eq "client");
@@ -236,8 +235,9 @@ sub CopySolutionOutput
 	while ($sln =~ $rem)
 	{
 		my $pf = $1;
-		my $dir;
+		my @dirs;
 		my $ext;
+		my $is_sharedlib = 0;
 
 		$sln =~ s/$rem//;
 
@@ -247,17 +247,37 @@ sub CopySolutionOutput
 
 		my $proj = read_file("$pf.$vcproj")
 		  || croak "Could not open $pf.$vcproj\n";
+
+		# Check this project uses a shared library by looking if
+		# SO_MAJOR_VERSION is defined in its Makefile, whose path
+		# can be found using the resource file of this project.
+		if ($proj =~ qr{ResourceCompile\s*Include="([^"]+)"})
+		{
+			my $projpath = dirname($1);
+			my $mf = read_file($projpath . '/Makefile')
+				|| croak "Could not open $projpath/Makefile\n";
+
+			if ($mf =~ /^SO_MAJOR_VERSION\s*=\s*(.*)$/mg)
+			{
+				$is_sharedlib = 1;
+			}
+		}
+
 		if ($vcproj eq 'vcproj' && $proj =~ qr{ConfigurationType="([^"]+)"})
 		{
 			if ($1 == 1)
 			{
-				$dir = "bin";
+				@dirs = qw(bin);
 				$ext = "exe";
 			}
 			elsif ($1 == 2)
 			{
-				$dir = "lib";
+				@dirs = qw(lib);
 				$ext = "dll";
+				if ($is_sharedlib)
+				{
+					push(@dirs, 'bin');
+				}
 			}
 			else
 			{
@@ -271,13 +291,17 @@ sub CopySolutionOutput
 		{
 			if ($1 eq 'Application')
 			{
-				$dir = "bin";
+				@dirs = qw(bin);
 				$ext = "exe";
 			}
 			elsif ($1 eq 'DynamicLibrary')
 			{
-				$dir = "lib";
+				@dirs = qw(lib);
 				$ext = "dll";
+				if ($is_sharedlib)
+				{
+					push(@dirs, 'bin');
+				}
 			}
 			else    # 'StaticLibrary'
 			{
@@ -290,8 +314,11 @@ sub CopySolutionOutput
 		{
 			croak "Could not parse $pf.$vcproj\n";
 		}
-		lcopy("$conf\\$pf\\$pf.$ext", "$target\\$dir\\$pf.$ext")
-		  || croak "Could not copy $pf.$ext\n";
+		foreach my $dir (@dirs)
+		{
+			lcopy("$conf\\$pf\\$pf.$ext", "$target\\$dir\\$pf.$ext")
+				|| croak "Could not copy $pf.$ext\n";
+		}
 		lcopy("$conf\\$pf\\$pf.pdb", "$target\\symbols\\$pf.pdb")
 		  || croak "Could not copy $pf.pdb\n";
 		print ".";
-- 
2.2.1

-- 
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