Skip to content

Commit 9c1b234

Browse files
committed
Add a suffix to the names of blas and lapack
1 parent 817c95f commit 9c1b234

File tree

1 file changed

+32
-18
lines changed

1 file changed

+32
-18
lines changed

build.rs

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,38 @@
11
extern crate cmake;
22

33
use cmake::Config;
4-
use std::env::var;
5-
use std::fs::metadata;
6-
use std::path::PathBuf;
7-
use std::process::Command;
4+
use std::{env, fs, os};
5+
use std::path::{Path, PathBuf};
86

9-
macro_rules! feature(($name:expr) => (var(concat!("CARGO_FEATURE_", $name)).is_ok()));
7+
macro_rules! feature(($name:expr) => (env::var(concat!("CARGO_FEATURE_", $name)).is_ok()));
108
macro_rules! switch(($condition:expr) => (if $condition { "ON" } else { "OFF" }));
119

1210
fn main() {
11+
let mut suffix = "";
1312
let kind = if feature!("STATIC") { "static" } else { "dylib" };
1413
let cblas = feature!("CBLAS");
1514
let lapacke = feature!("LAPACKE");
16-
1715
if !feature!("SYSTEM") {
16+
suffix = "-netlib";
1817
let source = PathBuf::from("source");
19-
20-
if metadata(&source.join("CBLAS/CMAKE")).is_err() {
21-
let _ = Command::new("ln")
22-
.args(&["-s", "cmake", "CMAKE"])
23-
.current_dir(&source.join("CBLAS"))
24-
.status();
18+
if !source.join("CBLAS").join("CMAKE").exists() {
19+
os::unix::fs::symlink(source.join("CBLAS").join("cmake"),
20+
source.join("CBLAS").join("CMAKE")).unwrap();
2521
}
26-
2722
let output = Config::new(&source)
2823
.define("BUILD_TESTING", "OFF")
2924
.define("BUILD_SHARED_LIBS", switch!(kind == "dylib"))
3025
.define("CBLAS", switch!(cblas))
3126
.define("LAPACKE_WITH_TMG", switch!(lapacke))
3227
.define("CMAKE_INSTALL_LIBDIR", "lib")
3328
.build();
34-
35-
println!("cargo:rustc-link-search={}", output.join("lib").display());
29+
let output = output.join("lib");
30+
rename(&output, "blas", suffix);
31+
rename(&output, "lapack", suffix);
32+
println!("cargo:rustc-link-search={}", output.display());
3633
}
37-
38-
println!("cargo:rustc-link-lib={}=blas", kind);
39-
println!("cargo:rustc-link-lib={}=lapack", kind);
34+
println!("cargo:rustc-link-lib={}=blas{}", kind, suffix);
35+
println!("cargo:rustc-link-lib={}=lapack{}", kind, suffix);
4036
println!("cargo:rustc-link-lib=dylib=gfortran");
4137
if cblas {
4238
println!("cargo:rustc-link-lib={}=cblas", kind);
@@ -46,3 +42,21 @@ fn main() {
4642
println!("cargo:rustc-link-lib={}=tmglib", kind);
4743
}
4844
}
45+
46+
fn rename(directory: &Path, name: &str, suffix: &str) {
47+
for entry in fs::read_dir(directory).unwrap() {
48+
let path = entry.unwrap().path();
49+
let stem = path.file_stem().unwrap().to_str().unwrap();
50+
if !stem.starts_with("lib") {
51+
continue;
52+
}
53+
if &stem[3..] != name {
54+
continue;
55+
}
56+
let mut new_path = path.clone();
57+
new_path.set_file_name(format!("lib{}{}", name, suffix));
58+
new_path.set_extension(path.extension().unwrap());
59+
fs::rename(&path, &new_path).unwrap();
60+
return;
61+
}
62+
}

0 commit comments

Comments
 (0)