arrange core::os::consts

This commit is contained in:
ILyoan 2012-12-20 18:26:27 +09:00 committed by Graydon Hoare
parent 9f7dc1cb33
commit 2d3c22ae59
7 changed files with 111 additions and 61 deletions

View file

@ -41,6 +41,8 @@ use syntax::ast_map::{path, path_mod, path_name};
use syntax::attr;
use syntax::print::pprust;
use core::os::consts::{macos, freebsd, linux, win32};
enum output_type {
output_type_none,
output_type_bitcode,
@ -676,6 +678,19 @@ fn mangle_internal_name_by_seq(ccx: @crate_ctxt, +flav: ~str) -> ~str {
return fmt!("%s_%u", flav, (ccx.names)(flav).repr);
}
fn output_dll_filename(os: session::os, lm: &link_meta) -> ~str {
let libname = fmt!("%s-%s-%s", lm.name, lm.extras_hash, lm.vers);
let (dll_prefix, dll_suffix) = match os {
session::os_win32 => (win32::DLL_PREFIX, win32::DLL_SUFFIX),
session::os_macos => (macos::DLL_PREFIX, macos::DLL_SUFFIX),
session::os_linux => (linux::DLL_PREFIX, linux::DLL_SUFFIX),
session::os_freebsd => (freebsd::DLL_PREFIX, freebsd::DLL_SUFFIX),
};
return str::from_slice(dll_prefix) + libname +
str::from_slice(dll_suffix);
}
// If the user wants an exe generated we need to invoke
// cc to link the object file with some libs
fn link_binary(sess: Session,
@ -693,9 +708,7 @@ fn link_binary(sess: Session,
}
let output = if sess.building_library {
let long_libname =
os::dll_filename(fmt!("%s-%s-%s",
lm.name, lm.extras_hash, lm.vers));
let long_libname = output_dll_filename(sess.targ_cfg.os, &lm);
debug!("link_meta.name: %s", lm.name);
debug!("long_libname: %s", long_libname);
debug!("out_filename: %s", out_filename.to_str());

View file

@ -86,9 +86,9 @@ fn default_configuration(sess: Session, +argv0: ~str, input: input) ->
};
return ~[ // Target bindings.
attr::mk_word_item(os::family()),
mk(~"target_os", os::sysname()),
mk(~"target_family", os::family()),
attr::mk_word_item(str::from_slice(os::FAMILY)),
mk(~"target_os", str::from_slice(os::SYSNAME)),
mk(~"target_family", str::from_slice(os::FAMILY)),
mk(~"target_arch", arch),
mk(~"target_word_size", wordsz),
mk(~"target_libc", libc),

View file

@ -32,6 +32,8 @@ use core::str;
use core::uint;
use core::vec;
use core::os::consts::{macos, freebsd, linux, win32};
export os;
export os_macos, os_win32, os_linux, os_freebsd;
export ctxt;
@ -79,11 +81,15 @@ fn find_library_crate(cx: ctxt) -> Option<{ident: ~str, data: @~[u8]}> {
fn libname(cx: ctxt) -> {prefix: ~str, suffix: ~str} {
if cx.static { return {prefix: ~"lib", suffix: ~".rlib"}; }
match cx.os {
os_win32 => return {prefix: ~"", suffix: ~".dll"},
os_macos => return {prefix: ~"lib", suffix: ~".dylib"},
os_linux => return {prefix: ~"lib", suffix: ~".so"},
os_freebsd => return {prefix: ~"lib", suffix: ~".so"}
let (dll_prefix, dll_suffix) = match cx.os {
os_win32 => (win32::DLL_PREFIX, win32::DLL_SUFFIX),
os_macos => (macos::DLL_PREFIX, macos::DLL_SUFFIX),
os_linux => (linux::DLL_PREFIX, linux::DLL_SUFFIX),
os_freebsd => (freebsd::DLL_PREFIX, freebsd::DLL_SUFFIX),
};
return {
prefix: str::from_slice(dll_prefix),
suffix: str::from_slice(dll_suffix)
}
}