Command line changes for adding support for static libraries.

This commit is contained in:
Rafael Ávila de Espíndola 2011-07-07 14:42:18 -04:00
parent 16f82dce1c
commit 6d6c4c2a76
7 changed files with 22 additions and 20 deletions

View File

@ -2,7 +2,7 @@ stage1/lib/$(CFG_STDLIB): $(STDLIB_CRATE) $(STDLIB_INPUTS) \
stage1/rustc$(X) stage0/lib/$(CFG_STDLIB) stage1/intrinsics.bc \
stage1/glue.o $(LREQ) $(MKFILES)
@$(call E, compile_and_link: $@)
$(STAGE1) --shared -o $@ $<
$(STAGE1) --lib -o $@ $<
stage1/lib/glue.o: stage1/rustc$(X) stage0/lib/$(CFG_STDLIB) \
stage1/intrinsics.bc $(LREQ) $(MKFILES)

View File

@ -2,7 +2,7 @@ stage2/lib/$(CFG_STDLIB): $(STDLIB_CRATE) $(STDLIB_INPUTS) \
stage2/rustc$(X) stage1/lib/$(CFG_STDLIB) stage2/intrinsics.bc \
stage2/glue.o $(LREQ) $(MKFILES)
@$(call E, compile_and_link: $@)
$(STAGE2) --shared -o $@ $<
$(STAGE2) --lib -o $@ $<
stage2/lib/glue.o: stage2/rustc$(X) stage1/lib/$(CFG_STDLIB) \
stage2/intrinsics.bc rustllvm/$(CFG_RUSTLLVM) rt/$(CFG_RUNTIME)

View File

@ -2,7 +2,7 @@ stage3/lib/$(CFG_STDLIB): $(STDLIB_CRATE) $(STDLIB_INPUTS) \
stage3/rustc$(X) stage2/lib/$(CFG_STDLIB) stage3/intrinsics.bc \
stage3/glue.o $(LREQ) $(MKFILES)
@$(call E, compile_and_link: $@)
$(STAGE3) --shared -o $@ $<
$(STAGE3) --lib -o $@ $<
stage3/lib/glue.o: stage3/rustc$(X) stage2/lib/$(CFG_STDLIB) \
stage3/intrinsics.bc rustllvm/$(CFG_RUSTLLVM) rt/$(CFG_RUNTIME)

View File

@ -348,7 +348,7 @@ fn build_link_meta(&session::session sess, &ast::crate c,
}
fn warn_missing(&session::session sess, str name, str default) {
if (!sess.get_opts().shared) { ret; }
if (!sess.get_opts().library) { ret; }
sess.warn(#fmt("missing crate link meta '%s', using '%s' as default",
name, default));
}

View File

