1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-12 05:01:15 +03:00

Reorganize code to allow path-relative installs.

Create new get_* functions to access compiled-in paths and adjust if
relative installs are to be used.

Clean up substitute_libpath_macro() code.
This commit is contained in:
Bruce Momjian
2004-05-17 14:35:34 +00:00
parent 85383214ea
commit 3febb477e6
19 changed files with 374 additions and 170 deletions

View File

@@ -4,7 +4,7 @@
# Makefile for utils/fmgr
#
# IDENTIFICATION
# $PostgreSQL: pgsql/src/backend/utils/fmgr/Makefile,v 1.15 2003/12/23 21:56:20 tgl Exp $
# $PostgreSQL: pgsql/src/backend/utils/fmgr/Makefile,v 1.16 2004/05/17 14:35:31 momjian Exp $
#
#-------------------------------------------------------------------------
@@ -14,7 +14,7 @@ include $(top_builddir)/src/Makefile.global
OBJS = dfmgr.o fmgr.o funcapi.o
override CPPFLAGS += -DPKGLIBDIR=\"$(pkglibdir)\" -DDLSUFFIX=\"$(DLSUFFIX)\"
override CPPFLAGS += -DDLSUFFIX=\"$(DLSUFFIX)\"
all: SUBSYS.o

View File

@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/fmgr/dfmgr.c,v 1.71 2004/03/09 05:06:45 momjian Exp $
* $PostgreSQL: pgsql/src/backend/utils/fmgr/dfmgr.c,v 1.72 2004/05/17 14:35:31 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -270,12 +270,6 @@ file_exists(const char *name)
#error "DLSUFFIX must be defined to compile this file."
#endif
/* Example format: "/usr/local/pgsql/lib" */
#ifndef PKGLIBDIR
#error "PKGLIBDIR needs to be defined to compile this file."
#endif
/*
* If name contains a slash, check if the file exists, if so return
* the name. Else (no slash) try to expand using search path (see
@@ -341,62 +335,29 @@ expand_dynamic_library_name(const char *name)
static char *
substitute_libpath_macro(const char *name)
{
size_t macroname_len;
char *replacement = NULL;
#ifdef WIN32
char basename[MAXPGPATH];
#endif
const char *sep_ptr;
char *ret;
AssertArg(name != NULL);
if (name[0] != '$')
return pstrdup(name);
#ifndef WIN32
macroname_len = strcspn(name + 1, "/") + 1;
#else
macroname_len = strcspn(name + 1, "/\\") + 1;
#endif
if (strncmp(name, "$libdir", macroname_len) == 0)
#ifndef WIN32
replacement = PKGLIBDIR;
#else
{
char *p;
if (GetModuleFileName(NULL,basename,MAXPGPATH) == 0)
ereport(FATAL,
(errmsg("GetModuleFileName failed (%i)",(int)GetLastError())));
canonicalize_path(basename);
if ((p = last_path_separator(basename)) == NULL)
ereport(FATAL,
(errmsg("unexpected failure in determining PKGLIBDIR (%s)",basename)));
else
*p = '\0';
strcat(basename,"/../lib");
replacement = basename;
}
#endif
else
if ((sep_ptr = first_path_separator(name)) == NULL)
sep_ptr = name + strlen(name);
if (strlen("$libdir") != sep_ptr - name ||
strncmp(name, "$libdir", strlen("$libdir")) != 0)
ereport(ERROR,
(errcode(ERRCODE_INVALID_NAME),
errmsg("invalid macro name in dynamic library path")));
if (name[macroname_len] == '\0')
return pstrdup(replacement);
else
{
char *new;
ret = palloc(strlen(pkglib_path) + strlen(sep_ptr) + 1);
new = palloc(strlen(replacement) + (strlen(name) - macroname_len) + 1);
strcpy(ret, pkglib_path);
strcat(ret, sep_ptr);
strcpy(new, replacement);
strcat(new, name + macroname_len);
return new;
}
return ret;
}

View File

@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/init/globals.c,v 1.85 2004/05/13 22:45:03 momjian Exp $
* $PostgreSQL: pgsql/src/backend/utils/init/globals.c,v 1.86 2004/05/17 14:35:32 momjian Exp $
*
* NOTES
* Globals used all over the place should be declared here and not
@@ -46,6 +46,7 @@ char *DataDir = NULL;
char OutputFileName[MAXPGPATH];
char my_exec_path[MAXPGPATH]; /* full path to postgres executable */
char pkglib_path[MAXPGPATH]; /* full path to lib directory */
BackendId MyBackendId;