@@ -213,8 +213,7 @@ options:
213
213
214
214
-o <filename> write output to <filename>
215
215
--glue generate glue.bc file
216
- --lib compile a library crate
217
- --static use or produce static libraries
216
+ --shared compile a shared-library crate
218
217
--pretty [type] pretty-print the input instead of compiling
219
218
--ls list the symbols defined by a crate file
220
219
-L <path> add a directory to the library search path
@@ -282,8 +281,7 @@ fn build_target_config() -> @session::config {
282
281
283
282
fn build_session_options( str binary , getopts:: match match, str binary_dir ) ->
284
283
@session:: options {
285
- auto library = opt_present ( match , "lib" ) ;
286
- auto static = opt_present ( match , "static" ) ;
284
+ auto shared = opt_present ( match , "shared" ) ;
287
285
auto library_search_paths = [ binary_dir + "/lib" ] ;
288
286
library_search_paths += getopts:: opt_strs ( match , "L" ) ;
289
287
auto output_type =
@@ -332,8 +330,7 @@ fn build_session_options(str binary, getopts::match match, str binary_dir) ->
332
330
auto cfg = parse_cfgspecs ( getopts:: opt_strs ( match , "cfg" ) ) ;
333
331
auto test = opt_present ( match , "test" ) ;
334
332
let @session:: options sopts =
335
- @rec ( library=library,
336
- static =static ,
333
+ @rec ( shared=shared,
337
334
optimize=opt_level,
338
335
debuginfo=debuginfo,
339
336
verify=verify,
@@ -372,12 +369,11 @@ fn main(vec[str] args) {
372
369
[ optflag ( "h" ) , optflag ( "help" ) , optflag ( "v" ) , optflag ( "version" ) ,
373
370
optflag ( "glue" ) , optflag ( "emit-llvm" ) , optflagopt ( "pretty" ) ,
374
371
optflag ( "ls" ) , optflag ( "parse-only" ) , optflag ( "O" ) ,
375
- optopt ( "OptLevel" ) , optmulti ( "L" ) , optflag ( "S" ) ,
372
+ optopt ( "OptLevel" ) , optflag ( "shared" ) , optmulti ( "L" ) , optflag ( "S" ) ,
376
373
optflag ( "c" ) , optopt ( "o" ) , optflag ( "g" ) , optflag ( "save-temps" ) ,
377
374
optopt ( "sysroot" ) , optflag ( "stats" ) , optflag ( "time-passes" ) ,
378
375
optflag ( "time-llvm-passes" ) , optflag ( "no-typestate" ) ,
379
- optflag ( "noverify" ) , optmulti ( "cfg" ) , optflag ( "test" ) ,
380
- optflag ( "lib" ) , optflag ( "static" ) ] ;
376
+ optflag ( "noverify" ) , optmulti ( "cfg" ) , optflag ( "test" ) ] ;
381
377
auto binary = vec:: shift[ str] ( args) ;
382
378
auto binary_dir = fs:: dirname ( binary) ;
383
379
auto match =
@@ -457,10 +453,13 @@ fn main(vec[str] args) {
457
453
458
454
saved_out_filename = ofile;
459
455
auto temp_filename;
460
- if ( sopts. output_type == link:: output_type_exe && !sopts. static ) {
461
- temp_filename = ofile + ".o" ;
462
- } else {
463
- temp_filename = ofile;
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; }
464
463
}
465
464
compile_input ( sess, cfg, ifile, temp_filename) ;
466
465
}
@@ -470,90 +469,88 @@ fn main(vec[str] args) {
470
469
// gcc to link the object file with some libs
471
470
//
472
471
// TODO: Factor this out of main.
473
- if ( sopts. output_type != link:: output_type_exe || sopts. static ) {
474
- ret;
475
- }
476
-
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
- }
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
+ }
494
490
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;
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, "." ) ;
505
507
}
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 , "." ) ;
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
+ } ;
511
513
}
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
- }
518
514
519
- for ( str cratepath in sess. get_used_crate_files( ) ) {
520
- auto dir = fs:: dirname( cratepath) ;
521
- if ( dir != "" ) {
522
- gcc_args += [ "-L" + dir] ;
515
+ for ( str cratepath in sess. get_used_crate_files( ) ) {
516
+ auto dir = fs:: dirname( cratepath) ;
517
+ if ( dir != "" ) {
518
+ gcc_args += [ "-L" + dir] ;
519
+ }
520
+ auto libarg = unlib( sess. get_targ_cfg( ) , fs:: basename( cratepath) ) ;
521
+ gcc_args += [ "-l" + libarg] ;
523
522
}
524
- auto libarg = unlib( sess. get_targ_cfg( ) , fs:: basename( cratepath) ) ;
525
- gcc_args += [ "-l" + libarg] ;
526
- }
527
523
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
- }
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] ;
528
+ }
533
529
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
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
541
537
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
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
549
545
550
- if ( sess. get_targ_cfg( ) . os == session:: os_macos) {
551
- run:: run_program( "dsymutil" , [ saved_out_filename] ) ;
552
- }
546
+ if ( sess. get_targ_cfg( ) . os == session:: os_macos) {
547
+ run:: run_program( "dsymutil" , [ saved_out_filename] ) ;
548
+ }
553
549
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" ] ) ;
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
+ }
557
554
}
558
555
}
559
556
// Local Variables:
0 commit comments