[Rcpp-commits] r930 - in pkg/Rcpp: . R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sat Mar 20 19:46:13 CET 2010


Author: romain
Date: 2010-03-20 19:46:12 +0100 (Sat, 20 Mar 2010)
New Revision: 930

Modified:
   pkg/Rcpp/DESCRIPTION
   pkg/Rcpp/R/RcppLdpath.R
Log:
factor things out to reduce the inter package copy and paste factor

Modified: pkg/Rcpp/DESCRIPTION
===================================================================
--- pkg/Rcpp/DESCRIPTION	2010-03-20 18:06:14 UTC (rev 929)
+++ pkg/Rcpp/DESCRIPTION	2010-03-20 18:46:12 UTC (rev 930)
@@ -1,6 +1,6 @@
 Package: Rcpp
 Title: Rcpp R/C++ interface package
-Version: 0.7.10.2
+Version: 0.7.10.3
 Date: $Date$
 Author: Dirk Eddelbuettel and Romain Francois, with contributions 
  by Simon Urbanek, David Reiss and Douglas Bates; based on code written during 

Modified: pkg/Rcpp/R/RcppLdpath.R
===================================================================
--- pkg/Rcpp/R/RcppLdpath.R	2010-03-20 18:06:14 UTC (rev 929)
+++ pkg/Rcpp/R/RcppLdpath.R	2010-03-20 18:46:12 UTC (rev 930)
@@ -2,12 +2,7 @@
 ## Use R's internal knowledge of path settings to find the lib/ directory
 ## plus optinally an arch-specific directory on system building multi-arch
 RcppLdPath <- function() {
-    if (nzchar(.Platform$r_arch)) {	## eg amd64, ia64, mips
-        path <- system.file("lib",.Platform$r_arch,package="Rcpp")
-    } else {
-        path <- system.file("lib",package="Rcpp")
-    }
-    path
+	packageLibPath( package = "Rcpp" )
 }
 
 ## Provide linker flags -- i.e. -L/path/to/libRcpp -- as well as an
@@ -17,21 +12,8 @@
 ## Updated Jan 2010:  We now default to static linking but allow the use
 ##                    of rpath on Linux if static==FALSE has been chose
 ##                    Note that this is probably being called from LdFlags()
-RcppLdFlags <- function(static=TRUE) {
-    rcppdir <- RcppLdPath()
-    if (static) {                               # static is default on Windows and OS X
-        flags <- paste(rcppdir, "/libRcpp.a", sep="")
-        if (.Platform$OS.type=="windows") {
-            flags <- shQuote(flags)
-        }
-    } else {					# else for dynamic linking
-        flags <- paste("-L", rcppdir, " -lRcpp", sep="") # baseline setting
-        if ((.Platform$OS.type == "unix") &&    # on Linux, we can use rpath to encode path
-            (length(grep("^linux",R.version$os)))) {
-            flags <- paste(flags, " -Wl,-rpath,", rcppdir, sep="")
-        }
-    }
-    invisible(flags)
+RcppLdFlags <- function(static=staticLinking()) {
+    packageLdFlags( "Rcpp", static )
 }
 
 # indicates if Rcpp was compiled with GCC >= 4.3
@@ -39,11 +21,8 @@
 
 ## Provide compiler flags -- i.e. -I/path/to/Rcpp.h
 RcppCxxFlags <- function(cxx0x=FALSE) {
-    path <- RcppLdPath()
-    if (.Platform$OS.type=="windows") {
-        path <- shQuote(path)
-    }
-    paste("-I", path, if( cxx0x && canUseCXX0X() ) " -std=c++0x" else "", sep="")
+    iflag <- includeFlag( package = "Rcpp" )
+    paste( iflag, if( cxx0x && canUseCXX0X() ) " -std=c++0x" else "" )
 }
 
 ## Shorter names, and call cat() directly
@@ -52,7 +31,7 @@
     cat(RcppCxxFlags(cxx0x=cxx0x))
 }
 ## LdFlags defaults to static linking on the non-Linux platforms Windows and OS X
-LdFlags <- function(static=ifelse(length(grep("^linux",R.version$os))==0, TRUE, FALSE)) {
+LdFlags <- function(static=staticLinking()) {
     cat(RcppLdFlags(static=static))
 }
 
@@ -69,8 +48,73 @@
 
 Cxx0xFlags <- function() cat( RcppCxx0xFlags() )
 
+
+
+
+# indicates the default linking on the current platform
+#
 # default is to use static linking on windows an OSX
 staticLinking <- function(){
 	.Platform$OS.type == "windows" || grepl( "^darwin", R.version$os )
 }
 
+# the /lib path of the specified package (maybe including the arch)
+packageLibPath <- function( package = "Rcpp" ){
+	if (nzchar(.Platform$r_arch)) {	## eg amd64, ia64, mips
+        system.file("lib",.Platform$r_arch,package=package)
+    } else {
+        system.file("lib",package="RInside")
+    }
+}
+
+# on windows wrap the file with shQuote, 
+# otherwise, do nothing
+wrapFile <- function( file ){
+	if (.Platform$OS.type=="windows") {
+        file <- shQuote(file)
+    }
+    file
+}
+
+# generic include flag 
+includeFlag <- function( package = "Rcpp" ){
+	paste( "-I", wrapFile(packageLibPath(package)), sep = "" )
+}
+
+# path to the static library file
+staticLib <- function(package = "Rcpp" ){
+	libfoo.a <- file.path( packageLibPath(), sprintf( "lib%s.a", package ) )
+	wrapFile( libfoo.a )
+}
+
+# dynamic library flags for the given package
+dynamicLib <- function( package = "Rcpp" ){
+	libPath <- packageLibPath( package )
+
+	# general default
+	flags <- sprintf( "-L%s -l%s", 
+		libPath, 
+		package
+	)
+	
+	# linux -rpath bonus
+	if (.Platform$OS.type == "unix") {
+        if (length(grep("^linux",R.version$os))) {
+            flags <- sprintf( "%s -Wl,-rpath,%s", flags, libPath)
+        }
+    }
+    
+    flags
+}
+
+
+packageLdFlags <- function( package = "Rcpp", static = staticLinking() ){
+	if( static ){
+		staticLib( package )
+	} else {
+		dynamicLib( package )
+	}
+}
+
+
+



More information about the Rcpp-commits mailing list