-
Notifications
You must be signed in to change notification settings - Fork 6
/
build.rs
61 lines (57 loc) · 2.01 KB
/
build.rs
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
extern crate cmake;
use cmake::Config;
use std::path::Path;
use std::{env, fs};
macro_rules! feature(($name:expr) => (env::var(concat!("CARGO_FEATURE_", $name)).is_ok()));
macro_rules! switch(($condition:expr) => (if $condition { "ON" } else { "OFF" }));
fn main() {
let mut suffix = "";
let kind = if feature!("STATIC") {
"static"
} else {
"dylib"
};
let cblas = feature!("CBLAS");
let lapacke = feature!("LAPACKE");
let tmg = feature!("TMG");
if !feature!("SYSTEM") {
suffix = "-netlib";
let output = Config::new("source")
.define("BUILD_TESTING", "OFF")
.define("BUILD_SHARED_LIBS", switch!(kind == "dylib"))
.define("CBLAS", switch!(cblas))
.define("LAPACKE_WITH_TMG", switch!(lapacke && tmg))
.define("CMAKE_INSTALL_LIBDIR", "lib")
.build();
let output = output.join("lib");
rename(&output, "blas", suffix);
rename(&output, "lapack", suffix);
println!("cargo:rustc-link-search={}", output.display());
}
println!("cargo:rustc-link-lib=dylib=gfortran");
println!("cargo:rustc-link-lib={}=blas{}", kind, suffix);
println!("cargo:rustc-link-lib={}=lapack{}", kind, suffix);
if cblas {
println!("cargo:rustc-link-lib={}=cblas", kind);
}
if lapacke {
println!("cargo:rustc-link-lib={}=lapacke", kind);
if tmg {
println!("cargo:rustc-link-lib={}=tmglib", kind);
}
}
}
fn rename(directory: &Path, name: &str, suffix: &str) {
for entry in fs::read_dir(directory).unwrap() {
let path = entry.unwrap().path();
let stem = path.file_stem().unwrap().to_str().unwrap();
if !stem.starts_with("lib") || &stem[3..] != name {
continue;
}
let mut new_path = path.clone();
new_path.set_file_name(format!("lib{}{}", name, suffix));
new_path.set_extension(path.extension().unwrap());
fs::rename(&path, &new_path).unwrap();
return;
}
}