1 // Copyright © 2018 Mozilla Foundation
2 //
3 // This program is made available under an ISC-style license. See the
4 // accompanying file LICENSE for details.
5
6 extern crate cmake;
7 extern crate pkg_config;
8
9 use std::env;
10 use std::fs;
11 use std::path::Path;
12 use std::process::Command;
13
14 macro_rules! t {
15 ($e:expr) => (match $e {
16 Ok(e) => e,
17 Err(e) => panic!("{} failed with {}", stringify!($e), e),
18 })
19 }
20
main()21 fn main() {
22 let gecko_in_tree = env::var("CARGO_FEATURE_GECKO_IN_TREE").is_ok();
23 if gecko_in_tree {
24 return;
25 }
26
27 if env::var("LIBCUBEB_SYS_USE_PKG_CONFIG").is_ok() {
28 if pkg_config::find_library("libcubeb").is_ok() {
29 return;
30 }
31 }
32
33 if !Path::new("libcubeb/.git").exists() {
34 let _ = Command::new("git")
35 .args(&["submodule", "update", "--init", "--recursive"])
36 .status();
37 }
38
39 let target = env::var("TARGET").unwrap();
40 // let host = env::var("HOST").unwrap();
41 let windows = target.contains("windows");
42 let darwin = target.contains("darwin");
43 let freebsd = target.contains("freebsd");
44 let mut cfg = cmake::Config::new("libcubeb");
45
46 let _ = fs::remove_dir_all(env::var("OUT_DIR").unwrap());
47 t!(fs::create_dir_all(env::var("OUT_DIR").unwrap()));
48
49 env::remove_var("DESTDIR");
50 let dst = cfg.define("BUILD_SHARED_LIBS", "OFF")
51 .define("BUILD_TESTS", "OFF")
52 .define("BUILD_TOOLS", "OFF")
53 .build();
54
55 println!("cargo:rustc-link-lib=static=cubeb");
56 if windows {
57 println!("cargo:rustc-link-lib=dylib=avrt");
58 println!("cargo:rustc-link-lib=dylib=ole32");
59 println!("cargo:rustc-link-lib=dylib=user32");
60 println!("cargo:rustc-link-lib=dylib=winmm");
61 println!("cargo:rustc-link-search=native={}/lib", dst.display());
62 } else if darwin {
63 println!("cargo:rustc-link-lib=framework=AudioUnit");
64 println!("cargo:rustc-link-lib=framework=CoreAudio");
65 println!("cargo:rustc-link-lib=framework=CoreServices");
66 println!("cargo:rustc-link-lib=dylib=c++");
67 println!("cargo:rustc-link-search=native={}/lib", dst.display());
68 } else {
69 if freebsd {
70 println!("cargo:rustc-link-lib=dylib=c++");
71 } else {
72 println!("cargo:rustc-link-lib=dylib=stdc++");
73 }
74 println!("cargo:rustc-link-search=native={}/lib", dst.display());
75 println!("cargo:rustc-link-search=native={}/lib64", dst.display());
76
77 // Ignore the result of find_library. We don't care if the
78 // libraries are missing.
79 let _ = pkg_config::find_library("alsa");
80 let _ = pkg_config::find_library("libpulse");
81 let _ = pkg_config::find_library("jack");
82 }
83 }
84