use std::env;
use crate::spec::{LinkArgs, TargetOptions};
pub fn opts() -> TargetOptions {
let version = macos_deployment_target();
TargetOptions {
function_sections: false,
dynamic_linking: true,
executables: true,
target_family: Some("unix".to_string()),
is_like_osx: true,
has_rpath: true,
dll_prefix: "lib".to_string(),
dll_suffix: ".dylib".to_string(),
archive_format: "bsd".to_string(),
pre_link_args: LinkArgs::new(),
has_elf_tls: version >= (10, 7),
abi_return_struct_as_int: true,
emit_debug_gdb_scripts: false,
.. Default::default()
}
}
fn macos_deployment_target() -> (u32, u32) {
let deployment_target = env::var("MACOSX_DEPLOYMENT_TARGET").ok();
let version = deployment_target.as_ref().and_then(|s| {
let mut i = s.splitn(2, '.');
i.next().and_then(|a| i.next().map(|b| (a, b)))
}).and_then(|(a, b)| {
a.parse::<u32>().and_then(|a| b.parse::<u32>().map(|b| (a, b))).ok()
});
version.unwrap_or((10, 7))
}
pub fn macos_llvm_target(arch: &str) -> String {
let (major, minor) = macos_deployment_target();
format!("{}-apple-macosx{}.{}.0", arch, major, minor)
}