summaryrefslogtreecommitdiff
path: root/build.rs
blob: 83fcc3c17c8b31d1efc4762299403a5da7f8def5 (plain) (blame)
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
#[cfg(feature = "guile")]
use std::env;
#[cfg(feature = "guile")]
use std::process::Command;

// cargo build has to be run twice for some reason.
fn build_guile() {
    const LIBGUILE_INCLUDE_PATH: &str = "/usr/include/guile/3.0/";
    const GUILEDEFS_SRC: &str = "src/guile/guiledefs.c";
    const GUILEDEFS_TARGET_OBJ: &str = "guiledefs.o";
    const GUILEDEFS_TARGET_ARCHIVE: &str = "libguiledefs.a";

    let out_dir = env::var("OUT_DIR").unwrap();

    Command::new("gcc")
        .arg("-c")
        .arg("-I")
        .arg(LIBGUILE_INCLUDE_PATH)
        .arg("-lguile-3.0")
        .arg(GUILEDEFS_SRC)
        .arg("-o")
        .arg(format!("{}/{}", out_dir, GUILEDEFS_TARGET_OBJ))
        .spawn()
        .expect("Error compiling guiledefs.c");

    Command::new("ar")
        .arg("r")
        .arg(format!("{}/{}", out_dir, GUILEDEFS_TARGET_ARCHIVE))
        .arg(format!("{}/{}", out_dir, GUILEDEFS_TARGET_OBJ))
        .spawn()
        .expect("Error creating libguiledefs.a");

    println!("cargo:rustc-link-search=native={}", out_dir);
}

fn main() {
    #[cfg(feature = "guile")]
    build_guile();
}