Debian Codegraph @

R/get_conf.r

raw symbols SCIP
1 ### This file is only called by
2 ### "pbd*/src/Makevars.in" or "pbd*/src/Makevar.win"
3 ### to find the default configurations from
4 ### "pbd*/etc${R_ARCH}/Makconf".
5
6 get.path.lib <- function(arch, fn.in, debug = FALSE){
7 ### For the nm outputs to check 32- and 64-bits libraries.
8 if(arch == "/i386"){
9 n.zero <- 8
10 } else if(arch == "/x64"){
11 n.zero <- 16
12 } else{
13 stop(paste(arch, " is not found.", sep = ""))
14 }
15
16 ### Find which path gcc.exe is located.
17 path.env <- Sys.getenv("PATH")
18 path <- unlist(strsplit(path.env, ";"))
19 check.gcc <- FALSE
20 for(i.path in 1:length(path)){
21 dir.gcc <- gsub("\\\\", "/", path[i.path])
22 path.gcc <- paste(dir.gcc, "./gcc.exe", sep = "")
23 check.gcc <- file.exists(path.gcc)
24 if(check.gcc){
25 break
26 }
27 }
28
29 ### Get root for the Rtools
30 if(!check.gcc){
31 if(debug){
32 print(path)
33 }
34 stop("gcc is not found.")
35 } else{
36 if(debug){
37 print(path.gcc)
38 }
39 path.rtools <- gsub("/bin.*", "", path.gcc)
40 }
41
42 ### Check libraries.
43 # fn.in <- "libiphlpapi.a"
44 cmd <- paste("find ", path.rtools, " | grep '", fn.in, "$'", sep = "")
45 libs <- shell(cmd, intern = TRUE, ignore.stderr = TRUE)
46 if(debug){
47 print(libs)
48 }
49 if(length(libs) == 0){
50 stop(paste(fn.in, " is not found in ", path.rtools, sep = ""))
51 } else{
52 check.bits <- FALSE
53 for(i.lib in 1:length(libs)){
54 fn.out <- libs[i.lib]
55 cmd <- paste("nm ", fn.out, " | grep '^0' | head -1 | sed -e 's/ .*//'",
56 sep = "")
57 bits <- shell(cmd, intern = TRUE, ignore.stderr = TRUE)
58 zeros <- bits[1]
59 if(debug){
60 print(zeros)
61 }
62 if(nchar(zeros) == n.zero){
63 check.bits <- TRUE
64 break
65 }
66 }
67
68 if(check.bits){
69 fn.in <- gsub("\\+", "\\\\+", fn.in)
70 path.lib <- gsub(paste("/", fn.in, sep = ""), "/", fn.out)
71 if(debug){
72 print(path.lib)
73 }
74 } else{
75 stop("check.bits is neither 8 nor 16.")
76 }
77 }
78
79 path.lib
80 } # End of get.path.lib().
81
82 get.path.lib.330 <- function(arch, binpref, fn.in, debug = FALSE){
83 ### For the nm outputs to check 32- and 64-bits libraries.
84 if(arch == "/i386"){
85 arch <- gsub("^.", "", arch)
86 } else if(arch == "/x64"){
87 arch <- gsub("^.", "", arch)
88 } else{
89 stop(paste(arch, " is not found.", sep = ""))
90 }
91
92 ### Find which path gcc.exe is located.
93 if(binpref != ""){
94 path.gcc <- paste(binpref, "gcc.exe", sep = "")
95 } else{
96 ### For Rtools33 or newer version.
97 ### This dose not work.
98 cmd <- paste("R --arch ", arch, " CMD config CC", sep = "")
99 path.gcc <- shell(cmd, intern = TRUE, ignore.stderr = TRUE)
100 path.gcc <- paste(path.gcc, ".exe", sep = "")
101 }
102 check.gcc <- file.exists(path.gcc)
103
104 ### Get root for the Rtools
105 if(debug){
106 print(path.gcc)
107 }
108 path.rtools <- gsub("/bin.*", "", path.gcc)
109
110 ### Check libraries.
111 # fn.in <- "libiphlpapi.a"
112 cmd <- paste("find ", path.rtools, " | grep '", fn.in, "$'", sep = "")
113 libs <- shell(cmd, intern = TRUE, ignore.stderr = TRUE)
114 fn.out <- libs[1]
115 fn.in <- gsub("\\+", "\\\\+", fn.in)
116 path.lib <- gsub(paste("/", fn.in, sep = ""), "/", fn.out)
117 if(debug){
118 print(path.lib)
119 }
120
121 path.lib
122 } # End of get.path.lib().
123
124 ### For libiphlpapi.a, librpcrt4.a, and libws2_32.a
125 ### C:\Rtools32\gcc-4.6.3\i686-w64-mingw32\lib
126 ### C:\Rtools32\gcc-4.6.3\i686-w64-mingw32\lib64
127 ### C:\Rtools33\mingw_32\i686-w64-mingw32\lib
128 ### C:\Rtools33\mingw_64\x86_64-w64-mingw32\lib
129 get.mingw.lib <- function(arch = '', binpref = '', debug = FALSE){
130 if(getRversion() < '3.3.0'){
131 fn.in <- "libiphlpapi.a"
132 path.lib <- get.path.lib(arch, fn.in, debug = debug)
133
134 fn.in <- "librpcrt4.a"
135 path.fn <- paste(path.lib, fn.in, sep = "")
136 check.fn <- file.exists(path.fn)
137 if(!check.fn){
138 stop(paste(path.fn, " is not found.", sep = ""))
139 }
140
141 fn.in <- "libws2_32.a"
142 path.fn <- paste(path.lib, fn.in, sep = "")
143 check.fn <- file.exists(path.fn)
144 if(!check.fn){
145 stop(paste(path.fn, " is not found.", sep = ""))
146 }
147
148 ### Cat back to "Makefile.win".
149 cat(path.lib)
150 }
151
152 invisible()
153 } # End of get.mingw.lib().
154
155 ### For libstdc++.a
156 ### C:\Rtools32\gcc-4.6.3\lib
157 ### C:\Rtools32\gcc-4.6.3\lib64
158 ### C:\Rtools33\mingw_32\lib\gcc\i686-w64-mingw32\4.9.3
159 ### C:\Rtools33\mingw_64\lib\gcc\x86_64-w64-mingw32\4.9.3
160 get.stdcxx.lib <- function(arch = '', binpref = '', debug = FALSE){
161 if(getRversion() < '3.3.0'){
162 fn.in <- "libstdc++.a"
163 path.lib <- get.path.lib(arch, fn.in, debug = debug)
164
165 ### Cat back to "Makefile.win".
166 cat(path.lib)
167 }
168
169 invisible()
170 } # End of get.stdcxx.lib().
171