@@ -561,12 +561,12 @@ fn mangle_internal_name_by_seq(ccx: @crate_ctxt, flav: str) -> str {
561561}
562562
563563// 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
565565fn link_binary ( sess : session ,
566566 obj_filename : str ,
567567 out_filename : str ,
568568 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
570570 fn unlib ( config : @session:: config , filename : str ) -> str unsafe {
571571 let rmlib = fn @( filename: str ) -> str {
572572 if config. os == session:: os_macos ||
@@ -610,12 +610,15 @@ fn link_binary(sess: session,
610610
611611 // In the future, FreeBSD will use clang as default compiler.
612612 // 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 +
619622 [ "-o" , output, obj_filename] ;
620623
621624 let lib_cmd;
@@ -627,47 +630,47 @@ fn link_binary(sess: session,
627630 let cstore = sess. cstore ;
628631 for cratepath: str in cstore:: get_used_crate_files ( cstore) {
629632 if str:: ends_with ( cratepath, ".rlib" ) {
630- gcc_args += [ cratepath] ;
633+ cc_args += [ cratepath] ;
631634 cont;
632635 }
633636 let cratepath = cratepath;
634637 let dir = fs:: dirname ( cratepath) ;
635- if dir != "" { gcc_args += [ "-L" + dir] ; }
638+ if dir != "" { cc_args += [ "-L" + dir] ; }
636639 let libarg = unlib ( sess. targ_cfg , fs:: basename ( cratepath) ) ;
637- gcc_args += [ "-l" + libarg] ;
640+ cc_args += [ "-l" + libarg] ;
638641 }
639642
640643 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] ; }
642645
643646 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] ; }
645648
646649 if sess. building_library {
647- gcc_args += [ lib_cmd] ;
650+ cc_args += [ lib_cmd] ;
648651
649652 // On mac we need to tell the linker to let this library
650653 // be rpathed
651654 if sess. targ_cfg . os == session:: os_macos {
652- gcc_args += [ "-Wl,-install_name,@rpath/"
655+ cc_args += [ "-Wl,-install_name,@rpath/"
653656 + fs:: basename ( output) ] ;
654657 }
655658 } else {
656659 // FIXME: why do we hardcode -lm?
657- gcc_args += [ "-lm" ] ;
660+ cc_args += [ "-lm" ] ;
658661 }
659662
660663 // Always want the runtime linked in
661- gcc_args += [ "-lrustrt" ] ;
664+ cc_args += [ "-lrustrt" ] ;
662665
663666 // On linux librt and libdl are an indirect dependencies via rustrt,
664667 // and binutils 2.22+ won't add them automatically
665668 if sess. targ_cfg . os == session:: os_linux {
666- gcc_args += [ "-lrt" , "-ldl" ] ;
669+ cc_args += [ "-lrt" , "-ldl" ] ;
667670 }
668671
669672 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" ,
671674 "-L/usr/local/lib/gcc46" ,
672675 "-L/usr/local/lib/gcc44" , "-lstdc++" ,
673676 "-Wl,-z,origin" ,
@@ -680,20 +683,22 @@ fn link_binary(sess: session,
680683 // understand how to unwind our __morestack frame, so we have to turn it
681684 // off. This has impacted some other projects like GHC.
682685 if sess. targ_cfg . os == session:: os_macos {
683- gcc_args += [ "-Wl,-no_compact_unwind" ] ;
686+ cc_args += [ "-Wl,-no_compact_unwind" ] ;
684687 }
685688
686689 // Stack growth requires statically linking a __morestack function
687- gcc_args += [ "-lmorestack" ] ;
690+ cc_args += [ "-lmorestack" ] ;
688691
689- gcc_args += rpath:: get_rpath_flags ( sess, output) ;
692+ cc_args += rpath:: get_rpath_flags ( sess, output) ;
690693
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 ) ;
694697 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, " " ) ] ) ;
697702 sess. note ( prog. err + prog. out ) ;
698703 sess. abort_if_errors ( ) ;
699704 }
0 commit comments