File: zzz.R

package info (click to toggle)
r-bioc-rhdf5lib 1.12.1%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 268 kB
  • sloc: sh: 108; ansic: 43; makefile: 7
file content (142 lines) | stat: -rw-r--r-- 6,356 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#' Compiler arguments for using Rhdf5lib
#' 
#' This function returns values for \code{PKG_LIBS} variables for use in 
#' Makevars files.
#' 
#' @param opt A scalar character from the list of available options; 
#' default is \code{PKG_CXX_LIBS}.  Valid options are \code{PKG_C_LIBS},
#' \code{PKG_CXX_LIBS}, \code{PKG_C_HL_LIBS} and \code{PKG_CXX_HL_LIBS}, where
#' \code{HL} indicates that you want to include the HDF5 'high-level' API and
#' \code{CXX} denotes including the C++ interface. 
#' @return \code{NULL}; prints the corresponding value to stdout.
#' @examples
#' pkgconfig("PKG_C_LIBS")
#' pkgconfig("PKG_CXX_LIBS")
#' pkgconfig("PKG_C_HL_LIBS")
#' pkgconfig("PKG_CXX_HL_LIBS")
#' @export
#' @rawNamespace if(tools:::.OStype() == "windows") { importFrom(utils, shortPathName) }
pkgconfig <- function(opt = c("PKG_CXX_LIBS", "PKG_C_LIBS", "PKG_CXX_HL_LIBS", "PKG_C_HL_LIBS")) {
    
    path <- Sys.getenv(
        x = "RHDF5LIB_RPATH",
        unset = system.file("lib", package="Rhdf5lib", mustWork=TRUE)
    )
    
    if (nzchar(.Platform$r_arch)) {
        arch <- sprintf("/%s", .Platform$r_arch)
    } else {
        arch <- ""
    }
    patharch <- paste0(path, arch)

    result <- switch(match.arg(opt), 
                     PKG_C_LIBS = {
                         switch(Sys.info()['sysname'], 
                                Windows = {
                                    patharch <- gsub(x = utils::shortPathName(patharch),
                                                   pattern = "\\",
                                                   replacement = "/", 
                                                   fixed = TRUE)
                                    sprintf('-L%s -lhdf5 -lcurl -lssh2 -lssl -lcrypto -lwldap32 -lws2_32 -lcrypt32 -lszip -lz -lpsapi', 
                                            patharch)
                                }, {
                                    sprintf('"%s/libhdf5.a" "%s/libsz.a" %s', 
                                            patharch, patharch, .getDynamicLinks())
                                }
                         )
                     }, 
                     PKG_CXX_LIBS = {
                         switch(Sys.info()['sysname'], 
                                Windows = {
                                   ## for some reason double quotes aren't always sufficient
                                   ## so we use the 8+3 form of the path
                                   patharch <- gsub(x = utils::shortPathName(patharch),
                                                   pattern = "\\",
                                                   replacement = "/", 
                                                   fixed = TRUE)
                                    sprintf('-L%s -lhdf5_cpp -lhdf5 -lcurl -lssh2 -lssl -lcrypto -lwldap32 -lws2_32 -lcrypt32 -lszip -lz -lpsapi', 
                                            patharch)
                                }, {
                                    sprintf('"%s/libhdf5_cpp.a" "%s/libhdf5.a" "%s/libsz.a" %s',
                                            patharch, patharch, patharch, .getDynamicLinks())
                                }
                         )
                     },
                     PKG_C_HL_LIBS = {
                       switch(Sys.info()['sysname'], 
                              Windows = {
                                patharch <- gsub(x = shortPathName(patharch),
                                                 pattern = "\\",
                                                 replacement = "/", 
                                                 fixed = TRUE)
                                sprintf('-L%s -lhdf5_hl -lhdf5 -lcurl -lssh2 -lssl -lcrypto -lwldap32 -lws2_32 -lcrypt32 -lwldap32 -lws2_32 -lcrypt32 -lszip -lz -lpsapi', 
                                        patharch)
                              }, {
                                sprintf('"%s/libhdf5_hl.a" "%s/libhdf5.a" "%s/libsz.a" %s', 
                                        patharch, patharch, patharch, .getDynamicLinks())
                              }
                       )
                     }, 
                     PKG_CXX_HL_LIBS = {
                       switch(Sys.info()['sysname'], 
                              Windows = {
                                ## for some reason double quotes aren't always sufficient
                                ## so we use the 8+3 form of the path
                                patharch <- gsub(x = shortPathName(patharch),
                                                 pattern = "\\",
                                                 replacement = "/", 
                                                 fixed = TRUE)
                                sprintf('-L%s -lhdf5_hl_cpp -lhdf5_hl -lhdf5_cpp -lhdf5 -lcrypto -lcurl -lszip -lz -lpsapi', 
                                        patharch)
                              }, {
                                sprintf('"%s/libhdf5_hl_cpp.a" "%s/libhdf5_hl.a" "%s/libhdf5_cpp.a" "%s/libhdf5.a" "%s/libsz.a" %s',
                                        patharch, patharch, patharch, patharch, patharch, .getDynamicLinks())
                              }
                       )
                     }
    )
    
    cat(result)
}

#' Report the version of HDF5 distributed with this package
#' 
#' This function returns the version number of the HDF5 library that is 
#' distributed with this package.
#' 
#' @return Returns a \code{character} vector of length 1 containing the version
#' number.
#' 
#' @examples
#' getHdf5Version()
#' @export
getHdf5Version <- function() {
  cReturn <- .Call("Rhdf5lib_hdf5_libversion", 
        PACKAGE = "Rhdf5lib")
  versionNum <- paste(cReturn, collapse = ".")
  return(versionNum)
}

#' Determine whether libcurl and libcrypto were found during package 
#' installation
#' 
#' @keywords internal
.curlStatus <- function() {
  settings_file <- system.file('include', 'libhdf5.settings', package = "Rhdf5lib")
  libhdf5_settings <- readLines(settings_file)
  line <- grep("Extra libraries", x = libhdf5_settings)
  return(grepl(pattern = "-lcurl", x = libhdf5_settings[line]))
}

.getDynamicLinks <- function() {
  
  if(isTRUE(.curlStatus())) {
    links <- "-lcrypto -lcurl -lz"
  } else {
    links <- "-lz"
  }
  
  return(links)
  
}