Permalink
Browse files

- fix Makefile so that R.dll is found on win32

- remove embedded carriage returns from prosrc datum to
  prevent R engine syntax errors
  • Loading branch information...
1 parent e273684 commit 891c309583cb38522d84f10047e0735d2f4d9fdb jconway committed Jun 24, 2007
Showing with 59 additions and 26 deletions.
  1. +38 −26 Makefile
  2. +21 −0 plr.c
View
64 Makefile
@@ -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
@@ -34,20 +13,53 @@ SHLIB_LINK += -L$(r_libdir1x) -L$(r_libdir2x) -lR
DATA_built := plr.sql
DOCS := README.plr
REGRESS := plr
-EXTRA_CLEAN := doc/HTML.index
+EXTRA_CLEAN := doc/HTML.index expected/plr.out
-ifdef USE_PGXS
-PGXS := $(shell pg_config --pgxs)
-include $(PGXS)
-else
subdir = contrib/plr
top_builddir = ../..
include $(top_builddir)/src/Makefile.global
include $(top_srcdir)/contrib/contrib-global.mk
+
+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)\"
+rpath :=
+
+installcheck: plrinstallcheck
+
+plrinstallcheck:
+ifeq ($(findstring 7.3,$(VERSION)),7.3)
+ cp -f $(top_builddir)/$(subdir)/expected/plr.out.7.3 $(top_builddir)/$(subdir)/expected/plr.out
+else
+ cp -f $(top_builddir)/$(subdir)/expected/plr.out.7.4 $(top_builddir)/$(subdir)/expected/plr.out
+endif
else # can't build
View
21 plr.c
@@ -809,6 +809,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);
@@ -1199,6 +1200,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 */

0 comments on commit 891c309

Please sign in to comment.