|
| 1 | +NT2_URL <- "https://github.com/jfalcou/nt2" |
| 2 | +COMMIT <- "f19e80f55cad6db21ccb3c7f216efecf45c91250" |
| 3 | + |
| 4 | +# Helpers |
| 5 | +pathProg <- function(name) { |
| 6 | + prog <- Sys.which(name) |
| 7 | + if (!nzchar(prog)) |
| 8 | + stop("No program named '", name, "' on the PATH!", call. = FALSE) |
| 9 | + prog |
| 10 | +} |
| 11 | + |
| 12 | +cmakeDef <- function(name, value) { |
| 13 | + sprintf("-D%s=%s", name, value) |
| 14 | +} |
| 15 | + |
| 16 | +cmake <- pathProg("cmake") |
| 17 | +make <- pathProg("make") |
| 18 | +git <- pathProg("git") |
| 19 | +patch <- pathProg("patch") |
| 20 | + |
| 21 | +# End helpers |
| 22 | + |
| 23 | +owd <- getwd() |
| 24 | + |
| 25 | +# Check out the 'nt2' sources |
| 26 | +if (!dir.exists("nt2")) |
| 27 | + system2(git, c("clone", NT2_URL)) |
| 28 | +setwd("nt2") |
| 29 | + |
| 30 | +# Check out the relevant commit |
| 31 | +system2(git, c("checkout", COMMIT)) |
| 32 | + |
| 33 | +# Prepare installation directory |
| 34 | +if (dir.exists("install")) |
| 35 | + unlink("install", recursive = TRUE) |
| 36 | +dir.create("install") |
| 37 | +installDir <- file.path(getwd(), "install") |
| 38 | + |
| 39 | +# Enter 'nt2' directory, and check out relevant commit |
| 40 | +if (dir.exists("build")) |
| 41 | + unlink("build", recursive = TRUE) |
| 42 | +dir.create("build") |
| 43 | +setwd("build") |
| 44 | + |
| 45 | +# Call cmake to prepare the build |
| 46 | +system2(cmake, c( |
| 47 | + "..", |
| 48 | + cmakeDef("CMAKE_INSTALL_PREFIX", installDir) |
| 49 | +)) |
| 50 | + |
| 51 | +# Call 'make', 'make install' to build and install |
| 52 | +system2(make) |
| 53 | +system2(make, "install") |
| 54 | + |
| 55 | +# Go back to parent directory |
| 56 | +setwd(owd) |
| 57 | + |
| 58 | +# Copy all of the relevant headers over |
| 59 | +includePath <- file.path(installDir, "include") |
| 60 | +from <- list.files(includePath, full.names = TRUE) |
| 61 | +to <- file.path("inst/include") |
| 62 | +if (!dir.exists(to)) |
| 63 | + dir.create(to, recursive = TRUE) |
| 64 | +file.copy(from, to, recursive = TRUE) |
| 65 | + |
| 66 | +# Apply all of our patches |
| 67 | +patches <- list.files("patch", full.names = TRUE) |
| 68 | +for (patch in patches) { |
| 69 | + system2(patch, c("-p1", "<", patch)) |
| 70 | +} |
0 commit comments