@@ -561,12 +561,12 @@ fn mangle_internal_name_by_seq(ccx: @crate_ctxt, flav: str) -> str {
561
561
}
562
562
563
563
// If the user wants an exe generated we need to invoke
564
- // gcc to link the object file with some libs
564
+ // cc to link the object file with some libs
565
565
fn link_binary ( sess : session ,
566
566
obj_filename : str ,
567
567
out_filename : str ,
568
568
lm : link_meta ) {
569
- // Converts a library file name into a gcc -l argument
569
+ // Converts a library file name into a cc -l argument
570
570
fn unlib ( config : @session:: config , filename : str ) -> str unsafe {
571
571
let rmlib = fn @( filename: str ) -> str {
572
572
if config. os == session:: os_macos ||
@@ -610,12 +610,15 @@ fn link_binary(sess: session,
610
610
611
611
// In the future, FreeBSD will use clang as default compiler.
612
612
// It would be flexible to use cc (system's default C compiler)
613
- // instead of hard-coded gcc
614
- let prog: str = "cc" ;
615
- // The invocations of gcc share some flags across platforms
616
-
617
- let gcc_args =
618
- [ stage] + sess. targ_cfg . target_strs . gcc_args +
613
+ // instead of hard-coded gcc.
614
+ // For win32, there is no cc command,
615
+ // so we add a condition to make it use gcc.
616
+ let cc_prog: str =
617
+ if sess. targ_cfg . os == session:: os_win32 { "gcc" } else { "cc" } ;
618
+ // The invocations of cc share some flags across platforms
619
+
620
+ let cc_args =
621
+ [ stage] + sess. targ_cfg . target_strs . cc_args +
619
622
[ "-o" , output, obj_filename] ;
620
623
621
624
let lib_cmd;
@@ -627,47 +630,47 @@ fn link_binary(sess: session,
627
630
let cstore = sess. cstore ;
628
631
for cratepath: str in cstore:: get_used_crate_files ( cstore) {
629
632
if str:: ends_with ( cratepath, ".rlib" ) {
630
- gcc_args += [ cratepath] ;
633
+ cc_args += [ cratepath] ;
631
634
cont;
632
635
}
633
636
let cratepath = cratepath;
634
637
let dir = fs:: dirname ( cratepath) ;
635
- if dir != "" { gcc_args += [ "-L" + dir] ; }
638
+ if dir != "" { cc_args += [ "-L" + dir] ; }
636
639
let libarg = unlib ( sess. targ_cfg , fs:: basename ( cratepath) ) ;
637
- gcc_args += [ "-l" + libarg] ;
640
+ cc_args += [ "-l" + libarg] ;
638
641
}
639
642
640
643
let ula = cstore:: get_used_link_args ( cstore) ;
641
- for arg: str in ula { gcc_args += [ arg] ; }
644
+ for arg: str in ula { cc_args += [ arg] ; }
642
645
643
646
let used_libs = cstore:: get_used_libraries ( cstore) ;
644
- for l: str in used_libs { gcc_args += [ "-l" + l] ; }
647
+ for l: str in used_libs { cc_args += [ "-l" + l] ; }
645
648
646
649
if sess. building_library {
647
- gcc_args += [ lib_cmd] ;
650
+ cc_args += [ lib_cmd] ;
648
651
649
652
// On mac we need to tell the linker to let this library
650
653
// be rpathed
651
654
if sess. targ_cfg . os == session:: os_macos {
652
- gcc_args += [ "-Wl,-install_name,@rpath/"
655
+ cc_args += [ "-Wl,-install_name,@rpath/"
653
656
+ fs:: basename ( output) ] ;
654
657
}
655
658
} else {
656
659
// FIXME: why do we hardcode -lm?
657
- gcc_args += [ "-lm" ] ;
660
+ cc_args += [ "-lm" ] ;
658
661
}
659
662
660
663
// Always want the runtime linked in
661
- gcc_args += [ "-lrustrt" ] ;
664
+ cc_args += [ "-lrustrt" ] ;
662
665
663
666
// On linux librt and libdl are an indirect dependencies via rustrt,
664
667
// and binutils 2.22+ won't add them automatically
665
668
if sess. targ_cfg . os == session:: os_linux {
666
- gcc_args += [ "-lrt" , "-ldl" ] ;
669
+ cc_args += [ "-lrt" , "-ldl" ] ;
667
670
}
668
671
669
672
if sess. targ_cfg . os == session:: os_freebsd {
670
- gcc_args += [ "-lrt" , "-L/usr/local/lib" , "-lexecinfo" ,
673
+ cc_args += [ "-lrt" , "-L/usr/local/lib" , "-lexecinfo" ,
671
674
"-L/usr/local/lib/gcc46" ,
672
675
"-L/usr/local/lib/gcc44" , "-lstdc++" ,
673
676
"-Wl,-z,origin" ,
@@ -680,20 +683,22 @@ fn link_binary(sess: session,
680
683
// understand how to unwind our __morestack frame, so we have to turn it
681
684
// off. This has impacted some other projects like GHC.
682
685
if sess. targ_cfg . os == session:: os_macos {
683
- gcc_args += [ "-Wl,-no_compact_unwind" ] ;
686
+ cc_args += [ "-Wl,-no_compact_unwind" ] ;
684
687
}
685
688
686
689
// Stack growth requires statically linking a __morestack function
687
- gcc_args += [ "-lmorestack" ] ;
690
+ cc_args += [ "-lmorestack" ] ;
688
691
689
- gcc_args += rpath:: get_rpath_flags ( sess, output) ;
692
+ cc_args += rpath:: get_rpath_flags ( sess, output) ;
690
693
691
- #debug ( "gcc link args: %s" , str:: connect ( gcc_args , " " ) ) ;
692
- // We run 'gcc ' here
693
- let prog = run:: program_output ( prog , gcc_args ) ;
694
+ #debug ( "%s link args: %s" , cc_prog , str:: connect ( cc_args , " " ) ) ;
695
+ // We run 'cc ' here
696
+ let prog = run:: program_output ( cc_prog , cc_args ) ;
694
697
if 0 != prog. status {
695
- sess. err ( #fmt[ "linking with gcc failed with code %d" , prog. status ] ) ;
696
- sess. note ( #fmt[ "gcc arguments: %s" , str:: connect ( gcc_args, " " ) ] ) ;
698
+ sess. err ( #fmt[ "linking with %s failed with code %d" ,
699
+ cc_prog, prog. status ] ) ;
700
+ sess. note ( #fmt[ "%s arguments: %s" ,
701
+ cc_prog, str:: connect ( cc_args, " " ) ] ) ;
697
702
sess. note ( prog. err + prog. out ) ;
698
703
sess. abort_if_errors ( ) ;
699
704
}
0 commit comments