@ -213,7 +213,8 @@ options:
-o <filename> write output to <filename>
--glue generate glue.bc file
--shared compile a shared-library crate
--lib compile a library crate
--static use or produce static libraries
--pretty [type] pretty-print the input instead of compiling
--ls list the symbols defined by a crate file
-L <path> add a directory to the library search path
@ -281,7 +282,7 @@ fn build_target_config() -> @session::config {
fn build_session_options(str binary, getopts::match match, str binary_dir) ->
@session::options {
auto shared = opt_present(match, "shared");
auto library = opt_present(match, "lib");
auto library_search_paths = [binary_dir + "/lib"];
library_search_paths += getopts::opt_strs(match, "L");
auto output_type =
@ -330,7 +331,7 @@ fn build_session_options(str binary, getopts::match match, str binary_dir) ->
auto cfg = parse_cfgspecs(getopts::opt_strs(match, "cfg"));
auto test = opt_present(match, "test");
let @session::options sopts =
@rec(shared=shared,
@rec(library=library,
optimize=opt_level,
debuginfo=debuginfo,
verify=verify,
@ -369,11 +370,12 @@ fn main(vec[str] args) {
[optflag("h"), optflag("help"), optflag("v"), optflag("version"),
optflag("glue"), optflag("emit-llvm"), optflagopt("pretty"),
optflag("ls"), optflag("parse-only"), optflag("O"),
optopt("OptLevel"), optflag("shared"), optmulti("L"), optflag("S"),
optopt("OptLevel"), optmulti("L"), optflag("S"),
optflag("c"), optopt("o"), optflag("g"), optflag("save-temps"),
optopt("sysroot"), optflag("stats"), optflag("time-passes"),
optflag("time-llvm-passes"), optflag("no-typestate"),
optflag("noverify"), optmulti("cfg"), optflag("test")];
optflag("noverify"), optmulti("cfg"), optflag("test"),
optflag("lib"), optflag("static")];
auto binary = vec::shift[str](args);
auto binary_dir = fs::dirname(binary);
auto match =
@ -455,7 +457,7 @@ fn main(vec[str] args) {
auto temp_filename;
alt (sopts.output_type) {
case (link::output_type_exe) {
// FIXME: what about shared?
// FIXME: what about --lib?
temp_filename = ofile + ".o";
}
@ -479,13 +481,13 @@ fn main(vec[str] args) {
let vec[str] gcc_args =
[stage, "-Lrt", "-lrustrt", glu, "-m32", "-o",
saved_out_filename, saved_out_filename + ".o"];
auto shared_cmd;
auto lib_cmd;
auto os = sess.get_targ_cfg().os;
if (os == session::os_macos) {
shared_cmd = "-dynamiclib";
lib_cmd = "-dynamiclib";
} else {
shared_cmd = "-shared";
lib_cmd = "-shared";
}
// Converts a library file name into a gcc -l argument
@ -527,8 +529,8 @@ fn main(vec[str] args) {
gcc_args += ["-l" + l];
}
if (sopts.shared) {
gcc_args += [shared_cmd];
if (sopts.library) {
gcc_args += [lib_cmd];
} else {
// FIXME: why do we hardcode -lm?
gcc_args += ["-lm", main];

View File

@ -23,7 +23,7 @@ type config =
ty_mach float_type);
type options =
rec(bool shared,
rec(bool library,
uint optimize,
bool debuginfo,
bool verify,

View File

@ -8701,7 +8701,7 @@ fn decl_fn_and_pair_full(&@crate_ctxt ccx, &span sp, &vec[str] path, str flav,
}
}
let bool is_main =
str::eq(vec::top(path), "main") && !ccx.sess.get_opts().shared;
str::eq(vec::top(path), "main") && !ccx.sess.get_opts().library;
// Declare the function itself.
let str s =
@ -8745,7 +8745,7 @@ fn register_fn_pair(&@crate_ctxt cx, str ps, TypeRef llfnty, ValueRef llfn,
// FIXME: We should also hide the unexported pairs in crates.
auto gvar =
create_fn_pair(cx, ps, llfnty, llfn, cx.sess.get_opts().shared);
create_fn_pair(cx, ps, llfnty, llfn, cx.sess.get_opts().library);
cx.item_ids.insert(id, llfn);
cx.item_symbols.insert(id, ps);
cx.fn_pairs.insert(id, gvar);
@ -9219,7 +9219,7 @@ fn create_crate_map(&@crate_ctxt ccx) -> ValueRef {
}
vec::push[ValueRef](subcrates, C_int(0));
auto mapname;
if (ccx.sess.get_opts().shared) {
if (ccx.sess.get_opts().library) {
mapname = ccx.link_meta.name;
} else { mapname = "toplevel"; }
auto sym_name = "_rust_crate_map_" + mapname;
@ -9235,7 +9235,7 @@ fn create_crate_map(&@crate_ctxt ccx) -> ValueRef {
}
fn write_metadata(&@trans::crate_ctxt cx, &@ast::crate crate) {
if (!cx.sess.get_opts().shared) { ret; }
if (!cx.sess.get_opts().library) { ret; }
auto llmeta = C_postr(metadata::encoder::encode_metadata(cx, crate));
auto llconst = trans::C_struct([llmeta]);
auto llglobal =