@@ -393,24 +393,33 @@ pub fn phase_6_link_output(sess: Session,
393393 & outputs. out_filename ,
394394 & trans. link ) ) ;
395395
396- // Write out dependency rules to the .d file if requested
397- if sess. opts . write_dependency_info {
398- match * input {
396+ // Write out dependency rules to the dep-info file if requested with --dep-info
397+ let deps_filename = match sess. opts . write_dependency_info {
398+ // Use filename from --dep-file argument if given
399+ ( true , Some ( ref filename) ) => filename. clone ( ) ,
400+ // Use default filename: crate source filename with extension replaced by ".d"
401+ ( true , None ) => match * input {
399402 file_input( ref input_path) => {
400- let files: ~[ @str ] = sess. codemap . files . iter ( )
401- . filter_map ( |fmap| if fmap. is_real_file ( ) { Some ( fmap. name ) } else { None } )
402- . collect ( ) ;
403- let mut output_path = outputs[ 0 ] . dir_path ( ) ;
404403 let filestem = input_path. filestem ( ) . expect ( "input file must have stem" ) ;
405- output_path. push ( Path :: new ( filestem) . with_extension ( "d" ) ) ;
406- let mut file = io:: File :: create ( & output_path) ;
407- for output in outputs. iter ( ) {
408- write ! ( & mut file as & mut Writer ,
409- "{}: {}\n \n " , output. display( ) , files. connect( " " ) ) ;
410- }
411- }
412- str_input( _) => { }
413- }
404+ let filename = outputs[ 0 ] . dir_path ( ) . join ( filestem) . with_extension ( "d" ) ;
405+ filename
406+ } ,
407+ str_input( ..) => {
408+ sess. warn ( "can not write --dep-info without a filename when compiling stdin." ) ;
409+ return ;
410+ } ,
411+ } ,
412+ _ => return ,
413+ } ;
414+ // Build a list of files used to compile the output and
415+ // write Makefile-compatible dependency rules
416+ let files: ~[ @str ] = sess. codemap . files . iter ( )
417+ . filter_map ( |fmap| if fmap. is_real_file ( ) { Some ( fmap. name ) } else { None } )
418+ . collect ( ) ;
419+ let mut file = io:: File :: create ( & deps_filename) ;
420+ for output in outputs. iter ( ) {
421+ write ! ( & mut file as & mut Writer ,
422+ "{}: {}\n \n " , output. display( ) , files. connect( " " ) ) ;
414423 }
415424}
416425
@@ -771,7 +780,8 @@ pub fn build_session_options(binary: @str,
771780 let cfg = parse_cfgspecs ( matches. opt_strs ( "cfg" ) , demitter) ;
772781 let test = matches. opt_present ( "test" ) ;
773782 let android_cross_path = matches. opt_str ( "android-cross-path" ) ;
774- let write_dependency_info = matches. opt_present ( "dep-info" ) ;
783+ let write_dependency_info = ( matches. opt_present ( "dep-info" ) ,
784+ matches. opt_str ( "dep-info" ) . map ( |p| Path :: new ( p) ) ) ;
775785
776786 let custom_passes = match matches. opt_str ( "passes" ) {
777787 None => ~[ ] ,
@@ -933,8 +943,8 @@ pub fn optgroups() -> ~[getopts::groups::OptGroup] {
933943 or identified (fully parenthesized,
934944 AST nodes and blocks with IDs)" , "TYPE" ) ,
935945 optflag ( "S" , "" , "Compile only; do not assemble or link" ) ,
936- optflag ( "" , "dep-info" ,
937- "Output dependency info to .d file after compiling" ) ,
946+ optflagopt ( "" , "dep-info" ,
947+ "Output dependency info to <filename> after compiling" , "FILENAME ") ,
938948 optflag ( "" , "save-temps" ,
939949 "Write intermediate files (.bc, .opt.bc, .o)
940950 in addition to normal output" ) ,
0 commit comments