Skip to content

Commit

Permalink
Add back in find_my_exec() support on platforms that include pgport.
Browse files Browse the repository at this point in the history
find_my_exec, a postgresql pgport function is again used to find the
location of the slonik binary to locate the share directory.
This is for installs where the install location is not known at
compile time.

Some distributions don't include pgport, this is disabled by default
if you compile with pgport support set to yes (a configure option/check)
then this will be enabled.

Patch submitted by Sandeep Thakkar <sandeep.thakkar@enterprisedb.com>
(cherry picked from commit b034434)

Conflicts:

	configure.ac
  • Loading branch information
ssinger committed Dec 7, 2012
1 parent 2da421b commit b266145
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 3 deletions.
3 changes: 3 additions & 0 deletions Makefile.global.in
Expand Up @@ -55,6 +55,9 @@ enable_rpath= @enable_rpath@

#libs
PTHREAD_LIBS= @PTHREAD_LIBS@
ifeq (@HAVE_PGPORT@,1)
HAVE_PGPORT= @HAVE_PGPORT@
endif

# Documentation
JADE= @JADE@
Expand Down
4 changes: 4 additions & 0 deletions config.h.in
Expand Up @@ -65,6 +65,10 @@
/* Set to 1 if we have POSIX signals */
#undef HAVE_POSIX_SIGNALS

/* Set to 1 if we have PGPORT */
#undef HAVE_PGPORT


#undef SETCONFIGOPTION_6
#undef SETCONFIGOPTION_7

Expand Down
7 changes: 7 additions & 0 deletions config/acx_libpq.m4
Expand Up @@ -506,6 +506,13 @@ AC_CHECK_DECLS([GetTopTransactionId],[],[],[
AC_SUBST(NLSLIB)
if test "$with_pgport" = "yes"; then
AC_MSG_CHECKING(for pgport)
AC_DEFINE(HAVE_PGPORT)
LIBS="$LIBS -lpgport"
AC_TRY_LINK_FUNC(find_my_exec,HAVE_PGPORT=1, AC_MSG_ERROR("pgport was not found. build without --with-pgport=yes to disable"))
fi
AC_LANG_RESTORE
])dnl ACX_LIBPQ

2 changes: 2 additions & 0 deletions configure.ac
Expand Up @@ -212,6 +212,7 @@ AC_ARG_WITH(docs, [ --with-docs=<yes|no> Build the sgml documentat
AC_ARG_WITH(docdir, [ --with-docdir=<dir> Location to install all the documentation. Default is $PREFIX/doc. ])
AC_ARG_WITH(d2mdir, [ --with-d2mdir=<dir> Location of docbook2man-spec.pl (Manpages will be skipped if not specified)])
AC_ARG_WITH(mandir, [ --with-mandir=<dir> Location to install the manpages. Default is $PREFIX/man.])
AC_ARG_WITH(pgport, [ --with-pgport=<yes|no> Link with pgport [default=no]])

SLON_AC_ARG_BOOL(enable, engine, yes,
[ --disable-engine Don't build slony1-engine source. (Used when building documentation only)])
Expand Down Expand Up @@ -250,6 +251,7 @@ AC_SUBST(SLONYPATH)
AC_SUBST(HOST_OS,$host_os)
AC_SUBST(PORTNAME,$template)

AC_SUBST(HAVE_PGPORT,$HAVE_PGPORT)
if test "${SLON_BINDIR}" = ""; then
if test ${prefix} = "NONE"; then
SLON_BINDIR="${PG_BINDIR}"
Expand Down
2 changes: 2 additions & 0 deletions src/slonik/Makefile
Expand Up @@ -26,6 +26,8 @@ endif
ifeq ($(PORTNAME), win32)
PROG = slonik.exe
LDFLAGS += -lpgport
else ifdef HAVE_PGPORT
LDFLAGS += -lpgport
endif

OBJS = \
Expand Down
19 changes: 19 additions & 0 deletions src/slonik/slonik.c
Expand Up @@ -23,6 +23,7 @@
#include <sys/types.h>
#include <sys/wait.h>
#else
#include <winsock2.h>
#include <windows.h>
#define sleep(x) Sleep(x*1000)
#endif
Expand All @@ -32,6 +33,10 @@
#include "libpq-fe.h"
#include "slonik.h"

#ifdef HAVE_PGPORT
#undef USE_REPL_SNPRINTF
#include "port.h"
#endif

#ifdef MSVC
#include "config_msvc.h"
Expand All @@ -54,6 +59,9 @@ int last_event_node = -1;
int auto_wait_disabled = 0;

static char share_path[MAXPGPATH];
#if HAVE_PGPORT
static char myfull_path[MAXPGPATH];
#endif



Expand Down Expand Up @@ -189,10 +197,21 @@ main(int argc, const char *argv[])
if (parser_errors)
usage();

#ifdef HAVE_PGPORT
/*
* We need to find a share directory like PostgreSQL.
*/
if (find_my_exec(argv[0],myfull_path) < 0)
{
strcpy(share_path, PGSHARE);
}
else
{
get_share_path(myfull_path, share_path);
}
#else
strcpy(share_path, PGSHARE);
#endif

if (optind < argc)
{
Expand Down
6 changes: 3 additions & 3 deletions src/slonik/win32.mak
@@ -1,6 +1,6 @@
CPP=cl.exe
LINK32=link.exe
LINK32_FLAGS=/libpath:$(PG_LIB) libpq.lib libpgport.lib kernel32.lib
LINK32_FLAGS=/libpath:$(PG_LIB) libpq.lib libpgport.lib ws2_32.lib kernel32.lib user32.lib advapi32.lib /libpath:$(GETTEXT_LIB) intl.lib
OBJS = slonik.obj \
dbutil.obj \
parser.obj \
Expand All @@ -9,7 +9,7 @@ OBJS = slonik.obj \



CPP_FLAGS=/c /D MSVC /D WIN32 /D PGSHARE=\"$(PGSHARE)\" /D YY_NO_UNISTD_H /I..\..\ /I$(PG_INC) /MD
CPP_FLAGS=/c /D MSVC /D WIN32 /D PGSHARE=\"$(PGSHARE)\" /D YY_NO_UNISTD_H /I..\..\ /D HAVE_PGPORT /I$(PG_INC) /I$(PG_INC)\server /I$(PG_INC)\server\port\win32 /MD

slonik.obj: slonik.c
$(CPP)$(CPP_FLAGS) slonik.c
Expand All @@ -27,4 +27,4 @@ scan.obj: scan.c
$(CPP) $(CPP_FLAGS) scan.c

slonik.exe: $(OBJS)
$(LINK32) $(LINK32_FLAGS) $(OBJS)
$(LINK32) $(LINK32_FLAGS) $(OBJS)

0 comments on commit b266145

Please sign in to comment.