@@ -213,7 +213,8 @@ options:
213
213
214
214
-o <filename> write output to <filename>
215
215
--glue generate glue.bc file
216
- --shared compile a shared-library crate
216
+ --lib compile a library crate
217
+ --static use or produce static libraries
217
218
--pretty [type] pretty-print the input instead of compiling
218
219
--ls list the symbols defined by a crate file
219
220
-L <path> add a directory to the library search path
@@ -281,7 +282,8 @@ fn build_target_config() -> @session::config {
281
282
282
283
fn build_session_options( str binary , getopts:: match match, str binary_dir ) ->
283
284
@session:: options {
284
- auto shared = opt_present ( match , "shared" ) ;
285
+ auto library = opt_present ( match , "lib" ) ;
286
+ auto static = opt_present ( match , "static" ) ;
285
287
auto library_search_paths = [ binary_dir + "/lib" ] ;
286
288
library_search_paths += getopts:: opt_strs ( match , "L" ) ;
287
289
auto output_type =
@@ -330,7 +332,8 @@ fn build_session_options(str binary, getopts::match match, str binary_dir) ->
330
332
auto cfg = parse_cfgspecs ( getopts:: opt_strs ( match , "cfg" ) ) ;
331
333
auto test = opt_present ( match , "test" ) ;
332
334
let @session:: options sopts =
333
- @rec ( shared=shared,
335
+ @rec ( library=library,
336
+ static =static ,
334
337
optimize=opt_level,
335
338
debuginfo=debuginfo,
336
339
verify=verify,
@@ -369,11 +372,12 @@ fn main(vec[str] args) {
369
372
[ optflag ( "h" ) , optflag ( "help" ) , optflag ( "v" ) , optflag ( "version" ) ,
370
373
optflag ( "glue" ) , optflag ( "emit-llvm" ) , optflagopt ( "pretty" ) ,
371
374
optflag ( "ls" ) , optflag ( "parse-only" ) , optflag ( "O" ) ,
372
- optopt ( "OptLevel" ) , optflag ( "shared" ) , optmulti ( "L" ) , optflag ( "S" ) ,
375
+ optopt ( "OptLevel" ) , optmulti ( "L" ) , optflag ( "S" ) ,
373
376
optflag ( "c" ) , optopt ( "o" ) , optflag ( "g" ) , optflag ( "save-temps" ) ,
374
377
optopt ( "sysroot" ) , optflag ( "stats" ) , optflag ( "time-passes" ) ,
375
378
optflag ( "time-llvm-passes" ) , optflag ( "no-typestate" ) ,
376
- optflag ( "noverify" ) , optmulti ( "cfg" ) , optflag ( "test" ) ] ;
379
+ optflag ( "noverify" ) , optmulti ( "cfg" ) , optflag ( "test" ) ,
380
+ optflag ( "lib" ) , optflag ( "static" ) ] ;
377
381
auto binary = vec:: shift[ str] ( args) ;
378
382
auto binary_dir = fs:: dirname ( binary) ;
379
383
auto match =
@@ -453,13 +457,10 @@ fn main(vec[str] args) {
453
457
454
458
saved_out_filename = ofile;
455
459
auto temp_filename;
456
- alt ( sopts. output_type ) {
457
- case ( link:: output_type_exe) {
458
- // FIXME: what about shared?
459
-
460
- temp_filename = ofile + ".o" ;
461
- }
462
- case ( _) { temp_filename = ofile; }
460
+ if ( sopts. output_type == link:: output_type_exe && !sopts. static ) {
461
+ temp_filename = ofile + ".o" ;
462
+ } else {
463
+ temp_filename = ofile;
463
464
}
464
465
compile_input ( sess, cfg, ifile, temp_filename) ;
465
466
}
@@ -469,88 +470,90 @@ fn main(vec[str] args) {
469
470
// gcc to link the object file with some libs
470
471
//
471
472
// TODO: Factor this out of main.
472
- if ( sopts. output_type == link:: output_type_exe) {
473
- let str glu = binary_dir + "/lib/glue.o" ;
474
- let str main = "rt/main.o" ;
475
- let str stage = "-L" + binary_dir + "/lib" ;
476
- let str prog = "gcc" ;
477
- // The invocations of gcc share some flags across platforms
478
-
479
- let vec[ str] gcc_args =
480
- [ stage, "-Lrt" , "-lrustrt" , glu, "-m32" , "-o" ,
481
- saved_out_filename, saved_out_filename + ".o" ] ;
482
- auto shared_cmd;
483
-
484
- auto os = sess. get_targ_cfg ( ) . os ;
485
- if ( os == session:: os_macos) {
486
- shared_cmd = "-dynamiclib" ;
487
- } else {
488
- shared_cmd = "-shared" ;
489
- }
473
+ if ( sopts. output_type != link:: output_type_exe || sopts. static ) {
474
+ ret;
475
+ }
490
476
491
- // Converts a library file name into a gcc -l argument
492
- fn unlib ( @session:: config config, str filename ) -> str {
493
- auto rmlib = bind fn( @session:: config config,
494
- str filename) -> str {
495
- if ( config. os == session:: os_macos
496
- || config. os == session:: os_linux
497
- && str:: find ( filename, "lib" ) == 0 ) {
498
- ret str:: slice ( filename, 3 u, str:: byte_len ( filename) ) ;
499
- } else {
500
- ret filename;
501
- }
502
- } ( config, _) ;
503
- fn rmext ( str filename ) -> str {
504
- auto parts = str:: split ( filename, '.' as u8 ) ;
505
- vec:: pop ( parts) ;
506
- ret str:: connect ( parts, "." ) ;
507
- }
508
- ret alt ( config. os ) {
509
- case ( session:: os_macos) { rmext ( rmlib ( filename) ) }
510
- case ( session:: os_linux) { rmext ( rmlib ( filename) ) }
511
- case ( _) { rmext ( filename) }
512
- } ;
513
- }
477
+ let str glu = binary_dir + "/lib/glue.o" ;
478
+ let str main = "rt/main.o" ;
479
+ let str stage = "-L" + binary_dir + "/lib" ;
480
+ let str prog = "gcc" ;
481
+ // The invocations of gcc share some flags across platforms
482
+
483
+ let vec[ str] gcc_args =
484
+ [ stage, "-Lrt" , "-lrustrt" , glu, "-m32" , "-o" ,
485
+ saved_out_filename, saved_out_filename + ".o" ] ;
486
+ auto lib_cmd;
487
+
488
+ auto os = sess. get_targ_cfg ( ) . os ;
489
+ if ( os == session:: os_macos) {
490
+ lib_cmd = "-dynamiclib" ;
491
+ } else {
492
+ lib_cmd = "-shared" ;
493
+ }
514
494
515
- for ( str cratepath in sess. get_used_crate_files( ) ) {
516
- auto dir = fs:: dirname( cratepath) ;
517
- if ( dir != "" ) {
518
- gcc_args += [ "-L" + dir] ;
495
+ // Converts a library file name into a gcc -l argument
496
+ fn unlib ( @session:: config config, str filename ) -> str {
497
+ auto rmlib = bind fn( @session:: config config,
498
+ str filename) -> str {
499
+ if ( config. os == session:: os_macos
500
+ || config. os == session:: os_linux
501
+ && str:: find ( filename, "lib" ) == 0 ) {
502
+ ret str:: slice ( filename, 3 u, str:: byte_len ( filename) ) ;
503
+ } else {
504
+ ret filename;
519
505
}
520
- auto libarg = unlib( sess. get_targ_cfg( ) , fs:: basename( cratepath) ) ;
521
- gcc_args += [ "-l" + libarg] ;
506
+ } ( config, _) ;
507
+ fn rmext ( str filename ) -> str {
508
+ auto parts = str:: split ( filename, '.' as u8 ) ;
509
+ vec:: pop ( parts) ;
510
+ ret str:: connect ( parts, "." ) ;
522
511
}
512
+ ret alt ( config. os ) {
513
+ case ( session:: os_macos) { rmext ( rmlib ( filename) ) }
514
+ case ( session:: os_linux) { rmext ( rmlib ( filename) ) }
515
+ case ( _) { rmext ( filename) }
516
+ } ;
517
+ }
523
518
524
- gcc_args += sess. get_used_link_args ( ) ;
525
- auto used_libs = sess . get_used_libraries ( ) ;
526
- for ( str l in used_libs ) {
527
- gcc_args += [ "-l " + l ] ;
519
+ for ( str cratepath in sess. get_used_crate_files ( ) ) {
520
+ auto dir = fs :: dirname ( cratepath ) ;
521
+ if ( dir != "" ) {
522
+ gcc_args += [ "-L " + dir ] ;
528
523
}
524
+ auto libarg = unlib( sess. get_targ_cfg( ) , fs:: basename( cratepath) ) ;
525
+ gcc_args += [ "-l" + libarg] ;
526
+ }
529
527
530
- if ( sopts. shared) {
531
- gcc_args += [ shared_cmd] ;
532
- } else {
533
- // FIXME: why do we hardcode -lm?
534
- gcc_args += [ "-lm" , main] ;
535
- }
536
- // We run 'gcc' here
528
+ gcc_args += sess. get_used_link_args( ) ;
529
+ auto used_libs = sess. get_used_libraries( ) ;
530
+ for ( str l in used_libs) {
531
+ gcc_args += [ "-l" + l] ;
532
+ }
537
533
538
- auto err_code = run :: run_program ( prog , gcc_args ) ;
539
- if ( 0 != err_code ) {
540
- sess . err ( #fmt ( "linking with gcc failed with code %d" , err_code ) ) ;
541
- sess . note ( #fmt ( "gcc arguments: %s" , str :: connect ( gcc_args , " " ) ) ) ;
542
- sess . abort_if_errors ( ) ;
543
- }
544
- // Clean up on Darwin
534
+ if ( sopts . library ) {
535
+ gcc_args += [ lib_cmd ] ;
536
+ } else {
537
+ // FIXME: why do we hardcode -lm?
538
+ gcc_args += [ "-lm" , main ] ;
539
+ }
540
+ // We run 'gcc' here
545
541
546
- if ( sess. get_targ_cfg( ) . os == session:: os_macos) {
547
- run:: run_program( "dsymutil" , [ saved_out_filename] ) ;
548
- }
542
+ auto err_code = run:: run_program( prog, gcc_args) ;
543
+ if ( 0 != err_code) {
544
+ sess. err( #fmt( "linking with gcc failed with code %d" , err_code) ) ;
545
+ sess. note( #fmt( "gcc arguments: %s" , str:: connect( gcc_args, " " ) ) ) ;
546
+ sess. abort_if_errors( ) ;
547
+ }
548
+ // Clean up on Darwin
549
549
550
- // Remove the temporary object file if we aren't saving temps
551
- if ( !sopts. save_temps) {
552
- run:: run_program( "rm" , [ saved_out_filename + ".o" ] ) ;
553
- }
550
+ if ( sess. get_targ_cfg( ) . os == session:: os_macos) {
551
+ run:: run_program( "dsymutil" , [ saved_out_filename] ) ;
552
+ }
553
+
554
+ // Remove the temporary object file if we aren't saving temps
555
+ if ( !sopts. save_temps) {
556
+ run:: run_program( "rm" , [ saved_out_filename + ".o" ] ) ;
554
557
}
555
558
}
556
559
// Local Variables:
0 commit comments