Debian Codegraph @

src/install.libs.R

raw
1 ### Modified from Rserve/src/install.libs.R
2 ### For libs
3 files <- c("pbdZMQ.so", "pbdZMQ.so.dSYM", "pbdZMQ.dylib", "pbdZMQ.dll",
4 "symbols.rds",
5 "libzmq.so", "libzmq.so.dSYM", "libzmq.dll")
6 files <- files[file.exists(files)]
7 lib.osx <- list.files(pattern = "libzmq\\.(.*)\\.dylib")
8 files <- c(files, lib.osx)
9
10 if(length(files) > 0){
11 libsarch <- if (nzchar(R_ARCH)) paste("libs", R_ARCH, sep='') else "libs"
12 dest <- file.path(R_PACKAGE_DIR, libsarch)
13 dir.create(dest, recursive = TRUE, showWarnings = FALSE)
14 file.copy(files, dest, overwrite = TRUE, recursive = TRUE)
15
16 ### For Mac OSX and when "internal ZMQ" is asked.
17 ### Overwrite RPATH from the shared library installed to the destination.
18 if(Sys.info()[['sysname']] == "Darwin" && length(lib.osx) > 0){
19 cmd.int <- system("which install_name_tool", intern = TRUE)
20 cmd.ot <- system("which otool", intern = TRUE)
21 fn.pbdZMQ.so <- file.path(dest, "pbdZMQ.so")
22
23 if(length(lib.osx) != 1){
24 print(lib.osx)
25 stop("More than one libzmq.*.dylib are found.")
26 } else{
27 fn.libzmq.dylib <- file.path(dest, lib.osx)
28
29 if(file.exists(fn.pbdZMQ.so) && file.exists(fn.libzmq.dylib)){
30 ### For pbdZMQ.so
31 rpath <- system(paste(cmd.ot, " -L ", fn.pbdZMQ.so, sep = ""),
32 intern = TRUE)
33 cat("\nBefore install_name_tool (install.libs.R & pbdZMQ.so):\n")
34 print(rpath)
35
36 ### R-3.6.* does not like absolute path and staged installation has
37 ### it's own way (see "tools/R/install.R") to overwrite the id.
38 if(getRversion() < "3.6.0"){
39 cmd <- paste(cmd.int, " -id ", fn.pbdZMQ.so, " ",
40 fn.pbdZMQ.so, sep = "")
41 cat("\nIn install_name_tool (install.libs.R & pbdZMQ.so & id):\n")
42 print(cmd)
43 system(cmd)
44 }
45
46 str.lib <- paste("zmq/lib/", lib.osx, sep = "")
47 org <- file.path(getwd(), str.lib)
48 cmd <- paste(cmd.int, " -change ", org, " @loader_path/", lib.osx, " ",
49 fn.pbdZMQ.so, sep = "")
50 cat("\nIn install_name_tool (install.libs.R & pbdZMQ.so & path):\n")
51 print(cmd)
52 system(cmd)
53
54 rpath <- system(paste(cmd.ot, " -L ", fn.pbdZMQ.so, sep = ""),
55 intern = TRUE)
56 cat("\nAfter install_name_tool (install.libs.R & pbdZMQ.so):\n")
57 print(rpath)
58
59 ### For libzmq.dylib
60 rpath <- system(paste(cmd.ot, " -L ", fn.libzmq.dylib, sep = ""),
61 intern = TRUE)
62 cat("\nBefore install_name_tool (install.libs.R & libzmq.dylib):\n")
63 print(rpath)
64
65 ### R-3.6.* does not like absolute path because of staged installation.
66 if(getRversion() < "3.6.0"){
67 cmd <- paste(cmd.int, " -id ", fn.libzmq.dylib, " ",
68 fn.libzmq.dylib, sep = "")
69 } else{
70 cmd <- paste(cmd.int, " -id ", lib.osx, " ",
71 fn.libzmq.dylib, sep = "")
72 }
73 cat("\nIn install_name_tool (install.libs.R & libzmq.dylib & id):\n")
74 print(cmd)
75 system(cmd)
76
77 rpath <- system(paste(cmd.ot, " -L ", fn.libzmq.dylib, sep = ""),
78 intern = TRUE)
79 cat("\nAfter install_name_tool (install.libs.R & libzmq.dylib):\n")
80 print(rpath)
81 }
82 }
83 }
84 }
85
86 ### For etc
87 file <- "Makeconf"
88 if(file.exists(file)){
89 etcarch <- if (nzchar(R_ARCH)) paste("etc", R_ARCH, sep='') else "etc"
90 dest <- file.path(R_PACKAGE_DIR, etcarch)
91 dir.create(dest, recursive = TRUE, showWarnings = FALSE)
92 file.copy(file, dest, overwrite = TRUE)
93 }
94
95 ### For zmq and pbdZMQ include
96 dir.zmq <- "./zmq"
97 if(file.exists(dir.zmq)){
98 libarch <- if (nzchar(R_ARCH)) paste("zmq", R_ARCH, sep='') else "zmq"
99 dest <- file.path(R_PACKAGE_DIR, libarch)
100 dir.create(dest, recursive = TRUE, showWarnings = FALSE)
101 files <- paste(dir.zmq, "/include" , sep = "")
102 file.copy("./R_zmq.h", files)
103 file.copy(files, dest, overwrite = TRUE, recursive = TRUE)
104 }
105