-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathbuild.rs
96 lines (84 loc) · 2.35 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
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
use std::env;
use std::fs;
use std::path::Path;
use std::process::{Stdio, Command};
fn main() {
let out_dir = env::var("OUT_DIR").unwrap();
let dst = Path::new(&out_dir);
clean();
setup();
configure();
build();
install(&dst);
clean();
println!("cargo:rustc-link-search={}", dst.join("lib").display());
println!("cargo:rustc-link-lib=static=termbox");
}
fn setup() {
let mut cmd = Command::new("git");
cmd.arg("clone");
cmd.arg("https://github.com/nsf/termbox");
cmd.arg(".termbox");
let manifest_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
let cargo_dir = Path::new(&manifest_dir);
cmd.current_dir(&cargo_dir);
run(&mut cmd);
}
fn clean() {
let mut cmd = Command::new("rm");
cmd.arg("-rf");
cmd.arg(".termbox");
let manifest_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
let cargo_dir = Path::new(&manifest_dir);
cmd.current_dir(&cargo_dir);
run(&mut cmd);
}
fn configure() {
let mut cmd = waf();
cmd.arg("configure");
cmd.arg("--prefix=/");
cmd.arg("--libdir=/lib");
let target = env::var("TARGET").unwrap();
let mut cflags;
if target.contains("i686") {
cflags = "-m32"
} else if target.contains("x86_64") {
cflags = "-m64 -fPIC"
} else {
cflags = "-fPIC"
}
println!("waf configure: setting CFLAGS to: `{}`", cflags);
env::set_var("CFLAGS", cflags);
run(&mut cmd);
env::remove_var("CFLAGS");
}
fn build() {
let mut cmd = waf();
cmd.arg("build");
cmd.arg("--targets=termbox_static");
run(&mut cmd);
}
fn install(dst: &Path) {
let mut cmd = waf();
cmd.arg("install");
cmd.arg("--targets=termbox_static");
cmd.arg(format!("--destdir={}", dst.display()));
run(&mut cmd);
}
fn waf() -> Command {
let manifest_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
let cargo_dir = Path::new(&manifest_dir);
let termbox_dir = cargo_dir.join(".termbox");
let waf_file = fs::canonicalize(&termbox_dir.join("waf")).expect("Invalid location of waf file");
let mut cmd = Command::new(waf_file);
cmd.current_dir(&termbox_dir);
cmd
}
fn run(cmd: &mut Command) {
println!("running: {:?}", cmd);
assert!(cmd.stdout(Stdio::inherit())
.stderr(Stdio::inherit())
.status()
.unwrap()
.success());
}