| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
get.path.lib <- function(arch, fn.in, debug = FALSE){ |
| 7 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 43 |
|
| 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 |
} |
| 81 |
|
| 82 |
get.path.lib.330 <- function(arch, binpref, fn.in, debug = FALSE){ |
| 83 |
|
| 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 |
|
| 93 |
if(binpref != ""){ |
| 94 |
path.gcc <- paste(binpref, "gcc.exe", sep = "") |
| 95 |
} else{ |
| 96 |
|
| 97 |
|
| 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 |
|
| 105 |
if(debug){ |
| 106 |
print(path.gcc) |
| 107 |
} |
| 108 |
path.rtools <- gsub("/bin.*", "", path.gcc) |
| 109 |
|
| 110 |
|
| 111 |
|
| 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 |
} |
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 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 |
|
| 149 |
cat(path.lib) |
| 150 |
} |
| 151 |
|
| 152 |
invisible() |
| 153 |
} |
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 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 |
|
| 166 |
cat(path.lib) |
| 167 |
} |
| 168 |
|
| 169 |
invisible() |
| 170 |
} |
| 171 |
|