Skip to content

Commit

Permalink
- fix Makefile so that R.dll is found on win32
Browse files Browse the repository at this point in the history
- remove embedded carriage returns from prosrc datum to
  prevent R engine syntax errors
  • Loading branch information
jconway committed Jun 24, 2007
1 parent 5b09a95 commit 412947a
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 21 deletions.
49 changes: 28 additions & 21 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,6 @@ r_libdir2x = ${R_HOME}/lib
# location of R includes
r_includespec = ${R_HOME}/include

ifeq ($(PORTNAME), darwin)
DYSUFFIX = dylib
endif

# we can only build PL/R if libR is available
# Since there is no official way to determine this,
# we see if there is a file that is named like a shared library.
ifneq ($(PORTNAME), darwin)
ifneq (,$(wildcard $(r_libdir1x)/libR*$(DLSUFFIX)*)$(wildcard $(r_libdir2x)/libR*$(DLSUFFIX)*))
shared_libr = yes;
endif
else
ifneq (,$(wildcard $(r_libdir1x)/libR*$(DYSUFFIX)*)$(wildcard $(r_libdir2x)/libR*$(DYSUFFIX)*))
shared_libr = yes
endif
endif

# If we don't have a shared library and the platform doesn't allow it
# to work without, we have to skip it.
ifneq (,$(findstring yes, $(shared_libr)$(allow_nonpic_in_shlib)))

MODULE_big := plr
PG_CPPFLAGS += -I$(r_includespec)
SRCS += plr.c pg_conversion.c pg_backend_support.c pg_userfuncs.c pg_rsupport.c
Expand All @@ -46,6 +25,34 @@ include $(top_builddir)/src/Makefile.global
include $(top_srcdir)/contrib/contrib-global.mk
endif

ifeq ($(PORTNAME), darwin)
DYSUFFIX = dylib
DLPREFIX = libR
else
ifeq ($(PORTNAME), win32)
DLPREFIX = R
else
DLPREFIX = libR
endif
endif

# we can only build PL/R if libR is available
# Since there is no official way to determine this,
# we see if there is a file that is named like a shared library.
ifneq ($(PORTNAME), darwin)
ifneq (,$(wildcard $(r_libdir1x)/$(DLPREFIX)*$(DLSUFFIX)*)$(wildcard $(r_libdir2x)/$(DLPREFIX)*$(DLSUFFIX)*))
shared_libr = yes;
endif
else
ifneq (,$(wildcard $(r_libdir1x)/$(DLPREFIX)*$(DYSUFFIX)*)$(wildcard $(r_libdir2x)/$(DLPREFIX)*$(DYSUFFIX)*))
shared_libr = yes
endif
endif

# If we don't have a shared library and the platform doesn't allow it
# to work without, we have to skip it.
ifneq (,$(findstring yes, $(shared_libr)$(allow_nonpic_in_shlib)))

override CPPFLAGS := -I$(srcdir) -I$(r_includespec) $(CPPFLAGS)
override CPPFLAGS += -DPKGLIBDIR=\"$(pkglibdir)\" -DDLSUFFIX=\"$(DLSUFFIX)\"

Expand Down
21 changes: 21 additions & 0 deletions plr.c
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,7 @@ do_compile(FunctionCallInfo fcinfo,
StringInfo proc_internal_args = makeStringInfo();
char *proc_source;
MemoryContext oldcontext;
char *p;

/* grab the function name */
proname = NameStr(procStruct->proname);
Expand Down Expand Up @@ -1204,6 +1205,26 @@ do_compile(FunctionCallInfo fcinfo,
elog(ERROR, "null prosrc");
proc_source = DatumGetCString(DirectFunctionCall1(textout, prosrcdatum));

/*
* replace any carriage returns with either a space or a newline,
* as appropriate
*/
p = proc_source;
while (*p != '\0')
{
if (p[0] == '\r')
{
if (p[1] == '\n')
/* for crlf sequence, write over the cr with a space */
*p++ = ' ';
else
/* otherwise write over the cr with a nl */
*p++ = '\n';
}
else
p++;
}

appendStringInfo(proc_internal_def, "%s}", proc_source);

/* parse or find the R function */
Expand Down

0 comments on commit 412947a

Please sign in to comment.